Repository: james-project
Updated Branches:
  refs/heads/master 81f7f3a4c -> 7c8a65bc3


MAILBOX-271 CassandraAttachmentMapper should not prepare requests

As it is instantiated on a per request basis


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

Branch: refs/heads/master
Commit: 7c8a65bc3e6e105095d20e7f095380cd89da6e3f
Parents: 81f7f3a
Author: Benoit Tellier <btell...@linagora.com>
Authored: Tue Jun 7 14:37:06 2016 +0700
Committer: Benoit Tellier <btell...@linagora.com>
Committed: Tue Jun 7 14:37:06 2016 +0700

----------------------------------------------------------------------
 .../mail/CassandraAttachmentMapper.java         | 36 +++++++-------------
 1 file changed, 13 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/7c8a65bc/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapper.java
----------------------------------------------------------------------
diff --git 
a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapper.java
 
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapper.java
index 865c5fb..c36d824 100644
--- 
a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapper.java
+++ 
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapper.java
@@ -19,7 +19,6 @@
 
 package org.apache.james.mailbox.cassandra.mail;
 
-import static com.datastax.driver.core.querybuilder.QueryBuilder.bindMarker;
 import static com.datastax.driver.core.querybuilder.QueryBuilder.eq;
 import static com.datastax.driver.core.querybuilder.QueryBuilder.insertInto;
 import static com.datastax.driver.core.querybuilder.QueryBuilder.select;
@@ -43,7 +42,6 @@ import org.apache.james.mailbox.store.mail.AttachmentMapper;
 import org.apache.james.mailbox.store.mail.model.Attachment;
 import org.apache.james.mailbox.store.mail.model.AttachmentId;
 
-import com.datastax.driver.core.PreparedStatement;
 import com.datastax.driver.core.Row;
 import com.datastax.driver.core.Session;
 import com.github.fge.lambdas.Throwing;
@@ -53,19 +51,9 @@ import com.google.common.base.Preconditions;
 public class CassandraAttachmentMapper implements AttachmentMapper {
 
     private final CassandraAsyncExecutor cassandraAsyncExecutor;
-    private final PreparedStatement select;
-    private final PreparedStatement insert;
 
     public CassandraAttachmentMapper(Session session) {
         this.cassandraAsyncExecutor = new CassandraAsyncExecutor(session);
-        this.select = session.prepare(select(FIELDS)
-                .from(TABLE_NAME)
-                .where(eq(ID, bindMarker(ID))));
-        this.insert = session.prepare(insertInto(TABLE_NAME)
-                .value(ID, bindMarker(ID))
-                .value(PAYLOAD, bindMarker(PAYLOAD))
-                .value(TYPE, bindMarker(TYPE))
-                .value(SIZE, bindMarker(SIZE)));
     }
 
     @Override
@@ -80,11 +68,13 @@ public class CassandraAttachmentMapper implements 
AttachmentMapper {
     @Override
     public Attachment getAttachment(AttachmentId attachmentId) throws 
AttachmentNotFoundException {
         Preconditions.checkArgument(attachmentId != null);
-        return cassandraAsyncExecutor.executeSingleRow(select.bind()
-                .setString(ID, attachmentId.getId()))
-                .thenApply(optional -> optional.map(this::attachment))
-                .join()
-                .orElseThrow(() -> new 
AttachmentNotFoundException(attachmentId.getId()));
+        return cassandraAsyncExecutor.executeSingleRow(
+            select(FIELDS)
+                .from(TABLE_NAME)
+                .where(eq(ID, attachmentId.getId())))
+            .thenApply(optional -> optional.map(this::attachment))
+            .join()
+            .orElseThrow(() -> new 
AttachmentNotFoundException(attachmentId.getId()));
     }
 
     private Attachment attachment(Row row) {
@@ -107,12 +97,12 @@ public class CassandraAttachmentMapper implements 
AttachmentMapper {
 
     private CompletableFuture<Void> asyncStoreAttachment(Attachment 
attachment) throws IOException {
         return cassandraAsyncExecutor.executeVoid(
-                insert.bind()
-                    .setString(ID, attachment.getAttachmentId().getId())
-                    .setBytes(PAYLOAD, 
ByteBuffer.wrap(IOUtils.toByteArray(attachment.getStream())))
-                    .setString(TYPE, attachment.getType())
-                    .setLong(SIZE, attachment.getSize())
-            );
+            insertInto(TABLE_NAME)
+                .value(ID, attachment.getAttachmentId().getId())
+                .value(PAYLOAD, 
ByteBuffer.wrap(IOUtils.toByteArray(attachment.getStream())))
+                .value(TYPE, attachment.getType())
+                .value(SIZE, attachment.getSize())
+        );
     }
 
     @Override


---------------------------------------------------------------------
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