From ff409b6f2c790b15a7b9078fe49be896e71f1006 Mon Sep 17 00:00:00 2001 From: Hiram Chirino Date: Fri, 21 Mar 2014 13:52:41 -0400 Subject: [PATCH] Applying https://github.com/apache/activemq/pull/18.patch to fix AMQ-5116: batchStatment is misspelled for JDBC adaptors. This closes #18 @github. --- .../jdbc/adapter/DefaultJDBCAdapter.java | 61 +++++++++++++------ 1 file changed, 43 insertions(+), 18 deletions(-) diff --git a/activemq-jdbc-store/src/main/java/org/apache/activemq/store/jdbc/adapter/DefaultJDBCAdapter.java b/activemq-jdbc-store/src/main/java/org/apache/activemq/store/jdbc/adapter/DefaultJDBCAdapter.java index cabe99cb6b..3243048a37 100755 --- a/activemq-jdbc-store/src/main/java/org/apache/activemq/store/jdbc/adapter/DefaultJDBCAdapter.java +++ b/activemq-jdbc-store/src/main/java/org/apache/activemq/store/jdbc/adapter/DefaultJDBCAdapter.java @@ -65,6 +65,8 @@ public class DefaultJDBCAdapter implements JDBCAdapter { private static final Logger LOG = LoggerFactory.getLogger(DefaultJDBCAdapter.class); public static final int MAX_ROWS = org.apache.activemq.ActiveMQPrefetchPolicy.MAX_PREFETCH_SIZE; protected Statements statements; + private boolean batchStatements = true; + //This is deprecated and should be removed in a future release protected boolean batchStatments = true; protected boolean prioritizedMessages; protected ReadWriteLock cleanupExclusiveLock = new ReentrantReadWriteLock(); @@ -216,7 +218,7 @@ public class DefaultJDBCAdapter implements JDBCAdapter { try { if (s == null) { s = c.getConnection().prepareStatement(this.statements.getAddMessageStatement()); - if (this.batchStatments) { + if (this.batchStatements) { c.setAddMessageStatement(s); } } @@ -235,14 +237,14 @@ public class DefaultJDBCAdapter implements JDBCAdapter { } else { s.setString(8, null); } - if (this.batchStatments) { + if (this.batchStatements) { s.addBatch(); } else if (s.executeUpdate() != 1) { throw new SQLException("Failed add a message"); } } finally { cleanupExclusiveLock.readLock().unlock(); - if (!this.batchStatments) { + if (!this.batchStatements) { if (s != null) { s.close(); } @@ -259,7 +261,7 @@ public class DefaultJDBCAdapter implements JDBCAdapter { try { if (s == null) { s = c.getConnection().prepareStatement(this.statements.getAddMessageStatement()); - if (this.batchStatments) { + if (this.batchStatements) { c.setAddMessageStatement(s); } } @@ -269,14 +271,14 @@ public class DefaultJDBCAdapter implements JDBCAdapter { s.setString(4, destination.getQualifiedName()); s.setLong(5, expirationTime); s.setString(6, messageRef); - if (this.batchStatments) { + if (this.batchStatements) { s.addBatch(); } else if (s.executeUpdate() != 1) { throw new SQLException("Failed add a message"); } } finally { cleanupExclusiveLock.readLock().unlock(); - if (!this.batchStatments) { + if (!this.batchStatements) { s.close(); } } @@ -352,7 +354,7 @@ public class DefaultJDBCAdapter implements JDBCAdapter { if (s == null) { s = c.getConnection().prepareStatement(xid == null ? this.statements.getRemoveMessageStatement() : this.statements.getUpdateXidFlagStatement()); - if (this.batchStatments) { + if (this.batchStatements) { c.setRemovedMessageStatement(s); } } @@ -365,14 +367,14 @@ public class DefaultJDBCAdapter implements JDBCAdapter { s.setString(1, xidString); s.setLong(2, seq); } - if (this.batchStatments) { + if (this.batchStatements) { s.addBatch(); } else if (s.executeUpdate() != 1) { throw new SQLException("Failed to remove message"); } } finally { cleanupExclusiveLock.readLock().unlock(); - if (!this.batchStatments && s != null) { + if (!this.batchStatements && s != null) { s.close(); } } @@ -443,7 +445,7 @@ public class DefaultJDBCAdapter implements JDBCAdapter { s = c.getConnection().prepareStatement(xid == null ? this.statements.getUpdateDurableLastAckWithPriorityStatement() : this.statements.getUpdateDurableLastAckWithPriorityInTxStatement()); - if (this.batchStatments) { + if (this.batchStatements) { c.setUpdateLastAckStatement(s); } } @@ -458,14 +460,14 @@ public class DefaultJDBCAdapter implements JDBCAdapter { s.setString(3, clientId); s.setString(4, subscriptionName); s.setLong(5, priority); - if (this.batchStatments) { + if (this.batchStatements) { s.addBatch(); } else if (s.executeUpdate() != 1) { throw new SQLException("Failed update last ack with priority: " + priority + ", for sub: " + subscriptionName); } } finally { cleanupExclusiveLock.readLock().unlock(); - if (!this.batchStatments) { + if (!this.batchStatements) { close(s); } } @@ -481,7 +483,7 @@ public class DefaultJDBCAdapter implements JDBCAdapter { s = c.getConnection().prepareStatement(xid == null ? this.statements.getUpdateDurableLastAckStatement() : this.statements.getUpdateDurableLastAckInTxStatement()); - if (this.batchStatments) { + if (this.batchStatements) { c.setUpdateLastAckStatement(s); } } @@ -496,7 +498,7 @@ public class DefaultJDBCAdapter implements JDBCAdapter { s.setString(3, clientId); s.setString(4, subscriptionName); - if (this.batchStatments) { + if (this.batchStatements) { s.addBatch(); } else if (s.executeUpdate() != 1) { throw new IOException("Could not update last ack seq : " @@ -504,7 +506,7 @@ public class DefaultJDBCAdapter implements JDBCAdapter { } } finally { cleanupExclusiveLock.readLock().unlock(); - if (!this.batchStatments) { + if (!this.batchStatements) { close(s); } } @@ -893,16 +895,39 @@ public class DefaultJDBCAdapter implements JDBCAdapter { } /** - * @return true if batchStements + * @return true if batchStatements */ - public boolean isBatchStatments() { - return this.batchStatments; + public boolean isBatchStatements() { + return batchStatements; } /** + * Set the number of statements to process as a single batch DB update + * @param batchStatements + */ + public void setBatchStatements(boolean batchStatements) { + this.batchStatements = batchStatements; + // The next lines are deprecated and should be removed in a future release + // and is here in case someone created their own + this.batchStatments = batchStatements; + } + + // Note - remove batchStatment in future distributions. Here for backward compatibility + /** + * @return true if batchStements + */ + public boolean isBatchStatments() { + return this.batchStatements; + } + + /** + * This value batchStatments is deprecated and will be removed in a future release. Use batchStatements instead (Note the 'e' in Statement)" + * @deprecated * @param batchStatments */ public void setBatchStatments(boolean batchStatments) { + LOG.warn("batchStatments is deprecated and will be removed in a future release. Use batchStatements instead (Note the 'e' in Statement)"); + this.batchStatements = batchStatments; this.batchStatments = batchStatments; }