Repository: james-project
Updated Branches:
  refs/heads/master 0ae36b298 -> 6c72ae84a


MAILBOX-323 Avoid non prepared query recycling

We should rather rely on a more generic prepared query.


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

Branch: refs/heads/master
Commit: c43e97457b6b15db3efbe9851f6a89987604d171
Parents: 0ae36b2
Author: benwa <[email protected]>
Authored: Mon Jan 22 18:32:01 2018 +0700
Committer: benwa <[email protected]>
Committed: Mon Jan 22 18:32:01 2018 +0700

----------------------------------------------------------------------
 .../quota/CassandraPerUserMaxQuotaManager.java     | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/c43e9745/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/quota/CassandraPerUserMaxQuotaManager.java
----------------------------------------------------------------------
diff --git 
a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/quota/CassandraPerUserMaxQuotaManager.java
 
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/quota/CassandraPerUserMaxQuotaManager.java
index c5b5e7f..5a6a1b3 100644
--- 
a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/quota/CassandraPerUserMaxQuotaManager.java
+++ 
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/quota/CassandraPerUserMaxQuotaManager.java
@@ -36,7 +36,6 @@ import org.apache.james.mailbox.quota.MaxQuotaManager;
 import com.datastax.driver.core.PreparedStatement;
 import com.datastax.driver.core.ResultSet;
 import com.datastax.driver.core.Session;
-import com.datastax.driver.core.Statement;
 
 public class CassandraPerUserMaxQuotaManager implements MaxQuotaManager {
 
@@ -47,8 +46,7 @@ public class CassandraPerUserMaxQuotaManager implements 
MaxQuotaManager {
     private final PreparedStatement getMaxMessageStatement;
     private final PreparedStatement setDefaultMaxStorageStatement;
     private final PreparedStatement setDefaultMaxMessageStatement;
-    private final Statement getDefaultMaxStorageStatement;
-    private final Statement getDefaultMaxMessageStatement;
+    private final PreparedStatement getDefaultMaxStatement;
 
     @Inject
     public CassandraPerUserMaxQuotaManager(Session session) {
@@ -65,12 +63,9 @@ public class CassandraPerUserMaxQuotaManager implements 
MaxQuotaManager {
         this.getMaxMessageStatement = 
session.prepare(select(CassandraMaxQuota.MESSAGE_COUNT)
             .from(CassandraMaxQuota.TABLE_NAME)
             .where(eq(CassandraMaxQuota.QUOTA_ROOT, bindMarker())));
-        this.getDefaultMaxMessageStatement = 
select(CassandraDefaultMaxQuota.VALUE)
+        this.getDefaultMaxStatement = 
session.prepare(select(CassandraDefaultMaxQuota.VALUE)
             .from(CassandraDefaultMaxQuota.TABLE_NAME)
-            .where(eq(CassandraDefaultMaxQuota.TYPE, 
CassandraDefaultMaxQuota.MESSAGE));
-        this.getDefaultMaxStorageStatement = 
select(CassandraDefaultMaxQuota.VALUE)
-            .from(CassandraDefaultMaxQuota.TABLE_NAME)
-            .where(eq(CassandraDefaultMaxQuota.TYPE, 
CassandraDefaultMaxQuota.STORAGE));
+            .where(eq(CassandraDefaultMaxQuota.TYPE, 
bindMarker(CassandraDefaultMaxQuota.TYPE))));
         this.setDefaultMaxMessageStatement = 
session.prepare(insertInto(CassandraDefaultMaxQuota.TABLE_NAME)
             .value(CassandraDefaultMaxQuota.TYPE, 
CassandraDefaultMaxQuota.MESSAGE)
             .value(CassandraDefaultMaxQuota.VALUE, bindMarker()));
@@ -101,7 +96,8 @@ public class CassandraPerUserMaxQuotaManager implements 
MaxQuotaManager {
 
     @Override
     public long getDefaultMaxStorage() throws MailboxException {
-        ResultSet resultSet = session.execute(getDefaultMaxStorageStatement);
+        ResultSet resultSet = session.execute(getDefaultMaxStatement.bind()
+            .setString(CassandraDefaultMaxQuota.TYPE, 
CassandraDefaultMaxQuota.STORAGE));
         if (resultSet.isExhausted()) {
             return Quota.UNLIMITED;
         }
@@ -110,7 +106,8 @@ public class CassandraPerUserMaxQuotaManager implements 
MaxQuotaManager {
 
     @Override
     public long getDefaultMaxMessage() throws MailboxException {
-        ResultSet resultSet = session.execute(getDefaultMaxMessageStatement);
+        ResultSet resultSet = session.execute(getDefaultMaxStatement.bind()
+            .setString(CassandraDefaultMaxQuota.TYPE, 
CassandraDefaultMaxQuota.MESSAGE));
         if (resultSet.isExhausted()) {
             return Quota.UNLIMITED;
         }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to