Applying https://github.com/apache/activemq/pull/18.patch to fix AMQ-5116: batchStatment is misspelled for JDBC adaptors.

This closes #18 @github.
This commit is contained in:
Hiram Chirino 2014-03-21 13:52:41 -04:00
parent db321727c9
commit ff409b6f2c
1 changed files with 43 additions and 18 deletions

View File

@ -65,6 +65,8 @@ public class DefaultJDBCAdapter implements JDBCAdapter {
private static final Logger LOG = LoggerFactory.getLogger(DefaultJDBCAdapter.class); private static final Logger LOG = LoggerFactory.getLogger(DefaultJDBCAdapter.class);
public static final int MAX_ROWS = org.apache.activemq.ActiveMQPrefetchPolicy.MAX_PREFETCH_SIZE; public static final int MAX_ROWS = org.apache.activemq.ActiveMQPrefetchPolicy.MAX_PREFETCH_SIZE;
protected Statements statements; protected Statements statements;
private boolean batchStatements = true;
//This is deprecated and should be removed in a future release
protected boolean batchStatments = true; protected boolean batchStatments = true;
protected boolean prioritizedMessages; protected boolean prioritizedMessages;
protected ReadWriteLock cleanupExclusiveLock = new ReentrantReadWriteLock(); protected ReadWriteLock cleanupExclusiveLock = new ReentrantReadWriteLock();
@ -216,7 +218,7 @@ public class DefaultJDBCAdapter implements JDBCAdapter {
try { try {
if (s == null) { if (s == null) {
s = c.getConnection().prepareStatement(this.statements.getAddMessageStatement()); s = c.getConnection().prepareStatement(this.statements.getAddMessageStatement());
if (this.batchStatments) { if (this.batchStatements) {
c.setAddMessageStatement(s); c.setAddMessageStatement(s);
} }
} }
@ -235,14 +237,14 @@ public class DefaultJDBCAdapter implements JDBCAdapter {
} else { } else {
s.setString(8, null); s.setString(8, null);
} }
if (this.batchStatments) { if (this.batchStatements) {
s.addBatch(); s.addBatch();
} else if (s.executeUpdate() != 1) { } else if (s.executeUpdate() != 1) {
throw new SQLException("Failed add a message"); throw new SQLException("Failed add a message");
} }
} finally { } finally {
cleanupExclusiveLock.readLock().unlock(); cleanupExclusiveLock.readLock().unlock();
if (!this.batchStatments) { if (!this.batchStatements) {
if (s != null) { if (s != null) {
s.close(); s.close();
} }
@ -259,7 +261,7 @@ public class DefaultJDBCAdapter implements JDBCAdapter {
try { try {
if (s == null) { if (s == null) {
s = c.getConnection().prepareStatement(this.statements.getAddMessageStatement()); s = c.getConnection().prepareStatement(this.statements.getAddMessageStatement());
if (this.batchStatments) { if (this.batchStatements) {
c.setAddMessageStatement(s); c.setAddMessageStatement(s);
} }
} }
@ -269,14 +271,14 @@ public class DefaultJDBCAdapter implements JDBCAdapter {
s.setString(4, destination.getQualifiedName()); s.setString(4, destination.getQualifiedName());
s.setLong(5, expirationTime); s.setLong(5, expirationTime);
s.setString(6, messageRef); s.setString(6, messageRef);
if (this.batchStatments) { if (this.batchStatements) {
s.addBatch(); s.addBatch();
} else if (s.executeUpdate() != 1) { } else if (s.executeUpdate() != 1) {
throw new SQLException("Failed add a message"); throw new SQLException("Failed add a message");
} }
} finally { } finally {
cleanupExclusiveLock.readLock().unlock(); cleanupExclusiveLock.readLock().unlock();
if (!this.batchStatments) { if (!this.batchStatements) {
s.close(); s.close();
} }
} }
@ -352,7 +354,7 @@ public class DefaultJDBCAdapter implements JDBCAdapter {
if (s == null) { if (s == null) {
s = c.getConnection().prepareStatement(xid == null ? s = c.getConnection().prepareStatement(xid == null ?
this.statements.getRemoveMessageStatement() : this.statements.getUpdateXidFlagStatement()); this.statements.getRemoveMessageStatement() : this.statements.getUpdateXidFlagStatement());
if (this.batchStatments) { if (this.batchStatements) {
c.setRemovedMessageStatement(s); c.setRemovedMessageStatement(s);
} }
} }
@ -365,14 +367,14 @@ public class DefaultJDBCAdapter implements JDBCAdapter {
s.setString(1, xidString); s.setString(1, xidString);
s.setLong(2, seq); s.setLong(2, seq);
} }
if (this.batchStatments) { if (this.batchStatements) {
s.addBatch(); s.addBatch();
} else if (s.executeUpdate() != 1) { } else if (s.executeUpdate() != 1) {
throw new SQLException("Failed to remove message"); throw new SQLException("Failed to remove message");
} }
} finally { } finally {
cleanupExclusiveLock.readLock().unlock(); cleanupExclusiveLock.readLock().unlock();
if (!this.batchStatments && s != null) { if (!this.batchStatements && s != null) {
s.close(); s.close();
} }
} }
@ -443,7 +445,7 @@ public class DefaultJDBCAdapter implements JDBCAdapter {
s = c.getConnection().prepareStatement(xid == null ? s = c.getConnection().prepareStatement(xid == null ?
this.statements.getUpdateDurableLastAckWithPriorityStatement() : this.statements.getUpdateDurableLastAckWithPriorityStatement() :
this.statements.getUpdateDurableLastAckWithPriorityInTxStatement()); this.statements.getUpdateDurableLastAckWithPriorityInTxStatement());
if (this.batchStatments) { if (this.batchStatements) {
c.setUpdateLastAckStatement(s); c.setUpdateLastAckStatement(s);
} }
} }
@ -458,14 +460,14 @@ public class DefaultJDBCAdapter implements JDBCAdapter {
s.setString(3, clientId); s.setString(3, clientId);
s.setString(4, subscriptionName); s.setString(4, subscriptionName);
s.setLong(5, priority); s.setLong(5, priority);
if (this.batchStatments) { if (this.batchStatements) {
s.addBatch(); s.addBatch();
} else if (s.executeUpdate() != 1) { } else if (s.executeUpdate() != 1) {
throw new SQLException("Failed update last ack with priority: " + priority + ", for sub: " + subscriptionName); throw new SQLException("Failed update last ack with priority: " + priority + ", for sub: " + subscriptionName);
} }
} finally { } finally {
cleanupExclusiveLock.readLock().unlock(); cleanupExclusiveLock.readLock().unlock();
if (!this.batchStatments) { if (!this.batchStatements) {
close(s); close(s);
} }
} }
@ -481,7 +483,7 @@ public class DefaultJDBCAdapter implements JDBCAdapter {
s = c.getConnection().prepareStatement(xid == null ? s = c.getConnection().prepareStatement(xid == null ?
this.statements.getUpdateDurableLastAckStatement() : this.statements.getUpdateDurableLastAckStatement() :
this.statements.getUpdateDurableLastAckInTxStatement()); this.statements.getUpdateDurableLastAckInTxStatement());
if (this.batchStatments) { if (this.batchStatements) {
c.setUpdateLastAckStatement(s); c.setUpdateLastAckStatement(s);
} }
} }
@ -496,7 +498,7 @@ public class DefaultJDBCAdapter implements JDBCAdapter {
s.setString(3, clientId); s.setString(3, clientId);
s.setString(4, subscriptionName); s.setString(4, subscriptionName);
if (this.batchStatments) { if (this.batchStatements) {
s.addBatch(); s.addBatch();
} else if (s.executeUpdate() != 1) { } else if (s.executeUpdate() != 1) {
throw new IOException("Could not update last ack seq : " throw new IOException("Could not update last ack seq : "
@ -504,7 +506,7 @@ public class DefaultJDBCAdapter implements JDBCAdapter {
} }
} finally { } finally {
cleanupExclusiveLock.readLock().unlock(); cleanupExclusiveLock.readLock().unlock();
if (!this.batchStatments) { if (!this.batchStatements) {
close(s); close(s);
} }
} }
@ -893,16 +895,39 @@ public class DefaultJDBCAdapter implements JDBCAdapter {
} }
/** /**
* @return true if batchStements * @return true if batchStatements
*/ */
public boolean isBatchStatments() { public boolean isBatchStatements() {
return this.batchStatments; 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 * @param batchStatments
*/ */
public void setBatchStatments(boolean 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; this.batchStatments = batchStatments;
} }