entityManager.getTransaction().begin(); UnitOfWork unitOfWork = (UnitOfWork)((JpaEntityManager)entityManager.getDelegate()).getActiveSession(); unitOfWork.beginEarlyTransaction(); Accessor accessor = unitOfWork.getAccessor(); accessor.incrementCallCount(unitOfWork.getParent()); accessor.decrementCallCount(); java.sql.Connection connection = accessor.getConnection(); ... entityManager.getTransaction().commit();
/** * INTERNAL: * When we acquire a connection from an ExternalConnectionPool we build * a new connection (retrieve it from the external pool). */ public Accessor acquireConnection() throws ConcurrencyException { return (Accessor)getCachedConnection().clone(); }
/** * INTERNAL: * When you release an external connection, you simply let it go. */ public void releaseConnection(Accessor connection) throws DatabaseException { if (this.owner.shouldLog(SessionLog.FINEST, SessionLog.CONNECTION)) { Object[] args = new Object[1]; args[0] = this.name; this.owner.log(SessionLog.FINEST, SessionLog.CONNECTION, "release_connection", args, connection); } if (!this.failoverConnectionPools.isEmpty()) { if (!connection.isValid()) { if (this.checkConnections) { // If 2nd dead connection, then assume dead. this.isDead = true; } else { this.checkConnections = true; } } else { this.checkConnections = false; } } connection.closeConnection(); connection.releaseCustomizer(); }
/** * INTERNAL: * When you release an external connection, you simply let it go. */ public void releaseConnection(Accessor connection) throws DatabaseException { connection.closeConnection(); connection.releaseCustomizer(); }
/** * INTERNAL: * Set the connection to be used for database modification. */ public void setWriteConnection(Accessor writeConnection) { if(writeConnection != null) { // new writeConnection is set this.writeConnection = writeConnection; this.writeConnection.createCustomizer(this); } else { // existing writeConnection is released; the not null check in case the method called twice. if(this.writeConnection != null) { this.writeConnection.releaseCustomizer(this); this.writeConnection = null; } } }
try { connection.closeConnection(); } catch (Exception ex){ connection.releaseCustomizer(); if (connection.getCallCount() == 0) { leastBusyConnection = connection; break; if ((leastBusyConnection == null) || (leastBusyConnection.getCallCount() > connection.getCallCount())) { leastBusyConnection = connection; if (((leastBusyConnection == null) || (leastBusyConnection.getCallCount() != 0)) && (this.connectionsAvailable.size() + this.connectionsUsed.size()) < this.maxNumberOfConnections) { Accessor connection = null; leastBusyConnection.incrementCallCount(getOwner()); if (this.owner.shouldLog(SessionLog.FINEST, SessionLog.CONNECTION)) { Object[] args = new Object[1];
UnitOfWorkImpl unitOfWork = (UnitOfWorkImpl) this.getUnitOfWork(); if(unitOfWork.isInTransaction() || unitOfWork.getParent().isExclusiveIsolatedClientSession()) { return (T) unitOfWork.getAccessor().getConnection(); Accessor accessor = unitOfWork.getAccessor(); accessor.incrementCallCount(unitOfWork.getParent()); accessor.decrementCallCount(); return (T) accessor.getConnection(); UnitOfWorkImpl unitOfWork = (UnitOfWorkImpl) this.getUnitOfWork(); if(unitOfWork.isInTransaction() || unitOfWork.getParent().isExclusiveIsolatedClientSession()) { return (T) unitOfWork.getAccessor().getConnection(); Accessor accessor = unitOfWork.getAccessor(); accessor.incrementCallCount(unitOfWork.getParent()); accessor.decrementCallCount(); return (T) accessor.getDatasourceConnection();
/** * INTERNAL: * Because connections are not exclusive nothing is required. */ public synchronized void releaseConnection(Accessor connection) throws DatabaseException { connection.decrementCallCount(); if (!connection.isValid()){ getOwner().setCheckConnections(); this.connectionsAvailable.remove(connection); try{ connection.disconnect(getOwner()); }catch (Exception ex){ //ignore } } } }
/** * INTERNAL: * A call to this method will perform a platform based check on the connection and exception * error code to determine if the connection is still valid or if a communication error has occurred. * If a communication error has occurred then the query may be retried. * If this platform is unable to determine if the error was communication based it will return * false forcing the error to be thrown to the user. */ @Override public boolean wasFailureCommunicationBased(SQLException exception, Accessor connection, AbstractSession sessionForProfile){ return getDatabaseSession().getPlatform().wasFailureCommunicationBased(exception, connection.getConnection(), sessionForProfile); }
accessor.beginTransaction(writeSession); try { Vector sequences = sequence.getGeneratedVector(accessor, writeSession); accessor.commitTransaction(writeSession); try { accessor.rollbackTransaction(writeSession); } catch (Exception rollbackException) { accessor.beginTransaction(writeSession); try { accessor.commitTransaction(writeSession); return sequenceValue; } catch (RuntimeException ex) { try { accessor.rollbackTransaction(writeSession); } catch (Exception rollbackException) {
/** * INTERNAL: * Release any invalid connection in the client session. */ public void releaseInvalidClientSession(ClientSession clientSession) throws DatabaseException { for (Iterator<Accessor> accessors = clientSession.getWriteConnections().values().iterator(); accessors.hasNext(); ) { Accessor accessor = accessors.next(); if (!accessor.isValid()) { if (clientSession.getConnectionPolicy().isPooled()) { try { accessor.getPool().releaseConnection(accessor); } catch (Exception ignore) {} } else { if (!accessor.usesExternalConnectionPooling()) { clientSession.disconnect(accessor); } else { accessor.closeConnection(); } if (this.maxNumberOfNonPooledConnections != NO_MAX) { synchronized (this) { this.numberOfNonPooledConnectionsUsed--; notify(); } } } accessors.remove(); } } }
if (writeConnection.getPool() == null) { return super.retryTransaction(writeConnection, databaseException, retryCount, executionSession); String poolName = writeConnection.getPool().getName(); DatabaseLogin login = getLogin(); int count = login.getQueryRetryAttemptCount(); getWriteConnections().remove(poolName); if (!writeConnection.usesExternalConnectionPooling()) { preReleaseConnection(writeConnection); writeConnection.getPool().releaseConnection(writeConnection); try { writeConnection = writeConnection.getPool().acquireConnection(); writeConnection.beginTransaction(this); writeConnection.createCustomizer(this); if (!writeConnection.usesExternalConnectionPooling()) { postAcquireConnection(writeConnection);
for (Accessor accessor : clientSession.getWriteConnections().values()) { if(!accessor.usesExternalConnectionPooling()) { clientSession.preReleaseConnection(accessor); accessor.getPool().releaseConnection(accessor); for (Accessor accessor : clientSession.getWriteConnections().values()) { if(!accessor.usesExternalConnectionPooling()) { clientSession.preReleaseConnection(accessor); try { accessor.closeConnection();
accessor.reestablishConnection(this); accessor.beginTransaction(this); return null; } catch (DatabaseException newException) {
/** * INTERNAL: * Connect the session only (this must be the write connection as the read is shared). */ public void connect(Accessor accessor) throws DatabaseException { accessor.connect(getDatasourceLogin(), this); }
if (connection.getCallCount() == 0) { connection.incrementCallCount(getOwner()); return connection; if ((leastBusyConnection == null) || (leastBusyConnection.getCallCount() > connection.getCallCount())) { leastBusyConnection = connection; Accessor connection = buildConnection(); this.connectionsAvailable.add(connection); connection.incrementCallCount(getOwner()); return connection; leastBusyConnection.incrementCallCount(getOwner()); return leastBusyConnection;
/** * INTERNAL: * Add the connection to the client session. * Multiple connections are supported to allow data partitioning and replication. * The accessor is returned, as if detected to be dead it may be replaced. */ public Accessor addWriteConnection(String poolName, Accessor writeConnection) { getWriteConnections().put(poolName, writeConnection); writeConnection.createCustomizer(this); //if connection is using external connection pooling then the event will be risen right after it connects. if (!writeConnection.usesExternalConnectionPooling()) { postAcquireConnection(writeConnection); } // Transactions are lazily started on connections. if (isInTransaction()) { basicBeginTransaction(writeConnection); } return getWriteConnections().get(poolName); }
/** * INTERNAL: * Called in the end of beforeCompletion of external transaction synchronization listener. * Close the managed sql connection corresponding to the external transaction. */ @Override public void releaseJTSConnection() { getAccessor().closeJTSConnection(); }
ConnectionPool pool = (ConnectionPool)getConnectionPools().get(clientSession.getConnectionPolicy().getPoolName()); if (!clientSession.getWriteConnection().usesExternalConnectionPooling()) { if (clientSession.hasEventManager()) { clientSession.getEventManager().preReleaseConnection(clientSession.getWriteConnection()); } else { if(!clientSession.getWriteConnection().usesExternalConnectionPooling()) { clientSession.getEventManager().preReleaseConnection(clientSession.getWriteConnection()); if (clientSession.isExclusiveIsolatedClientSession()) { } else { clientSession.getWriteConnection().closeConnection();