List of usage examples for java.sql Connection isClosed
boolean isClosed() throws SQLException;
Connection
object has been closed. From source file:com.moss.blankslate.PostgresqlCatalogFactory.java
private void assertClosed(Connection connection) throws Exception { if (!connection.isClosed()) throw new Exception("Connection not closed!"); }
From source file:org.apache.sqoop.mapreduce.db.BasicRetrySQLFailureHandler.java
/** * Verify the provided connection is valid. */// w w w .ja va2s.com protected boolean validateConnection(Connection connection) throws SQLException { return connection != null && !connection.isClosed() && connection.isValid(DEFAULT_RETRY_WAIT_INTERVAL); }
From source file:opa.DatabaseResourceBundle.java
/** * Try and release the given database connection. * /*from w ww. j av a 2s . com*/ * @param conn * true if successful or if it was already closed/null, false if * the close operation failed. * @return */ private boolean releaseConnection(Connection conn) { try { if (conn != null && !conn.isClosed()) { conn.close(); } return true; } catch (SQLException e) { return false; } }
From source file:org.apache.kylin.query.adhoc.JdbcConnectionFactory.java
@Override public boolean validateObject(Object pooledObject) { if (pooledObject instanceof Connection) { Connection connection = (Connection) pooledObject; if (connection != null) { try { return ((!connection.isClosed()) && (connection.isValid(1))); } catch (SQLException e) { throw new RuntimeException(e.getMessage(), e); }/* www . j a v a2s . c o m*/ } } return false; }
From source file:com.micromux.cassandra.jdbc.DataSourceTest.java
@Test public void testConstructor() throws Exception { CassandraDataSource cds = new CassandraDataSource(HOST, PORT, KEYSPACE, USER, PASSWORD, VERSION, CONSISTENCY, TRUST_STORE, TRUST_PASS); assertEquals(HOST, cds.getServerName()); assertEquals(PORT, cds.getPortNumber()); assertEquals(KEYSPACE, cds.getDatabaseName()); assertEquals(USER, cds.getUser());/*from w w w.j a v a2 s . com*/ assertEquals(PASSWORD, cds.getPassword()); assertEquals(VERSION, cds.getVersion()); DataSource ds = new CassandraDataSource(HOST, PORT, KEYSPACE, USER, PASSWORD, VERSION, CONSISTENCY, TRUST_STORE, TRUST_PASS); assertNotNull(ds); // null username and password java.sql.Connection cnx = ds.getConnection(null, null); assertFalse(cnx.isClosed()); ds.setLoginTimeout(5); assertEquals(5, ds.getLoginTimeout()); // no username and password cnx = ds.getConnection(); assertFalse(cnx.isClosed()); ds.setLoginTimeout(5); assertEquals(VERSION, ((CassandraConnection) cnx).getConnectionProps().get(Utils.TAG_CQL_VERSION)); assertEquals(5, ds.getLoginTimeout()); }
From source file:com.sky.projects.pool.jdbc.JdbcConnectionFactory.java
@Override public boolean validateObject(PooledObject<Connection> p) { Connection connection = p.getObject(); if (connection != null) try {//from w w w . ja v a 2 s .c o m return ((!connection.isClosed()) && (connection.isValid(1))); } catch (SQLException e) { return false; } return false; }
From source file:org.moneta.config.ConnectionPoolFactoryTest.java
@Test public void testBasicHappyPath() throws Exception { ObjectPool<PoolableConnection> pool = ConnectionPoolFactory.createConnectionPool(dataSource); Assert.assertTrue(pool != null);// w w w. j ava 2 s . co m Connection conn = pool.borrowObject(); Assert.assertTrue(conn != null); Assert.assertTrue(!conn.isClosed()); }
From source file:lineage2.commons.dbcp.BasicDataSource.java
/** * Method getConnection.//w ww . ja v a 2 s . co m * @param con Connection * @return Connection * @throws SQLException */ public Connection getConnection(Connection con) throws SQLException { return (con == null) || con.isClosed() ? _source.getConnection() : con; }
From source file:org.azkfw.business.test.AbstractDatabaseTestCase.java
@Override public void tearDown() { for (Connection connection : connections) { try {//from w w w . j ava 2 s. co m if (!connection.isClosed()) { connection.close(); } } catch (SQLException ex) { ex.printStackTrace(); } } super.tearDown(); }
From source file:com.vertica.hadoop.AbstractVerticaOutputCommitter.java
/** * Commits and closes the connection if the connection is non-null and open. * @throws IOException if either isClosed or commit fails. *//* ww w. j a va 2 s . c o m*/ protected final void sqlCommit(Connection connection) throws IOException { try { if (connection == null || connection.isClosed()) { throw new IOException("Trying to commit a connection that is null or closed: " + connection); } } catch (SQLException e) { throw new IOException("Exception calling isClosed on connection", e); } try { connection.commit(); } catch (SQLException e) { throw new IOException("Exception committing connection", e); } finally { sqlClose(connection); } }