Search in sources :

Example 1 with OracleObjectType

use of org.eclipse.persistence.platform.database.oracle.jdbc.OracleObjectType in project eclipselink by eclipse-ee4j.

the class OracleObjectTypeMetadata method process.

/**
 * INTERNAL:
 * Build a runtime Oracle object type from the meta-data.
 */
@Override
public OracleObjectType process() {
    OracleObjectType objectType = new OracleObjectType();
    super.process(objectType);
    Map<String, DatabaseType> typeFields = new HashMap<String, DatabaseType>();
    for (PLSQLParameterMetadata field : this.fields) {
        typeFields.put(field.getName(), getDatabaseTypeEnum(field.getDatabaseType()));
    }
    objectType.setFields(typeFields);
    return objectType;
}
Also used : DatabaseType(org.eclipse.persistence.internal.helper.DatabaseType) OracleObjectType(org.eclipse.persistence.platform.database.oracle.jdbc.OracleObjectType) HashMap(java.util.HashMap)

Example 2 with OracleObjectType

use of org.eclipse.persistence.platform.database.oracle.jdbc.OracleObjectType in project eclipselink by eclipse-ee4j.

the class OracleHelper method buildQueryForProcedureType.

/**
 * Build a Query for the given ProcedureType instance and add
 * it to the given OR project's list of queries.
 */
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
protected void buildQueryForProcedureType(ProcedureType procType, Project orProject, Project oxProject, ProcedureOperationModel opModel, boolean hasPLSQLArgs) {
    // if there are one or more PL/SQL args, then we need a PLSQLStoredProcedureCall
    StoredProcedureCall call;
    ArgumentType returnArg = procType.isFunctionType() ? ((FunctionType) procType).getReturnArgument() : null;
    // check for PL/SQL cursor arg
    boolean hasCursor = hasPLSQLCursorArg(getArgumentListForProcedureType(procType));
    hasPLSQLArgs = hasPLSQLArgs || hasCursor || opModel.isPLSQLProcedureOperation();
    if (hasPLSQLArgs) {
        if (procType.isFunctionType()) {
            org.eclipse.persistence.internal.helper.DatabaseType dType = buildDatabaseTypeFromMetadataType(returnArg, procType.getCatalogName());
            if (hasCursor) {
                call = new PLSQLStoredFunctionCall();
                // constructor by default adds a RETURN argument, so remove it
                ((PLSQLStoredFunctionCall) call).getArguments().remove(0);
                ((PLSQLStoredFunctionCall) call).useNamedCursorOutputAsResultSet(CURSOR_STR, dType);
            } else {
                Class wrapperClass = getWrapperClass(dType);
                if (wrapperClass != null) {
                    ((ComplexDatabaseType) dType).setJavaType(wrapperClass);
                }
                call = new PLSQLStoredFunctionCall(dType);
                // check for non-associative collection
                if (returnArg.getEnclosedType().isPLSQLCollectionType() && !((PLSQLCollectionType) returnArg.getEnclosedType()).isIndexed()) {
                    PLSQLargument plsqlArg = ((PLSQLStoredFunctionCall) call).getArguments().get(0);
                    ((PLSQLCollection) plsqlArg.databaseType).setIsNestedTable(true);
                }
            }
        } else {
            call = new PLSQLStoredProcedureCall();
        }
    } else {
        if (procType.isFunctionType()) {
            String javaTypeName = returnArg.getTypeName();
            ClassDescriptor desc = oxProject.getDescriptorForAlias(getGeneratedAlias(javaTypeName));
            if (desc != null) {
                javaTypeName = desc.getJavaClassName();
            }
            if (returnArg.isComposite()) {
                DatabaseType dataType = returnArg.getEnclosedType();
                if (dataType.isVArrayType() || dataType.isObjectTableType()) {
                    call = new StoredFunctionCall(Types.ARRAY, returnArg.getTypeName(), javaTypeName, buildFieldForNestedType(dataType));
                } else {
                    // assumes ObjectType
                    call = new StoredFunctionCall(Types.STRUCT, returnArg.getTypeName(), javaTypeName);
                }
            } else {
                // scalar
                call = new StoredFunctionCall();
                if (returnArg.getEnclosedType().isBlobType()) {
                    // handle BLOBs
                    ((StoredFunctionCall) call).setResult(null, ClassConstants.BLOB);
                } else {
                    int resultType = Util.getJDBCTypeFromTypeName(javaTypeName);
                    // need special handling for Date types
                    if (resultType == Types.DATE || resultType == Types.TIME || resultType == Types.TIMESTAMP) {
                        ((StoredFunctionCall) call).setResult(null, ClassConstants.TIMESTAMP);
                    } else if (returnArg.getEnclosedType() == ScalarDatabaseTypeEnum.XMLTYPE_TYPE) {
                        // special handling for XMLType types
                        ((StoredFunctionCall) call).setResult(getJDBCTypeForTypeName(XMLTYPE_STR), XMLTYPE_STR, ClassConstants.OBJECT);
                    } else if (resultType == Types.OTHER || resultType == Types.CLOB) {
                        // default to OBJECT for OTHER, CLOB and LONG types
                        ((StoredFunctionCall) call).setResult(null, ClassConstants.OBJECT);
                    } else {
                        ((StoredFunctionCall) call).setResult(null, resultType);
                    }
                }
            }
        } else {
            call = new StoredProcedureCall();
        }
    }
    String cat = procType.getCatalogName();
    String catalogPrefix = (cat == null || cat.length() == 0) ? EMPTY_STRING : cat + DOT;
    call.setProcedureName(catalogPrefix + procType.getProcedureName());
    String returnType = opModel.getReturnType();
    boolean hasResponse = returnType != null;
    DatabaseQuery dq = null;
    if (hasCursor || (hasResponse && opModel.isCollection())) {
        dq = new DataReadQuery();
    } else {
        dq = new ValueReadQuery();
    }
    dq.bindAllParameters();
    dq.setName(getNameForQueryOperation(opModel, procType));
    dq.setCall(call);
    for (ArgumentType arg : procType.getArguments()) {
        // handle optional arg
        if (arg.optional()) {
            call.addOptionalArgument(arg.getArgumentName());
        }
        DatabaseType argType = arg.getEnclosedType();
        ArgumentTypeDirection direction = arg.getDirection();
        // for PL/SQL
        org.eclipse.persistence.internal.helper.DatabaseType databaseType = null;
        // for Advanced JDBC
        String javaTypeName = null;
        if (hasPLSQLArgs) {
            databaseType = buildDatabaseTypeFromMetadataType(argType, cat);
        } else {
            javaTypeName = argType.getTypeName();
            ClassDescriptor desc = oxProject.getDescriptorForAlias(getGeneratedAlias(javaTypeName));
            if (desc != null) {
                // anything there's a descriptor for will include "packagename." in the class name
                javaTypeName = desc.getJavaClassName();
            }
        }
        if (direction == IN) {
            if (hasPLSQLArgs) {
                Class wrapperClass = getWrapperClass(databaseType);
                if (wrapperClass != null) {
                    ((ComplexDatabaseType) databaseType).setJavaType(wrapperClass);
                }
                ((PLSQLStoredProcedureCall) call).addNamedArgument(arg.getArgumentName(), databaseType);
                // check for non-associative collection
                if (argType.isPLSQLCollectionType() && !((PLSQLCollectionType) argType).isIndexed()) {
                    PLSQLargument plsqlArg = ((PLSQLStoredProcedureCall) call).getArguments().get(((PLSQLStoredProcedureCall) call).getArguments().size() - 1);
                    ((PLSQLCollection) plsqlArg.databaseType).setIsNestedTable(true);
                }
            } else {
                if (argType.isVArrayType()) {
                    dq.addArgument(arg.getArgumentName());
                    call.addNamedArgument(arg.getArgumentName(), arg.getArgumentName(), Types.ARRAY, argType.getTypeName(), javaTypeName);
                } else if (argType.isObjectType()) {
                    dq.addArgument(arg.getArgumentName());
                    call.addNamedArgument(arg.getArgumentName(), arg.getArgumentName(), Types.STRUCT, argType.getTypeName(), javaTypeName);
                } else if (argType.isObjectTableType()) {
                    dq.addArgument(arg.getArgumentName(), java.sql.Array.class);
                    call.addNamedArgument(arg.getArgumentName(), arg.getArgumentName(), Types.ARRAY, argType.getTypeName(), getWrapperClass(javaTypeName), buildFieldForNestedType(argType));
                } else {
                    dq.addArgument(arg.getArgumentName());
                    call.addNamedArgument(arg.getArgumentName(), arg.getArgumentName(), Util.getJDBCTypeFromTypeName(argType.getTypeName()));
                }
            }
        } else if (direction == OUT) {
            if (hasPLSQLArgs) {
                if (arg.isPLSQLCursorType()) {
                    ((PLSQLStoredProcedureCall) call).useNamedCursorOutputAsResultSet(arg.getArgumentName(), databaseType);
                } else {
                    Class wrapperClass = getWrapperClass(databaseType);
                    if (wrapperClass != null) {
                        ((ComplexDatabaseType) databaseType).setJavaType(wrapperClass);
                    }
                    ((PLSQLStoredProcedureCall) call).addNamedOutputArgument(arg.getArgumentName(), databaseType);
                }
            } else {
                if (argType.isComposite()) {
                    Class wrapperClass = getWrapperClass(javaTypeName);
                    if (argType.isVArrayType() || argType.isObjectTableType()) {
                        call.addNamedOutputArgument(arg.getArgumentName(), arg.getArgumentName(), Types.ARRAY, argType.getTypeName(), wrapperClass, buildFieldForNestedType(argType));
                    } else {
                        // assumes ObjectType
                        call.addNamedOutputArgument(arg.getArgumentName(), arg.getArgumentName(), Types.STRUCT, argType.getTypeName(), wrapperClass);
                    }
                } else {
                    // need special handling for XMLType - we want the type code to be 'OPAQUE' (2007)
                    if (argType == ScalarDatabaseTypeEnum.XMLTYPE_TYPE) {
                        call.addNamedOutputArgument(arg.getArgumentName(), arg.getArgumentName(), getJDBCTypeForTypeName(XMLTYPE_STR), XMLTYPE_STR);
                    } else if (argType == ScalarDatabaseTypeEnum.SYS_REFCURSOR_TYPE) {
                        call.addNamedCursorOutputArgument(arg.getArgumentName());
                    } else {
                        call.addNamedOutputArgument(arg.getArgumentName(), arg.getArgumentName(), Util.getJDBCTypeFromTypeName(argType.getTypeName()));
                    }
                }
            }
        } else {
            // INOUT
            if (hasPLSQLArgs) {
                Class wrapperClass = getWrapperClass(databaseType);
                if (wrapperClass != null) {
                    ((ComplexDatabaseType) databaseType).setJavaType(wrapperClass);
                }
                ((PLSQLStoredProcedureCall) call).addNamedInOutputArgument(arg.getArgumentName(), databaseType);
                // check for non-associative collection
                if (argType.isPLSQLCollectionType() && !((PLSQLCollectionType) argType).isIndexed()) {
                    PLSQLargument plsqlArg = ((PLSQLStoredProcedureCall) call).getArguments().get(((PLSQLStoredProcedureCall) call).getArguments().size() - 1);
                    ((PLSQLCollection) plsqlArg.databaseType).setIsNestedTable(true);
                }
            } else {
                dq.addArgument(arg.getArgumentName());
                if (argType.isComposite()) {
                    Class wrapperClass = getWrapperClass(javaTypeName);
                    if (argType.isVArrayType() || argType.isObjectTableType()) {
                        call.addNamedInOutputArgument(arg.getArgumentName(), arg.getArgumentName(), arg.getArgumentName(), Types.ARRAY, argType.getTypeName(), wrapperClass, buildFieldForNestedType(argType));
                    } else {
                        // assumes ObjectType
                        call.addNamedInOutputArgument(arg.getArgumentName(), arg.getArgumentName(), arg.getArgumentName(), Types.STRUCT, argType.getTypeName());
                    }
                } else {
                    // for some reason setting "java.lang.String" as the java type causes problems at runtime
                    Class javaType = getClassFromJDBCType(argType.getTypeName(), dbwsBuilder.getDatabasePlatform());
                    if (shouldSetJavaType(javaType.getName())) {
                        call.addNamedInOutputArgument(arg.getArgumentName(), arg.getArgumentName(), arg.getArgumentName(), Util.getJDBCTypeFromTypeName(argType.getTypeName()), argType.getTypeName(), javaType);
                    } else {
                        call.addNamedInOutputArgument(arg.getArgumentName());
                    }
                }
            }
        }
        if (hasPLSQLArgs && (direction == IN || direction == INOUT)) {
            ClassDescriptor xdesc = null;
            if (hasResponse) {
                int idx = returnType.indexOf(COLON);
                if (idx == -1) {
                    idx = returnType.indexOf(CLOSE_PAREN);
                }
                if (idx > 0) {
                    String typ = returnType.substring(idx + 1);
                    for (XMLDescriptor xd : (List<XMLDescriptor>) (List) oxProject.getOrderedDescriptors()) {
                        if (xd.getSchemaReference() != null) {
                            String context = xd.getSchemaReference().getSchemaContext();
                            if (context.substring(1).equals(typ)) {
                                xdesc = xd;
                                break;
                            }
                        }
                    }
                }
            }
            if (xdesc != null) {
                dq.addArgumentByTypeName(arg.getArgumentName(), xdesc.getJavaClassName());
            } else {
                if (databaseType instanceof PLSQLCollection || databaseType instanceof VArrayType) {
                    dq.addArgument(arg.getArgumentName(), Array.class);
                } else if (databaseType instanceof PLSQLrecord || databaseType instanceof OracleObjectType) {
                    dq.addArgument(arg.getArgumentName(), Struct.class);
                } else {
                    dq.addArgument(arg.getArgumentName(), JDBCTypes.getClassForCode(databaseType.getConversionCode()));
                }
            }
        }
    }
    orProject.getQueries().add(dq);
}
Also used : PLSQLStoredFunctionCall(org.eclipse.persistence.platform.database.oracle.plsql.PLSQLStoredFunctionCall) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) CompositeDatabaseType(org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType) ComplexDatabaseType(org.eclipse.persistence.internal.helper.ComplexDatabaseType) DatabaseType(org.eclipse.persistence.tools.oracleddl.metadata.DatabaseType) Util.getAttributeClassForDatabaseType(org.eclipse.persistence.tools.dbws.Util.getAttributeClassForDatabaseType) DataReadQuery(org.eclipse.persistence.queries.DataReadQuery) Util.qNameFromString(org.eclipse.persistence.tools.dbws.Util.qNameFromString) ArgumentType(org.eclipse.persistence.tools.oracleddl.metadata.ArgumentType) PLSQLargument(org.eclipse.persistence.platform.database.oracle.plsql.PLSQLargument) Struct(java.sql.Struct) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) VArrayType(org.eclipse.persistence.tools.oracleddl.metadata.VArrayType) OracleObjectType(org.eclipse.persistence.platform.database.oracle.jdbc.OracleObjectType) PLSQLrecord(org.eclipse.persistence.platform.database.oracle.plsql.PLSQLrecord) ArrayList(java.util.ArrayList) List(java.util.List) ArgumentTypeDirection(org.eclipse.persistence.tools.oracleddl.metadata.ArgumentTypeDirection) PLSQLStoredProcedureCall(org.eclipse.persistence.platform.database.oracle.plsql.PLSQLStoredProcedureCall) StoredProcedureCall(org.eclipse.persistence.queries.StoredProcedureCall) DatabaseQuery(org.eclipse.persistence.queries.DatabaseQuery) ValueReadQuery(org.eclipse.persistence.queries.ValueReadQuery) StoredFunctionCall(org.eclipse.persistence.queries.StoredFunctionCall) PLSQLStoredFunctionCall(org.eclipse.persistence.platform.database.oracle.plsql.PLSQLStoredFunctionCall) ComplexDatabaseType(org.eclipse.persistence.internal.helper.ComplexDatabaseType) PLSQLCollectionType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLCollectionType) PLSQLStoredProcedureCall(org.eclipse.persistence.platform.database.oracle.plsql.PLSQLStoredProcedureCall) PLSQLCollection(org.eclipse.persistence.platform.database.oracle.plsql.PLSQLCollection)

Example 3 with OracleObjectType

use of org.eclipse.persistence.platform.database.oracle.jdbc.OracleObjectType in project eclipselink by eclipse-ee4j.

the class ObjectPersistenceRuntimeXMLProject_11_1_1 method buildOracleObjectTypeDescriptor.

/**
 * Builds a descriptor for the OracleObjectType class.
 */
protected ClassDescriptor buildOracleObjectTypeDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(OracleObjectType.class);
    XMLDirectMapping typeNameMapping = new XMLDirectMapping();
    typeNameMapping.setAttributeName("typeName");
    typeNameMapping.setXPath(getPrimaryNamespaceXPath() + "type-name/text()");
    descriptor.addMapping(typeNameMapping);
    XMLDirectMapping compatibleTypeMapping = new XMLDirectMapping();
    compatibleTypeMapping.setAttributeName("compatibleType");
    compatibleTypeMapping.setXPath(getPrimaryNamespaceXPath() + "compatible-type/text()");
    descriptor.addMapping(compatibleTypeMapping);
    XMLDirectMapping javaTypeMapping = new XMLDirectMapping();
    javaTypeMapping.setAttributeName("javaType");
    javaTypeMapping.setXPath(getPrimaryNamespaceXPath() + "java-type/text()");
    descriptor.addMapping(javaTypeMapping);
    XMLCompositeCollectionMapping fieldsMapping = new XMLCompositeCollectionMapping();
    fieldsMapping.setAttributeName("fields");
    fieldsMapping.setReferenceClass(ObjectTypeFieldAssociation.class);
    // handle translation of 'field' LinkedHashMap
    fieldsMapping.setAttributeAccessor(new AttributeAccessor() {

        @Override
        public Object getAttributeValueFromObject(Object object) {
            Map<String, DatabaseType> fields = ((OracleObjectType) object).getFields();
            List<ObjectTypeFieldAssociation> associations = new ArrayList<>(fields.size());
            Iterator<Map.Entry<String, DatabaseType>> iterator = fields.entrySet().iterator();
            while (iterator.hasNext()) {
                Map.Entry<String, DatabaseType> entry = iterator.next();
                associations.add(new ObjectTypeFieldAssociation(entry.getKey(), wrapType(entry.getValue())));
            }
            return associations;
        }

        @Override
        public void setAttributeValueInObject(Object object, Object value) {
            OracleObjectType objectType = (OracleObjectType) object;
            List<ObjectTypeFieldAssociation> associations = (List<ObjectTypeFieldAssociation>) value;
            Map<String, DatabaseType> fieldMap = new LinkedHashMap<>(associations.size() + 1);
            Iterator<ObjectTypeFieldAssociation> iterator = associations.iterator();
            while (iterator.hasNext()) {
                ObjectTypeFieldAssociation association = iterator.next();
                fieldMap.put(association.getKey(), unwrapType(association.getValue()));
            }
            objectType.setFields(fieldMap);
        }
    });
    fieldsMapping.setXPath(getPrimaryNamespaceXPath() + "fields/" + getPrimaryNamespaceXPath() + "field");
    descriptor.addMapping(fieldsMapping);
    return descriptor;
}
Also used : DatabaseType(org.eclipse.persistence.internal.helper.DatabaseType) ComplexDatabaseType(org.eclipse.persistence.internal.helper.ComplexDatabaseType) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) OracleObjectType(org.eclipse.persistence.platform.database.oracle.jdbc.OracleObjectType) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) AttributeAccessor(org.eclipse.persistence.mappings.AttributeAccessor) SoftIdentityMap(org.eclipse.persistence.internal.identitymaps.SoftIdentityMap) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with OracleObjectType

use of org.eclipse.persistence.platform.database.oracle.jdbc.OracleObjectType 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 5 with OracleObjectType

use of org.eclipse.persistence.platform.database.oracle.jdbc.OracleObjectType in project eclipselink by eclipse-ee4j.

the class BaseDBWSBuilderHelper method buildDatabaseTypeFromMetadataType.

/**
 * Build a org.eclipse.persistence.internal.helper.DatabaseType  instance  from an
 * org.eclipse.persistence.tools.oracleddl.metadata.DatabaseType instance.  In the
 * the case of PLSQL Packages, the catalog (package) name can be passed in as well.
 */
@SuppressWarnings("rawtypes")
protected org.eclipse.persistence.internal.helper.DatabaseType buildDatabaseTypeFromMetadataType(DatabaseType dType, String catalog) {
    // argument could be from a different package
    if (dType.isPLSQLType()) {
        PLSQLType pType = (PLSQLType) dType;
        catalog = pType.getParentType().getPackageName();
    }
    // handle cursors
    if (dType.isPLSQLCursorType()) {
        if (dType.isArgumentType()) {
            dType = ((ArgumentType) dType).getEnclosedType();
        }
        PLSQLCursorType pType = (PLSQLCursorType) dType;
        return new PLSQLCursor(pType.getParentType().getPackageName() + DOT + pType.getCursorName());
    }
    if (dType.isArgumentType()) {
        dType = ((ArgumentType) dType).getEnclosedType();
    } else if (dType.isTYPEType()) {
        dType = ((TYPEType) dType).getEnclosedType();
    }
    // composite types
    if (dType.isComposite()) {
        String typeName = dType.getTypeName();
        // for %ROWTYPE, the compatible JDBC type name cannot contain '%'
        String compatibleType = typeName.contains(PERCENT) ? typeName.replace(PERCENT, UNDERSCORE) : typeName;
        String javaTypeName = compatibleType.toLowerCase();
        // handle PL/SQL types
        if (dType.isPLSQLType()) {
            // for %ROWTYPE we don't want the catalog name prepended even if non-null
            if (catalog != null && !typeName.contains(ROWTYPE_STR)) {
                typeName = (catalog + DOT).concat(typeName);
                compatibleType = (catalog + UNDERSCORE).concat(compatibleType);
                javaTypeName = (catalog.toLowerCase() + DOT).concat(javaTypeName);
            }
            // handle PL/SQL record
            if (dType.isPLSQLRecordType()) {
                PLSQLrecord plsqlRec = new PLSQLrecord();
                plsqlRec.setTypeName(typeName);
                plsqlRec.setCompatibleType(compatibleType);
                plsqlRec.setJavaTypeName(javaTypeName);
                // process fields
                for (FieldType fld : ((PLSQLRecordType) dType).getFields()) {
                    if (fld.getEnclosedType().isPrecisionType()) {
                        PrecisionType precisionType = (PrecisionType) fld.getEnclosedType();
                        plsqlRec.addField(fld.getFieldName(), buildDatabaseTypeFromMetadataType(precisionType), (int) precisionType.getPrecision(), (int) precisionType.getScale());
                    } else if (fld.getEnclosedType().isSizedType()) {
                        SizedType sizedType = (SizedType) fld.getEnclosedType();
                        plsqlRec.addField(fld.getFieldName(), buildDatabaseTypeFromMetadataType(sizedType), (int) sizedType.getSize());
                    } else {
                        plsqlRec.addField(fld.getFieldName(), buildDatabaseTypeFromMetadataType(fld.getEnclosedType(), catalog));
                    }
                }
                return plsqlRec;
            }
            // assumes PL/SQL collection
            PLSQLCollection plsqlCollection = new PLSQLCollection();
            plsqlCollection.setTypeName(typeName);
            plsqlCollection.setCompatibleType(compatibleType);
            plsqlCollection.setJavaTypeName(javaTypeName + COLLECTION_WRAPPER_SUFFIX);
            plsqlCollection.setNestedType(buildDatabaseTypeFromMetadataType(((PLSQLCollectionType) dType).getEnclosedType(), catalog));
            return plsqlCollection;
        }
        // handle advanced Oracle types
        if (dType.isVArrayType()) {
            OracleArrayType varray = new OracleArrayType();
            varray.setTypeName(typeName);
            varray.setCompatibleType(compatibleType);
            varray.setJavaTypeName(getGeneratedWrapperClassName(javaTypeName, dbwsBuilder.getProjectName()));
            varray.setNestedType(buildDatabaseTypeFromMetadataType(((VArrayType) dType).getEnclosedType(), null));
            return varray;
        }
        if (dType.isObjectType()) {
            OracleObjectType objType = new OracleObjectType();
            objType.setTypeName(typeName);
            objType.setCompatibleType(compatibleType);
            objType.setJavaTypeName(getGeneratedJavaClassName(javaTypeName, dbwsBuilder.getProjectName()));
            objType.setJavaType(getWrapperClass(objType.getJavaTypeName()));
            Map<String, org.eclipse.persistence.internal.helper.DatabaseType> fields = objType.getFields();
            ObjectType oType = (ObjectType) dType;
            for (FieldType field : oType.getFields()) {
                fields.put(field.getFieldName(), buildDatabaseTypeFromMetadataType(field.getEnclosedType()));
            }
            return objType;
        }
        if (dType.isObjectTableType()) {
            OracleArrayType tableType = new OracleArrayType();
            tableType.setTypeName(typeName);
            tableType.setCompatibleType(compatibleType);
            tableType.setJavaTypeName(getGeneratedWrapperClassName(javaTypeName, dbwsBuilder.getProjectName()));
            org.eclipse.persistence.internal.helper.DatabaseType nestedType = buildDatabaseTypeFromMetadataType(((ObjectTableType) dType).getEnclosedType(), null);
            // need to set the Java Type on the nested type
            Class wrapper = getWrapperClass(nestedType);
            if (wrapper != null) {
                ((ComplexDatabaseType) nestedType).setJavaType(wrapper);
            }
            tableType.setNestedType(nestedType);
            return tableType;
        }
        return null;
    } else if (dType.isScalar()) {
        org.eclipse.persistence.internal.helper.DatabaseType theType = OraclePLSQLTypes.getDatabaseTypeForCode(dType.getTypeName());
        if (theType != null) {
            return theType;
        }
    }
    // scalar types
    return JDBCTypes.getDatabaseTypeForCode(org.eclipse.persistence.tools.dbws.Util.getJDBCTypeFromTypeName(dType.getTypeName()));
}
Also used : ScalarDatabaseType(org.eclipse.persistence.tools.oracleddl.metadata.ScalarDatabaseType) CompositeDatabaseType(org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType) ComplexDatabaseType(org.eclipse.persistence.internal.helper.ComplexDatabaseType) DatabaseType(org.eclipse.persistence.tools.oracleddl.metadata.DatabaseType) PLSQLCursorType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLCursorType) PrecisionType(org.eclipse.persistence.tools.oracleddl.metadata.PrecisionType) ObjectType(org.eclipse.persistence.tools.oracleddl.metadata.ObjectType) OracleObjectType(org.eclipse.persistence.platform.database.oracle.jdbc.OracleObjectType) VArrayType(org.eclipse.persistence.tools.oracleddl.metadata.VArrayType) OracleObjectType(org.eclipse.persistence.platform.database.oracle.jdbc.OracleObjectType) PLSQLrecord(org.eclipse.persistence.platform.database.oracle.plsql.PLSQLrecord) PLSQLCursor(org.eclipse.persistence.platform.database.oracle.plsql.PLSQLCursor) PLSQLRecordType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLRecordType) FieldType(org.eclipse.persistence.tools.oracleddl.metadata.FieldType) ComplexDatabaseType(org.eclipse.persistence.internal.helper.ComplexDatabaseType) ROWTYPEType(org.eclipse.persistence.tools.oracleddl.metadata.ROWTYPEType) TYPEType(org.eclipse.persistence.tools.oracleddl.metadata.TYPEType) PLSQLCollectionType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLCollectionType) PLSQLCollection(org.eclipse.persistence.platform.database.oracle.plsql.PLSQLCollection) SizedType(org.eclipse.persistence.tools.oracleddl.metadata.SizedType) PLSQLType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLType) OracleArrayType(org.eclipse.persistence.platform.database.oracle.jdbc.OracleArrayType)

Aggregations

OracleObjectType (org.eclipse.persistence.platform.database.oracle.jdbc.OracleObjectType)5 ComplexDatabaseType (org.eclipse.persistence.internal.helper.ComplexDatabaseType)3 DatabaseType (org.eclipse.persistence.internal.helper.DatabaseType)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)2 OracleArrayType (org.eclipse.persistence.platform.database.oracle.jdbc.OracleArrayType)2 PLSQLCollection (org.eclipse.persistence.platform.database.oracle.plsql.PLSQLCollection)2 PLSQLStoredProcedureCall (org.eclipse.persistence.platform.database.oracle.plsql.PLSQLStoredProcedureCall)2 PLSQLargument (org.eclipse.persistence.platform.database.oracle.plsql.PLSQLargument)2 PLSQLrecord (org.eclipse.persistence.platform.database.oracle.plsql.PLSQLrecord)2 CompositeDatabaseType (org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType)2 DatabaseType (org.eclipse.persistence.tools.oracleddl.metadata.DatabaseType)2 PLSQLCollectionType (org.eclipse.persistence.tools.oracleddl.metadata.PLSQLCollectionType)2 VArrayType (org.eclipse.persistence.tools.oracleddl.metadata.VArrayType)2 EntityManager (jakarta.persistence.EntityManager)1 Query (jakarta.persistence.Query)1 Struct (java.sql.Struct)1 Iterator (java.util.Iterator)1