Search in sources :

Example 1 with DatasourceCall

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

the class DescriptorQueryManager method putCachedUpdateCalls.

/**
 * INTERNAL:
 * Cache a clone of the update SQL calls based on the updated fields.
 * If the max size is reached, do not cache the call.
 * The call's query must be dereferenced in order to allow the GC of a related session.
 * PERF: Allow caching of the update SQL call to avoid regeneration.
 */
public void putCachedUpdateCalls(Vector updateFields, Vector updateCalls) {
    Vector vectorToCache = updateCalls;
    if (!updateCalls.isEmpty()) {
        int updateCallsSize = updateCalls.size();
        vectorToCache = new NonSynchronizedVector(updateCallsSize);
        for (int i = 0; i < updateCallsSize; i++) {
            DatasourceCall updateCall = (DatasourceCall) updateCalls.get(i);
            // clone call and dereference query for DatasourceCall and EJBQLCall
            DatasourceCall clonedUpdateCall = (DatasourceCall) updateCall.clone();
            clonedUpdateCall.setQuery(null);
            vectorToCache.add(clonedUpdateCall);
        }
    }
    getCachedUpdateCalls().put(updateFields, vectorToCache);
}
Also used : Vector(java.util.Vector) NonSynchronizedVector(org.eclipse.persistence.internal.helper.NonSynchronizedVector) NonSynchronizedVector(org.eclipse.persistence.internal.helper.NonSynchronizedVector) DatasourceCall(org.eclipse.persistence.internal.databaseaccess.DatasourceCall)

Example 2 with DatasourceCall

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

the class DatasourceCallQueryMechanism method deleteAll.

/**
 * INTERNAL:
 * Delete a collection of objects. Assume call is correct.
 * @exception  DatabaseException - an error has occurred on the database
 */
@Override
public Integer deleteAll() throws DatabaseException {
    if (((DeleteAllQuery) this.query).isPreparedUsingTempStorage()) {
        return deleteAllUsingTempTables();
    } else {
        if (hasMultipleCalls()) {
            Integer returnedRowCount = null;
            // Deletion must occur in reverse order.
            for (int index = getCalls().size() - 1; index >= 0; index--) {
                DatasourceCall databseCall = (DatasourceCall) getCalls().elementAt(index);
                returnedRowCount = (Integer) executeCall(databseCall);
            }
            // returns the number of rows removed from the first table in insert order
            return returnedRowCount;
        } else {
            return (Integer) executeCall();
        }
    }
}
Also used : DeleteAllQuery(org.eclipse.persistence.queries.DeleteAllQuery) DatasourceCall(org.eclipse.persistence.internal.databaseaccess.DatasourceCall)

Example 3 with DatasourceCall

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

the class DatasourceCallQueryMechanism method prepareExecuteSelect.

/**
 * Pre-build configure the call.
 */
@Override
public void prepareExecuteSelect() {
    if (hasMultipleCalls()) {
        for (Enumeration callsEnum = getCalls().elements(); callsEnum.hasMoreElements(); ) {
            DatasourceCall databseCall = (DatasourceCall) callsEnum.nextElement();
            databseCall.returnManyRows();
        }
    } else {
        getCall().returnManyRows();
    }
    prepareCall();
}
Also used : Enumeration(java.util.Enumeration) DatasourceCall(org.eclipse.persistence.internal.databaseaccess.DatasourceCall)

Example 4 with DatasourceCall

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

the class DatasourceCallQueryMechanism method deleteAllUsingTempTables.

/**
 * Execute deleteAll using temp tables
 * @exception  DatabaseException - an error has occurred on the database.
 * @return the row count.
 */
public Integer deleteAllUsingTempTables() throws DatabaseException {
    DatabaseException ex = null;
    Integer returnedRowCount = null;
    // may fail in case global temp table already exists.
    try {
        DatasourceCall databseCall = (DatasourceCall) getCalls().elementAt(getCalls().size() - 1);
        executeCall(databseCall);
    } catch (DatabaseException databaseEx) {
    // ignore
    }
    // if that fails save the exception and untill cleanup
    try {
        DatasourceCall databseCall = (DatasourceCall) getCalls().elementAt(getCalls().size() - 2);
        executeCall(databseCall);
    } catch (DatabaseException databaseEx) {
        ex = databaseEx;
    }
    // if that fails save the exception untill cleanup
    for (int index = getCalls().size() - 3; index >= 1 && ex == null; index--) {
        DatasourceCall databseCall = (DatasourceCall) getCalls().elementAt(index);
        try {
            // returns the number of rows removed from the first table in insert order
            returnedRowCount = (Integer) executeCall(databseCall);
        } catch (DatabaseException databaseEx) {
            ex = databaseEx;
        }
    }
    // ignore exceptions here.
    try {
        DatasourceCall databseCall = (DatasourceCall) getCalls().elementAt(0);
        executeCall(databseCall);
    } catch (DatabaseException databaseEx) {
    // ignore
    }
    if (ex != null) {
        throw ex;
    }
    return returnedRowCount;
}
Also used : DatabaseException(org.eclipse.persistence.exceptions.DatabaseException) DatasourceCall(org.eclipse.persistence.internal.databaseaccess.DatasourceCall)

Example 5 with DatasourceCall

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

the class DatasourceCallQueryMechanism method prepareSelectAllRows.

/**
 * Pre-build configure the call.
 */
@Override
public void prepareSelectAllRows() {
    if (hasMultipleCalls()) {
        for (Enumeration callsEnum = getCalls().elements(); callsEnum.hasMoreElements(); ) {
            DatasourceCall databseCall = (DatasourceCall) callsEnum.nextElement();
            databseCall.returnManyRows();
        }
    } else {
        getCall().returnManyRows();
    }
    prepareCall();
}
Also used : Enumeration(java.util.Enumeration) DatasourceCall(org.eclipse.persistence.internal.databaseaccess.DatasourceCall)

Aggregations

DatasourceCall (org.eclipse.persistence.internal.databaseaccess.DatasourceCall)24 Enumeration (java.util.Enumeration)10 Vector (java.util.Vector)7 AbstractRecord (org.eclipse.persistence.internal.sessions.AbstractRecord)6 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)5 DatabaseTable (org.eclipse.persistence.internal.helper.DatabaseTable)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 List (java.util.List)2 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)2 DatabaseException (org.eclipse.persistence.exceptions.DatabaseException)2 Accessor (org.eclipse.persistence.internal.databaseaccess.Accessor)2 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)2 NonSynchronizedVector (org.eclipse.persistence.internal.helper.NonSynchronizedVector)2 DatabaseQuery (org.eclipse.persistence.queries.DatabaseQuery)2 EntityManager (jakarta.persistence.EntityManager)1 Query (jakarta.persistence.Query)1 Constructor (java.lang.reflect.Constructor)1 Method (java.lang.reflect.Method)1 Blob (java.sql.Blob)1