Today is not my day... I forgot the check in comment. Can this be corrected? Thomas
On 9/21/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Author: thomasm > Date: Fri Sep 21 03:10:54 2007 > New Revision: 578043 > > URL: http://svn.apache.org/viewvc?rev=578043&view=rev > Log: (empty) > > Modified: > > jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/AbstractBundlePersistenceManager.java > > jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java > > jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionRecoveryManager.java > > Modified: > jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/AbstractBundlePersistenceManager.java > URL: > http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/AbstractBundlePersistenceManager.java?rev=578043&r1=578042&r2=578043&view=diff > ============================================================================== > --- > jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/AbstractBundlePersistenceManager.java > (original) > +++ > jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/AbstractBundlePersistenceManager.java > Fri Sep 21 03:10:54 2007 > @@ -50,6 +50,7 @@ > import java.util.Set; > > import javax.jcr.PropertyType; > +import javax.jcr.RepositoryException; > > /** > * The <code>AbstractBundlePersistenceManager</code> acts as base for all > @@ -714,8 +715,9 @@ > * @param maxCount the maximum number of node ids to return, or 0 for no > limit. > * @return an iterator of all bundles. > * @throws ItemStateException if an error while loading occurs. > + * @throws RepositoryException if a repository exception occurs > */ > public abstract NodeIdIterator getAllNodeIds(NodeId after, int maxCount) > - throws ItemStateException; > + throws ItemStateException, RepositoryException; > > } > > Modified: > jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java > URL: > http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java?rev=578043&r1=578042&r2=578043&view=diff > ============================================================================== > --- > jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java > (original) > +++ > jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java > Fri Sep 21 03:10:54 2007 > @@ -466,9 +466,10 @@ > * @return <code>true</code> if the tables exist; > * <code>false</code> otherwise. > * > - * @throws SQLException if an SQL erro occurs. > + * @throws SQLException if a database error occurs. > + * @throws RepositoryException if a repository exception occurs. > */ > - protected boolean checkTablesExist() throws SQLException { > + protected boolean checkTablesExist() throws SQLException, > RepositoryException { > DatabaseMetaData metaData = > connectionManager.getConnection().getMetaData(); > String tableName = schemaObjectPrefix + "BUNDLE"; > if (metaData.storesLowerCaseIdentifiers()) { > @@ -504,40 +505,36 @@ > * Basically wrapps a JDBC transaction around super.store(). > */ > public synchronized void store(ChangeLog changeLog) throws > ItemStateException { > - Connection con = null; > - try { > - boolean tryAgain = true; > - do { > + int trials = 2; > + Throwable lastException = null; > + do { > + trials--; > + Connection con = null; > + try { > + con = connectionManager.getConnection(); > + connectionManager.setAutoReconnect(false); > + con.setAutoCommit(false); > + super.store(changeLog); > + con.commit(); > + con.setAutoCommit(true); > + return; > + } catch (Throwable th) { > + lastException = th; > try { > - con = connectionManager.getConnection(); > - connectionManager.setAutoReconnect(false); > - con.setAutoCommit(false); > - super.store(changeLog); > - con.commit(); > - con.setAutoCommit(true); > - } catch (SQLException e) { > - if (tryAgain) { > - tryAgain = false; > - continue; > + if (con != null) { > + con.rollback(); > } > - throw e; > + } catch (SQLException e) { > + logException("rollback failed", e); > } > - } while(false); > - } catch (Throwable th) { > - try { > - if (con != null) { > - con.rollback(); > + if (th instanceof SQLException || th.getCause() instanceof > SQLException) { > + connectionManager.close(); > } > - } catch (SQLException e) { > - logException("rollback failed", e); > - } > - if (th instanceof SQLException || th.getCause() instanceof > SQLException) { > - connectionManager.close(); > + } finally { > + connectionManager.setAutoReconnect(true); > } > - throw new ItemStateException(th.getMessage()); > - } finally { > - connectionManager.setAutoReconnect(true); > - } > + } while(blockOnConnectionLoss || trials > 0); > + throw new ItemStateException(lastException.getMessage()); > } > > /** > @@ -896,7 +893,7 @@ > * [EMAIL PROTECTED] > */ > public synchronized NodeIdIterator getAllNodeIds(NodeId bigger, int > maxCount) > - throws ItemStateException { > + throws ItemStateException, RepositoryException { > ResultSet rs = null; > try { > UUID lowUuid; > > Modified: > jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionRecoveryManager.java > URL: > http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionRecoveryManager.java?rev=578043&r1=578042&r2=578043&view=diff > ============================================================================== > --- > jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionRecoveryManager.java > (original) > +++ > jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionRecoveryManager.java > Fri Sep 21 03:10:54 2007 > @@ -26,6 +26,8 @@ > import java.sql.Statement; > import java.util.HashMap; > > +import javax.jcr.RepositoryException; > + > import org.slf4j.Logger; > import org.slf4j.LoggerFactory; > > @@ -124,8 +126,9 @@ > * @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 > + * @throws RepositoryException if the database driver could not be loaded > */ > - public ConnectionRecoveryManager(boolean block, String driver, String > url, String user, String password) { > + public ConnectionRecoveryManager(boolean block, String driver, String > url, String user, String password) throws RepositoryException { > this.block = block; > this.driver = driver; > this.url = url; > @@ -147,8 +150,9 @@ > * > * @return the database connection that is managed > * @throws SQLException on error > + * @throws RepositoryException if the database driver could not be loaded > */ > - public synchronized Connection getConnection() throws SQLException { > + public synchronized Connection getConnection() throws SQLException, > RepositoryException { > if (isClosed) { > if (autoReconnect) { > reestablishConnection(); > @@ -172,13 +176,38 @@ > } > > /** > + * Executes the given SQL query. Retries once or blocks (when the > + * <code>block</code> parameter has been set to true on construction) > + * if this fails and autoReconnect is enabled. > + * > + * @param sql the SQL query to execute > + * @return the executed ResultSet > + * @throws SQLException on error > + * @throws RepositoryException if the database driver could not be loaded > + */ > + public synchronized ResultSet executeQuery(String sql) throws > SQLException, RepositoryException { > + int trials = 2; > + SQLException lastException = null; > + do { > + trials--; > + try { > + return executeQueryInternal(sql); > + } catch (SQLException e) { > + lastException = e; > + } > + } while(autoReconnect && (block || trials > 0)); > + throw lastException; > + } > + > + /** > * Executes the given SQL query. > * > * @param sql query to execute > * @return a <code>ResultSet</code> object > * @throws SQLException if an error occurs > + * @throws RepositoryException if the database driver could not be loaded > */ > - public synchronized ResultSet executeQuery(String sql) throws > SQLException { > + private ResultSet executeQueryInternal(String sql) throws SQLException, > RepositoryException { > PreparedStatement stmt = null; > try { > stmt = (PreparedStatement) preparedStatements.get(sql); > @@ -203,8 +232,9 @@ > * @param params parameters to set > * @return the <code>Statement</code> object that had been executed > * @throws SQLException if an error occurs > + * @throws RepositoryException if the database driver could not be loaded > */ > - public synchronized Statement executeStmt(String sql, Object[] params) > throws SQLException { > + public Statement executeStmt(String sql, Object[] params) throws > SQLException, RepositoryException { > return executeStmt(sql, params, false, 0); > } > > @@ -217,8 +247,34 @@ > * @param maxRows the maximum number of rows to return (0 for all rows) > * @return the <code>Statement</code> object that had been executed > * @throws SQLException if an error occurs > + * @throws RepositoryException if the database driver could not be loaded > */ > - public synchronized Statement executeStmt(String sql, Object[] params, > boolean returnGeneratedKeys, int maxRows) throws SQLException { > + public synchronized Statement executeStmt(String sql, Object[] params, > boolean returnGeneratedKeys, int maxRows) throws SQLException, > RepositoryException { > + int trials = 2; > + SQLException lastException = null; > + do { > + trials--; > + try { > + return executeStmtInternal(sql, params, returnGeneratedKeys, > maxRows); > + } catch (SQLException e) { > + lastException = e; > + } > + } while(autoReconnect && (block || trials > 0)); > + throw lastException; > + } > + > + /** > + * Executes the given SQL statement with the specified parameters. > + * > + * @param sql statement to execute > + * @param params parameters to set > + * @param returnGeneratedKeys if the statement should return auto > generated keys > + * @param maxRows the maximum number of rows to return (0 for all rows) > + * @return the <code>Statement</code> object that had been executed > + * @throws SQLException if an error occurs > + * @throws RepositoryException if the database driver could not be loaded > + */ > + private Statement executeStmtInternal(String sql, Object[] params, > boolean returnGeneratedKeys, int maxRows) throws SQLException, > RepositoryException { > try { > String key = sql; > if (returnGeneratedKeys) { > @@ -266,14 +322,24 @@ > * Creates the database connection. > * > * @throws SQLException on error > + * @throws RepositoryException if the database driver could not be loaded > */ > - private void setupConnection() throws SQLException { > + private void setupConnection() throws SQLException, RepositoryException { > + try { > + Class driverClass = Class.forName(driver); > + // Workaround for Apache Derby: > + // The JDBC specification recommends the Class.ForName method > without the .newInstance() method call, > + // but adding the newInstance() guarantees that Derby will be > booted on any Java Virtual Machine. > + driverClass.newInstance(); > + } catch (Throwable e) { > + throw new RepositoryException("Could not load or initialize the > database driver class " + driver, e); > + } > try { > - Class.forName(driver).newInstance(); > - } catch (Exception e) { > - throw new SQLException("could not load driver: " + > e.getMessage()); > + connection = DriverManager.getConnection(url, user, password); > + } catch (SQLException e) { > + log.warn("Could not connect; driver: " + driver + " url: " + url > + " user: " + user + " error: " + e.toString(), e); > + throw e; > } > - connection = DriverManager.getConnection(url, user, password); > connection.setAutoCommit(true); > try { > DatabaseMetaData meta = connection.getMetaData(); > @@ -308,8 +374,9 @@ > * Re-establishes the database connection. > * > * @throws SQLException if reconnecting failed > + * @throws RepositoryException > */ > - private void reestablishConnection() throws SQLException { > + private void reestablishConnection() throws SQLException, > RepositoryException { > > long trials = TRIALS; > SQLException exception = null; > > >
