From 36ad3c8bebb5b216199132b06aab31e1e561fc8c Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Tue, 6 May 2008 16:10:51 +0000 Subject: Preparations for hiding JDBCRepository class. --- .../carbonado/repo/jdbc/JDBCRepositoryBuilder.java | 2 +- .../amazon/carbonado/repo/jdbc/JDBCStorage.java | 64 ++++++++++++++++------ 2 files changed, 47 insertions(+), 19 deletions(-) (limited to 'src/main/java/com/amazon/carbonado/repo/jdbc') diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepositoryBuilder.java b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepositoryBuilder.java index 0421e28..9996aac 100644 --- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepositoryBuilder.java +++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepositoryBuilder.java @@ -79,7 +79,7 @@ public class JDBCRepositoryBuilder extends AbstractRepositoryBuilder { public JDBCRepositoryBuilder() { } - public JDBCRepository build(AtomicReference rootRef) throws RepositoryException { + public Repository build(AtomicReference rootRef) throws RepositoryException { assertReady(); JDBCRepository repo = new JDBCRepository (rootRef, getName(), isMaster(), getTriggerFactories(), diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java index d89a291..dd81f90 100644 --- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java +++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java @@ -143,7 +143,7 @@ class JDBCStorage extends StandardQueryFactory return; } - Connection con = mRepository.getConnection(); + Connection con = getConnection(); try { java.sql.Statement st = con.createStatement(); try { @@ -152,9 +152,9 @@ class JDBCStorage extends StandardQueryFactory st.close(); } } catch (SQLException e) { - throw JDBCExceptionTransformer.getInstance().toPersistException(e); + throw toPersistException(e); } finally { - mRepository.yieldConnection(con); + yieldConnection(con); } } catch (FetchException e) { throw e.toPersistException(); @@ -205,6 +205,34 @@ class JDBCStorage extends StandardQueryFactory mTriggerManager.locallyEnableLoad(); } + public boolean isTransactionForUpdate() { + return mRepository.isTransactionForUpdate(); + } + + public FetchException toFetchException(Throwable e) { + return mRepository.toFetchException(e); + } + + public PersistException toPersistException(Throwable e) { + return mRepository.toPersistException(e); + } + + public boolean isUniqueConstraintError(SQLException e) { + return mRepository.isUniqueConstraintError(e); + } + + public Connection getConnection() throws FetchException { + return mRepository.getConnection(); + } + + public void yieldConnection(Connection con) throws FetchException { + mRepository.yieldConnection(con); + } + + public String getDatabaseProductName() { + return mRepository.getDatabaseProductName(); + } + /** * @param loader used to reload Blob outside original transaction */ @@ -220,7 +248,7 @@ class JDBCStorage extends StandardQueryFactory txn.register(jblob); } } catch (Exception e) { - throw mRepository.toFetchException(e); + throw toFetchException(e); } } @@ -242,7 +270,7 @@ class JDBCStorage extends StandardQueryFactory txn.register(jclob); } } catch (Exception e) { - throw mRepository.toFetchException(e); + throw toFetchException(e); } } @@ -334,7 +362,7 @@ class JDBCStorage extends StandardQueryFactory jn = jnb.getRootJoinNode(); jnb.captureOrderings(ordering); } catch (UndeclaredThrowableException e) { - throw mRepository.toFetchException(e); + throw toFetchException(e); } SQLStatementBuilder selectBuilder = new SQLStatementBuilder(mRepository); @@ -617,7 +645,7 @@ class JDBCStorage extends StandardQueryFactory public Cursor fetch(FilterValues values) throws FetchException { boolean forUpdate = mRepository.localTransactionScope().isForUpdate(); - Connection con = mRepository.getConnection(); + Connection con = getConnection(); try { PreparedStatement ps = con.prepareStatement(prepareSelect(values, forUpdate)); Integer fetchSize = mRepository.getFetchSize(); @@ -640,11 +668,11 @@ class JDBCStorage extends StandardQueryFactory } catch (Exception e) { // in case of exception, yield connection try { - mRepository.yieldConnection(con); + yieldConnection(con); } catch (FetchException e2) { // ignore and allow triggering exception to propagate } - throw mRepository.toFetchException(e); + throw toFetchException(e); } } @@ -689,7 +717,7 @@ class JDBCStorage extends StandardQueryFactory select = select.concat(" FOR UPDATE"); } - Connection con = mRepository.getConnection(); + Connection con = getConnection(); try { PreparedStatement ps = con.prepareStatement(select); Integer fetchSize = mRepository.getFetchSize(); @@ -740,17 +768,17 @@ class JDBCStorage extends StandardQueryFactory } catch (Exception e) { // in case of exception, yield connection try { - mRepository.yieldConnection(con); + yieldConnection(con); } catch (FetchException e2) { // ignore and allow triggering exception to propagate } - throw mRepository.toFetchException(e); + throw toFetchException(e); } } @Override public long count(FilterValues values) throws FetchException { - Connection con = mRepository.getConnection(); + Connection con = getConnection(); try { PreparedStatement ps = con.prepareStatement(prepareCount(values)); try { @@ -766,9 +794,9 @@ class JDBCStorage extends StandardQueryFactory ps.close(); } } catch (Exception e) { - throw mRepository.toFetchException(e); + throw toFetchException(e); } finally { - mRepository.yieldConnection(con); + yieldConnection(con); } } @@ -810,7 +838,7 @@ class JDBCStorage extends StandardQueryFactory int executeDelete(FilterValues filterValues) throws PersistException { Connection con; try { - con = mRepository.getConnection(); + con = getConnection(); } catch (FetchException e) { throw e.toPersistException(); } @@ -823,10 +851,10 @@ class JDBCStorage extends StandardQueryFactory ps.close(); } } catch (Exception e) { - throw mRepository.toPersistException(e); + throw toPersistException(e); } finally { try { - mRepository.yieldConnection(con); + yieldConnection(con); } catch (FetchException e) { throw e.toPersistException(); } -- cgit v1.2.3