Search in sources :

Example 1 with PLSQLCollectionType

use of org.eclipse.persistence.tools.oracleddl.metadata.PLSQLCollectionType in project eclipselink by eclipse-ee4j.

the class ShadowDDLGenerationTestSuite method testNewShadowDDLGeneration.

@Test
public void testNewShadowDDLGeneration() {
    ShadowDDLGenerator shadowDDLGenerator = new ShadowDDLGenerator(shadowDDLTestPackage);
    PLSQLCollectionType collectionType = (PLSQLCollectionType) shadowDDLTestPackage.getTypes().get(0);
    String numTblCreateDDL = removeLineTerminators(shadowDDLGenerator.getCreateDDLFor(collectionType));
    String numTblDropDDL = removeLineTerminators(shadowDDLGenerator.getDropDDLFor(collectionType));
    PLSQLRecordType recordType3 = (PLSQLRecordType) shadowDDLTestPackage.getTypes().get(1);
    String numRecord3CreateDDL = removeLineTerminators(shadowDDLGenerator.getCreateDDLFor(recordType3));
    String numRecord3DropDDL = removeLineTerminators(shadowDDLGenerator.getDropDDLFor(recordType3));
    PLSQLCollectionType collectionType3 = (PLSQLCollectionType) shadowDDLTestPackage.getTypes().get(2);
    String numTbl3CreateDDL = removeLineTerminators(shadowDDLGenerator.getCreateDDLFor(collectionType3));
    String numTbl3DropDDL = removeLineTerminators(shadowDDLGenerator.getDropDDLFor(collectionType3));
    PLSQLRecordType recordType = (PLSQLRecordType) shadowDDLTestPackage.getTypes().get(3);
    String numRecordCreateDDL = removeLineTerminators(shadowDDLGenerator.getCreateDDLFor(recordType));
    String numRecordDropDDL = removeLineTerminators(shadowDDLGenerator.getDropDDLFor(recordType));
    PLSQLCollectionType collectionType2 = (PLSQLCollectionType) shadowDDLTestPackage.getTypes().get(4);
    String numTbl2CreateDDL = removeLineTerminators(shadowDDLGenerator.getCreateDDLFor(collectionType2));
    String numTbl2DropDDL = removeLineTerminators(shadowDDLGenerator.getDropDDLFor(collectionType2));
    PLSQLRecordType recordType2 = (PLSQLRecordType) shadowDDLTestPackage.getTypes().get(5);
    String numRecord2CreateDDL = removeLineTerminators(shadowDDLGenerator.getCreateDDLFor(recordType2));
    String numRecord2DropDDL = removeLineTerminators(shadowDDLGenerator.getDropDDLFor(recordType2));
    assertEquals("generated create shadow DDL for " + SHADOWDDLTEST_RECORD_TYPE2 + " does not match expected shadow DDL", numRecord2CreateDDL, EXPECTED_NUMRECORD2_CREATE_SHADOWDDL);
    assertEquals("generated drop shadow DDL for " + SHADOWDDLTEST_RECORD_TYPE2 + " does not match expected shadow DDL", numRecord2DropDDL, EXPECTED_NUMRECORD2_DROP_SHADOWDDL);
    assertEquals("generated create shadow DDL for " + SHADOWDDLTEST_RECORD_TYPE + " does not match expected shadow DDL", numRecordCreateDDL, EXPECTED_NUMRECORD_CREATE_SHADOWDDL);
    assertEquals("generated drop shadow DDL for " + SHADOWDDLTEST_RECORD_TYPE + " does not match expected shadow DDL", numRecordDropDDL, EXPECTED_NUMRECORD_DROP_SHADOWDDL);
    assertEquals("generated create shadow DDL for " + SHADOWDDLTEST_TABLE_TYPE + " does not match expected shadow DDL", numTblCreateDDL, EXPECTED_NUMTBL_CREATE_SHADOWDDL);
    assertEquals("generated drop shadow DDL for " + SHADOWDDLTEST_TABLE_TYPE + " does not match expected shadow DDL", numTblDropDDL, EXPECTED_NUMTBL_DROP_SHADOWDDL);
    assertEquals("generated create shadow DDL for " + SHADOWDDLTEST_TABLE_TYPE2 + " does not match expected shadow DDL", numTbl2CreateDDL, EXPECTED_NUMTBL2_CREATE_SHADOWDDL);
    assertEquals("generated drop shadow DDL for " + SHADOWDDLTEST_TABLE_TYPE2 + " does not match expected shadow DDL", numTbl2DropDDL, EXPECTED_NUMTBL2_DROP_SHADOWDDL);
    assertEquals("generated create shadow DDL for " + SHADOWDDLTEST_TABLE_TYPE3 + " does not match expected shadow DDL", numTbl3CreateDDL, EXPECTED_NUMTBL3_CREATE_SHADOWDDL);
    assertEquals("generated drop shadow DDL for " + SHADOWDDLTEST_TABLE_TYPE3 + " does not match expected shadow DDL", numTbl3DropDDL, EXPECTED_NUMTBL3_DROP_SHADOWDDL);
    assertEquals("generated create shadow DDL for " + SHADOWDDLTEST_RECORD_TYPE3 + " does not match expected shadow DDL", numRecord3CreateDDL, EXPECTED_NUMRECORD3_CREATE_SHADOWDDL);
    assertEquals("generated drop shadow DDL for " + SHADOWDDLTEST_RECORD_TYPE3 + " does not match expected shadow DDL", numRecord3DropDDL, EXPECTED_NUMRECORD3_DROP_SHADOWDDL);
}
Also used : PLSQLCollectionType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLCollectionType) ShadowDDLGenerator(org.eclipse.persistence.tools.dbws.oracle.ShadowDDLGenerator) PLSQLRecordType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLRecordType) Test(org.junit.Test)

Example 2 with PLSQLCollectionType

use of org.eclipse.persistence.tools.oracleddl.metadata.PLSQLCollectionType 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 PLSQLCollectionType

use of org.eclipse.persistence.tools.oracleddl.metadata.PLSQLCollectionType in project eclipselink by eclipse-ee4j.

the class OracleHelper method addToOXProjectForPLSQLTableArg.

/**
 * Build descriptor and mappings for a PL/SQL collection argument.  The newly
 * created descriptor will be added to the given OX project.
 */
protected void addToOXProjectForPLSQLTableArg(DatabaseType dbType, Project oxProject, String tableName, String tableAlias, String targetTypeName, String catalogPattern) {
    XMLDescriptor xdesc = (XMLDescriptor) oxProject.getDescriptorForAlias(tableAlias);
    if (xdesc == null) {
        xdesc = buildAndAddNewXMLDescriptor(oxProject, tableAlias, tableName.toLowerCase() + COLLECTION_WRAPPER_SUFFIX, nct.generateSchemaAlias(targetTypeName), buildCustomQName(targetTypeName, dbwsBuilder).getNamespaceURI());
    }
    boolean itemsMappingFound = xdesc.getMappingForAttributeName(ITEMS_MAPPING_ATTRIBUTE_NAME) == null ? false : true;
    if (!itemsMappingFound) {
        DatabaseType nestedType = ((PLSQLCollectionType) dbType).getEnclosedType();
        if (nestedType.isPLSQLRecordType()) {
            String referenceClassName = (catalogPattern + DOT + ((PLSQLRecordType) nestedType).getTypeName()).toLowerCase();
            buildAndAddXMLCompositeCollectionMapping(xdesc, referenceClassName);
            if (oxProject.getDescriptorForAlias(referenceClassName) == null) {
                String refTypeName = catalogPattern + UNDERSCORE + ((PLSQLRecordType) nestedType).getTypeName();
                addToOXProjectForPLSQLRecordArg(nestedType, oxProject, referenceClassName, refTypeName.toLowerCase(), refTypeName, catalogPattern);
            }
        } else if (nestedType.isObjectType()) {
            buildAndAddXMLCompositeCollectionMapping(xdesc, getGeneratedJavaClassName(nestedType.getTypeName(), dbwsBuilder.getProjectName()));
        } else {
            if (nestedType.isComposite()) {
                buildAndAddXMLCompositeCollectionMapping(xdesc, tableName.toLowerCase() + COLLECTION_WRAPPER_SUFFIX);
            } else {
                buildAndAddXMLCompositeDirectCollectionMapping(xdesc, ITEMS_MAPPING_ATTRIBUTE_NAME, ITEM_MAPPING_NAME + SLASH + TEXT, getAttributeClassForDatabaseType(nestedType));
            }
        }
    }
}
Also used : PLSQLCollectionType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLCollectionType) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) 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) Util.qNameFromString(org.eclipse.persistence.tools.dbws.Util.qNameFromString)

Example 4 with PLSQLCollectionType

use of org.eclipse.persistence.tools.oracleddl.metadata.PLSQLCollectionType in project eclipselink by eclipse-ee4j.

the class OracleHelper method addToORProjectForPLSQLRecordArg.

/**
 * Build descriptor and mappings for a PL/SQL record argument.  The newly
 * created descriptor will be added to the given OR project.
 */
@SuppressWarnings("rawtypes")
protected void addToORProjectForPLSQLRecordArg(DatabaseType dbType, Project orProject, String recordName, String recordAlias, String targetTypeName, String catalogPattern) {
    ObjectRelationalDataTypeDescriptor ordtDesc = (ObjectRelationalDataTypeDescriptor) orProject.getDescriptorForAlias(recordAlias);
    if (ordtDesc == null) {
        ordtDesc = buildAndAddNewObjectRelationalDataTypeDescriptor(orProject, recordAlias, recordName.toLowerCase());
    }
    // handle fields
    PLSQLRecordType plsqlRecType = (PLSQLRecordType) dbType;
    for (FieldType fType : plsqlRecType.getFields()) {
        String fieldName = fType.getFieldName();
        String lFieldName = fieldName.toLowerCase();
        // handle field ordering
        boolean found = false;
        Vector orderedFields = ordtDesc.getOrderedFields();
        for (Iterator i = orderedFields.iterator(); i.hasNext(); ) {
            Object o = i.next();
            if (o instanceof DatabaseField) {
                DatabaseField field = (DatabaseField) o;
                if (field.getName().equalsIgnoreCase(fieldName)) {
                    found = true;
                    break;
                }
            }
        }
        if (!found) {
            ordtDesc.addFieldOrdering(fieldName);
        }
        if (ordtDesc.getMappingForAttributeName(lFieldName) == null) {
            if (fType.isComposite()) {
                if (fType.getEnclosedType().isPLSQLRecordType()) {
                    buildAndAddStructureMapping(ordtDesc, lFieldName, fieldName, recordName.toLowerCase());
                } else if (fType.getEnclosedType().isPLSQLCollectionType()) {
                    PLSQLCollectionType tableType = (PLSQLCollectionType) fType.getEnclosedType();
                    if (tableType.getEnclosedType().isComposite()) {
                        buildAndAddObjectArrayMapping(ordtDesc, lFieldName, fieldName, (catalogPattern + "." + tableType.getTypeName()).toLowerCase() + COLLECTION_WRAPPER_SUFFIX, getStructureNameForField(fType, catalogPattern));
                    } else {
                        buildAndAddArrayMapping(ordtDesc, lFieldName, fieldName, getStructureNameForField(fType, catalogPattern));
                    }
                } else if (fType.getEnclosedType().isObjectType()) {
                    buildAndAddStructureMapping(ordtDesc, lFieldName, fieldName, getGeneratedJavaClassName(fType.getEnclosedType().getTypeName(), dbwsBuilder.getProjectName()));
                } else if (fType.getEnclosedType().isVArrayType()) {
                    if (((VArrayType) fType.getEnclosedType()).getEnclosedType().isComposite()) {
                        buildAndAddObjectArrayMapping(ordtDesc, lFieldName, fieldName, getGeneratedJavaClassName(((VArrayType) fType.getEnclosedType()).getEnclosedType().getTypeName(), dbwsBuilder.getProjectName()), getStructureNameForField(fType, null));
                    } else {
                        buildAndAddArrayMapping(ordtDesc, lFieldName, fieldName, getStructureNameForField(fType, null));
                    }
                } else if (fType.getEnclosedType().isObjectTableType()) {
                    ObjectTableType nestedType = (ObjectTableType) fType.getEnclosedType();
                    if (nestedType.getEnclosedType().isComposite()) {
                        ObjectType oType = (ObjectType) nestedType.getEnclosedType();
                        String oTypeAlias = oType.getTypeName().toLowerCase();
                        String oTypeName = getGeneratedJavaClassName(oTypeAlias, dbwsBuilder.getProjectName());
                        // ObjectType is composite
                        buildAndAddObjectArrayMapping(ordtDesc, lFieldName, fieldName, oTypeName, oTypeAlias.toUpperCase());
                    } else {
                        buildAndAddArrayMapping(ordtDesc, lFieldName, fieldName, nestedType.getTypeName().toUpperCase());
                    }
                } else if (fType.getEnclosedType().isTYPEType()) {
                    // handle %TYPE
                    TYPEType typeType = (TYPEType) fType.getEnclosedType();
                    if (typeType.getEnclosedType().isFieldType()) {
                        // direct mapping
                        AbstractDirectMapping absDirectMapping = (AbstractDirectMapping) ordtDesc.addDirectMapping(lFieldName, fieldName);
                        try {
                            absDirectMapping.setAttributeClassificationName(getClassFromJDBCType(fType.getTypeName(), dbwsBuilder.getDatabasePlatform()).getName());
                        } catch (Exception x) {
                        }
                    }
                }
            } else {
                // direct mapping
                DirectToFieldMapping dfm = new DirectToFieldMapping();
                dfm.setFieldName(fieldName);
                dfm.setAttributeName(lFieldName);
                dfm.setAttributeClassification(getAttributeClassForDatabaseType(fType.getEnclosedType()));
                ordtDesc.addMapping(dfm);
            }
        }
    }
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) PLSQLRecordType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLRecordType) Util.qNameFromString(org.eclipse.persistence.tools.dbws.Util.qNameFromString) ParseException(org.eclipse.persistence.tools.oracleddl.parser.ParseException) FieldType(org.eclipse.persistence.tools.oracleddl.metadata.FieldType) PLSQLCollectionType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLCollectionType) ObjectTableType(org.eclipse.persistence.tools.oracleddl.metadata.ObjectTableType) ObjectType(org.eclipse.persistence.tools.oracleddl.metadata.ObjectType) OracleObjectType(org.eclipse.persistence.platform.database.oracle.jdbc.OracleObjectType) ROWTYPEType(org.eclipse.persistence.tools.oracleddl.metadata.ROWTYPEType) TYPEType(org.eclipse.persistence.tools.oracleddl.metadata.TYPEType) VArrayType(org.eclipse.persistence.tools.oracleddl.metadata.VArrayType) AbstractDirectMapping(org.eclipse.persistence.mappings.foundation.AbstractDirectMapping) ObjectRelationalDatabaseField(org.eclipse.persistence.mappings.structures.ObjectRelationalDatabaseField) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) Iterator(java.util.Iterator) Vector(java.util.Vector) ObjectRelationalDataTypeDescriptor(org.eclipse.persistence.mappings.structures.ObjectRelationalDataTypeDescriptor)

Example 5 with PLSQLCollectionType

use of org.eclipse.persistence.tools.oracleddl.metadata.PLSQLCollectionType in project eclipselink by eclipse-ee4j.

the class OracleHelper method addToORProjectForPLSQLTableArg.

/**
 * Build descriptor and mappings for a PL/SQL collection argument.  The newly
 * created descriptor will be added to the given OR project.
 */
protected void addToORProjectForPLSQLTableArg(DatabaseType dbType, Project orProject, String tableName, String tableAlias, String targetTypeName, String catalogPattern) {
    ObjectRelationalDataTypeDescriptor ordt = (ObjectRelationalDataTypeDescriptor) orProject.getDescriptorForAlias(tableAlias);
    if (ordt == null) {
        ordt = buildAndAddNewObjectRelationalDataTypeDescriptor(orProject, tableAlias, tableName.toLowerCase() + COLLECTION_WRAPPER_SUFFIX);
    }
    boolean itemsMappingFound = ordt.getMappingForAttributeName(ITEMS_MAPPING_ATTRIBUTE_NAME) == null ? false : true;
    if (!itemsMappingFound) {
        DatabaseType nestedType = ((PLSQLCollectionType) dbType).getEnclosedType();
        if (nestedType.isPLSQLRecordType()) {
            String referenceClassName = (catalogPattern + DOT + ((PLSQLRecordType) nestedType).getTypeName()).toLowerCase();
            buildAndAddObjectArrayMapping(ordt, ITEMS_MAPPING_ATTRIBUTE_NAME, ITEMS_MAPPING_FIELD_NAME, referenceClassName, targetTypeName);
            if (orProject.getDescriptorForAlias(referenceClassName) == null) {
                String refTypeName = catalogPattern + UNDERSCORE + ((PLSQLRecordType) nestedType).getTypeName();
                addToORProjectForPLSQLRecordArg(nestedType, orProject, referenceClassName, refTypeName.toLowerCase(), refTypeName, catalogPattern);
            }
        } else if (nestedType.isObjectType()) {
            buildAndAddObjectArrayMapping(ordt, ITEMS_MAPPING_ATTRIBUTE_NAME, ITEMS_MAPPING_FIELD_NAME, getGeneratedJavaClassName(nestedType.getTypeName(), dbwsBuilder.getProjectName()), targetTypeName);
        } else {
            buildAndAddArrayMapping(ordt, ITEMS_MAPPING_ATTRIBUTE_NAME, ITEMS_MAPPING_FIELD_NAME, targetTypeName);
        }
    }
}
Also used : PLSQLCollectionType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLCollectionType) 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) Util.qNameFromString(org.eclipse.persistence.tools.dbws.Util.qNameFromString) ObjectRelationalDataTypeDescriptor(org.eclipse.persistence.mappings.structures.ObjectRelationalDataTypeDescriptor)

Aggregations

PLSQLCollectionType (org.eclipse.persistence.tools.oracleddl.metadata.PLSQLCollectionType)7 Util.qNameFromString (org.eclipse.persistence.tools.dbws.Util.qNameFromString)5 ComplexDatabaseType (org.eclipse.persistence.internal.helper.ComplexDatabaseType)4 CompositeDatabaseType (org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType)4 DatabaseType (org.eclipse.persistence.tools.oracleddl.metadata.DatabaseType)4 PLSQLRecordType (org.eclipse.persistence.tools.oracleddl.metadata.PLSQLRecordType)4 VArrayType (org.eclipse.persistence.tools.oracleddl.metadata.VArrayType)4 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)3 OracleObjectType (org.eclipse.persistence.platform.database.oracle.jdbc.OracleObjectType)3 Util.getAttributeClassForDatabaseType (org.eclipse.persistence.tools.dbws.Util.getAttributeClassForDatabaseType)3 FieldType (org.eclipse.persistence.tools.oracleddl.metadata.FieldType)3 ROWTYPEType (org.eclipse.persistence.tools.oracleddl.metadata.ROWTYPEType)3 TYPEType (org.eclipse.persistence.tools.oracleddl.metadata.TYPEType)3 ObjectRelationalDataTypeDescriptor (org.eclipse.persistence.mappings.structures.ObjectRelationalDataTypeDescriptor)2 PLSQLCollection (org.eclipse.persistence.platform.database.oracle.plsql.PLSQLCollection)2 PLSQLrecord (org.eclipse.persistence.platform.database.oracle.plsql.PLSQLrecord)2 ObjectTableType (org.eclipse.persistence.tools.oracleddl.metadata.ObjectTableType)2 ObjectType (org.eclipse.persistence.tools.oracleddl.metadata.ObjectType)2 Struct (java.sql.Struct)1 ArrayList (java.util.ArrayList)1