Search in sources :

Example 16 with PLSQLStoredProcedureCall

use of org.eclipse.persistence.platform.database.oracle.plsql.PLSQLStoredProcedureCall in project eclipselink by eclipse-ee4j.

the class PLSQLProject method buildAddressListOutQuery.

protected DatabaseQuery buildAddressListOutQuery() {
    PLSQLrecord record = buildAddressRecord();
    PLSQLCollection collection = new PLSQLCollection();
    collection.setTypeName("PLSQL_P.PLSQL_ADDRESS_LIST");
    collection.setCompatibleType("PLSQL_P_PLSQL_ADDRESS_LIST");
    collection.setNestedType(record);
    PLSQLStoredProcedureCall call = new PLSQLStoredProcedureCall();
    call.setProcedureName("PLSQL_P.PLSQL_ADDRESS_LIST_OUT");
    call.addNamedOutputArgument("P_ADDRESS_LIST", collection);
    call.addNamedOutputArgument("P_CITY", JDBCTypes.VARCHAR_TYPE);
    DataReadQuery query = new DataReadQuery();
    query.setCall(call);
    return query;
}
Also used : PLSQLStoredProcedureCall(org.eclipse.persistence.platform.database.oracle.plsql.PLSQLStoredProcedureCall) PLSQLCollection(org.eclipse.persistence.platform.database.oracle.plsql.PLSQLCollection) PLSQLrecord(org.eclipse.persistence.platform.database.oracle.plsql.PLSQLrecord) DataReadQuery(org.eclipse.persistence.queries.DataReadQuery)

Example 17 with PLSQLStoredProcedureCall

use of org.eclipse.persistence.platform.database.oracle.plsql.PLSQLStoredProcedureCall in project eclipselink by eclipse-ee4j.

the class PLSQLProject method buildEmployeeListInQuery.

protected DatabaseQuery buildEmployeeListInQuery() {
    PLSQLrecord record = buildEmployeeRecord();
    PLSQLCollection collection = new PLSQLCollection();
    collection.setTypeName("PLSQL_P.PLSQL_EMP_LIST");
    collection.setCompatibleType("PLSQL_P_PLSQL_EMP_LIST");
    collection.setNestedType(record);
    PLSQLStoredProcedureCall call = new PLSQLStoredProcedureCall();
    call.setProcedureName("PLSQL_P.PLSQL_EMP_LIST_IN");
    call.addNamedArgument("P_EMP_LIST", collection);
    call.addNamedArgument("P_CITY", JDBCTypes.VARCHAR_TYPE);
    DataModifyQuery query = new DataModifyQuery();
    query.addArgument("P_EMP_LIST", java.sql.Array.class);
    query.addArgument("P_CITY", String.class);
    query.setCall(call);
    return query;
}
Also used : PLSQLStoredProcedureCall(org.eclipse.persistence.platform.database.oracle.plsql.PLSQLStoredProcedureCall) PLSQLCollection(org.eclipse.persistence.platform.database.oracle.plsql.PLSQLCollection) PLSQLrecord(org.eclipse.persistence.platform.database.oracle.plsql.PLSQLrecord) DataModifyQuery(org.eclipse.persistence.queries.DataModifyQuery)

Example 18 with PLSQLStoredProcedureCall

use of org.eclipse.persistence.platform.database.oracle.plsql.PLSQLStoredProcedureCall in project eclipselink by eclipse-ee4j.

the class PLSQLTestSuite method testOracleTypeProcessing.

/**
 * Test processing of OracleObject and OracleArray annotations.
 *
 * @see OracleArray
 * @see org.eclipse.persistence.platform.database.oracle.annotations.OracleObject
 */
public void testOracleTypeProcessing() {
    if (!getServerSession().getPlatform().isOracle()) {
        return;
    }
    EntityManager em = createEntityManager();
    beginTransaction(em);
    try {
        Query query = em.createNamedQuery("TEST_ORACLE_TYPES");
        assertNotNull("EntityManager could not create query [TEST_ORACLE_TYPES]", query);
        assertTrue("Expected EJBQueryImpl but was [" + query.getClass().getName() + "]", query instanceof EJBQueryImpl);
        DatabaseCall call = ((EJBQueryImpl) query).getDatabaseQuery().getCall();
        assertNotNull("The DatabaseCall was not set on the query", call);
        assertTrue("Expected PLSQLStoredProcedureCall but was [" + call.getClass().getName() + "]", call instanceof PLSQLStoredProcedureCall);
        PLSQLStoredProcedureCall plsqlCall = (PLSQLStoredProcedureCall) call;
        List<PLSQLargument> args = plsqlCall.getArguments();
        assertTrue("Expected 2 arguments, but was [" + args.size() + "]", args.size() == 2);
        boolean foundINArg = false;
        boolean foundOUTArg = false;
        for (PLSQLargument arg : args) {
            if (arg.name.equals("P_IN")) {
                foundINArg = true;
                assertNotNull("databaseType for arg P_IN is null", arg.databaseType);
                assertTrue("Expected arg P_IN to be an OracleArrayType, but was [" + arg.databaseType.getClass().getName() + "]", arg.databaseType instanceof OracleArrayType);
                OracleArrayType arrayType = (OracleArrayType) arg.databaseType;
                assertTrue("Expected arg P_IN to have databaseType set with type name VARRAY_NUMERO_UNO, but was [" + arrayType.getTypeName() + "]", arrayType.getTypeName().equals("VARRAY_NUMERO_UNO"));
                assertNotNull("Expected VARRAY_NUMERO_UNO to have nested type VARCHAR, but was null", arrayType.getNestedType());
                assertTrue("Expected VARRAY_NUMERO_UNO to have nested type VARCHAR, but was [" + arrayType.getNestedType().getTypeName() + "]", arrayType.getNestedType().getTypeName().equals("VARCHAR"));
            } else if (arg.name.equals("P_OUT")) {
                foundOUTArg = true;
                assertNotNull("databaseType for arg P_OUT is null", arg.databaseType);
                assertTrue("Expected arg P_OUT to be an OracleObjectType, but was [" + arg.databaseType.getClass().getName() + "]", arg.databaseType instanceof OracleObjectType);
                OracleObjectType objectType = (OracleObjectType) arg.databaseType;
                assertTrue("Expected arg P_OUT to have databaseType set with type name OBJECT_NUMERO_DOS, but was [" + objectType.getTypeName() + "]", objectType.getTypeName().equals("OBJECT_NUMERO_DOS"));
                assertTrue("Expected OBJECT_NUMERO_DOS to have 2 fields, but was [" + objectType.getFields().size() + "]", objectType.getFields().size() == 2);
                for (String key : objectType.getFields().keySet()) {
                    DatabaseType dbType = objectType.getFields().get(key);
                    if (key.equals("OO_FLD1")) {
                        assertTrue("Expected field OO_FLD1 to have databaseType NUMERIC, but was [" + dbType.getTypeName() + "]", dbType.getTypeName().equals("NUMERIC"));
                    } else if (key.equals("OO_FLD2")) {
                        assertTrue("Expected field OO_FLD2 to have databaseType NUMERIC, but was [" + dbType.getTypeName() + "]", dbType.getTypeName().equals("NUMERIC"));
                    } else {
                        fail("Expected OBJECT_NUMERO_DOS to have fields OO_FLD1 and OO_FLD2 but encountered field [" + key + "]");
                    }
                }
            } else {
                fail("Expected arg name to be one of P_IN or P_OUT, but was [" + arg.name + "]");
            }
        }
        assertTrue("IN arg P_IN was not processed", foundINArg);
        assertTrue("OUT arg P_OUT was not processed", foundOUTArg);
    } finally {
        closeEntityManagerAndTransaction(em);
    }
}
Also used : DatabaseCall(org.eclipse.persistence.internal.databaseaccess.DatabaseCall) EntityManager(jakarta.persistence.EntityManager) PLSQLStoredProcedureCall(org.eclipse.persistence.platform.database.oracle.plsql.PLSQLStoredProcedureCall) Query(jakarta.persistence.Query) DatabaseType(org.eclipse.persistence.internal.helper.DatabaseType) OracleObjectType(org.eclipse.persistence.platform.database.oracle.jdbc.OracleObjectType) EJBQueryImpl(org.eclipse.persistence.internal.jpa.EJBQueryImpl) PLSQLargument(org.eclipse.persistence.platform.database.oracle.plsql.PLSQLargument) OracleArrayType(org.eclipse.persistence.platform.database.oracle.jdbc.OracleArrayType)

Example 19 with PLSQLStoredProcedureCall

use of org.eclipse.persistence.platform.database.oracle.plsql.PLSQLStoredProcedureCall in project eclipselink by eclipse-ee4j.

the class NijioNijioTestSet method writeToXml.

@Test
public void writeToXml() {
    // PROCEDURE NIJIONIJIO(X IN PLS_INTEGER, Y IN OUT NUMBER, Z IN BOOLEAN, AA IN OUT VARCHAR)
    PLSQLStoredProcedureCall call = new PLSQLStoredProcedureCall();
    call.setProcedureName("NijioNijio");
    call.addNamedArgument("X", OraclePLSQLTypes.PLSQLInteger);
    call.addNamedInOutputArgument("Y", JDBCTypes.NUMERIC_TYPE, 22, 2);
    call.addNamedArgument("Z", OraclePLSQLTypes.PLSQLBoolean);
    call.addNamedInOutputArgument("AA", JDBCTypes.VARCHAR_TYPE, 10);
    DataReadQuery query = new DataReadQuery();
    query.addArgument("X", Integer.class);
    query.addArgument("Y", BigDecimal.class);
    query.addArgument("Z", Integer.class);
    query.addArgument("AA", String.class);
    query.setCall(call);
    project.getDescriptor(Empty.class).getQueryManager().addQuery("NijioNijio", query);
    Project projectToXml = project.clone();
    // trim off login 'cause it changes under test - this way, a comparison
    // can be done to a control document
    projectToXml.setDatasourceLogin(null);
    XMLContext context = new XMLContext(workbenchXMLProject);
    XMLMarshaller marshaller = context.createMarshaller();
    Document doc = marshaller.objectToXML(projectToXml);
    Document controlDoc = xmlParser.parse(new StringReader(NIJIONIJIO_PROJECT_XML));
    assertTrue("control document not same as instance document", comparer.isNodeEqual(controlDoc, doc));
}
Also used : ObjectPersistenceWorkbenchXMLProject(org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceWorkbenchXMLProject) NonJDBCTestHelper.buildTestProject(org.eclipse.persistence.testing.tests.nonJDBC.NonJDBCTestHelper.buildTestProject) NonJDBCTestHelper.buildWorkbenchXMLProject(org.eclipse.persistence.testing.tests.nonJDBC.NonJDBCTestHelper.buildWorkbenchXMLProject) Project(org.eclipse.persistence.sessions.Project) PLSQLStoredProcedureCall(org.eclipse.persistence.platform.database.oracle.plsql.PLSQLStoredProcedureCall) XMLContext(org.eclipse.persistence.oxm.XMLContext) XMLMarshaller(org.eclipse.persistence.oxm.XMLMarshaller) StringReader(java.io.StringReader) DataReadQuery(org.eclipse.persistence.queries.DataReadQuery) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 20 with PLSQLStoredProcedureCall

use of org.eclipse.persistence.platform.database.oracle.plsql.PLSQLStoredProcedureCall in project eclipselink by eclipse-ee4j.

the class Ni4TestSet method writeToXml.

@Test
public void writeToXml() {
    // (y in dec)
    PLSQLStoredProcedureCall call = new PLSQLStoredProcedureCall();
    call.setProcedureName("dec_in_test");
    call.addNamedArgument("Y", OraclePLSQLTypes.Dec);
    DataModifyQuery query = new DataModifyQuery();
    query.addArgument("Y", Integer.class);
    query.setCall(call);
    project.getDescriptor(Empty.class).getQueryManager().addQuery("Ni4", query);
    Project projectToXml = project.clone();
    // trim off login 'cause it changes under test - this way, a comparison
    // can be done to a control document
    projectToXml.setDatasourceLogin(null);
    XMLContext context = new XMLContext(workbenchXMLProject);
    XMLMarshaller marshaller = context.createMarshaller();
    Document doc = marshaller.objectToXML(projectToXml);
    Document controlDoc = xmlParser.parse(new StringReader(NI4_PROJECT_XML));
    assertTrue("control document not same as instance document", comparer.isNodeEqual(controlDoc, doc));
}
Also used : ObjectPersistenceWorkbenchXMLProject(org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceWorkbenchXMLProject) NonJDBCTestHelper.buildTestProject(org.eclipse.persistence.testing.tests.nonJDBC.NonJDBCTestHelper.buildTestProject) NonJDBCTestHelper.buildWorkbenchXMLProject(org.eclipse.persistence.testing.tests.nonJDBC.NonJDBCTestHelper.buildWorkbenchXMLProject) Project(org.eclipse.persistence.sessions.Project) PLSQLStoredProcedureCall(org.eclipse.persistence.platform.database.oracle.plsql.PLSQLStoredProcedureCall) XMLContext(org.eclipse.persistence.oxm.XMLContext) XMLMarshaller(org.eclipse.persistence.oxm.XMLMarshaller) StringReader(java.io.StringReader) Document(org.w3c.dom.Document) DataModifyQuery(org.eclipse.persistence.queries.DataModifyQuery) Test(org.junit.Test)

Aggregations

PLSQLStoredProcedureCall (org.eclipse.persistence.platform.database.oracle.plsql.PLSQLStoredProcedureCall)67 ObjectPersistenceWorkbenchXMLProject (org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceWorkbenchXMLProject)37 Project (org.eclipse.persistence.sessions.Project)37 StringReader (java.io.StringReader)36 XMLContext (org.eclipse.persistence.oxm.XMLContext)36 XMLMarshaller (org.eclipse.persistence.oxm.XMLMarshaller)36 Test (org.junit.Test)36 Document (org.w3c.dom.Document)36 DataModifyQuery (org.eclipse.persistence.queries.DataModifyQuery)32 NonJDBCTestHelper.buildTestProject (org.eclipse.persistence.testing.tests.nonJDBC.NonJDBCTestHelper.buildTestProject)30 NonJDBCTestHelper.buildWorkbenchXMLProject (org.eclipse.persistence.testing.tests.nonJDBC.NonJDBCTestHelper.buildWorkbenchXMLProject)30 DataReadQuery (org.eclipse.persistence.queries.DataReadQuery)28 PLSQLrecord (org.eclipse.persistence.platform.database.oracle.plsql.PLSQLrecord)24 PLSQLCollection (org.eclipse.persistence.platform.database.oracle.plsql.PLSQLCollection)12 PLSQLrecordTestHelper.buildTestProject (org.eclipse.persistence.testing.tests.plsqlrecord.PLSQLrecordTestHelper.buildTestProject)6 PLSQLrecordTestHelper.buildWorkbenchXMLProject (org.eclipse.persistence.testing.tests.plsqlrecord.PLSQLrecordTestHelper.buildWorkbenchXMLProject)6 PLSQLargument (org.eclipse.persistence.platform.database.oracle.plsql.PLSQLargument)3 ReadObjectQuery (org.eclipse.persistence.queries.ReadObjectQuery)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2