Search in sources :

Example 1 with DatabaseCall

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

the class StoredProcedureTest_Inout_Out_In method test.

@Override
public void test() {
    DatabaseCall call = null;
    if (useCustomSQL) {
        String str;
        SQLCall sqlCall = null;
        if (mode == PROC) {
            str = "BEGIN StoredProcedure_InOut_Out_In(####P_INOUT, ###P_OUT, #P_IN); END;";
            sqlCall = new SQLCall(str);
        } else if (mode == FUNC) {
            str = "BEGIN ###RESULT := StoredFunction_InOut_Out_In(####P_INOUT, ###P_OUT, #P_IN); END;";
            sqlCall = new SQLCall(str);
            sqlCall.setCustomSQLArgumentType("RESULT", Integer.class);
        }
        sqlCall.setCustomSQLArgumentType("P_OUT", Integer.class);
        call = sqlCall;
    } else {
        StoredProcedureCall spCall = null;
        if (mode == PROC) {
            spCall = new StoredProcedureCall();
            spCall.setProcedureName("StoredProcedure_InOut_Out_In");
        } else if (mode == FUNC) {
            StoredFunctionCall sfCall = new StoredFunctionCall();
            sfCall.setProcedureName("StoredFunction_InOut_Out_In");
            sfCall.setResult("RESULT", Integer.class);
            spCall = sfCall;
        }
        if (useArgumentNames) {
            // spCall.addNamedInOutputArgument("P_INOUT", "P_INOUT", "P_INOUT", Integer.class);
            spCall.addNamedInOutputArgument("P_INOUT");
            spCall.addNamedOutputArgument("P_OUT", "P_OUT", Integer.class);
            spCall.addNamedArgument("P_IN");
        } else {
            // spCall.addUnamedInOutputArgument("P_INOUT", Integer.class);
            spCall.addUnamedInOutputArgument("P_INOUT");
            spCall.addUnamedOutputArgument("P_OUT", Integer.class);
            spCall.addUnamedArgument("P_IN");
        }
        call = spCall;
    }
    DataReadQuery query = new DataReadQuery();
    query.setShouldBindAllParameters(shouldBindAllParameters);
    query.setCall(call);
    query.addArgument("P_IN");
    query.addArgument("P_INOUT");
    Vector args = new Vector(2);
    args.addElement(in);
    args.addElement(inout);
    row = (DatabaseRecord) ((Vector) getSession().executeQuery(query, args)).firstElement();
}
Also used : DatabaseCall(org.eclipse.persistence.internal.databaseaccess.DatabaseCall)

Example 2 with DatabaseCall

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

the class StoredProcedureVARRAYParametersTest method getDeleteCall.

@Override
public DatabaseCall getDeleteCall() {
    DatabaseCall call = null;
    ObjectRelationalDatabaseField ordf = new ObjectRelationalDatabaseField("");
    ordf.setSqlType(Types.STRUCT);
    ordf.setSqlTypeName("PHONE_TYPE");
    ordf.setType(Phone.class);
    if (useCustomSQL) {
        String sqlString = "BEGIN SProc_Delete_PHolders(####ssn, ####occupation, ####sex, " + "####firstName, ####birthDate, ####lastName, ####address, ####childrenNames, ####phones); END;";
        SQLCall sqlcall = new SQLCall(sqlString);
        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);
        sqlcall.setCustomSQLArgumentType("address", Types.STRUCT, "ADDRESS_TYPE");
        sqlcall.setCustomSQLArgumentType("childrenNames", Types.ARRAY, "NAMELIST_TYPE", Vector.class);
        sqlcall.setCustomSQLArgumentType("phones", Types.ARRAY, "PHONELIST_TYPE", Vector.class, ordf);
        call = sqlcall;
    } else {
        StoredProcedureCall sqlcall = new StoredProcedureCall();
        sqlcall.setProcedureName("SProc_Delete_PHolders");
        sqlcall.addUnamedInOutputArgument("ssn", Long.class);
        sqlcall.addUnamedInOutputArgument("occupation", String.class);
        sqlcall.addUnamedInOutputArgument("sex", Character.class);
        sqlcall.addUnamedInOutputArgument("firstName", String.class);
        sqlcall.addUnamedInOutputArgument("birthDate", java.sql.Date.class);
        sqlcall.addUnamedInOutputArgument("lastName", String.class);
        sqlcall.addUnamedInOutputArgument("address", "address", Types.STRUCT, "ADDRESS_TYPE");
        sqlcall.addUnamedInOutputArgument("childrenNames", "childrenNames", Types.ARRAY, "NAMELIST_TYPE", Vector.class);
        sqlcall.addUnamedInOutputArgument("phones", "phones", Types.ARRAY, "PHONELIST_TYPE", Vector.class, ordf);
        call = sqlcall;
    }
    return call;
}
Also used : DatabaseCall(org.eclipse.persistence.internal.databaseaccess.DatabaseCall) SQLCall(org.eclipse.persistence.queries.SQLCall) ObjectRelationalDatabaseField(org.eclipse.persistence.mappings.structures.ObjectRelationalDatabaseField) StoredProcedureCall(org.eclipse.persistence.queries.StoredProcedureCall)

Example 3 with DatabaseCall

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

the class StoredProcedureVARRAYParametersTest method getReadCall.

@Override
public DatabaseCall getReadCall() {
    DatabaseCall call = null;
    ObjectRelationalDatabaseField ordf = new ObjectRelationalDatabaseField("");
    ordf.setSqlType(Types.STRUCT);
    ordf.setSqlTypeName("PHONE_TYPE");
    ordf.setType(Phone.class);
    if (useCustomSQL) {
        String sqlString = "BEGIN SProc_Read_PHolders(####ssn, ###occupation, ###sex, " + "###firstName, ###birthDate, ###lastName, ###address, ###childrenNames, ###phones); END;";
        SQLCall sqlcall = new SQLCall(sqlString);
        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);
        sqlcall.setCustomSQLArgumentType("address", Types.STRUCT, "ADDRESS_TYPE");
        sqlcall.setCustomSQLArgumentType("childrenNames", Types.ARRAY, "NAMELIST_TYPE", Vector.class);
        sqlcall.setCustomSQLArgumentType("phones", Types.ARRAY, "PHONELIST_TYPE", Vector.class, ordf);
        call = sqlcall;
    } else {
        StoredProcedureCall spcall = new StoredProcedureCall();
        spcall.setProcedureName("SProc_Read_PHolders");
        spcall.addUnamedInOutputArgument("ssn", Long.class);
        spcall.addUnamedOutputArgument("occupation", String.class);
        spcall.addUnamedOutputArgument("sex", Character.class);
        spcall.addUnamedOutputArgument("firstName", String.class);
        spcall.addUnamedOutputArgument("birthDate", java.sql.Date.class);
        spcall.addUnamedOutputArgument("lastName", String.class);
        spcall.addUnamedOutputArgument("address", Types.STRUCT, "ADDRESS_TYPE");
        spcall.addUnamedOutputArgument("childrenNames", Types.ARRAY, "NAMELIST_TYPE", Vector.class);
        spcall.addUnamedOutputArgument("phones", Types.ARRAY, "PHONELIST_TYPE", Vector.class, ordf);
        call = spcall;
    }
    return call;
}
Also used : DatabaseCall(org.eclipse.persistence.internal.databaseaccess.DatabaseCall) SQLCall(org.eclipse.persistence.queries.SQLCall) ObjectRelationalDatabaseField(org.eclipse.persistence.mappings.structures.ObjectRelationalDatabaseField) StoredProcedureCall(org.eclipse.persistence.queries.StoredProcedureCall)

Example 4 with DatabaseCall

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

the class StoredProcWithOutputParamsAndResultSetTest method test.

@Override
public void test() {
    ReadAllQuery readQuery = new ReadAllQuery(Employee.class);
    DatabaseCall call;
    SQLCall sqlCall;
    StoredProcedureCall spCall;
    // sybase can not do out params only
    boolean useInOut = getSession().getPlatform().isSybase() || getSession().getPlatform().isSQLAnywhere();
    if (useCustomSQL) {
        String prefix;
        if (useInOut) {
            prefix = "####";
        } else {
            prefix = "###";
        }
        String parameterNamePrefix = getSession().getPlatform().getStoredProcedureParameterPrefix();
        sqlCall = new SQLCall("EXECUTE Select_Output_and_ResultSet " + parameterNamePrefix + "ARG1 = #argument, " + parameterNamePrefix + "VERSION = " + prefix + "version " + getSession().getPlatform().getOutputProcedureToken());
        sqlCall.setCustomSQLArgumentType("version", BigDecimal.class);
        call = sqlCall;
    } else {
        spCall = new StoredProcedureCall();
        spCall.setProcedureName("Select_Output_and_ResultSet");
        spCall.addNamedArgument("ARG1", "argument");
        if (useInOut) {
            spCall.addNamedInOutputArgumentValue("VERSION", 0L, "VERSION", java.math.BigDecimal.class);
        } else {
            spCall.addNamedOutputArgument("VERSION", "VERSION", BigDecimal.class);
        }
        call = spCall;
    }
    call.setReturnsResultSet(true);
    readQuery.setCall(call);
    readQuery.addArgument("argument");
    if (useCustomSQL && useInOut) {
        readQuery.addArgument("version");
    }
    getSession().removeQuery("dblogin");
    getSession().addQuery("dblogin", readQuery);
    Vector args = new Vector(2);
    args.addElement(1);
    if (useCustomSQL && useInOut) {
        args.addElement(0L);
    }
    try {
        Vector vResult = (Vector) getSession().executeQuery("dblogin", args);
    } catch (ClassCastException e) {
        throw new TestErrorException("Stored Procedure is returning a Row and the query expects a Vector");
    }
    readQuery = new ReadAllQuery(Employee.class);
    if (useCustomSQL) {
        return;
    } else {
        spCall = new StoredProcedureCall();
        spCall.setProcedureName("Select_Output_and_ResultSet");
        spCall.addNamedArgumentValue("ARG1", 1);
        if (useInOut) {
            spCall.addNamedInOutputArgumentValue("VERSION", 0L, "VERSION", java.math.BigDecimal.class);
        } else {
            spCall.addNamedOutputArgument("VERSION", "VERSION", BigDecimal.class);
        }
        call = spCall;
    }
    call.setReturnsResultSet(true);
    readQuery.setCall(call);
    try {
        Vector vResult = (Vector) getSession().executeQuery(readQuery);
    } catch (ClassCastException e) {
        throw new TestErrorException("Stored Procedure is returning a Row and the query expects a Vector");
    }
}
Also used : DatabaseCall(org.eclipse.persistence.internal.databaseaccess.DatabaseCall) Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) Vector(java.util.Vector)

Example 5 with DatabaseCall

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

the class StoredProcedureObjectRelationalParameters method getReadCall.

public DatabaseCall getReadCall() {
    DatabaseCall call = null;
    if (useCustomSQL) {
        String sqlString = "BEGIN SProc_Read_PHolders(####ssn, ###occupation, ###sex, " + "###firstName, ###birthDate, ###lastName, ###address, ###childrenNames, ###phones); END;";
        SQLCall sqlcall = new SQLCall(sqlString);
        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);
        sqlcall.setCustomSQLArgumentType("address", Types.STRUCT, "ADDRESS_TYPE", Address.class);
        sqlcall.setCustomSQLArgumentType("childrenNames", Types.ARRAY, "NAMELIST_TYPE");
        sqlcall.setCustomSQLArgumentType("phones", Types.ARRAY, "PHONELIST_TYPE");
        call = sqlcall;
    } else {
        StoredProcedureCall spcall = new StoredProcedureCall();
        spcall.setProcedureName("SProc_Read_PHolders");
        spcall.addUnamedInOutputArgument("ssn", Long.class);
        spcall.addUnamedOutputArgument("occupation", String.class);
        spcall.addUnamedOutputArgument("sex", Character.class);
        spcall.addUnamedOutputArgument("firstName", String.class);
        spcall.addUnamedOutputArgument("birthDate", java.sql.Date.class);
        spcall.addUnamedOutputArgument("lastName", String.class);
        spcall.addUnamedOutputArgument("address", Types.STRUCT, "ADDRESS_TYPE", Address.class);
        spcall.addUnamedOutputArgument("childrenNames", Types.ARRAY, "NAMELIST_TYPE");
        spcall.addUnamedOutputArgument("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)

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