MAILBOX-342 Use CassandraModule.Builder for Cassandra mail repositories

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

Branch: refs/heads/master
Commit: b100add19d2adec8b5473e8396f0e1d320efc6c0
Parents: 3a92def
Author: benwa <btell...@linagora.com>
Authored: Tue Jul 24 14:58:38 2018 +0700
Committer: benwa <btell...@linagora.com>
Committed: Thu Jul 26 13:47:39 2018 +0700

----------------------------------------------------------------------
 .../data/CassandraMailRepositoryModule.java     |  2 +-
 .../CassandraMailRepositoryModule.java          | 99 ++++++++------------
 .../CassandraMailRepositoryCountDAOTest.java    |  3 +-
 .../CassandraMailRepositoryKeysDAOTest.java     |  2 +-
 .../CassandraMailRepositoryMailDAOTest.java     |  2 +-
 .../cassandra/CassandraMailRepositoryTest.java  |  8 +-
 6 files changed, 46 insertions(+), 70 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/b100add1/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/data/CassandraMailRepositoryModule.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/data/CassandraMailRepositoryModule.java
 
b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/data/CassandraMailRepositoryModule.java
index 695d0e8..2f3769b 100644
--- 
a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/data/CassandraMailRepositoryModule.java
+++ 
b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/data/CassandraMailRepositoryModule.java
@@ -51,7 +51,7 @@ public class CassandraMailRepositoryModule extends 
AbstractModule {
         multibinder.addBinding().to(CassandraMailRepositoryProvider.class);
 
         Multibinder<CassandraModule> cassandraModuleBinder = 
Multibinder.newSetBinder(binder(), CassandraModule.class);
-        
cassandraModuleBinder.addBinding().to(org.apache.james.mailrepository.cassandra.CassandraMailRepositoryModule.class);
+        
cassandraModuleBinder.addBinding().toInstance(org.apache.james.mailrepository.cassandra.CassandraMailRepositoryModule.MODULE);
         
cassandraModuleBinder.addBinding().toInstance(CassandraMailRepositoryUrlModule.MODULE);
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/b100add1/server/mailrepository/mailrepository-cassandra/src/main/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryModule.java
----------------------------------------------------------------------
diff --git 
a/server/mailrepository/mailrepository-cassandra/src/main/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryModule.java
 
b/server/mailrepository/mailrepository-cassandra/src/main/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryModule.java
index 4369db0..4d4ed3d 100644
--- 
a/server/mailrepository/mailrepository-cassandra/src/main/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryModule.java
+++ 
b/server/mailrepository/mailrepository-cassandra/src/main/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryModule.java
@@ -28,67 +28,44 @@ import static com.datastax.driver.core.DataType.text;
 import static com.datastax.driver.core.DataType.timestamp;
 import static com.datastax.driver.core.schemabuilder.SchemaBuilder.frozen;
 
-import java.util.List;
-
 import org.apache.james.backends.cassandra.components.CassandraModule;
-import org.apache.james.backends.cassandra.components.CassandraTable;
-import org.apache.james.backends.cassandra.components.CassandraType;
-
-import com.datastax.driver.core.schemabuilder.SchemaBuilder;
-import com.google.common.collect.ImmutableList;
-
-public class CassandraMailRepositoryModule implements CassandraModule {
-
-    private final List<CassandraTable> tables;
-    private final List<CassandraType> types;
-
-    public CassandraMailRepositoryModule() {
-        tables = ImmutableList.of(
-            new CassandraTable(MailRepositoryTable.COUNT_TABLE,
-                SchemaBuilder.createTable(MailRepositoryTable.COUNT_TABLE)
-                    .ifNotExists()
-                    .addPartitionKey(MailRepositoryTable.REPOSITORY_NAME, 
text())
-                    .addColumn(MailRepositoryTable.COUNT, counter())),
-            new CassandraTable(MailRepositoryTable.KEYS_TABLE_NAME,
-                SchemaBuilder.createTable(MailRepositoryTable.KEYS_TABLE_NAME)
-                    .ifNotExists()
-                    .addPartitionKey(MailRepositoryTable.REPOSITORY_NAME, 
text())
-                    .addClusteringColumn(MailRepositoryTable.MAIL_KEY, 
text())),
-            new CassandraTable(MailRepositoryTable.CONTENT_TABLE_NAME,
-                
SchemaBuilder.createTable(MailRepositoryTable.CONTENT_TABLE_NAME)
-                    .ifNotExists()
-                    .addPartitionKey(MailRepositoryTable.REPOSITORY_NAME, 
text())
-                    .addPartitionKey(MailRepositoryTable.MAIL_KEY, text())
-                    .addColumn(MailRepositoryTable.MESSAGE_SIZE, bigint())
-                    .addColumn(MailRepositoryTable.STATE, text())
-                    .addColumn(MailRepositoryTable.HEADER_BLOB_ID, text())
-                    .addColumn(MailRepositoryTable.BODY_BLOB_ID, text())
-                    .addColumn(MailRepositoryTable.ATTRIBUTES, map(text(), 
blob()))
-                    .addColumn(MailRepositoryTable.ERROR_MESSAGE, text())
-                    .addColumn(MailRepositoryTable.SENDER, text())
-                    .addColumn(MailRepositoryTable.RECIPIENTS, list(text()))
-                    .addColumn(MailRepositoryTable.REMOTE_HOST, text())
-                    .addColumn(MailRepositoryTable.REMOTE_ADDR, text())
-                    .addColumn(MailRepositoryTable.LAST_UPDATED, timestamp())
-                    
.addUDTMapColumn(MailRepositoryTable.PER_RECIPIENT_SPECIFIC_HEADERS, text(), 
frozen(MailRepositoryTable.HEADER_TYPE))
-                    .withOptions()
-                    .comment("Stores the mails for a given repository. " +
-                        "Content is stored with other blobs")));
-        types = ImmutableList.of(
-            new CassandraType(MailRepositoryTable.HEADER_TYPE,
-                SchemaBuilder.createType(MailRepositoryTable.HEADER_TYPE)
-                    .ifNotExists()
-                    .addColumn(MailRepositoryTable.HEADER_NAME, text())
-                    .addColumn(MailRepositoryTable.HEADER_VALUE, text())));
-    }
-
-    @Override
-    public List<CassandraTable> moduleTables() {
-        return tables;
-    }
 
-    @Override
-    public List<CassandraType> moduleTypes() {
-        return types;
-    }
+public interface CassandraMailRepositoryModule {
+    CassandraModule MODULE = CassandraModule.builder()
+        .type(MailRepositoryTable.HEADER_TYPE)
+        .statement(statement -> statement
+            .ifNotExists()
+            .addColumn(MailRepositoryTable.HEADER_NAME, text())
+            .addColumn(MailRepositoryTable.HEADER_VALUE, text()))
+        .table(MailRepositoryTable.COUNT_TABLE)
+        .statement(statement -> statement
+            .ifNotExists()
+            .addPartitionKey(MailRepositoryTable.REPOSITORY_NAME, text())
+            .addColumn(MailRepositoryTable.COUNT, counter()))
+        .table(MailRepositoryTable.KEYS_TABLE_NAME)
+        .statement(statement -> statement
+            .ifNotExists()
+            .addPartitionKey(MailRepositoryTable.REPOSITORY_NAME, text())
+            .addClusteringColumn(MailRepositoryTable.MAIL_KEY, text()))
+        .table(MailRepositoryTable.CONTENT_TABLE_NAME)
+        .statement(statement -> statement
+            .ifNotExists()
+            .addPartitionKey(MailRepositoryTable.REPOSITORY_NAME, text())
+            .addPartitionKey(MailRepositoryTable.MAIL_KEY, text())
+            .addColumn(MailRepositoryTable.MESSAGE_SIZE, bigint())
+            .addColumn(MailRepositoryTable.STATE, text())
+            .addColumn(MailRepositoryTable.HEADER_BLOB_ID, text())
+            .addColumn(MailRepositoryTable.BODY_BLOB_ID, text())
+            .addColumn(MailRepositoryTable.ATTRIBUTES, map(text(), blob()))
+            .addColumn(MailRepositoryTable.ERROR_MESSAGE, text())
+            .addColumn(MailRepositoryTable.SENDER, text())
+            .addColumn(MailRepositoryTable.RECIPIENTS, list(text()))
+            .addColumn(MailRepositoryTable.REMOTE_HOST, text())
+            .addColumn(MailRepositoryTable.REMOTE_ADDR, text())
+            .addColumn(MailRepositoryTable.LAST_UPDATED, timestamp())
+            
.addUDTMapColumn(MailRepositoryTable.PER_RECIPIENT_SPECIFIC_HEADERS, text(), 
frozen(MailRepositoryTable.HEADER_TYPE))
+            .withOptions()
+            .comment("Stores the mails for a given repository. " +
+                "Content is stored with other blobs"))
+        .build();
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b100add1/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryCountDAOTest.java
----------------------------------------------------------------------
diff --git 
a/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryCountDAOTest.java
 
b/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryCountDAOTest.java
index b68b602..f5255d0 100644
--- 
a/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryCountDAOTest.java
+++ 
b/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryCountDAOTest.java
@@ -41,12 +41,11 @@ public class CassandraMailRepositoryCountDAOTest {
 
     @BeforeAll
     static void setUpClass(DockerCassandraExtension.DockerCassandra 
dockerCassandra) {
-        cassandra = CassandraCluster.create(new 
CassandraMailRepositoryModule(), dockerCassandra.getHost());
+        cassandra = 
CassandraCluster.create(CassandraMailRepositoryModule.MODULE, 
dockerCassandra.getHost());
     }
 
     @BeforeEach
     public void setUp() {
-
         testee = new CassandraMailRepositoryCountDAO(cassandra.getConf());
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/b100add1/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryKeysDAOTest.java
----------------------------------------------------------------------
diff --git 
a/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryKeysDAOTest.java
 
b/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryKeysDAOTest.java
index 03a905c..feebf98 100644
--- 
a/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryKeysDAOTest.java
+++ 
b/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryKeysDAOTest.java
@@ -47,7 +47,7 @@ public class CassandraMailRepositoryKeysDAOTest {
 
     @BeforeAll
     static void setUpClass(DockerCassandraExtension.DockerCassandra 
dockerCassandra) {
-        cassandra = CassandraCluster.create(new 
CassandraMailRepositoryModule(), dockerCassandra.getHost());
+        cassandra = 
CassandraCluster.create(CassandraMailRepositoryModule.MODULE, 
dockerCassandra.getHost());
     }
 
     @BeforeEach

http://git-wip-us.apache.org/repos/asf/james-project/blob/b100add1/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryMailDAOTest.java
----------------------------------------------------------------------
diff --git 
a/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryMailDAOTest.java
 
b/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryMailDAOTest.java
index 8bc858e..48b4aee 100644
--- 
a/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryMailDAOTest.java
+++ 
b/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryMailDAOTest.java
@@ -52,7 +52,7 @@ public class CassandraMailRepositoryMailDAOTest {
 
     @BeforeAll
     static void setUpClass(DockerCassandraExtension.DockerCassandra 
dockerCassandra) {
-        cassandra = CassandraCluster.create(new 
CassandraMailRepositoryModule(), dockerCassandra.getHost());
+        cassandra = 
CassandraCluster.create(CassandraMailRepositoryModule.MODULE, 
dockerCassandra.getHost());
     }
 
     @BeforeEach

http://git-wip-us.apache.org/repos/asf/james-project/blob/b100add1/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryTest.java
----------------------------------------------------------------------
diff --git 
a/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryTest.java
 
b/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryTest.java
index 2b21c0d..84cf4c0 100644
--- 
a/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryTest.java
+++ 
b/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryTest.java
@@ -21,7 +21,7 @@ package org.apache.james.mailrepository.cassandra;
 
 import org.apache.james.backends.cassandra.CassandraCluster;
 import org.apache.james.backends.cassandra.DockerCassandraExtension;
-import org.apache.james.backends.cassandra.init.CassandraModuleComposite;
+import org.apache.james.backends.cassandra.components.CassandraModule;
 import org.apache.james.backends.cassandra.utils.CassandraUtils;
 import org.apache.james.blob.cassandra.CassandraBlobId;
 import org.apache.james.blob.cassandra.CassandraBlobModule;
@@ -47,9 +47,9 @@ class CassandraMailRepositoryTest implements 
MailRepositoryContract {
 
     @BeforeAll
     static void setUpClass(DockerCassandraExtension.DockerCassandra 
dockerCassandra) {
-        CassandraModuleComposite modules = new CassandraModuleComposite(
-            new CassandraMailRepositoryModule(),
-            new CassandraBlobModule());
+        CassandraModule modules = CassandraModule.aggregateModules(
+            CassandraMailRepositoryModule.MODULE,
+            CassandraBlobModule.MODULE);
         cassandra = CassandraCluster.create(modules, 
dockerCassandra.getHost());
     }
 


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

Reply via email to