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();
/** * Rollback a transaction on the database. This means toggling the auto-commit option. */ public void rollbackTransaction(AbstractSession session) throws DatabaseException { getActiveBatchWritingMechanism(session).clear(); super.rollbackTransaction(session); }
/** * Allow for the field order to be matched if required. * This is required for custom SQL. */ public void matchFieldOrder(ResultSet resultSet, DatabaseAccessor accessor, AbstractSession session) { if ((getFields() != null) && (!isFieldMatchingRequired())) { return; } setFields(accessor.buildSortedFields(getFields(), resultSet, session)); }
public void populateRow(DatabaseField[] fieldsArray, Object[] values, ResultSet resultSet, ResultSetMetaData metaData, AbstractSession session, int startIndex, int endIndex) throws DatabaseException { // PERF: Pass platform and optimize data flag. DatabasePlatform platform = getPlatform(); boolean optimizeData = platform.shouldOptimizeDataConversion(); for (int index = startIndex; index < endIndex; index++) { DatabaseField field = fieldsArray[index]; // Field can be null for fetch groups. if (field != null) { values[index] = getObject(resultSet, field, metaData, index + 1, platform, optimizeData, session); } } }
/** * INTERNAL: * Swaps out the Mechanism for the other Mechanism */ protected void switchMechanisms(AbstractSession session, DatabaseCall dbCall) { this.databaseAccessor.setActiveBatchWritingMechanismToDynamicSQL(); this.databaseAccessor.getActiveBatchWritingMechanism(session).appendCall(session, dbCall); }
/** * INTERNAL: * This method is used to switch from this mechanism to the alternate automatically */ protected void switchMechanisms(AbstractSession session, DatabaseCall dbCall) { this.databaseAccessor.setActiveBatchWritingMechanismToParameterizedSQL(); this.databaseAccessor.getActiveBatchWritingMechanism(session).appendCall(session, dbCall); }
/** * This method will be called after a series of writes have been issued to * mark where a particular set of writes has completed. It will be called * from commitTransaction and may be called from writeChanges. Its main * purpose is to ensure that the batched statements have been executed */ public void writesCompleted(AbstractSession session) { if (isInBatchWritingMode(session)) { getActiveBatchWritingMechanism().executeBatchedStatements(session); } } }
/** * Disconnect from the datasource. * Added for bug 3046465 to ensure the statement cache is cleared. */ @Override public void disconnect(AbstractSession session) throws DatabaseException { clearStatementCache(session); super.disconnect(session); }
/** * Close the accessor's connection. * This is used only for external connection pooling * when it is intended for the connection to be reconnected in the future. */ @Override public void closeConnection() { // Unfortunately do not have the session to pass, fortunately it is not used. clearStatementCache(null); super.closeConnection(); }
/** * Commit a transaction on the database. First flush any batched statements. */ @Override public void commitTransaction(AbstractSession session) throws DatabaseException { this.writesCompleted(session); super.commitTransaction(session); }
/** * Attempt to save some of the cost associated with getting a fresh connection. * Assume the DatabaseDriver has been cached, if appropriate. * Note: Connections that are participating in transactions will not be refreshed.^M * Added for bug 3046465 to ensure the statement cache is cleared */ protected void reconnect(AbstractSession session) { clearStatementCache(session); super.reconnect(session); }
/** * Set customizer, customize the connection if it's available. */ protected void setCustomizer(ConnectionCustomizer newCustomizer) { this.customizer = newCustomizer; if(getDatasourceConnection() != null) { customizer.customize(); } }
/** * Return the batch writing mode. */ protected boolean isInBatchWritingMode(AbstractSession session) { return getPlatform().usesBatchWriting() && this.isInTransaction; }
/** * Connect to the database. * Exceptions are caught and re-thrown as EclipseLink exceptions. * Must set the transaction isolation. */ protected void connectInternal(Login login, AbstractSession session) throws DatabaseException { super.connectInternal(login, session); checkTransactionIsolation(session); }
/** * Allow for the field order to be matched if required. * This is required for custom SQL. */ public void matchFieldOrder(ResultSet resultSet, DatabaseAccessor accessor, AbstractSession session) { if ((getFields() != null) && (!isFieldMatchingRequired())) { return; } setFields(accessor.buildSortedFields(getFields(), resultSet, session)); }
public void populateRow(DatabaseField[] fieldsArray, Object[] values, ResultSet resultSet, ResultSetMetaData metaData, AbstractSession session, int startIndex, int endIndex) throws DatabaseException { // PERF: Pass platform and optimize data flag. DatabasePlatform platform = getPlatform(); boolean optimizeData = platform.shouldOptimizeDataConversion(); for (int index = startIndex; index < endIndex; index++) { DatabaseField field = fieldsArray[index]; // Field can be null for fetch groups. if (field != null) { values[index] = getObject(resultSet, field, metaData, index + 1, platform, optimizeData, session); } } }
/** * INTERNAL: * Swaps out the Mechanism for the other Mechanism */ protected void switchMechanisms(AbstractSession session, DatabaseCall dbCall) { this.databaseAccessor.setActiveBatchWritingMechanismToDynamicSQL(); this.databaseAccessor.getActiveBatchWritingMechanism(session).appendCall(session, dbCall); }
/** * Disconnect from the datasource. * Added for bug 3046465 to ensure the statement cache is cleared. */ @Override public void disconnect(AbstractSession session) throws DatabaseException { clearStatementCache(session); super.disconnect(session); }
/** * Close the accessor's connection. * This is used only for external connection pooling * when it is intended for the connection to be reconnected in the future. */ @Override public void closeConnection() { // Unfortunately do not have the session to pass, fortunately it is not used. clearStatementCache(null); super.closeConnection(); }
/** * Commit a transaction on the database. First flush any batched statements. */ @Override public void commitTransaction(AbstractSession session) throws DatabaseException { this.writesCompleted(session); super.commitTransaction(session); }