You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2018/06/13 17:28:59 UTC
[37/50] [abbrv] commons-dbcp git commit: Line length 120.
http://git-wip-us.apache.org/repos/asf/commons-dbcp/blob/d5a24430/src/main/java/org/apache/commons/dbcp2/DelegatingStatement.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/dbcp2/DelegatingStatement.java b/src/main/java/org/apache/commons/dbcp2/DelegatingStatement.java
index 1442536..098950d 100644
--- a/src/main/java/org/apache/commons/dbcp2/DelegatingStatement.java
+++ b/src/main/java/org/apache/commons/dbcp2/DelegatingStatement.java
@@ -26,15 +26,11 @@ import java.util.List;
/**
* A base delegating implementation of {@link Statement}.
* <p>
- * All of the methods from the {@link Statement} interface
- * simply check to see that the {@link Statement} is active,
- * and call the corresponding method on the "delegate"
- * provided in my constructor.
+ * All of the methods from the {@link Statement} interface simply check to see that the {@link Statement} is active, and
+ * call the corresponding method on the "delegate" provided in my constructor.
* <p>
- * Extends AbandonedTrace to implement Statement tracking and
- * logging of code which created the Statement. Tracking the
- * Statement ensures that the Connection which created it can
- * close any open Statement's on Connection close.
+ * Extends AbandonedTrace to implement Statement tracking and logging of code which created the Statement. Tracking the
+ * Statement ensures that the Connection which created it can close any open Statement's on Connection close.
*
* @since 2.0
*/
@@ -71,7 +67,6 @@ public class DelegatingStatement extends AbandonedTrace implements Statement {
return statement;
}
-
/**
* If my underlying {@link Statement} is not a {@code DelegatingStatement}, returns it, otherwise recursively
* invokes this method on my delegate.
@@ -83,6 +78,7 @@ public class DelegatingStatement extends AbandonedTrace implements Statement {
* This method is useful when you may have nested {@code DelegatingStatement}s, and you want to make sure to obtain
* a "genuine" {@link Statement}.
* </p>
+ *
* @return The innermost delegate.
*
* @see #getDelegate
@@ -101,7 +97,8 @@ public class DelegatingStatement extends AbandonedTrace implements Statement {
/**
* Sets my delegate.
*
- * @param statement my delegate.
+ * @param statement
+ * my delegate.
*/
public void setDelegate(final Statement statement) {
this.statement = statement;
@@ -118,10 +115,8 @@ public class DelegatingStatement extends AbandonedTrace implements Statement {
}
protected void checkOpen() throws SQLException {
- if(isClosed()) {
- throw new SQLException
- (this.getClass().getName() + " with address: \"" +
- this.toString() + "\" is closed.");
+ if (isClosed()) {
+ throw new SQLException(this.getClass().getName() + " with address: \"" + this.toString() + "\" is closed.");
}
}
@@ -168,8 +163,7 @@ public class DelegatingStatement extends AbandonedTrace implements Statement {
protected void handleException(final SQLException e) throws SQLException {
if (connection != null) {
connection.handleException(e);
- }
- else {
+ } else {
throw e;
}
}
@@ -215,9 +209,8 @@ public class DelegatingStatement extends AbandonedTrace implements Statement {
connection.setLastUsed();
}
try {
- return DelegatingResultSet.wrapResultSet(this,statement.executeQuery(sql));
- }
- catch (final SQLException e) {
+ return DelegatingResultSet.wrapResultSet(this, statement.executeQuery(sql));
+ } catch (final SQLException e) {
handleException(e);
throw new AssertionError();
}
@@ -227,9 +220,8 @@ public class DelegatingStatement extends AbandonedTrace implements Statement {
public ResultSet getResultSet() throws SQLException {
checkOpen();
try {
- return DelegatingResultSet.wrapResultSet(this,statement.getResultSet());
- }
- catch (final SQLException e) {
+ return DelegatingResultSet.wrapResultSet(this, statement.getResultSet());
+ } catch (final SQLException e) {
handleException(e);
throw new AssertionError();
}
@@ -244,7 +236,8 @@ public class DelegatingStatement extends AbandonedTrace implements Statement {
try {
return statement.executeUpdate(sql);
} catch (final SQLException e) {
- handleException(e); return 0;
+ handleException(e);
+ return 0;
}
}
@@ -631,7 +624,6 @@ public class DelegatingStatement extends AbandonedTrace implements Statement {
return closed;
}
-
@Override
public boolean isWrapperFor(final Class<?> iface) throws SQLException {
if (iface.isAssignableFrom(getClass())) {
@@ -659,8 +651,7 @@ public class DelegatingStatement extends AbandonedTrace implements Statement {
checkOpen();
try {
statement.setPoolable(poolable);
- }
- catch (final SQLException e) {
+ } catch (final SQLException e) {
handleException(e);
}
}
@@ -670,8 +661,7 @@ public class DelegatingStatement extends AbandonedTrace implements Statement {
checkOpen();
try {
return statement.isPoolable();
- }
- catch (final SQLException e) {
+ } catch (final SQLException e) {
handleException(e);
return false;
}
http://git-wip-us.apache.org/repos/asf/commons-dbcp/blob/d5a24430/src/main/java/org/apache/commons/dbcp2/DriverManagerConnectionFactory.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/dbcp2/DriverManagerConnectionFactory.java b/src/main/java/org/apache/commons/dbcp2/DriverManagerConnectionFactory.java
index f9b1561..7c62ed5 100644
--- a/src/main/java/org/apache/commons/dbcp2/DriverManagerConnectionFactory.java
+++ b/src/main/java/org/apache/commons/dbcp2/DriverManagerConnectionFactory.java
@@ -16,6 +16,7 @@
*/
package org.apache.commons.dbcp2;
+
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
@@ -37,11 +38,11 @@ public class DriverManagerConnectionFactory implements ConnectionFactory {
DriverManager.getDrivers();
}
-
/**
* Constructor for DriverManagerConnectionFactory.
- * @param connectionUri a database url of the form
- * <code> jdbc:<em>subprotocol</em>:<em>subname</em></code>
+ *
+ * @param connectionUri
+ * a database url of the form <code> jdbc:<em>subprotocol</em>:<em>subname</em></code>
* @since 2.2
*/
public DriverManagerConnectionFactory(final String connectionUri) {
@@ -51,11 +52,12 @@ public class DriverManagerConnectionFactory implements ConnectionFactory {
/**
* Constructor for DriverManagerConnectionFactory.
- * @param connectionUri a database url of the form
- * <code> jdbc:<em>subprotocol</em>:<em>subname</em></code>
- * @param properties a list of arbitrary string tag/value pairs as
- * connection arguments; normally at least a "user" and "password"
- * property should be included.
+ *
+ * @param connectionUri
+ * a database url of the form <code> jdbc:<em>subprotocol</em>:<em>subname</em></code>
+ * @param properties
+ * a list of arbitrary string tag/value pairs as connection arguments; normally at least a "user" and
+ * "password" property should be included.
*/
public DriverManagerConnectionFactory(final String connectionUri, final Properties properties) {
this.connectionUri = connectionUri;
@@ -64,12 +66,16 @@ public class DriverManagerConnectionFactory implements ConnectionFactory {
/**
* Constructor for DriverManagerConnectionFactory.
- * @param connectionUri a database url of the form
- * <code>jdbc:<em>subprotocol</em>:<em>subname</em></code>
- * @param userName the database user
- * @param userPassword the user's password
+ *
+ * @param connectionUri
+ * a database url of the form <code>jdbc:<em>subprotocol</em>:<em>subname</em></code>
+ * @param userName
+ * the database user
+ * @param userPassword
+ * the user's password
*/
- public DriverManagerConnectionFactory(final String connectionUri, final String userName, final String userPassword) {
+ public DriverManagerConnectionFactory(final String connectionUri, final String userName,
+ final String userPassword) {
this.connectionUri = connectionUri;
this.userName = userName;
this.userPassword = userPassword;
http://git-wip-us.apache.org/repos/asf/commons-dbcp/blob/d5a24430/src/main/java/org/apache/commons/dbcp2/LifetimeExceededException.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/dbcp2/LifetimeExceededException.java b/src/main/java/org/apache/commons/dbcp2/LifetimeExceededException.java
index 3e60818..3c69a54 100644
--- a/src/main/java/org/apache/commons/dbcp2/LifetimeExceededException.java
+++ b/src/main/java/org/apache/commons/dbcp2/LifetimeExceededException.java
@@ -21,7 +21,7 @@ package org.apache.commons.dbcp2;
*
* @since 2.1
*/
- class LifetimeExceededException extends Exception {
+class LifetimeExceededException extends Exception {
private static final long serialVersionUID = -3783783104516492659L;
@@ -35,7 +35,8 @@ package org.apache.commons.dbcp2;
/**
* Create a LifetimeExceededException with the given message.
*
- * @param message The message with which to create the exception
+ * @param message
+ * The message with which to create the exception
*/
public LifetimeExceededException(final String message) {
super(message);
http://git-wip-us.apache.org/repos/asf/commons-dbcp/blob/d5a24430/src/main/java/org/apache/commons/dbcp2/PoolableCallableStatement.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/dbcp2/PoolableCallableStatement.java b/src/main/java/org/apache/commons/dbcp2/PoolableCallableStatement.java
index b9dccad..969a7e1 100644
--- a/src/main/java/org/apache/commons/dbcp2/PoolableCallableStatement.java
+++ b/src/main/java/org/apache/commons/dbcp2/PoolableCallableStatement.java
@@ -26,8 +26,8 @@ import java.util.List;
import org.apache.commons.pool2.KeyedObjectPool;
/**
- * A {@link DelegatingCallableStatement} that cooperates with
- * {@link PoolingConnection} to implement a pool of {@link CallableStatement}s.
+ * A {@link DelegatingCallableStatement} that cooperates with {@link PoolingConnection} to implement a pool of
+ * {@link CallableStatement}s.
* <p>
* The {@link #close} method returns this statement to its containing pool. (See {@link PoolingConnection}.)
*
@@ -49,10 +49,14 @@ public class PoolableCallableStatement extends DelegatingCallableStatement {
/**
* Constructor.
*
- * @param callableStatement the underlying {@link CallableStatement}
- * @param key the key for this statement in the {@link KeyedObjectPool}
- * @param pool the {@link KeyedObjectPool} from which this CallableStatement was obtained
- * @param connection the {@link DelegatingConnection} that created this CallableStatement
+ * @param callableStatement
+ * the underlying {@link CallableStatement}
+ * @param key
+ * the key for this statement in the {@link KeyedObjectPool}
+ * @param pool
+ * the {@link KeyedObjectPool} from which this CallableStatement was obtained
+ * @param connection
+ * the {@link DelegatingConnection} that created this CallableStatement
*/
public PoolableCallableStatement(final CallableStatement callableStatement, final PStmtKey key,
final KeyedObjectPool<PStmtKey, DelegatingPreparedStatement> pool,
@@ -69,7 +73,7 @@ public class PoolableCallableStatement extends DelegatingCallableStatement {
}
/**
- * Returns the CallableStatement to the pool. If {{@link #isClosed()}, this is a No-op.
+ * Returns the CallableStatement to the pool. If {{@link #isClosed()}, this is a No-op.
*/
@Override
public void close() throws SQLException {
@@ -88,8 +92,8 @@ public class PoolableCallableStatement extends DelegatingCallableStatement {
}
/**
- * Activates after retrieval from the pool. Adds a trace for this CallableStatement to the Connection
- * that created it.
+ * Activates after retrieval from the pool. Adds a trace for this CallableStatement to the Connection that created
+ * it.
*
* @since 2.4.0 made public, was protected in 2.3.0.
*/
@@ -103,8 +107,8 @@ public class PoolableCallableStatement extends DelegatingCallableStatement {
}
/**
- * Passivates to prepare for return to the pool. Removes the trace associated with this CallableStatement
- * from the Connection that created it. Also closes any associated ResultSets.
+ * Passivates to prepare for return to the pool. Removes the trace associated with this CallableStatement from the
+ * Connection that created it. Also closes any associated ResultSets.
*
* @since 2.4.0 made public, was protected in 2.3.0.
*/
http://git-wip-us.apache.org/repos/asf/commons-dbcp/blob/d5a24430/src/main/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java b/src/main/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java
index a948d78..5d3c396 100644
--- a/src/main/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java
+++ b/src/main/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java
@@ -53,8 +53,7 @@ public class PoolableConnectionFactory implements PooledObjectFactory<PoolableCo
* @param dataSourceJmxObjectName
* The JMX object name, may be null.
*/
- public PoolableConnectionFactory(final ConnectionFactory connFactory,
- final ObjectName dataSourceJmxObjectName) {
+ public PoolableConnectionFactory(final ConnectionFactory connFactory, final ObjectName dataSourceJmxObjectName) {
this.connectionFactory = connFactory;
this.dataSourceJmxObjectName = dataSourceJmxObjectName;
}
@@ -199,7 +198,6 @@ public class PoolableConnectionFactory implements PooledObjectFactory<PoolableCo
this.maxConnLifetimeMillis = maxConnLifetimeMillis;
}
-
public boolean isEnableAutoCommitOnReturn() {
return enableAutoCommitOnReturn;
}
@@ -208,7 +206,6 @@ public class PoolableConnectionFactory implements PooledObjectFactory<PoolableCo
this.enableAutoCommitOnReturn = enableAutoCommitOnReturn;
}
-
public boolean isRollbackOnReturn() {
return rollbackOnReturn;
}
@@ -326,7 +323,8 @@ public class PoolableConnectionFactory implements PooledObjectFactory<PoolableCo
if (dataSourceJmxObjectName == null) {
connJmxName = null;
} else {
- connJmxName = new ObjectName(dataSourceJmxObjectName.toString() + Constants.JMX_CONNECTION_BASE_EXT + connIndex);
+ connJmxName = new ObjectName(
+ dataSourceJmxObjectName.toString() + Constants.JMX_CONNECTION_BASE_EXT + connIndex);
}
final PoolableConnection pc = new PoolableConnection(conn, pool, connJmxName, disconnectionSqlCodes,
@@ -352,8 +350,7 @@ public class PoolableConnectionFactory implements PooledObjectFactory<PoolableCo
}
@Override
- public void destroyObject(final PooledObject<PoolableConnection> p)
- throws Exception {
+ public void destroyObject(final PooledObject<PoolableConnection> p) throws Exception {
p.getObject().reallyClose();
}
@@ -366,8 +363,7 @@ public class PoolableConnectionFactory implements PooledObjectFactory<PoolableCo
return true;
} catch (final Exception e) {
if (log.isDebugEnabled()) {
- log.debug(Utils.getMessage(
- "poolableConnectionFactory.validateObject.fail"), e);
+ log.debug(Utils.getMessage("poolableConnectionFactory.validateObject.fail"), e);
}
return false;
}
@@ -438,10 +434,8 @@ public class PoolableConnectionFactory implements PooledObjectFactory<PoolableCo
if (maxConnLifetimeMillis > 0) {
final long lifetime = System.currentTimeMillis() - p.getCreateTime();
if (lifetime > maxConnLifetimeMillis) {
- throw new LifetimeExceededException(Utils.getMessage(
- "connectionFactory.lifetimeExceeded",
- Long.valueOf(lifetime),
- Long.valueOf(maxConnLifetimeMillis)));
+ throw new LifetimeExceededException(Utils.getMessage("connectionFactory.lifetimeExceeded",
+ Long.valueOf(lifetime), Long.valueOf(maxConnLifetimeMillis)));
}
}
}
http://git-wip-us.apache.org/repos/asf/commons-dbcp/blob/d5a24430/src/main/java/org/apache/commons/dbcp2/PoolableConnectionMXBean.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/dbcp2/PoolableConnectionMXBean.java b/src/main/java/org/apache/commons/dbcp2/PoolableConnectionMXBean.java
index fa3e95a..1601ab4 100644
--- a/src/main/java/org/apache/commons/dbcp2/PoolableConnectionMXBean.java
+++ b/src/main/java/org/apache/commons/dbcp2/PoolableConnectionMXBean.java
@@ -19,41 +19,52 @@ package org.apache.commons.dbcp2;
import java.sql.SQLException;
/**
- * Defines the attributes and methods that will be exposed via JMX for
- * {@link PoolableConnection} instances.
+ * Defines the attributes and methods that will be exposed via JMX for {@link PoolableConnection} instances.
+ *
* @since 2.0
*/
public interface PoolableConnectionMXBean {
// Read-only properties
boolean isClosed() throws SQLException;
- //SQLWarning getWarnings() throws SQLException;
+
+ // SQLWarning getWarnings() throws SQLException;
String getToString();
// Read-write properties
boolean getAutoCommit() throws SQLException;
+
void setAutoCommit(boolean autoCommit) throws SQLException;
boolean getCacheState();
+
void setCacheState(boolean cacheState);
String getCatalog() throws SQLException;
+
void setCatalog(String catalog) throws SQLException;
int getHoldability() throws SQLException;
+
void setHoldability(int holdability) throws SQLException;
boolean isReadOnly() throws SQLException;
+
void setReadOnly(boolean readOnly) throws SQLException;
String getSchema() throws SQLException;
+
void setSchema(String schema) throws SQLException;
int getTransactionIsolation() throws SQLException;
+
void setTransactionIsolation(int level) throws SQLException;
// Methods
void clearCachedState();
+
void clearWarnings() throws SQLException;
+
void close() throws SQLException;
+
void reallyClose() throws SQLException;
}
http://git-wip-us.apache.org/repos/asf/commons-dbcp/blob/d5a24430/src/main/java/org/apache/commons/dbcp2/PoolablePreparedStatement.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/dbcp2/PoolablePreparedStatement.java b/src/main/java/org/apache/commons/dbcp2/PoolablePreparedStatement.java
index 94bc92c..21676b6 100644
--- a/src/main/java/org/apache/commons/dbcp2/PoolablePreparedStatement.java
+++ b/src/main/java/org/apache/commons/dbcp2/PoolablePreparedStatement.java
@@ -25,12 +25,13 @@ import java.util.List;
import org.apache.commons.pool2.KeyedObjectPool;
/**
- * A {@link DelegatingPreparedStatement} that cooperates with
- * {@link PoolingConnection} to implement a pool of {@link PreparedStatement}s.
+ * A {@link DelegatingPreparedStatement} that cooperates with {@link PoolingConnection} to implement a pool of
+ * {@link PreparedStatement}s.
* <p>
* My {@link #close} method returns me to my containing pool. (See {@link PoolingConnection}.)
*
- * @param <K> the key type
+ * @param <K>
+ * the key type
*
* @see PoolingConnection
* @since 2.0
@@ -50,21 +51,25 @@ public class PoolablePreparedStatement<K> extends DelegatingPreparedStatement {
/**
* Constructor
- * @param stmt my underlying {@link PreparedStatement}
- * @param key my key" as used by {@link KeyedObjectPool}
- * @param pool the {@link KeyedObjectPool} from which I was obtained.
- * @param conn the {@link java.sql.Connection Connection} from which I was created
+ *
+ * @param stmt
+ * my underlying {@link PreparedStatement}
+ * @param key
+ * my key" as used by {@link KeyedObjectPool}
+ * @param pool
+ * the {@link KeyedObjectPool} from which I was obtained.
+ * @param conn
+ * the {@link java.sql.Connection Connection} from which I was created
*/
public PoolablePreparedStatement(final PreparedStatement stmt, final K key,
- final KeyedObjectPool<K, PoolablePreparedStatement<K>> pool,
- final DelegatingConnection<?> conn) {
+ final KeyedObjectPool<K, PoolablePreparedStatement<K>> pool, final DelegatingConnection<?> conn) {
super(conn, stmt);
this.pool = pool;
this.key = key;
// Remove from trace now because this statement will be
// added by the activate method.
- if(getConnectionInternal() != null) {
+ if (getConnectionInternal() != null) {
getConnectionInternal().removeTrace(this);
}
}
@@ -96,20 +101,20 @@ public class PoolablePreparedStatement<K> extends DelegatingPreparedStatement {
if (!isClosed()) {
try {
pool.returnObject(key, this);
- } catch(final SQLException e) {
+ } catch (final SQLException e) {
throw e;
- } catch(final RuntimeException e) {
+ } catch (final RuntimeException e) {
throw e;
- } catch(final Exception e) {
+ } catch (final Exception e) {
throw new SQLException("Cannot close preparedstatement (return to pool failed)", e);
}
}
}
@Override
- public void activate() throws SQLException{
+ public void activate() throws SQLException {
setClosedInternal(false);
- if(getConnectionInternal() != null) {
+ if (getConnectionInternal() != null) {
getConnectionInternal().addTrace(this);
}
super.activate();
@@ -123,7 +128,7 @@ public class PoolablePreparedStatement<K> extends DelegatingPreparedStatement {
clearBatch();
}
setClosedInternal(true);
- if(getConnectionInternal() != null) {
+ if (getConnectionInternal() != null) {
getConnectionInternal().removeTrace(this);
}
@@ -132,7 +137,7 @@ public class PoolablePreparedStatement<K> extends DelegatingPreparedStatement {
// FIXME The PreparedStatement we're wrapping should handle this for us.
// See bug 17301 for what could happen when ResultSets are closed twice.
final List<AbandonedTrace> resultSets = getTrace();
- if( resultSets != null) {
+ if (resultSets != null) {
final ResultSet[] set = resultSets.toArray(new ResultSet[resultSets.size()]);
for (final ResultSet element : set) {
element.close();
http://git-wip-us.apache.org/repos/asf/commons-dbcp/blob/d5a24430/src/main/java/org/apache/commons/dbcp2/PoolingDataSource.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/dbcp2/PoolingDataSource.java b/src/main/java/org/apache/commons/dbcp2/PoolingDataSource.java
index d28f7a4..114b704 100644
--- a/src/main/java/org/apache/commons/dbcp2/PoolingDataSource.java
+++ b/src/main/java/org/apache/commons/dbcp2/PoolingDataSource.java
@@ -55,9 +55,10 @@ public class PoolingDataSource<C extends Connection> implements DataSource, Auto
public PoolingDataSource(final ObjectPool<C> pool) {
Objects.requireNonNull(pool, "Pool must not be null.");
this.pool = pool;
- // Verify that pool's factory refers back to it. If not, log a warning and try to fix.
+ // Verify that pool's factory refers back to it. If not, log a warning and try to fix.
if (this.pool instanceof GenericObjectPool<?>) {
- final PoolableConnectionFactory pcf = (PoolableConnectionFactory) ((GenericObjectPool<?>) this.pool).getFactory();
+ final PoolableConnectionFactory pcf = (PoolableConnectionFactory) ((GenericObjectPool<?>) this.pool)
+ .getFactory();
Objects.requireNonNull(pcf, "PoolableConnectionFactory must not be null.");
if (pcf.getPool() != this.pool) {
log.warn(Utils.getMessage("poolingDataSource.factoryConfig"));
@@ -77,9 +78,9 @@ public class PoolingDataSource<C extends Connection> implements DataSource, Auto
public void close() throws Exception {
try {
pool.close();
- } catch(final RuntimeException rte) {
+ } catch (final RuntimeException rte) {
throw new RuntimeException(Utils.getMessage("pool.close.fail"), rte);
- } catch(final Exception e) {
+ } catch (final Exception e) {
throw new SQLException(Utils.getMessage("pool.close.fail"), e);
}
}
@@ -121,7 +122,7 @@ public class PoolingDataSource<C extends Connection> implements DataSource, Auto
throw new SQLFeatureNotSupportedException();
}
- //--- DataSource methods -----------------------------------------
+ // --- DataSource methods -----------------------------------------
/**
* Returns a {@link java.sql.Connection} from my pool, according to the contract specified by
@@ -135,17 +136,17 @@ public class PoolingDataSource<C extends Connection> implements DataSource, Auto
return null;
}
return new PoolGuardConnectionWrapper<>(conn);
- } catch(final SQLException e) {
+ } catch (final SQLException e) {
throw e;
- } catch(final NoSuchElementException e) {
+ } catch (final NoSuchElementException e) {
throw new SQLException("Cannot get a connection, pool error " + e.getMessage(), e);
- } catch(final RuntimeException e) {
+ } catch (final RuntimeException e) {
throw e;
- } catch(final InterruptedException e) {
+ } catch (final InterruptedException e) {
// Reset the interrupt status so it is visible to callers
Thread.currentThread().interrupt();
throw new SQLException("Cannot get a connection, general error", e);
- } catch(final Exception e) {
+ } catch (final Exception e) {
throw new SQLException("Cannot get a connection, general error", e);
}
}
@@ -153,7 +154,8 @@ public class PoolingDataSource<C extends Connection> implements DataSource, Auto
/**
* Throws {@link UnsupportedOperationException}
*
- * @throws UnsupportedOperationException always thrown
+ * @throws UnsupportedOperationException
+ * always thrown
*/
@Override
public Connection getConnection(final String uname, final String passwd) throws SQLException {
@@ -217,8 +219,7 @@ public class PoolingDataSource<C extends Connection> implements DataSource, Auto
*
* @since 2.0
*/
- private class PoolGuardConnectionWrapper<D extends Connection>
- extends DelegatingConnection<D> {
+ private class PoolGuardConnectionWrapper<D extends Connection> extends DelegatingConnection<D> {
PoolGuardConnectionWrapper(final D delegate) {
super(delegate);
http://git-wip-us.apache.org/repos/asf/commons-dbcp/blob/d5a24430/src/main/java/org/apache/commons/dbcp2/PoolingDriver.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/dbcp2/PoolingDriver.java b/src/main/java/org/apache/commons/dbcp2/PoolingDriver.java
index 87ff2ba..ab33596 100644
--- a/src/main/java/org/apache/commons/dbcp2/PoolingDriver.java
+++ b/src/main/java/org/apache/commons/dbcp2/PoolingDriver.java
@@ -30,11 +30,8 @@ import java.util.logging.Logger;
import org.apache.commons.pool2.ObjectPool;
-
/**
- * A {@link Driver} implementation that obtains
- * {@link Connection}s from a registered
- * {@link ObjectPool}.
+ * A {@link Driver} implementation that obtains {@link Connection}s from a registered {@link ObjectPool}.
*
* @since 2.0
*/
@@ -44,14 +41,13 @@ public class PoolingDriver implements Driver {
static {
try {
DriverManager.registerDriver(new PoolingDriver());
- } catch(final Exception e) {
+ } catch (final Exception e) {
// ignore
}
}
/** The map of registered pools. */
- protected static final HashMap<String, ObjectPool<? extends Connection>> pools =
- new HashMap<>();
+ protected static final HashMap<String, ObjectPool<? extends Connection>> pools = new HashMap<>();
/** Controls access to the underlying connection */
private final boolean accessToUnderlyingConnectionAllowed;
@@ -70,7 +66,6 @@ public class PoolingDriver implements Driver {
this.accessToUnderlyingConnectionAllowed = accessToUnderlyingConnectionAllowed;
}
-
/**
* Returns the value of the accessToUnderlyingConnectionAllowed property.
*
@@ -89,8 +84,7 @@ public class PoolingDriver implements Driver {
* @throws SQLException
* Thrown when the named pool is not registered.
*/
- public synchronized ObjectPool<? extends Connection> getConnectionPool(final String name)
- throws SQLException {
+ public synchronized ObjectPool<? extends Connection> getConnectionPool(final String name) throws SQLException {
final ObjectPool<? extends Connection> pool = pools.get(name);
if (null == pool) {
throw new SQLException("Pool not registered: " + name);
@@ -106,8 +100,7 @@ public class PoolingDriver implements Driver {
* @param pool
* The pool.
*/
- public synchronized void registerPool(final String name,
- final ObjectPool<? extends Connection> pool) {
+ public synchronized void registerPool(final String name, final ObjectPool<? extends Connection> pool) {
pools.put(name, pool);
}
@@ -126,8 +119,7 @@ public class PoolingDriver implements Driver {
pools.remove(name);
try {
pool.close();
- }
- catch (final Exception e) {
+ } catch (final Exception e) {
throw new SQLException("Error closing pool " + name, e);
}
}
@@ -138,7 +130,7 @@ public class PoolingDriver implements Driver {
*
* @return the pool names.
*/
- public synchronized String[] getPoolNames(){
+ public synchronized String[] getPoolNames() {
final Set<String> names = pools.keySet();
return names.toArray(new String[names.size()]);
}
@@ -150,9 +142,8 @@ public class PoolingDriver implements Driver {
@Override
public Connection connect(final String url, final Properties info) throws SQLException {
- if(acceptsURL(url)) {
- final ObjectPool<? extends Connection> pool =
- getConnectionPool(url.substring(URL_PREFIX_LEN));
+ if (acceptsURL(url)) {
+ final ObjectPool<? extends Connection> pool = getConnectionPool(url.substring(URL_PREFIX_LEN));
try {
final Connection conn = pool.borrowObject();
@@ -160,13 +151,13 @@ public class PoolingDriver implements Driver {
return null;
}
return new PoolGuardConnectionWrapper(pool, conn);
- } catch(final SQLException e) {
+ } catch (final SQLException e) {
throw e;
- } catch(final NoSuchElementException e) {
+ } catch (final NoSuchElementException e) {
throw new SQLException("Cannot get a connection, pool error: " + e.getMessage(), e);
- } catch(final RuntimeException e) {
+ } catch (final RuntimeException e) {
throw e;
- } catch(final Exception e) {
+ } catch (final Exception e) {
throw new SQLException("Cannot get a connection, general error: " + e.getMessage(), e);
}
}
@@ -181,25 +172,23 @@ public class PoolingDriver implements Driver {
/**
* Invalidates the given connection.
*
- * @param conn connection to invalidate
- * @throws SQLException if the connection is not a
- * <code>PoolGuardConnectionWrapper</code> or an error occurs invalidating
- * the connection
+ * @param conn
+ * connection to invalidate
+ * @throws SQLException
+ * if the connection is not a <code>PoolGuardConnectionWrapper</code> or an error occurs invalidating
+ * the connection
*/
public void invalidateConnection(final Connection conn) throws SQLException {
if (conn instanceof PoolGuardConnectionWrapper) { // normal case
final PoolGuardConnectionWrapper pgconn = (PoolGuardConnectionWrapper) conn;
@SuppressWarnings("unchecked")
- final
- ObjectPool<Connection> pool = (ObjectPool<Connection>) pgconn.pool;
+ final ObjectPool<Connection> pool = (ObjectPool<Connection>) pgconn.pool;
try {
pool.invalidateObject(pgconn.getDelegateInternal());
- }
- catch (final Exception e) {
+ } catch (final Exception e) {
// Ignore.
}
- }
- else {
+ } else {
throw new SQLException("Invalid connection class");
}
}
@@ -233,16 +222,15 @@ public class PoolingDriver implements Driver {
protected static final int MINOR_VERSION = 0;
/**
- * PoolGuardConnectionWrapper is a Connection wrapper that makes sure a
- * closed connection cannot be used anymore.
+ * PoolGuardConnectionWrapper is a Connection wrapper that makes sure a closed connection cannot be used anymore.
+ *
* @since 2.0
*/
private class PoolGuardConnectionWrapper extends DelegatingConnection<Connection> {
private final ObjectPool<? extends Connection> pool;
- PoolGuardConnectionWrapper(final ObjectPool<? extends Connection> pool,
- final Connection delegate) {
+ PoolGuardConnectionWrapper(final ObjectPool<? extends Connection> pool, final Connection delegate) {
super(delegate);
this.pool = pool;
}
http://git-wip-us.apache.org/repos/asf/commons-dbcp/blob/d5a24430/src/main/java/org/apache/commons/dbcp2/SwallowedExceptionLogger.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/dbcp2/SwallowedExceptionLogger.java b/src/main/java/org/apache/commons/dbcp2/SwallowedExceptionLogger.java
index 0c793d5..3319a92 100644
--- a/src/main/java/org/apache/commons/dbcp2/SwallowedExceptionLogger.java
+++ b/src/main/java/org/apache/commons/dbcp2/SwallowedExceptionLogger.java
@@ -21,29 +21,31 @@ import org.apache.commons.pool2.SwallowedExceptionListener;
/**
* Class for logging swallowed exceptions.
+ *
* @since 2.0
*/
-public class SwallowedExceptionLogger implements SwallowedExceptionListener{
+public class SwallowedExceptionLogger implements SwallowedExceptionListener {
private final Log log;
private final boolean logExpiredConnections;
/**
- * Create a SwallowedExceptionLogger with the given logger. By default,
- * expired connection logging is turned on.
+ * Create a SwallowedExceptionLogger with the given logger. By default, expired connection logging is turned on.
*
- * @param log logger
+ * @param log
+ * logger
*/
public SwallowedExceptionLogger(final Log log) {
this(log, true);
}
/**
- * Create a SwallowedExceptionLogger with the given logger and expired
- * connection logging property.
+ * Create a SwallowedExceptionLogger with the given logger and expired connection logging property.
*
- * @param log logger
- * @param logExpiredConnections false suppresses logging of expired connection events
+ * @param log
+ * logger
+ * @param logExpiredConnections
+ * false suppresses logging of expired connection events
*/
public SwallowedExceptionLogger(final Log log, final boolean logExpiredConnections) {
this.log = log;
@@ -53,8 +55,7 @@ public class SwallowedExceptionLogger implements SwallowedExceptionListener{
@Override
public void onSwallowException(final Exception e) {
if (logExpiredConnections || !(e instanceof LifetimeExceededException)) {
- log.warn(Utils.getMessage(
- "swallowedExceptionLogger.onSwallowedException"), e);
+ log.warn(Utils.getMessage("swallowedExceptionLogger.onSwallowedException"), e);
}
}
}
http://git-wip-us.apache.org/repos/asf/commons-dbcp/blob/d5a24430/src/main/java/org/apache/commons/dbcp2/package-info.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/dbcp2/package-info.java b/src/main/java/org/apache/commons/dbcp2/package-info.java
index ecc2489..eddaf06 100644
--- a/src/main/java/org/apache/commons/dbcp2/package-info.java
+++ b/src/main/java/org/apache/commons/dbcp2/package-info.java
@@ -17,115 +17,116 @@
/**
* <p>
- * Database Connection Pool API.
+ * Database Connection Pool API.
* </p>
*
* <b>Overview in Dialog Form</b>
* <p>
- * Q: How do I use the DBCP package?
- * </p><p>
- * A: There are two primary ways to access the DBCP pool, as a
- * {@link java.sql.Driver Driver}, or as a {@link javax.sql.DataSource DataSource}.
- * You'll want to create an instance of {@link org.apache.commons.dbcp2.PoolingDriver} or
- * {@link org.apache.commons.dbcp2.PoolingDataSource}. When using one of these
- * interfaces, you can just use your JDBC objects the way you normally would.
- * Closing a {@link java.sql.Connection} will simply return it to its pool.
- * </p>
- * <p>
- * Q: But {@link org.apache.commons.dbcp2.PoolingDriver PoolingDriver} and
- * {@link org.apache.commons.dbcp2.PoolingDataSource PoolingDataSource} both expect an
- * {@link org.apache.commons.pool2.ObjectPool ObjectPool} as an input. Where do I
- * get one of those?
- * </p><p>
- * A: The {@link org.apache.commons.pool2.ObjectPool ObjectPool} interface is defined
- * in Commons Pool. You can use one of the provided implementations such as
- * {@link org.apache.commons.pool2.impl.GenericObjectPool GenericObjectPool},
- * {@link org.apache.commons.pool2.proxy.ProxiedObjectPool ProxiedObjectPool} or
- * {@link org.apache.commons.pool2.impl.SoftReferenceObjectPool SoftReferenceObjectPool}
- * or you can create your own.
- * </p>
- * <p>
- * Q: Ok, I've found an {@link org.apache.commons.pool2.ObjectPool ObjectPool}
- * implementation that I think suits my connection pooling needs. But it wants
- * a {@link org.apache.commons.pool2.PooledObjectFactory PooledObjectFactory}.
- * What should I use for that?
- * </p><p>
- * A: The DBCP package provides a class for this purpose. It's called
- * {@link org.apache.commons.dbcp2.PoolableConnectionFactory}.
- * It implements the factory and lifecycle methods of
- * {@link org.apache.commons.pool2.PooledObjectFactory}
- * for {@link java.sql.Connection}s. But it doesn't create the actual database
- * {@link java.sql.Connection}s itself, it uses a
- * {@link org.apache.commons.dbcp2.ConnectionFactory} for that.
- * The {@link org.apache.commons.dbcp2.PoolableConnectionFactory} will take
- * {@link java.sql.Connection}s created by the {@link org.apache.commons.dbcp2.ConnectionFactory}
- * and wrap them with classes that implement the pooling behaviour.
- * </p><p>
- * Several implementations of {@link org.apache.commons.dbcp2.ConnectionFactory} are
- * provided--one that uses {@link java.sql.DriverManager} to create connections
- * ({@link org.apache.commons.dbcp2.DriverManagerConnectionFactory}),
- * one that uses a {@link java.sql.Driver} to create connections
- * ({@link org.apache.commons.dbcp2.DriverConnectionFactory}),
- * one that uses a {@link javax.sql.DataSource} to create connections
- * ({@link org.apache.commons.dbcp2.DataSourceConnectionFactory}).
- * </p>
- * <p>
- * Q: I think I'm starting to get it, but can you walk me though it again?
- * </p><p>
- * A: Sure. Let's assume you want to create a {@link javax.sql.DataSource}
- * that pools {@link java.sql.Connection}s. Let's also assume that
- * those pooled {@link java.sql.Connection}s should be obtained from
- * the {@link java.sql.DriverManager}.
- * You'll want to create a {@link org.apache.commons.dbcp2.PoolingDataSource}.
- * </p><p>
- * The {@link org.apache.commons.dbcp2.PoolingDataSource} uses an underlying
- * {@link org.apache.commons.pool2.ObjectPool} to create and store its
- * {@link java.sql.Connection}.
- * </p><p>
- * To create a {@link org.apache.commons.pool2.ObjectPool}, you'll need
- * a {@link org.apache.commons.pool2.PooledObjectFactory} that creates
- * the actual {@link java.sql.Connection}s. That's what
- * {@link org.apache.commons.dbcp2.PoolableConnectionFactory} is for.
- * </p><p>
- * To create the {@link org.apache.commons.dbcp2.PoolableConnectionFactory},
- * you'll need at least two things:</p>
- * <ol>
- * <li>
- * A {@link org.apache.commons.dbcp2.ConnectionFactory} from which
- * the actual database {@link java.sql.Connection}s will be obtained.
- * </li>
- * <li>
- * An empty and factory-less {@link org.apache.commons.pool2.ObjectPool}
- * in which the {@link java.sql.Connection}s will be stored.
- * <br>
+ * Q: How do I use the DBCP package?
+ * </p>
+ * <p>
+ * A: There are two primary ways to access the DBCP pool, as a {@link java.sql.Driver Driver}, or as a
+ * {@link javax.sql.DataSource DataSource}. You'll want to create an instance of
+ * {@link org.apache.commons.dbcp2.PoolingDriver} or {@link org.apache.commons.dbcp2.PoolingDataSource}. When using one
+ * of these interfaces, you can just use your JDBC objects the way you normally would. Closing a
+ * {@link java.sql.Connection} will simply return it to its pool.
+ * </p>
+ * <p>
+ * Q: But {@link org.apache.commons.dbcp2.PoolingDriver PoolingDriver} and
+ * {@link org.apache.commons.dbcp2.PoolingDataSource PoolingDataSource} both expect an
+ * {@link org.apache.commons.pool2.ObjectPool ObjectPool} as an input. Where do I get one of those?
+ * </p>
+ * <p>
+ * A: The {@link org.apache.commons.pool2.ObjectPool ObjectPool} interface is defined in Commons Pool. You can use one
+ * of the provided implementations such as {@link org.apache.commons.pool2.impl.GenericObjectPool GenericObjectPool},
+ * {@link org.apache.commons.pool2.proxy.ProxiedObjectPool ProxiedObjectPool} or
+ * {@link org.apache.commons.pool2.impl.SoftReferenceObjectPool SoftReferenceObjectPool} or you can create your own.
+ * </p>
+ * <p>
+ * Q: Ok, I've found an {@link org.apache.commons.pool2.ObjectPool ObjectPool} implementation that I think suits my
+ * connection pooling needs. But it wants a {@link org.apache.commons.pool2.PooledObjectFactory PooledObjectFactory}.
+ * What should I use for that?
+ * </p>
+ * <p>
+ * A: The DBCP package provides a class for this purpose. It's called
+ * {@link org.apache.commons.dbcp2.PoolableConnectionFactory}. It implements the factory and lifecycle methods of
+ * {@link org.apache.commons.pool2.PooledObjectFactory} for {@link java.sql.Connection}s. But it doesn't create the
+ * actual database {@link java.sql.Connection}s itself, it uses a {@link org.apache.commons.dbcp2.ConnectionFactory} for
+ * that. The {@link org.apache.commons.dbcp2.PoolableConnectionFactory} will take {@link java.sql.Connection}s created
+ * by the {@link org.apache.commons.dbcp2.ConnectionFactory} and wrap them with classes that implement the pooling
+ * behaviour.
+ * </p>
+ * <p>
+ * Several implementations of {@link org.apache.commons.dbcp2.ConnectionFactory} are provided--one that uses
+ * {@link java.sql.DriverManager} to create connections
+ * ({@link org.apache.commons.dbcp2.DriverManagerConnectionFactory}), one that uses a {@link java.sql.Driver} to create
+ * connections ({@link org.apache.commons.dbcp2.DriverConnectionFactory}), one that uses a {@link javax.sql.DataSource}
+ * to create connections ({@link org.apache.commons.dbcp2.DataSourceConnectionFactory}).
+ * </p>
+ * <p>
+ * Q: I think I'm starting to get it, but can you walk me though it again?
+ * </p>
+ * <p>
+ * A: Sure. Let's assume you want to create a {@link javax.sql.DataSource} that pools {@link java.sql.Connection}s.
+ * Let's also assume that those pooled {@link java.sql.Connection}s should be obtained from the
+ * {@link java.sql.DriverManager}. You'll want to create a {@link org.apache.commons.dbcp2.PoolingDataSource}.
+ * </p>
+ * <p>
+ * The {@link org.apache.commons.dbcp2.PoolingDataSource} uses an underlying {@link org.apache.commons.pool2.ObjectPool}
+ * to create and store its {@link java.sql.Connection}.
+ * </p>
+ * <p>
+ * To create a {@link org.apache.commons.pool2.ObjectPool}, you'll need a
+ * {@link org.apache.commons.pool2.PooledObjectFactory} that creates the actual {@link java.sql.Connection}s. That's
+ * what {@link org.apache.commons.dbcp2.PoolableConnectionFactory} is for.
+ * </p>
+ * <p>
+ * To create the {@link org.apache.commons.dbcp2.PoolableConnectionFactory}, you'll need at least two things:
+ * </p>
+ * <ol>
+ * <li>A {@link org.apache.commons.dbcp2.ConnectionFactory} from which the actual database {@link java.sql.Connection}s
+ * will be obtained.</li>
+ * <li>An empty and factory-less {@link org.apache.commons.pool2.ObjectPool} in which the {@link java.sql.Connection}s
+ * will be stored. <br>
* When you pass an {@link org.apache.commons.pool2.ObjectPool} into the
- * {@link org.apache.commons.dbcp2.PoolableConnectionFactory}, it will
- * automatically register itself as the {@link org.apache.commons.pool2.PooledObjectFactory}
- * for that pool.
- * </li>
- * </ol>
- * <p>
- * In code, that might look like this:
- * </p>
- * <pre>GenericObjectPool connectionPool = new GenericObjectPool(null);
- * ConnectionFactory connectionFactory = new DriverManagerConnectionFactory("jdbc:some:connect:string", "userName", "password");
- * PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,connectionPool,null,null,false,true);
- * PoolingDataSource dataSource = new PoolingDataSource(connectionPool);</pre>
- * <p>
- * To create a {@link org.apache.commons.dbcp2.PoolingDriver}, we do the same thing,
- * except that instead of creating a {@link javax.sql.DataSource} on the last line,
- * we create a {@link org.apache.commons.dbcp2.PoolingDriver}, and register the
- * {@code connectionPool} with it. E.g.,:</p>
- * <pre>GenericObjectPool connectionPool = new GenericObjectPool(null);
- * ConnectionFactory connectionFactory = new DriverManagerConnectionFactory("jdbc:some:connect:string", "userName", "password");
- * PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,connectionPool,null,null,false,true);
+ * {@link org.apache.commons.dbcp2.PoolableConnectionFactory}, it will automatically register itself as the
+ * {@link org.apache.commons.pool2.PooledObjectFactory} for that pool.</li>
+ * </ol>
+ * <p>
+ * In code, that might look like this:
+ * </p>
+ *
+ * <pre>
+ * GenericObjectPool connectionPool = new GenericObjectPool(null);
+ * ConnectionFactory connectionFactory = new DriverManagerConnectionFactory("jdbc:some:connect:string", "userName",
+ * "password");
+ * PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,
+ * connectionPool, null, null, false, true);
+ * PoolingDataSource dataSource = new PoolingDataSource(connectionPool);
+ * </pre>
+ * <p>
+ * To create a {@link org.apache.commons.dbcp2.PoolingDriver}, we do the same thing, except that instead of creating a
+ * {@link javax.sql.DataSource} on the last line, we create a {@link org.apache.commons.dbcp2.PoolingDriver}, and
+ * register the {@code connectionPool} with it. E.g.,:
+ * </p>
+ *
+ * <pre>
+ * GenericObjectPool connectionPool = new GenericObjectPool(null);
+ * ConnectionFactory connectionFactory = new DriverManagerConnectionFactory("jdbc:some:connect:string", "userName",
+ * "password");
+ * PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,
+ * connectionPool, null, null, false, true);
* PoolingDriver driver = new PoolingDriver();
- * driver.registerPool("example",connectionPool);</pre>
+ * driver.registerPool("example", connectionPool);
+ * </pre>
* <p>
- * Since the {@link org.apache.commons.dbcp2.PoolingDriver} registers itself
- * with the {@link java.sql.DriverManager} when it is created, now you can just
- * go to the {@link java.sql.DriverManager} to create your {@link java.sql.Connection}s,
- * like you normally would:</p>
- * <pre>Connection conn = DriverManager.getConnection("jdbc:apache:commons:dbcp:example");</pre>
+ * Since the {@link org.apache.commons.dbcp2.PoolingDriver} registers itself with the {@link java.sql.DriverManager}
+ * when it is created, now you can just go to the {@link java.sql.DriverManager} to create your
+ * {@link java.sql.Connection}s, like you normally would:
+ * </p>
+ *
+ * <pre>
+ * Connection conn = DriverManager.getConnection("jdbc:apache:commons:dbcp:example");
+ * </pre>
*/
package org.apache.commons.dbcp2;