Index: src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java
===================================================================
--- src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java (revision 605592)
+++ src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java (working copy)
@@ -479,7 +479,7 @@
initDatabaseType();
connectionPool = new Pool(this, maxConnections);
ConnectionRecoveryManager conn = getConnection();
- conn = new ConnectionRecoveryManager(false, driver, url, user, password);
+ conn = new ConnectionRecoveryManager(driver, url, user, password, false, true);
conn.setAutoReconnect(true);
DatabaseMetaData meta = conn.getConnection().getMetaData();
log.info("Using JDBC driver " + meta.getDriverName() + " " + meta.getDriverVersion());
@@ -817,7 +817,7 @@
* @return the new connection
*/
public ConnectionRecoveryManager createNewConnection() throws RepositoryException {
- ConnectionRecoveryManager conn = new ConnectionRecoveryManager(false, driver, url, user, password);
+ ConnectionRecoveryManager conn = new ConnectionRecoveryManager(driver, url, user, password, false, true);
return conn;
}
Index: src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java
===================================================================
--- src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java (revision 605592)
+++ src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java (working copy)
@@ -85,6 +85,7 @@
*
<param name="{@link #setSchemaObjectPrefix(String) schemaObjectPrefix}" value=""/>
* <param name="{@link #setErrorHandling(String) errorHandling}" value=""/>
* <param name="{@link #setBlockOnConnectionLoss(String) blockOnConnectionLoss}" value="false"/>
+ * <param name="{@link #setAutoCommitMode(String) autoCommitMode}" value="true"/>
*
*/
public class BundleDbPersistenceManager extends AbstractBundlePersistenceManager {
@@ -140,6 +141,9 @@
/** indicates whether to block if the database connection is lost */
protected boolean blockOnConnectionLoss = false;
+
+ /** flag indicating autocommit mode for database connection */
+ protected boolean autoCommitMode = true;
/**
* The class that manages statement execution and recovery from connection loss.
@@ -261,6 +265,24 @@
}
/**
+ * Checks autoCommit mode for database connection.
+ * @return autoCommitMode.
+ */
+ public String getAutoCommitMode() {
+ return Boolean.toString(autoCommitMode);
+ }
+
+ /**
+ * Sets the autoCommitMode for database connection.
+ * Should be true in clustered environment.
+ *
+ * @param autoCommitMode autoCommit mode for database connections.
+ */
+ public void setAutoCommitMode(String autoCommitMode) {
+ this.autoCommitMode = Boolean.valueOf(autoCommitMode).booleanValue();
+ }
+
+ /**
* Returns the configured schema object prefix.
* @return the configured schema object prefix.
*/
@@ -519,13 +541,17 @@
try {
con = connectionManager.getConnection();
connectionManager.setAutoReconnect(false);
- con.setAutoCommit(false);
+ if (autoCommitMode) {
+ con.setAutoCommit(false);
+ }
super.store(changeLog);
con.commit();
- con.setAutoCommit(true);
+ if (autoCommitMode) {
+ con.setAutoCommit(true);
+ }
return;
- } catch (Throwable th) {
- lastException = th;
+ } catch (Exception ex) {
+ lastException = ex;
try {
if (con != null) {
con.rollback();
@@ -533,7 +559,7 @@
} catch (SQLException e) {
logException("rollback failed", e);
}
- if (th instanceof SQLException || th.getCause() instanceof SQLException) {
+ if (ex instanceof SQLException || ex.getCause() instanceof SQLException) {
connectionManager.close();
}
} finally {
@@ -554,8 +580,8 @@
this.name = context.getHomeDir().getName();
- connectionManager = new ConnectionRecoveryManager(blockOnConnectionLoss,
- getDriver(), getUrl(), getUser(), getPassword());
+ connectionManager = new ConnectionRecoveryManager(getDriver(),
+ getUrl(), getUser(), getPassword(), blockOnConnectionLoss, autoCommitMode);
// make sure schemaObjectPrefix consists of legal name characters only
prepareSchemaObjectPrefix();
Index: src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionRecoveryManager.java
===================================================================
--- src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionRecoveryManager.java (revision 605592)
+++ src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionRecoveryManager.java (working copy)
@@ -90,6 +90,11 @@
* until the connection is up again.
*/
private final boolean block;
+
+ /**
+ * AutoCommit mode for the created connection.
+ */
+ private final boolean autoCommitMode;
/**
* Time to sleep in ms before a reconnect is attempted.
@@ -111,7 +116,7 @@
* Indicates whether the managed connection is open or closed.
*/
private boolean isClosed;
-
+
/**
* Creates a {@link ConnectionRecoveryManager} and establishes
* a database Connection using the driver, user, password and url
@@ -119,20 +124,22 @@
*
* By default, the connection is in auto-commit mode, and this
* manager tries to reconnect if the connection is lost.
- *
- * @param block whether this class should block until the connection can be recovered
* @param driver the driver to use for the connection
* @param url the url to use for the connection
* @param user the user to use for the connection
* @param password the password to use for the connection
+ * @param block whether this class should block until the connection can be recovered
+ * @param autoCommitMode autoCommit mode for connections created by manager
+ *
* @throws RepositoryException if the database driver could not be loaded
*/
- public ConnectionRecoveryManager(boolean block, String driver, String url, String user, String password) throws RepositoryException {
- this.block = block;
+ public ConnectionRecoveryManager(String driver, String url, String user, String password, boolean block, boolean autoCommitMode) throws RepositoryException {
this.driver = driver;
this.url = url;
this.user = user;
this.password = password;
+ this.block = block;
+ this.autoCommitMode = autoCommitMode;
try {
setupConnection();
isClosed = false;
@@ -330,10 +337,9 @@
log.warn("Could not connect; driver: " + driver + " url: " + url + " user: " + user + " error: " + e.toString(), e);
throw e;
}
- // JCR-1013: Setter may fail unnecessarily on a managed connection
- if (!connection.getAutoCommit()) {
- connection.setAutoCommit(true);
- }
+ if (connection.getAutoCommit() != autoCommitMode) {
+ connection.setAutoCommit(autoCommitMode);
+ }
try {
DatabaseMetaData meta = connection.getMetaData();
log.info("Database: " + meta.getDatabaseProductName() + " / " + meta.getDatabaseProductVersion());