From: <tho...@us...> - 2014-06-05 12:30:03
|
Revision: 8447 http://sourceforge.net/p/bigdata/code/8447 Author: thompsonbry Date: 2014-06-05 12:29:44 +0000 (Thu, 05 Jun 2014) Log Message: ----------- Added javadoc for the correct handling of the try/finally pattern for BigdataSail.getUnisolatedConnection() and to the BigdataSailRepository getConnection() and getUnisolatedConnection() methods as well. Modified Paths: -------------- branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSail.java branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailRepository.java Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSail.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSail.java 2014-06-04 20:32:18 UTC (rev 8446) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSail.java 2014-06-05 12:29:44 UTC (rev 8447) @@ -1269,10 +1269,35 @@ * returns the unisolated view of the database. Note that truth maintenance * requires only one connection at a time and is therefore not compatible * with full read/write transactions. + * <p> + * The correct pattern for obtaining an updatable connection, doing work + * with that connection, and committing or rolling back that update is as + * follows. + * + * <pre> + * + * BigdataSailConnection conn = null; + * boolean ok = false; + * try { + * conn = sail.getConnection(); + * doWork(conn); + * conn.commit(); + * ok = true; + * } finally { + * if (conn != null) { + * if (!ok) { + * conn.rollback(); + * } + * conn.close(); + * } + * } + * </pre> + * + * This pattern can also be used with {@link #getUnisolatedConnection()}. */ @Override public BigdataSailConnection getConnection() throws SailException { - + return (BigdataSailConnection) super.getConnection(); } @@ -1297,25 +1322,49 @@ */ final private ReentrantReadWriteLock lock = new ReentrantReadWriteLock(false/*fair*/); - /** - * Return an unisolated connection to the database. The unisolated - * connection supports fast, scalable updates against the database. The - * unisolated connection is ACID when used with a local {@link Journal} and - * shard-wise ACID when used with an {@link IBigdataFederation}. - * <p> - * In order to guarantee that operations against the unisolated connection - * are ACID, only one of unisolated connection is permitted at a time for a - * {@link Journal} and this method will block until the connection is - * available. If there is an open unisolated connection against a local - * {@link Journal}, then the open connection must be closed before a new - * connection can be returned by this method. - * <p> - * This constraint that there can be only one unisolated connection is not - * enforced in scale-out since unisolated operations in scale-out are only - * shard-wise ACID. - * - * @return The unisolated connection to the database - */ + /** + * Return an unisolated connection to the database. The unisolated + * connection supports fast, scalable updates against the database. The + * unisolated connection is ACID when used with a local {@link Journal} and + * shard-wise ACID when used with an {@link IBigdataFederation}. + * <p> + * In order to guarantee that operations against the unisolated connection + * are ACID, only one of unisolated connection is permitted at a time for a + * {@link Journal} and this method will block until the connection is + * available. If there is an open unisolated connection against a local + * {@link Journal}, then the open connection must be closed before a new + * connection can be returned by this method. + * <p> + * This constraint that there can be only one unisolated connection is not + * enforced in scale-out since unisolated operations in scale-out are only + * shard-wise ACID. + * <p> + * The correct pattern for obtaining an updatable connection, doing work + * with that connection, and committing or rolling back that update is as + * follows. + * + * <pre> + * BigdataSailConnection conn = null; + * boolean ok = false; + * try { + * conn = sail.getUnisolatedConnection(); + * doWork(conn); + * conn.commit(); + * ok = true; + * } finally { + * if (conn != null) { + * if (!ok) { + * conn.rollback(); + * } + * conn.close(); + * } + * } + * </pre> + * + * @return The unisolated connection to the database + * + * @see #getConnection() + */ public BigdataSailConnection getUnisolatedConnection() throws InterruptedException { Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailRepository.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailRepository.java 2014-06-04 20:32:18 UTC (rev 8446) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailRepository.java 2014-06-05 12:29:44 UTC (rev 8447) @@ -33,6 +33,35 @@ // // } + /** + * {@inheritDoc} + * <p> + * The correct pattern for obtaining an updatable connection, doing work + * with that connection, and committing or rolling back that update is as + * follows. + * + * <pre> + * + * BigdataSailConnection conn = null; + * boolean ok = false; + * try { + * conn = repo.getConnection(); + * doWork(conn); + * conn.commit(); + * ok = true; + * } finally { + * if (conn != null) { + * if (!ok) { + * conn.rollback(); + * } + * conn.close(); + * } + * } + * </pre> + * + * @see BigdataSail#getConnection() + * @see #getUnisolatedConnection() + */ @Override public BigdataSailRepositoryConnection getConnection() throws RepositoryException { @@ -105,12 +134,36 @@ } /** - * Return an unisolated connection to the database. Only one of these + * Return an unisolated connection to the database. Only one of these * allowed at a time. + * <p> + * The correct pattern for obtaining an updatable connection, doing work + * with that connection, and committing or rolling back that update is as + * follows. * + * <pre> + * + * BigdataSailConnection conn = null; + * boolean ok = false; + * try { + * conn = repo.getConnection(); + * doWork(conn); + * conn.commit(); + * ok = true; + * } finally { + * if (conn != null) { + * if (!ok) { + * conn.rollback(); + * } + * conn.close(); + * } + * } + * </pre> + * * @return unisolated connection to the database * * @see BigdataSail#getUnisolatedConnection() + * @see #getConnection() */ public BigdataSailRepositoryConnection getUnisolatedConnection() throws RepositoryException { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |