Search in sources :

Example 31 with DatabaseCall

use of org.eclipse.persistence.internal.databaseaccess.DatabaseCall in project eclipselink by eclipse-ee4j.

the class ServerSession method executeCall.

/**
 * INTERNAL:
 * Execute the call on the correct connection accessor.
 * By default the server session executes calls using is read connection pool.
 * A connection is allocated for the execution of the query, then released back to the pool.
 * If partitioning is used the partition policy can use a different connection pool, or even
 * execute the call on multiple connections.
 */
@Override
public Object executeCall(Call call, AbstractRecord translationRow, DatabaseQuery query) throws DatabaseException {
    RuntimeException exception = null;
    Object result = null;
    boolean accessorAllocated = false;
    if (query.getAccessors() == null) {
        List<Accessor> accessors = getAccessors(call, translationRow, query);
        query.setAccessors(accessors);
        if (this.eventManager != null) {
            for (Accessor accessor : accessors) {
                // if connection is using external connection pooling then the event will be risen right after it connects.
                if (!accessor.usesExternalConnectionPooling()) {
                    this.eventManager.postAcquireConnection(accessor);
                }
            }
        }
        accessorAllocated = true;
    }
    try {
        result = basicExecuteCall(call, translationRow, query);
    } catch (RuntimeException caughtException) {
        exception = caughtException;
    } finally {
        // or unless an exception occurred executing the call.
        if (call.isFinished() || exception != null) {
            if (accessorAllocated) {
                try {
                    releaseConnectionAfterCall(query);
                } catch (RuntimeException releaseException) {
                    if (exception == null) {
                        throw releaseException;
                    }
                // else ignore
                }
            }
        } else {
            if (query.isObjectLevelReadQuery()) {
                ((DatabaseCall) call).setHasAllocatedConnection(accessorAllocated);
            }
        }
        if (exception != null) {
            throw exception;
        }
    }
    return result;
}
Also used : DatabaseCall(org.eclipse.persistence.internal.databaseaccess.DatabaseCall) Accessor(org.eclipse.persistence.internal.databaseaccess.Accessor)

Aggregations

DatabaseCall (org.eclipse.persistence.internal.databaseaccess.DatabaseCall)31 DatabasePlatform (org.eclipse.persistence.internal.databaseaccess.DatabasePlatform)11 EntityManager (jakarta.persistence.EntityManager)9 DatabaseException (org.eclipse.persistence.exceptions.DatabaseException)9 EntityManagerFactoryImpl (org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl)8 GenericEntity (org.eclipse.persistence.jpa.test.property.model.GenericEntity)8 Test (org.junit.Test)8 SQLCall (org.eclipse.persistence.queries.SQLCall)6 StoredProcedureCall (org.eclipse.persistence.queries.StoredProcedureCall)6 PersistenceException (jakarta.persistence.PersistenceException)5 Platform (org.eclipse.persistence.internal.databaseaccess.Platform)5 AbstractRecord (org.eclipse.persistence.internal.sessions.AbstractRecord)5 ResultSet (java.sql.ResultSet)4 SQLException (java.sql.SQLException)4 DatabaseAccessor (org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor)4 DatasourceCallQueryMechanism (org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism)4 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)4 ResultSetMetaData (java.sql.ResultSetMetaData)3 Statement (java.sql.Statement)3 UnitOfWorkImpl (org.eclipse.persistence.internal.sessions.UnitOfWorkImpl)3