Fix for #159 - Refactor - cleanup clode when closing query only transaction + change default option

This commit is contained in:
Rob Bygrave committed 2014-07-05 22:10:53 +12:00
1 parent 1ddc103582
commit cceb7c035c
11 files changed
+162 -144

No files matched your search

@@ -136,7 +136,7 @@ public class JdbcTransaction implements SpiTransaction {
try {
this.active = true;
this.id = id;
this.logPrefix = deriveLogPrefix(id,null);
this.logPrefix = deriveLogPrefix(id);
this.explicit = explicit;
this.manager = manager;
this.connection = connection;
@@ -152,23 +152,17 @@ public class JdbcTransaction implements SpiTransaction {
}
}
private static String deriveLogPrefix(String id, String label) {
private static String deriveLogPrefix(String id) {
StringBuilder sb = new StringBuilder();
sb.append("txn[");
if (id != null) {
sb.append(id);
}
sb.append("] ");
if (label != null) {
sb.append("label[").append(label).append("] ");
}
return sb.toString();
}
public void setLabel(String label) {
this.logPrefix = deriveLogPrefix(id,label);
}
public String getLogPrefix() {
return logPrefix;
}
@@ -541,16 +535,21 @@ public class JdbcTransaction implements SpiTransaction {
* Notify the transaction manager.
*/
protected void notifyCommit() {
if (manager == null) {
return;
}
if (queryOnly) {
manager.notifyOfQueryOnly(true, this, null);
} else {
manager.notifyOfCommit(this);
if (manager != null) {
if (queryOnly) {
manager.notifyOfQueryOnly(true, this, null);
} else {
manager.notifyOfCommit(this);
}
}
}
protected void notifyQueryOnly() {
if (manager != null) {
manager.notifyOfQueryOnly(true, this, null);
}
}
/**
* Rollback, Commit or Close for query only transaction.
* <p>
@@ -558,7 +557,7 @@ public class JdbcTransaction implements SpiTransaction {
* rollback or just close the connection for performance.
* </p>
*/
private void commitQueryOnly() {
private void connectionEndForQueryOnly() {
try {
switch (onQueryOnly) {
case ROLLBACK:
@@ -580,6 +579,22 @@ public class JdbcTransaction implements SpiTransaction {
}
}
/**
* End the transaction on a query only request.
*/
public void endQueryOnly() {
if (!isActive()) {
throw new IllegalStateException(illegalStateMessage);
}
try {
connectionEndForQueryOnly();
} finally {
// these will not throw an exception
deactivate();
notifyQueryOnly();
}
}
/**
* Commit the transaction.
*/
@@ -590,7 +605,7 @@ public class JdbcTransaction implements SpiTransaction {
try {
if (queryOnly) {
// can rollback or just close for performance
commitQueryOnly();
connectionEndForQueryOnly();
} else {
// commit
if (batchControl != null && !batchControl.isEmpty()) {
@@ -91,8 +91,6 @@ public class TransactionManager {
private final ClusterManager clusterManager;
//private final int commitDebugLevel;
private final String serverName;
/**
@@ -100,11 +98,11 @@ public class TransactionManager {
*/
private AtomicLong transactionCounter = new AtomicLong(1000);
private int clusterDebugLevel;
private final BulkEventListenerMap bulkEventListenerMap;
private int clusterDebugLevel;
private TransactionEventListener[] transactionEventListeners;
private final BulkEventListenerMap bulkEventListenerMap;
private TransactionEventListener[] transactionEventListeners;
/**
* Create the TransactionManager
@@ -130,7 +128,7 @@ public class TransactionManager {
this.prefix = GlobalProperties.get("transaction.prefix", "");
this.externalTransPrefix = GlobalProperties.get("transaction.prefix", "e");
String value = GlobalProperties.get("transaction.onqueryonly", "ROLLBACK").toUpperCase().trim();
String value = GlobalProperties.get("transaction.onqueryonly", "CLOSE").toUpperCase().trim();
this.onQueryOnly = getOnQueryOnly(value, dataSource);
initialiseHeartbeat();
@@ -171,7 +169,6 @@ public class TransactionManager {
*/
private OnQueryOnly getOnQueryOnly(String onQueryOnly, DataSource ds) {
if (onQueryOnly.equals("COMMIT")){
return OnQueryOnly.COMMIT;
}
@@ -429,9 +426,6 @@ public class TransactionManager {
logger.error(m, ex);
}
}
/**
* Process a Transaction that comes from another framework or local code.