james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [09/15] james-project git commit: JAMES-2090 All classes in data-cassandra should match our coding standard
Date Thu, 06 Jul 2017 12:13:15 GMT
JAMES-2090 All classes in data-cassandra should match our coding standard

Async, CassandraUtils (for prefetch), preparedStatements


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/366023f4
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/366023f4
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/366023f4

Branch: refs/heads/master
Commit: 366023f4247216c2db15be5863d9b32dccf38cee
Parents: 0b7b208
Author: benwa <btellier@linagora.com>
Authored: Wed Jul 5 13:41:39 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Thu Jul 6 08:48:54 2017 +0700

----------------------------------------------------------------------
 .../cassandra/CassandraDomainList.java          |  81 +++++++++----
 .../CassandraRecipientRewriteTable.java         | 105 ++++++++++++-----
 .../cassandra/CassandraUsersRepository.java     | 116 +++++++++++++------
 .../CassandraUsersRepositoryModule.java         |   3 +-
 .../CassandraRecipientRewriteTableTest.java     |   4 +-
 .../james/rrt/cassandra/CassandraStepdefs.java  |   4 +-
 6 files changed, 214 insertions(+), 99 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/366023f4/server/data/data-cassandra/src/main/java/org/apache/james/domainlist/cassandra/CassandraDomainList.java
----------------------------------------------------------------------
diff --git a/server/data/data-cassandra/src/main/java/org/apache/james/domainlist/cassandra/CassandraDomainList.java
b/server/data/data-cassandra/src/main/java/org/apache/james/domainlist/cassandra/CassandraDomainList.java
index fbee908..c49956c 100644
--- a/server/data/data-cassandra/src/main/java/org/apache/james/domainlist/cassandra/CassandraDomainList.java
+++ b/server/data/data-cassandra/src/main/java/org/apache/james/domainlist/cassandra/CassandraDomainList.java
@@ -19,6 +19,10 @@
 
 package org.apache.james.domainlist.cassandra;
 
+import static org.apache.james.domainlist.cassandra.tables.CassandraDomainsTable.TABLE_NAME;
+import static org.apache.james.domainlist.cassandra.tables.CassandraDomainsTable.DOMAIN;
+
+import static com.datastax.driver.core.querybuilder.QueryBuilder.bindMarker;
 import static com.datastax.driver.core.querybuilder.QueryBuilder.delete;
 import static com.datastax.driver.core.querybuilder.QueryBuilder.eq;
 import static com.datastax.driver.core.querybuilder.QueryBuilder.insertInto;
@@ -26,29 +30,59 @@ import static com.datastax.driver.core.querybuilder.QueryBuilder.select;
 
 import java.util.List;
 import java.util.Locale;
-import java.util.stream.Collectors;
 
 import javax.inject.Inject;
 
-import org.apache.james.backends.cassandra.utils.CassandraConstants;
+import org.apache.james.backends.cassandra.utils.CassandraAsyncExecutor;
 import org.apache.james.backends.cassandra.utils.CassandraUtils;
 import org.apache.james.domainlist.api.DomainListException;
 import org.apache.james.domainlist.lib.AbstractDomainList;
-import org.apache.james.domainlist.cassandra.tables.CassandraDomainsTable;
 
-import com.datastax.driver.core.ResultSet;
+import com.datastax.driver.core.PreparedStatement;
 import com.datastax.driver.core.Session;
+import com.github.steveash.guavate.Guavate;
 import com.google.common.annotations.VisibleForTesting;
 
 public class CassandraDomainList extends AbstractDomainList {
-
-    private final Session session;
+    private final CassandraAsyncExecutor executor;
     private final CassandraUtils cassandraUtils;
+    private final PreparedStatement readAllStatement;
+    private final PreparedStatement readStatement;
+    private final PreparedStatement insertStatement;
+    private final PreparedStatement removeStatement;
 
     @Inject
     public CassandraDomainList(Session session, CassandraUtils cassandraUtils) {
-        this.session = session;
+        this.executor = new CassandraAsyncExecutor(session);
         this.cassandraUtils = cassandraUtils;
+        this.readAllStatement = prepareReadAllStatement(session);
+        this.readStatement = prepareReadStatement(session);
+        this.insertStatement = prepareInsertStatement(session);
+        this.removeStatement = prepareRemoveStatement(session);
+    }
+
+    private PreparedStatement prepareRemoveStatement(Session session) {
+        return session.prepare(delete()
+            .from(TABLE_NAME)
+            .ifExists()
+            .where(eq(DOMAIN, bindMarker(DOMAIN))));
+    }
+
+    private PreparedStatement prepareInsertStatement(Session session) {
+        return session.prepare(insertInto(TABLE_NAME)
+            .ifNotExists()
+            .value(DOMAIN, bindMarker(DOMAIN)));
+    }
+
+    private PreparedStatement prepareReadStatement(Session session) {
+        return session.prepare(select(DOMAIN)
+            .from(TABLE_NAME)
+            .where(eq(DOMAIN, bindMarker(DOMAIN))));
+    }
+
+    private PreparedStatement prepareReadAllStatement(Session session) {
+        return session.prepare(select(DOMAIN)
+            .from(TABLE_NAME));
     }
 
     @VisibleForTesting
@@ -58,26 +92,26 @@ public class CassandraDomainList extends AbstractDomainList {
 
     @Override
     protected List<String> getDomainListInternal() throws DomainListException {
-        return cassandraUtils.convertToStream(session.execute(select(CassandraDomainsTable.DOMAIN).from(CassandraDomainsTable.TABLE_NAME)))
-            .map(row -> row.getString(CassandraDomainsTable.DOMAIN))
-            .collect(Collectors.toList());
+        return executor.execute(readAllStatement.bind())
+            .thenApply(resultSet -> cassandraUtils.convertToStream(resultSet)
+                .map(row -> row.getString(DOMAIN))
+                .collect(Guavate.toImmutableList()))
+            .join();
     }
 
     @Override
     public boolean containsDomain(String domain) throws DomainListException {
-        return session.execute(select(CassandraDomainsTable.DOMAIN)
-            .from(CassandraDomainsTable.TABLE_NAME)
-            .where(eq(CassandraDomainsTable.DOMAIN, domain.toLowerCase(Locale.US))))
-            .one() != null;
+        return executor.executeSingleRow(readStatement.bind()
+                .setString(DOMAIN, domain.toLowerCase(Locale.US)))
+            .join()
+            .isPresent();
     }
 
     @Override
     public void addDomain(String domain) throws DomainListException {
-        boolean executed = session.execute(insertInto(CassandraDomainsTable.TABLE_NAME)
-            .ifNotExists()
-            .value(CassandraDomainsTable.DOMAIN, domain.toLowerCase(Locale.US)))
-            .one()
-            .getBool(CassandraConstants.LIGHTWEIGHT_TRANSACTION_APPLIED);
+        boolean executed = executor.executeReturnApplied(insertStatement.bind()
+            .setString(DOMAIN, domain.toLowerCase(Locale.US)))
+            .join();
         if (!executed) {
             throw new DomainListException(domain.toLowerCase(Locale.US) + " already exists.");
         }
@@ -85,11 +119,10 @@ public class CassandraDomainList extends AbstractDomainList {
 
     @Override
     public void removeDomain(String domain) throws DomainListException {
-        ResultSet resultSet = session.execute(delete()
-            .from(CassandraDomainsTable.TABLE_NAME)
-            .ifExists()
-            .where(eq(CassandraDomainsTable.DOMAIN, domain.toLowerCase(Locale.US))));
-        if (!resultSet.one().getBool(CassandraConstants.LIGHTWEIGHT_TRANSACTION_APPLIED))
{
+        boolean executed = executor.executeReturnApplied(removeStatement.bind()
+            .setString(DOMAIN, domain.toLowerCase(Locale.US)))
+            .join();
+        if (!executed) {
             throw new DomainListException(domain + " was not found");
         }
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/366023f4/server/data/data-cassandra/src/main/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTable.java
----------------------------------------------------------------------
diff --git a/server/data/data-cassandra/src/main/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTable.java
b/server/data/data-cassandra/src/main/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTable.java
index ad9ba4b..86e2b4d 100644
--- a/server/data/data-cassandra/src/main/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTable.java
+++ b/server/data/data-cassandra/src/main/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTable.java
@@ -18,6 +18,7 @@
  ****************************************************************/
 package org.apache.james.rrt.cassandra;
 
+import static com.datastax.driver.core.querybuilder.QueryBuilder.bindMarker;
 import static com.datastax.driver.core.querybuilder.QueryBuilder.delete;
 import static com.datastax.driver.core.querybuilder.QueryBuilder.eq;
 import static com.datastax.driver.core.querybuilder.QueryBuilder.insertInto;
@@ -29,44 +30,83 @@ import static org.apache.james.rrt.cassandra.tables.CassandraRecipientRewriteTab
 
 import java.util.List;
 import java.util.Map;
-import java.util.stream.Collectors;
 
-import javax.annotation.Resource;
 import javax.inject.Inject;
 
+import org.apache.james.backends.cassandra.utils.CassandraAsyncExecutor;
+import org.apache.james.backends.cassandra.utils.CassandraUtils;
 import org.apache.james.rrt.api.RecipientRewriteTableException;
 import org.apache.james.rrt.lib.AbstractRecipientRewriteTable;
 import org.apache.james.rrt.lib.Mappings;
 import org.apache.james.rrt.lib.MappingsImpl;
 
+import com.datastax.driver.core.PreparedStatement;
 import com.datastax.driver.core.Session;
+import com.github.steveash.guavate.Guavate;
 import com.google.common.base.Optional;
 
 public class CassandraRecipientRewriteTable extends AbstractRecipientRewriteTable {
 
-    private Session session;
+    private final CassandraAsyncExecutor executor;
+    private final CassandraUtils cassandraUtils;
+    private final PreparedStatement insertStatement;
+    private final PreparedStatement deleteStatement;
+    private final PreparedStatement retrieveMappingStatement;
+    private final PreparedStatement retrieveAllMappingsStatement;
 
     @Inject
-    @Resource
-    public void setSession(Session session) {
-        this.session = session;
+    public CassandraRecipientRewriteTable(Session session, CassandraUtils cassandraUtils)
{
+        this.executor = new CassandraAsyncExecutor(session);
+        this.cassandraUtils = cassandraUtils;
+        this.insertStatement = prepareInsertStatement(session);
+        this.deleteStatement = prepareDelete(session);
+        this.retrieveMappingStatement = prepareRetrieveMappingStatement(session);
+        this.retrieveAllMappingsStatement = prepareRetrieveAllMappingStatement(session);
+    }
+
+    private PreparedStatement prepareRetrieveAllMappingStatement(Session session) {
+        return session.prepare(select(USER, DOMAIN, MAPPING)
+            .from(TABLE_NAME));
+    }
+
+    private PreparedStatement prepareRetrieveMappingStatement(Session session) {
+        return session.prepare(select(MAPPING)
+            .from(TABLE_NAME)
+            .where(eq(USER, bindMarker(USER)))
+            .and(eq(DOMAIN, bindMarker(DOMAIN))));
+    }
+
+    private PreparedStatement prepareDelete(Session session) {
+        return session.prepare(delete()
+            .from(TABLE_NAME)
+            .where(eq(USER, bindMarker(USER)))
+            .and(eq(DOMAIN, bindMarker(DOMAIN)))
+            .and(eq(MAPPING, bindMarker(MAPPING))));
+    }
+
+    private PreparedStatement prepareInsertStatement(Session session) {
+        return session.prepare(insertInto(TABLE_NAME)
+            .value(USER, bindMarker(USER))
+            .value(DOMAIN, bindMarker(DOMAIN))
+            .value(MAPPING, bindMarker(MAPPING)));
     }
 
     @Override
     protected void addMappingInternal(String user, String domain, String mapping) throws
RecipientRewriteTableException {
-        session.execute(insertInto(TABLE_NAME)
-            .value(USER, getFixedUser(user))
-            .value(DOMAIN, getFixedDomain(domain))
-            .value(MAPPING, mapping));
+        executor.executeVoid(insertStatement.bind()
+            .setString(USER, getFixedUser(user))
+            .setString(DOMAIN, getFixedDomain(domain))
+            .setString(MAPPING, mapping))
+            .join();
     }
 
     @Override
     protected void removeMappingInternal(String user, String domain, String mapping) throws
RecipientRewriteTableException {
-        session.execute(delete()
-            .from(TABLE_NAME)
-            .where(eq(USER, getFixedUser(user)))
-            .and(eq(DOMAIN, getFixedDomain(domain)))
-            .and(eq(MAPPING, mapping)));
+        executor.executeVoid(deleteStatement.bind()
+                .setString(USER, getFixedUser(user))
+                .setString(DOMAIN, getFixedDomain(domain))
+                .setString(MAPPING, mapping))
+            .join();
     }
 
     @Override
@@ -76,28 +116,27 @@ public class CassandraRecipientRewriteTable extends AbstractRecipientRewriteTabl
     }
 
     private Optional<Mappings> retrieveMappings(String user, String domain) {
-        List<String> mappings = session.execute(select(MAPPING)
-                .from(TABLE_NAME)
-                .where(eq(USER, getFixedUser(user)))
-                .and(eq(DOMAIN, getFixedDomain(domain))))
-            .all()
-            .stream()
-            .map(row -> row.getString(MAPPING))
-            .collect(Collectors.toList());
+        List<String> mappings = executor.execute(retrieveMappingStatement.bind()
+            .setString(USER, getFixedUser(user))
+            .setString(DOMAIN, getFixedDomain(domain)))
+            .thenApply(resultSet -> cassandraUtils.convertToStream(resultSet)
+                .map(row -> row.getString(MAPPING))
+                .collect(Guavate.toImmutableList()))
+            .join();
 
         return MappingsImpl.fromCollection(mappings).toOptional();
     }
 
     @Override
     protected Map<String, Mappings> getAllMappingsInternal() throws RecipientRewriteTableException
{
-        Map<String, Mappings> map = session.execute(select(USER, DOMAIN, MAPPING)
-            .from(TABLE_NAME))
-            .all()
-            .stream()
-            .map(row -> new UserMapping(row.getString(USER), row.getString(DOMAIN), row.getString(MAPPING)))
-            .collect(Collectors.toMap(UserMapping::asKey, 
-                    userMapping -> MappingsImpl.fromRawString(userMapping.getMapping()),
-                    (first, second) -> first.union(second)));
+        Map<String, Mappings> map = executor.execute(retrieveAllMappingsStatement.bind())
+            .thenApply(resultSet -> cassandraUtils.convertToStream(resultSet)
+                .map(row -> new UserMapping(row.getString(USER), row.getString(DOMAIN),
row.getString(MAPPING)))
+                .collect(Guavate.toImmutableMap(
+                    UserMapping::asKey,
+                    UserMapping::toMapping,
+                    Mappings::union)))
+            .join();
         return map.isEmpty() ? null : map;
     }
 
@@ -125,6 +164,10 @@ public class CassandraRecipientRewriteTable extends AbstractRecipientRewriteTabl
             return mapping;
         }
 
+        public Mappings toMapping() {
+            return MappingsImpl.fromRawString(getMapping());
+        }
+
         public String asKey() {
             return getUser() + "@" + getDomain();
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/366023f4/server/data/data-cassandra/src/main/java/org/apache/james/user/cassandra/CassandraUsersRepository.java
----------------------------------------------------------------------
diff --git a/server/data/data-cassandra/src/main/java/org/apache/james/user/cassandra/CassandraUsersRepository.java
b/server/data/data-cassandra/src/main/java/org/apache/james/user/cassandra/CassandraUsersRepository.java
index f7b9251..028accb 100644
--- a/server/data/data-cassandra/src/main/java/org/apache/james/user/cassandra/CassandraUsersRepository.java
+++ b/server/data/data-cassandra/src/main/java/org/apache/james/user/cassandra/CassandraUsersRepository.java
@@ -19,6 +19,7 @@
 
 package org.apache.james.user.cassandra;
 
+import static com.datastax.driver.core.querybuilder.QueryBuilder.bindMarker;
 import static com.datastax.driver.core.querybuilder.QueryBuilder.delete;
 import static com.datastax.driver.core.querybuilder.QueryBuilder.eq;
 import static com.datastax.driver.core.querybuilder.QueryBuilder.insertInto;
@@ -35,10 +36,9 @@ import java.util.Iterator;
 import java.util.Locale;
 import java.util.Optional;
 
-import javax.annotation.Resource;
 import javax.inject.Inject;
 
-import org.apache.james.backends.cassandra.utils.CassandraConstants;
+import org.apache.james.backends.cassandra.utils.CassandraAsyncExecutor;
 import org.apache.james.backends.cassandra.utils.CassandraUtils;
 import org.apache.james.user.api.AlreadyExistInUsersRepositoryException;
 import org.apache.james.user.api.UsersRepositoryException;
@@ -46,6 +46,7 @@ import org.apache.james.user.api.model.User;
 import org.apache.james.user.lib.AbstractUsersRepository;
 import org.apache.james.user.lib.model.DefaultUser;
 
+import com.datastax.driver.core.PreparedStatement;
 import com.datastax.driver.core.ResultSet;
 import com.datastax.driver.core.Session;
 import com.google.common.base.Preconditions;
@@ -55,21 +56,68 @@ public class CassandraUsersRepository extends AbstractUsersRepository
{
 
     private static final String DEFAULT_ALGO_VALUE = "SHA1";
 
-    private final Session session;
+    private final CassandraAsyncExecutor executor;
     private final CassandraUtils cassandraUtils;
+    private final PreparedStatement getUserStatement;
+    private final PreparedStatement updateUserStatement;
+    private final PreparedStatement removeUserStatement;
+    private final PreparedStatement countUserStatement;
+    private final PreparedStatement listStatement;
+    private final PreparedStatement insertStatement;
 
     @Inject
     public CassandraUsersRepository(Session session, CassandraUtils cassandraUtils) {
-        this.session = session;
+        this.executor = new CassandraAsyncExecutor(session);
         this.cassandraUtils = cassandraUtils;
+        this.getUserStatement = prepareGetUserStatement(session);
+        this.updateUserStatement = prepareUpdateUserStatement(session);
+        this.removeUserStatement = prepareRemoveUserStatement(session);
+        this.countUserStatement = prepareCountStatement(session);
+        this.listStatement = prepareListStatement(session);
+        this.insertStatement = session.prepare(insertInto(TABLE_NAME)
+            .value(NAME, bindMarker(NAME))
+            .value(REALNAME, bindMarker(REALNAME))
+            .value(PASSWORD, bindMarker(PASSWORD))
+            .value(ALGORITHM, bindMarker(ALGORITHM))
+            .ifNotExists());
     }
-    
+
+    private PreparedStatement prepareListStatement(Session session) {
+        return session.prepare(select(REALNAME)
+            .from(TABLE_NAME));
+    }
+
+    private PreparedStatement prepareCountStatement(Session session) {
+        return session.prepare(select().countAll().from(TABLE_NAME));
+    }
+
+    private PreparedStatement prepareRemoveUserStatement(Session session) {
+        return session.prepare( delete()
+            .from(TABLE_NAME)
+            .where(eq(NAME, bindMarker(NAME)))
+            .ifExists());
+    }
+
+    private PreparedStatement prepareUpdateUserStatement(Session session) {
+        return session.prepare(update(TABLE_NAME)
+            .with(set(REALNAME, bindMarker(REALNAME)))
+            .and(set(PASSWORD, bindMarker(PASSWORD)))
+            .and(set(ALGORITHM, bindMarker(ALGORITHM)))
+            .where(eq(NAME, bindMarker(NAME)))
+            .ifExists());
+    }
+
+    private PreparedStatement prepareGetUserStatement(Session session) {
+        return session.prepare(select(REALNAME, PASSWORD, ALGORITHM)
+            .from(TABLE_NAME)
+            .where(eq(NAME, bindMarker(NAME))));
+    }
+
     @Override
     public User getUserByName(String name){
-        ResultSet result = session.execute(
-                select(REALNAME, PASSWORD, ALGORITHM)
-                .from(TABLE_NAME)
-                .where(eq(NAME, name.toLowerCase(Locale.US))));
+        ResultSet result = executor.execute(getUserStatement.bind()
+            .setString(NAME, name.toLowerCase(Locale.US)))
+            .join();
         return Optional.ofNullable(result.one())
             .map(row -> new DefaultUser(row.getString(REALNAME), row.getString(PASSWORD),
row.getString(ALGORITHM)))
             .filter(user -> user.getUserName().equals(name))
@@ -80,15 +128,13 @@ public class CassandraUsersRepository extends AbstractUsersRepository
{
     public void updateUser(User user) throws UsersRepositoryException {
         Preconditions.checkArgument(user instanceof DefaultUser);
         DefaultUser defaultUser = (DefaultUser) user;
-        boolean executed = session.execute(
-                update(TABLE_NAME)
-                    .with(set(REALNAME, defaultUser.getUserName()))
-                    .and(set(PASSWORD, defaultUser.getHashedPassword()))
-                    .and(set(ALGORITHM, defaultUser.getHashAlgorithm()))
-                    .where(eq(NAME, defaultUser.getUserName().toLowerCase(Locale.US)))
-                    .ifExists())
-                .one()
-                .getBool(CassandraConstants.LIGHTWEIGHT_TRANSACTION_APPLIED);
+        boolean executed = executor.executeReturnApplied(
+                updateUserStatement.bind()
+                    .setString(REALNAME, defaultUser.getUserName())
+                    .setString(PASSWORD, defaultUser.getHashedPassword())
+                    .setString(ALGORITHM, defaultUser.getHashAlgorithm())
+                    .setString(NAME, defaultUser.getUserName().toLowerCase(Locale.US)))
+            .join();
 
         if (!executed) {
             throw new UsersRepositoryException("Unable to update user");
@@ -97,13 +143,10 @@ public class CassandraUsersRepository extends AbstractUsersRepository
{
 
     @Override
     public void removeUser(String name) throws UsersRepositoryException {
-        boolean executed = session.execute(
-            delete()
-                .from(TABLE_NAME)
-                .where(eq(NAME, name))
-                .ifExists())
-            .one()
-            .getBool(CassandraConstants.LIGHTWEIGHT_TRANSACTION_APPLIED);
+        boolean executed = executor.executeReturnApplied(
+            removeUserStatement.bind()
+                .setString(NAME, name))
+            .join();
 
         if (!executed) {
             throw new UsersRepositoryException("unable to remove unknown user " + name);
@@ -124,15 +167,14 @@ public class CassandraUsersRepository extends AbstractUsersRepository
{
 
     @Override
     public int countUsers() throws UsersRepositoryException {
-        ResultSet result = session.execute(select().countAll().from(TABLE_NAME));
+        ResultSet result = executor.execute(countUserStatement.bind()).join();
         return Ints.checkedCast(result.one().getLong(0));
     }
 
     @Override
     public Iterator<String> list() throws UsersRepositoryException {
-        ResultSet result = session.execute(
-                select(REALNAME)
-                .from(TABLE_NAME));
+        ResultSet result = executor.execute(listStatement.bind())
+            .join();
         return cassandraUtils.convertToStream(result)
             .map(row -> row.getString(REALNAME))
             .iterator();
@@ -148,15 +190,13 @@ public class CassandraUsersRepository extends AbstractUsersRepository
{
     protected void doAddUser(String username, String password) throws UsersRepositoryException
{
         DefaultUser user = new DefaultUser(username, DEFAULT_ALGO_VALUE);
         user.setPassword(password);
-        boolean executed = session.execute(
-            insertInto(TABLE_NAME)
-                .value(NAME, user.getUserName().toLowerCase(Locale.US))
-                .value(REALNAME, user.getUserName())
-                .value(PASSWORD, user.getHashedPassword())
-                .value(ALGORITHM, user.getHashAlgorithm())
-                .ifNotExists())
-            .one()
-            .getBool(CassandraConstants.LIGHTWEIGHT_TRANSACTION_APPLIED);
+        boolean executed = executor.executeReturnApplied(
+            insertStatement.bind()
+                .setString(NAME, user.getUserName().toLowerCase(Locale.US))
+                .setString(REALNAME, user.getUserName())
+                .setString(PASSWORD, user.getHashedPassword())
+                .setString(ALGORITHM, user.getHashAlgorithm()))
+            .join();
 
         if (!executed) {
             throw new AlreadyExistInUsersRepositoryException("User with username " + username
+ " already exist!");

http://git-wip-us.apache.org/repos/asf/james-project/blob/366023f4/server/data/data-cassandra/src/main/java/org/apache/james/user/cassandra/CassandraUsersRepositoryModule.java
----------------------------------------------------------------------
diff --git a/server/data/data-cassandra/src/main/java/org/apache/james/user/cassandra/CassandraUsersRepositoryModule.java
b/server/data/data-cassandra/src/main/java/org/apache/james/user/cassandra/CassandraUsersRepositoryModule.java
index 74a3469..db7a337 100644
--- a/server/data/data-cassandra/src/main/java/org/apache/james/user/cassandra/CassandraUsersRepositoryModule.java
+++ b/server/data/data-cassandra/src/main/java/org/apache/james/user/cassandra/CassandraUsersRepositoryModule.java
@@ -44,8 +44,7 @@ public class CassandraUsersRepositoryModule implements CassandraModule {
                         .addPartitionKey(CassandraUserTable.NAME, text())
                         .addColumn(CassandraUserTable.REALNAME, text())
                         .addColumn(CassandraUserTable.PASSWORD, text())
-                        .addColumn(CassandraUserTable.ALGORITHM, text()))
-                    );
+                        .addColumn(CassandraUserTable.ALGORITHM, text())));
         types = ImmutableList.of();
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/366023f4/server/data/data-cassandra/src/test/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTableTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-cassandra/src/test/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTableTest.java
b/server/data/data-cassandra/src/test/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTableTest.java
index 60068e5..525eb2a 100644
--- a/server/data/data-cassandra/src/test/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTableTest.java
+++ b/server/data/data-cassandra/src/test/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTableTest.java
@@ -20,6 +20,7 @@ package org.apache.james.rrt.cassandra;
 
 import org.apache.commons.configuration.DefaultConfigurationBuilder;
 import org.apache.james.backends.cassandra.CassandraCluster;
+import org.apache.james.backends.cassandra.utils.CassandraUtils;
 import org.apache.james.rrt.api.RecipientRewriteTableException;
 import org.apache.james.rrt.lib.AbstractRecipientRewriteTable;
 import org.apache.james.rrt.lib.AbstractRecipientRewriteTableTest;
@@ -50,8 +51,7 @@ public class CassandraRecipientRewriteTableTest extends AbstractRecipientRewrite
 
     @Override
     protected AbstractRecipientRewriteTable getRecipientRewriteTable() throws Exception {
-        CassandraRecipientRewriteTable rrt = new CassandraRecipientRewriteTable();
-        rrt.setSession(cassandra.getConf());
+        CassandraRecipientRewriteTable rrt = new CassandraRecipientRewriteTable(cassandra.getConf(),
CassandraUtils.DEFAULT_CASSANDRA_UTILS);
         rrt.setLog(LoggerFactory.getLogger("MockLog"));
         rrt.configure(new DefaultConfigurationBuilder());
         return rrt;

http://git-wip-us.apache.org/repos/asf/james-project/blob/366023f4/server/data/data-cassandra/src/test/java/org/apache/james/rrt/cassandra/CassandraStepdefs.java
----------------------------------------------------------------------
diff --git a/server/data/data-cassandra/src/test/java/org/apache/james/rrt/cassandra/CassandraStepdefs.java
b/server/data/data-cassandra/src/test/java/org/apache/james/rrt/cassandra/CassandraStepdefs.java
index 6f25a92..61dc4a8 100644
--- a/server/data/data-cassandra/src/test/java/org/apache/james/rrt/cassandra/CassandraStepdefs.java
+++ b/server/data/data-cassandra/src/test/java/org/apache/james/rrt/cassandra/CassandraStepdefs.java
@@ -20,6 +20,7 @@ package org.apache.james.rrt.cassandra;
 
 import org.apache.commons.configuration.DefaultConfigurationBuilder;
 import org.apache.james.backends.cassandra.CassandraCluster;
+import org.apache.james.backends.cassandra.utils.CassandraUtils;
 import org.apache.james.rrt.lib.AbstractRecipientRewriteTable;
 import org.apache.james.rrt.lib.RewriteTablesStepdefs;
 import org.slf4j.LoggerFactory;
@@ -51,8 +52,7 @@ public class CassandraStepdefs {
     }
 
     private AbstractRecipientRewriteTable getRecipientRewriteTable() throws Exception {
-        CassandraRecipientRewriteTable rrt = new CassandraRecipientRewriteTable();
-        rrt.setSession(cassandra.getConf());
+        CassandraRecipientRewriteTable rrt = new CassandraRecipientRewriteTable(cassandra.getConf(),
CassandraUtils.DEFAULT_CASSANDRA_UTILS);
         rrt.setLog(LoggerFactory.getLogger("MockLog"));
         rrt.configure(new DefaultConfigurationBuilder());
         return rrt;


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message