Search in sources :

Example 6 with DatabaseCall

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

the class StoredProcedureObjectRelationalParameters method getInsertCall.

public DatabaseCall getInsertCall() {
    DatabaseCall call = null;
    if (useCustomSQL) {
        String sqlString = "BEGIN SProc_Insert_PHolders(#ssn, #occupation, #sex, " + "#firstName, #birthDate, #lastName, #address, #childrenNames, #phones); END;";
        SQLCall sqlcall = new SQLCall(sqlString);
        // most are not needed unless null it to be passed in
        sqlcall.setCustomSQLArgumentType("ssn", Long.class);
        sqlcall.setCustomSQLArgumentType("occupation", String.class);
        sqlcall.setCustomSQLArgumentType("sex", Character.class);
        sqlcall.setCustomSQLArgumentType("firstName", String.class);
        sqlcall.setCustomSQLArgumentType("birthDate", java.sql.Date.class);
        sqlcall.setCustomSQLArgumentType("lastName", String.class);
        // address arg type isn't needed to convert Address to a Struct
        sqlcall.setCustomSQLArgumentType("address", Types.STRUCT, "ADDRESS_TYPE");
        sqlcall.setCustomSQLArgumentType("childrenNames", Types.ARRAY, "NAMELIST_TYPE");
        sqlcall.setCustomSQLArgumentType("phones", Types.ARRAY, "PHONELIST_TYPE");
        call = sqlcall;
    } else {
        StoredProcedureCall spcall = new StoredProcedureCall();
        spcall.setProcedureName("SProc_Insert_PHolders");
        spcall.addUnamedArgument("ssn", Long.class);
        spcall.addUnamedArgument("occupation", String.class);
        spcall.addUnamedArgument("sex", Character.class);
        spcall.addUnamedArgument("firstName", String.class);
        spcall.addUnamedArgument("birthDate", java.sql.Date.class);
        spcall.addUnamedArgument("lastName", String.class);
        // address arg type isn't needed to convert Address to a Struct
        spcall.addUnamedArgument("address", Types.STRUCT, "ADDRESS_TYPE");
        // test just passing in array objects (or nulls)
        spcall.addUnamedArgument("childrenNames", Types.ARRAY, "NAMELIST_TYPE");
        spcall.addUnamedArgument("phones", Types.ARRAY, "PHONELIST_TYPE");
        call = spcall;
    }
    return call;
}
Also used : DatabaseCall(org.eclipse.persistence.internal.databaseaccess.DatabaseCall) SQLCall(org.eclipse.persistence.queries.SQLCall) StoredProcedureCall(org.eclipse.persistence.queries.StoredProcedureCall)

Example 7 with DatabaseCall

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

the class SQLStatement method toString.

/**
 * Try to print the SQL.
 */
@Override
public String toString() {
    StringWriter writer = new StringWriter();
    writer.write(Helper.getShortClassName(getClass()));
    writer.write("(");
    try {
        DatabaseCall call = buildCall(new DatabaseSessionImpl(new org.eclipse.persistence.sessions.DatabaseLogin()));
        writer.write(call.getSQLString());
    } catch (Exception exception) {
    }
    writer.write(")");
    return writer.toString();
}
Also used : DatabaseCall(org.eclipse.persistence.internal.databaseaccess.DatabaseCall) DatabaseSessionImpl(org.eclipse.persistence.internal.sessions.DatabaseSessionImpl)

Example 8 with DatabaseCall

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

the class LOBValueWriter method buildCallFromSelectStatementForLocator.

/**
 * Build the sql call from the select statement for selecting the locator
 */
private DatabaseCall buildCallFromSelectStatementForLocator(SQLSelectStatement selectStatement, WriteObjectQuery writeQuery, DatabaseCall dbCall, AbstractSession session) {
    DatabaseCall call = selectStatement.buildCall(session);
    // Locator LOB must not be wrapped (WLS wraps LOBs).
    call.setIsNativeConnectionRequired(this.isNativeConnectionRequired);
    // the LOB context must be passed into the new call object
    call.setContexts(dbCall.getContexts());
    // need to explicitly define one row return, otherwise, EL assumes multiple rows return and confuses the accessor
    call.returnOneRow();
    // the query object has to be set in order to access to the platform and login objects
    call.setQuery(writeQuery);
    // prepare it
    call.prepare(session);
    // finally do the translation
    call.translate(writeQuery.getTranslationRow(), writeQuery.getModifyRow(), session);
    return call;
}
Also used : DatabaseCall(org.eclipse.persistence.internal.databaseaccess.DatabaseCall)

Example 9 with DatabaseCall

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

the class ExpressionQueryMechanism method selectAllRowsFromConcreteTable.

/**
 * Read all rows from the database.
 * This is used only from query mechanism on a abstract-multiple table read.
 */
public Vector selectAllRowsFromConcreteTable() throws DatabaseException {
    ObjectLevelReadQuery query = (ObjectLevelReadQuery) this.query;
    // PERF: First check the subclass calls cache for the prepared call.
    // Must clear the translation row to avoid in-lining parameters unless not a prepared query.
    boolean shouldPrepare = query.shouldPrepare();
    DatabaseCall call = null;
    if (shouldPrepare) {
        call = query.getConcreteSubclassCalls().get(query.getReferenceClass());
    }
    if (call == null) {
        AbstractRecord translationRow = query.getTranslationRow();
        if (shouldPrepare) {
            query.setTranslationRow(null);
        }
        setSQLStatement(buildConcreteSelectStatement());
        // Must also build the call.
        super.prepareSelectAllRows();
        if (shouldPrepare) {
            if (query.hasJoining()) {
                query.getConcreteSubclassJoinedMappingIndexes().put(query.getReferenceClass(), query.getJoinedAttributeManager().getJoinedMappingIndexes_());
            }
            query.getConcreteSubclassCalls().put(query.getReferenceClass(), (DatabaseCall) this.call);
            query.setTranslationRow(translationRow);
        }
    } else {
        setCall(call);
        if (shouldPrepare && query.hasJoining()) {
            query.getJoinedAttributeManager().setJoinedMappingIndexes_(query.getConcreteSubclassJoinedMappingIndexes().get(query.getReferenceClass()));
        }
    }
    return super.selectAllRows();
}
Also used : ObjectLevelReadQuery(org.eclipse.persistence.queries.ObjectLevelReadQuery) DatabaseCall(org.eclipse.persistence.internal.databaseaccess.DatabaseCall) AbstractRecord(org.eclipse.persistence.internal.sessions.AbstractRecord)

Example 10 with DatabaseCall

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

the class DatasourceCallQueryMechanism method selectResultSet.

/**
 * Read all rows from the database, return ResultSet
 * @exception  DatabaseException - an error has occurred on the database
 */
public DatabaseCall selectResultSet() throws DatabaseException {
    try {
        // For CR 2923 must move to session we will execute call on now
        // so correct DatasourcePlatform used by translate.
        AbstractSession sessionToUse = this.query.getExecutionSession();
        DatabaseCall clonedCall = (DatabaseCall) this.call.clone();
        clonedCall.setQuery(this.query);
        clonedCall.translate(this.query.getTranslationRow(), getModifyRow(), sessionToUse);
        clonedCall.returnCursor();
        return (DatabaseCall) sessionToUse.executeCall(clonedCall, this.query.getTranslationRow(), this.query);
    } catch (java.lang.ClassCastException e) {
        throw QueryException.invalidDatabaseCall(this.call);
    }
}
Also used : DatabaseCall(org.eclipse.persistence.internal.databaseaccess.DatabaseCall) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession)

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