/** * Creates the connection handle again. We use this method to create a brand new connection * handle. That way if the application (wrongly) tries to do something else with the connection * that has already been "closed", it will fail. * @return ConnectionHandle * @throws SQLException */ public ConnectionHandle recreateConnectionHandle() throws SQLException{ ConnectionHandle handle = new ConnectionHandle(this.connection, this.originatingPartition, this.pool, true); handle.originatingPartition = this.originatingPartition; handle.connectionCreationTimeInMs = this.connectionCreationTimeInMs; handle.connectionLastResetInMs = this.connectionLastResetInMs; handle.connectionLastUsedInMs = this.connectionLastUsedInMs; handle.preparedStatementCache = this.preparedStatementCache; handle.callableStatementCache = this.callableStatementCache; handle.statementCachingEnabled = this.statementCachingEnabled; handle.connectionHook = this.connectionHook; handle.possiblyBroken = this.possiblyBroken; handle.debugHandle = this.debugHandle; this.connection = null; return handle; }
/** Adds new connections to the partition. * @param connectionsToCreate number of connections to create * @throws InterruptedException */ private void fillConnections(int connectionsToCreate) throws InterruptedException { try { for (int i=0; i < connectionsToCreate; i++){ // boolean dbDown = this.pool.getDbIsDown().get(); if (this.pool.poolShuttingDown){ break; } this.partition.addFreeConnection(new ConnectionHandle(null, this.partition, this.pool, false)); } } catch (Exception e) { logger.error("Error in trying to obtain a connection. Retrying in "+this.acquireRetryDelayInMs+"ms", e); Thread.sleep(this.acquireRetryDelayInMs); } }
/** Private -- used solely for unit testing. * @param connection * @param preparedStatementCache * @param callableStatementCache * @param pool * @return Connection Handle */ protected static ConnectionHandle createTestConnectionHandle(Connection connection, IStatementCache preparedStatementCache, IStatementCache callableStatementCache, BoneCP pool){ ConnectionHandle handle = new ConnectionHandle(); handle.connection = connection; handle.preparedStatementCache = preparedStatementCache; handle.callableStatementCache = callableStatementCache; handle.connectionLastUsedInMs = System.currentTimeMillis(); handle.connectionLastResetInMs = System.currentTimeMillis(); handle.connectionCreationTimeInMs = System.currentTimeMillis(); handle.recoveryResult = new TransactionRecoveryResult(); handle.trackedStatement = new MapMaker().makeMap(); handle.url = "foo"; handle.closeOpenStatements = true; handle.pool = pool; handle.url=null; int cacheSize = pool.getConfig().getStatementsCacheSize(); if (cacheSize > 0) { handle.statementCachingEnabled = true; } return handle; }
this.partitions[p].addFreeConnection(new ConnectionHandle(null, this.partitions[p], this, false));
this.partitions[p].addFreeConnection(new ConnectionHandle(null, this.partitions[p], this, false));