public void reset() throws SQLException { // reset default settings if (underlyingReadOnly != defaultReadOnly) { conn.setReadOnly(defaultReadOnly); underlyingReadOnly = defaultReadOnly; } if (underlyingHoldability != defaultHoldability) { conn.setHoldability(defaultHoldability); underlyingHoldability = defaultHoldability; } if (underlyingTransactionIsolation != defaultTransactionIsolation) { conn.setTransactionIsolation(defaultTransactionIsolation); underlyingTransactionIsolation = defaultTransactionIsolation; } if (underlyingAutoCommit != defaultAutoCommit) { conn.setAutoCommit(defaultAutoCommit); underlyingAutoCommit = defaultAutoCommit; } connectionEventListeners.clear(); statementEventListeners.clear(); for (Object item : statementTrace.toArray()) { Statement stmt = (Statement) item; JdbcUtils.close(stmt); } statementTrace.clear(); conn.clearWarnings(); }
@Override public void clearWarnings() throws SQLException { checkState(); try { conn.clearWarnings(); } catch (SQLException ex) { handleException(ex); } }
public void clearWarnings() throws SQLException { String methodCall = "clearWarnings()"; try { realConnection.clearWarnings(); } catch (SQLException s) { reportException(methodCall, s); throw s; } reportReturn(methodCall); }
@Test public void testConnection() throws Exception { Connection conn = getConnection(); assertNull(conn.getMetaData()); assertFalse(conn.getAutoCommit()); conn.setAutoCommit(true); assertTrue(conn.getAutoCommit()); conn.setAutoCommit(false); assertTrue(conn.isReadOnly()); conn.setReadOnly(true); assertTrue(conn.isReadOnly()); assertEquals(Connection.TRANSACTION_NONE, conn.getTransactionIsolation()); conn.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED); assertEquals(Connection.TRANSACTION_READ_UNCOMMITTED, conn.getTransactionIsolation()); conn.setTransactionIsolation(Connection.TRANSACTION_NONE); assertNull(conn.getWarnings()); conn.clearWarnings(); assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, conn.getHoldability()); conn.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT); assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, conn.getHoldability()); conn.setHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT); conn.commit(); conn.rollback(); assertTrue(conn.isValid(0)); conn.setClientInfo("prop1", "value1"); Properties props = new Properties(); props.setProperty("prop2", "value2"); props.setProperty("prop3", "value3"); conn.setClientInfo(props); assertEquals("value1", conn.getClientInfo("prop1")); assertEquals("value2", conn.getClientInfo("prop2")); assertEquals("value3", conn.getClientInfo("prop3")); Properties props2 = conn.getClientInfo(); assertEquals("value1", props2.getProperty("prop1")); assertEquals("value2", props2.getProperty("prop2")); assertEquals("value3", props2.getProperty("prop3")); assertNotNull(((JcrJdbcConnection) conn).getJcrSession()); assertFalse(conn.isClosed()); conn.close(); assertTrue(conn.isClosed()); }
public static final void clearWarnings(java.sql.Connection db, DBCommandHandler msghandler) { try { java.sql.SQLWarning warn = db.getWarnings(); if (warn != null) { msghandler.showSQLException(warn); while ((warn = warn.getNextWarning()) != null) { msghandler.showSQLException(warn); } } db.clearWarnings(); } catch (java.sql.SQLException sqle) { msghandler.showSQLException(sqle); } }
private void closeConnection() { try { if (statement != null) statement.close(); if (connection != null) { JDBCExceptionReporter.logWarnings(connection.getWarnings()); connection.clearWarnings(); connectionProvider.closeConnection(connection); connectionProvider.close(); } } catch (Exception e) { System.err.println("Could not close connection"); e.printStackTrace(); } }
public static void ShowWarnings(PrintStream out, Connection theConnection) { try { // GET CONNECTION WARNINGS SQLWarning warning = null; if (theConnection != null) { ShowWarnings(out, theConnection.getWarnings()); } if (theConnection != null) { theConnection.clearWarnings(); } } catch (SQLException e) { ShowSQLException(out, e); } } // ShowWarnings
@Override public boolean isValid(Connection c) { boolean valid = false; try { valid = c.isValid(getValidateTimeOutS()); // See https://github.com/brettwooldridge/HikariCP/wiki/Pool-Analysis // SQL warnings should be cleared. if (valid) { c.clearWarnings(); } } catch (SQLException e) { log.info("Database connection invalid.", e); } return valid; }
private synchronized Connection createConnection() throws SQLException { if (this.isClosed()) { throw new SQLException("Connection pool is closed."); } if (!this.currentlyUnusedConnections.isEmpty()) { final Connection ret = this.currentlyUnusedConnections.remove(0); if (!checkConnection(ret)) { log.warn("Connection within pool is closed or not working."); this.connectionCount--; return this.createConnection(); } ret.clearWarnings(); return ret; } if (this.connectionCount < MAXIMUM_CONNECTIONS) { return this.instantiateNewConnection(); } return null; }
/** * Pass thru method to the wrapped jdbc 1.x {@link java.sql.Connection}. * * @exception SQLException if this connection is closed or an error occurs in the wrapped * connection. */ public void clearWarnings() throws SQLException { assertOpen(); connection.clearWarnings(); }
/** * @return Connection * @roseuid 3F3A5FFD0338 */ public Connection getConnection() throws EmanagerDatabaseException { long connectionId; Connection connection; PooledConnection pooledConnection; connection = null; pooledConnection = null; connectionId = InvalidConnectionId; try { synchronized (connectionPool) { if (!connectionPool.isEmpty()) { try { boolean connectionClosed; connectionClosed = false; pooledConnection = (PooledConnection) connectionPool.remove(0); connection = pooledConnection.getConnection(); connection.clearWarnings(); connectionId = getConnectionID(connection); connectionClosed = connection.isClosed(); if (connectionId == InvalidConnectionId || connectionClosed == true) { logger.debug("Pooled connection closed."); connection = null; } } catch (SQLException sqe) { logger.debug("Pooled connection closed."); connection = null; } } } if (connection == null) { logger.debug("Getting a new connection."); pooledConnection = poolDataSource.getPooledConnection(); pooledConnection.addConnectionEventListener(this); connection = pooledConnection.getConnection(); connection.clearWarnings(); connectionId = getConnectionID(connection); } } catch (SQLException sqe) { String logString; EmanagerDatabaseException ede; logString = EmanagerDatabaseStatusCode.UnableToGetPooledConnection.getStatusCodeDescription() + sqe.getMessage(); logger.error(logString); ede = new EmanagerDatabaseException( EmanagerDatabaseStatusCode.UnableToGetPooledConnection, logString); throw ede; } if (connectionId == InvalidConnectionId) { EmanagerDatabaseException ede; ede = new EmanagerDatabaseException( EmanagerDatabaseStatusCode.UnableToGetPooledConnection, EmanagerDatabaseStatusCode.UnableToGetPooledConnection.getStatusCodeDescription()); throw ede; } logger.debug( "\n*****************************" + "\nPooled Connection Init" + "\nCon ID:" + connectionId + "\nCon Object:" + pooledConnection + "\nPool Object:" + connection + "\n*****************************"); return connection; }
/* * kevin 2002-10-04 * Note: JDK 1.3 * implements of java.sql.Connection */ public void clearWarnings() throws SQLException { con.clearWarnings(); }
/** * Attempt to retrieve a database connection using {@link #getPooledConnectionAndInfo(String, * String)} with the provided username and password. The password on the {@link * PooledConnectionAndInfo} instance returned by <code>getPooledConnectionAndInfo</code> is * compared to the <code>password</code> parameter. If the comparison fails, a database connection * using the supplied username and password is attempted. If the connection attempt fails, an * SQLException is thrown, indicating that the given password did not match the password used to * create the pooled connection. If the connection attempt succeeds, this means that the database * password has been changed. In this case, the <code>PooledConnectionAndInfo</code> instance * retrieved with the old password is destroyed and the <code>getPooledConnectionAndInfo</code> is * repeatedly invoked until a <code>PooledConnectionAndInfo</code> instance with the new password * is returned. */ @Override public Connection getConnection(String username, String password) throws SQLException { if (instanceKey == null) { throw new SQLException( "Must set the ConnectionPoolDataSource " + "through setDataSourceName or setConnectionPoolDataSource" + " before calling getConnection."); } getConnectionCalled = true; PooledConnectionAndInfo info = null; try { info = getPooledConnectionAndInfo(username, password); } catch (NoSuchElementException e) { closeDueToException(info); throw new SQLException("Cannot borrow connection from pool", e); } catch (RuntimeException e) { closeDueToException(info); throw e; } catch (SQLException e) { closeDueToException(info); throw e; } catch (Exception e) { closeDueToException(info); throw new SQLException("Cannot borrow connection from pool", e); } if (!(null == password ? null == info.getPassword() : password.equals( info.getPassword()))) { // Password on PooledConnectionAndInfo does not match try { // See if password has changed by attempting connection testCPDS(username, password); } catch (SQLException ex) { // Password has not changed, so refuse client, but return connection to the pool closeDueToException(info); throw new SQLException( "Given password did not match password used" + " to create the PooledConnection.", ex); } catch (javax.naming.NamingException ne) { throw new SQLException("NamingException encountered connecting to database", ne); } /* * Password must have changed -> destroy connection and keep retrying until we get a new, good one, * destroying any idle connections with the old passowrd as we pull them from the pool. */ final UserPassKey upkey = info.getUserPassKey(); final PooledConnectionManager manager = getConnectionManager(upkey); manager.invalidate(info.getPooledConnection()); // Destroy and remove from pool manager.setPassword( upkey.getPassword()); // Reset the password on the factory if using CPDSConnectionFactory info = null; for (int i = 0; i < 10; i++) { // Bound the number of retries - only needed if bad instances return try { info = getPooledConnectionAndInfo(username, password); } catch (NoSuchElementException e) { closeDueToException(info); throw new SQLException("Cannot borrow connection from pool", e); } catch (RuntimeException e) { closeDueToException(info); throw e; } catch (SQLException e) { closeDueToException(info); throw e; } catch (Exception e) { closeDueToException(info); throw new SQLException("Cannot borrow connection from pool", e); } if (info != null && password != null && password.equals(info.getPassword())) { break; } if (info != null) { manager.invalidate(info.getPooledConnection()); } info = null; } if (info == null) { throw new SQLException("Cannot borrow connection from pool - password change failure."); } } Connection con = info.getPooledConnection().getConnection(); try { setupDefaults(con, username); con.clearWarnings(); return con; } catch (SQLException ex) { try { con.close(); } catch (Exception exc) { getLogWriter().println("ignoring exception during close: " + exc); } throw ex; } }
@Override public void clearWarnings() throws SQLException { checkState(); conn.clearWarnings(); }
@Override public void clearWarnings() throws SQLException { _wrapped.clearWarnings(); }