You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2018/07/06 09:27:35 UTC

[09/21] james-project git commit: MAILBOX-342 Provide a Guice based mechanism for easy Mapper instanciation

MAILBOX-342 Provide a Guice based mechanism for easy Mapper instanciation

Guice use avoid constructor hell, while not requiring a full mapper factory (which requires all tables thus is slow).


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

Branch: refs/heads/master
Commit: ddb928dc701e5db86c75b6b82a2a4cbf0eb8c1cc
Parents: 4ba29b3
Author: benwa <bt...@linagora.com>
Authored: Thu Jul 5 11:24:49 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Fri Jul 6 16:25:50 2018 +0700

----------------------------------------------------------------------
 .../cassandra/mail/utils/GuiceUtils.java        | 48 ++++++++++++++++++++
 1 file changed, 48 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/ddb928dc/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/utils/GuiceUtils.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/utils/GuiceUtils.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/utils/GuiceUtils.java
new file mode 100644
index 0000000..31dc895
--- /dev/null
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/utils/GuiceUtils.java
@@ -0,0 +1,48 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mailbox.cassandra.mail.utils;
+
+import org.apache.james.backends.cassandra.CassandraCluster;
+import org.apache.james.backends.cassandra.init.CassandraTypesProvider;
+import org.apache.james.backends.cassandra.init.configuration.CassandraConfiguration;
+import org.apache.james.blob.api.BlobId;
+import org.apache.james.blob.api.ObjectStore;
+import org.apache.james.blob.cassandra.CassandraBlobId;
+import org.apache.james.blob.cassandra.CassandraBlobsDAO;
+import org.apache.james.mailbox.cassandra.ids.CassandraMessageId;
+import org.apache.james.mailbox.model.MessageId;
+
+import com.datastax.driver.core.Session;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.util.Modules;
+
+public class GuiceUtils {
+    public static Injector testInjector(CassandraCluster cluster) {
+        return Guice.createInjector(
+            Modules.combine(
+                binder -> binder.bind(MessageId.Factory.class).toInstance(new CassandraMessageId.Factory()),
+                binder -> binder.bind(BlobId.Factory.class).toInstance(new CassandraBlobId.Factory()),
+                binder -> binder.bind(ObjectStore.class).to(CassandraBlobsDAO.class),
+                binder -> binder.bind(Session.class).toInstance(cluster.getConf()),
+                binder -> binder.bind(CassandraTypesProvider.class).toInstance(cluster.getTypesProvider()),
+                binder -> binder.bind(CassandraConfiguration.class).toInstance(CassandraConfiguration.DEFAULT_CONFIGURATION)));
+    }
+}


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