Search in sources :

Example 1 with PLSQLRecordType

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

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

the class BaseDBWSBuilderHelper method buildTypesList.

/**
 * Uses a custom visitor to traverse each procedure/function argument and build
 * a list of required Types.  Only on instance of a given type will exist in
 * the list.
 */
public List<CompositeDatabaseType> buildTypesList(List<OperationModel> operations) {
    EnclosedTypeVisitor etVisitor = new EnclosedTypeVisitor();
    for (OperationModel opModel : operations) {
        if (opModel.isProcedureOperation()) {
            ProcedureOperationModel procedureOperation = (ProcedureOperationModel) opModel;
            if (procedureOperation.isPLSQLProcedureOperation() || procedureOperation.isAdvancedJDBCProcedureOperation()) {
                for (ProcedureType procType : procedureOperation.getDbStoredProcedures()) {
                    // build list of arguments to process (i.e. build descriptors for)
                    List<ArgumentType> args = new ArrayList<ArgumentType>();
                    // return argument
                    if (procType.isFunctionType()) {
                        // assumes that a function MUST have a return type
                        args.add(((FunctionType) procType).getReturnArgument());
                    }
                    args.addAll(procType.getArguments());
                    // now visit each argument
                    for (ArgumentType arg : args) {
                        // handle ROWTYPETypes
                        if (arg.getEnclosedType().isROWTYPEType()) {
                            ROWTYPEType rType = (ROWTYPEType) arg.getEnclosedType();
                            TableType tableType = (TableType) rType.getEnclosedType();
                            PLSQLRecordType plsqlRec = new PLSQLRecordType(rType.getTypeName());
                            plsqlRec.setParentType(new PLSQLPackageType());
                            for (FieldType col : tableType.getColumns()) {
                                FieldType ft = new FieldType(col.getFieldName());
                                ft.setEnclosedType(col.getEnclosedType());
                                plsqlRec.addField(ft);
                            }
                            arg.setEnclosedType(plsqlRec);
                        }
                        // now visit each, adding types (only one instance of each) to the list
                        if (arg.isComposite()) {
                            etVisitor.visit((CompositeDatabaseType) arg);
                        }
                    }
                }
            }
        }
    }
    // gather Complex types to hand into XMLEntityMappingsGenerator
    List<CompositeDatabaseType> types = etVisitor.getCompositeDatabaseTypes();
    for (CompositeDatabaseType type : types) {
        complextypes.add(type);
    }
    return etVisitor.getCompositeDatabaseTypes();
}
Also used : ProcedureType(org.eclipse.persistence.tools.oracleddl.metadata.ProcedureType) TableType(org.eclipse.persistence.tools.oracleddl.metadata.TableType) ObjectTableType(org.eclipse.persistence.tools.oracleddl.metadata.ObjectTableType) PLSQLRecordType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLRecordType) PLSQLPackageType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLPackageType) ArrayList(java.util.ArrayList) ArgumentType(org.eclipse.persistence.tools.oracleddl.metadata.ArgumentType) FieldType(org.eclipse.persistence.tools.oracleddl.metadata.FieldType) EnclosedTypeVisitor(org.eclipse.persistence.tools.oracleddl.metadata.visit.EnclosedTypeVisitor) ROWTYPEType(org.eclipse.persistence.tools.oracleddl.metadata.ROWTYPEType) CompositeDatabaseType(org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType)

Example 3 with PLSQLRecordType

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

the class JPAMetadataGenerator method processPLSQLArgument.

/**
 * Generate a PL/SQL parameter based on the given ArgumentType. For
 * non-PL/SQL arguments the processArgument method should be used.
 */
protected PLSQLParameterMetadata processPLSQLArgument(ArgumentType arg) {
    // for %ROWTYPE, we need to create a PL/SQL record that mirrors the Table
    if (arg.getEnclosedType().isROWTYPEType()) {
        ROWTYPEType rType = (ROWTYPEType) arg.getEnclosedType();
        TableType tableType = (TableType) rType.getEnclosedType();
        PLSQLRecordType plsqlRec = new PLSQLRecordType(rType.getTypeName());
        plsqlRec.setParentType(new PLSQLPackageType());
        for (FieldType col : tableType.getColumns()) {
            FieldType ft = new FieldType(col.getFieldName());
            ft.setEnclosedType(col.getEnclosedType());
            plsqlRec.addField(ft);
        }
        arg.setEnclosedType(plsqlRec);
    }
    PLSQLParameterMetadata param = new PLSQLParameterMetadata();
    // handle cursor
    if (arg.isPLSQLCursorType()) {
        param.setDirection(OUT_CURSOR_STR);
    }
    // handle stored function return type
    if (arg.getDirection() == ArgumentTypeDirection.RETURN) {
        param.setName(arg.isPLSQLCursorType() ? CURSOR_STR : RESULT_STR);
    } else {
        // direction is already set for cursor type
        if (!arg.isPLSQLCursorType()) {
            param.setDirection(arg.getDirection().name());
        }
        param.setName(arg.getArgumentName());
    }
    String dbType = arg.getTypeName();
    // handle composites
    if (arg.isComposite()) {
        DatabaseType enclosedType = arg.getEnclosedType();
        // need to prepend the package name for most PL/SQL and Cursor types
        if (enclosedType.isPLSQLType() || enclosedType.isPLSQLCursorType()) {
            dbType = getQualifiedTypeName(enclosedType);
        }
        // process the composite enclosed type
        processCompositeType(enclosedType, dbType);
    }
    param.setDatabaseType(processTypeName(dbType));
    return param;
}
Also used : TableType(org.eclipse.persistence.tools.oracleddl.metadata.TableType) ObjectTableType(org.eclipse.persistence.tools.oracleddl.metadata.ObjectTableType) PLSQLRecordType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLRecordType) PLSQLPackageType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLPackageType) CompositeDatabaseType(org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType) DatabaseType(org.eclipse.persistence.tools.oracleddl.metadata.DatabaseType) ROWTYPEType(org.eclipse.persistence.tools.oracleddl.metadata.ROWTYPEType) PLSQLParameterMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.PLSQLParameterMetadata) FieldType(org.eclipse.persistence.tools.oracleddl.metadata.FieldType) Util.getAttributeTypeNameForFieldType(org.eclipse.persistence.tools.metadata.generation.Util.getAttributeTypeNameForFieldType)

Example 4 with PLSQLRecordType

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

the class OracleHelper method customizeSimpleXMLTagNames.

/**
 * Customizes the simple-xml-format tags names to better represent the
 * PL/SQL record/table/column type. This is possible only with
 * strongly-typed ref cursors, since for weakly-typed ones we
 * don't know anything about the cursor's output type.
 */
protected void customizeSimpleXMLTagNames(PLSQLCursorType plsqlCursor, ProcedureOperationModel procedureOperationModel) {
    if (!plsqlCursor.isWeaklyTyped()) {
        // do not override user tag customization
        if (procedureOperationModel.getSimpleXMLFormatTag() == null) {
            procedureOperationModel.setSimpleXMLFormatTag(plsqlCursor.getCursorName());
        }
        // - TYPEType
        if (procedureOperationModel.getXmlTag() == null) {
            if (plsqlCursor.getEnclosedType().isPLSQLRecordType()) {
                PLSQLRecordType recType = (PLSQLRecordType) plsqlCursor.getEnclosedType();
                procedureOperationModel.setXmlTag(recType.getTypeName());
            } else if (plsqlCursor.getEnclosedType().isROWTYPEType()) {
                // assumes ROWTYPEType has an enclosed TableType
                ROWTYPEType rowType = (ROWTYPEType) plsqlCursor.getEnclosedType();
                TableType tableType = (TableType) rowType.getEnclosedType();
                procedureOperationModel.setXmlTag(tableType.getTableName());
            }
        }
    }
}
Also used : PLSQLRecordType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLRecordType) TableType(org.eclipse.persistence.tools.oracleddl.metadata.TableType) ObjectTableType(org.eclipse.persistence.tools.oracleddl.metadata.ObjectTableType) ROWTYPEType(org.eclipse.persistence.tools.oracleddl.metadata.ROWTYPEType)

Example 5 with PLSQLRecordType

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

Aggregations

PLSQLRecordType (org.eclipse.persistence.tools.oracleddl.metadata.PLSQLRecordType)7 ROWTYPEType (org.eclipse.persistence.tools.oracleddl.metadata.ROWTYPEType)6 FieldType (org.eclipse.persistence.tools.oracleddl.metadata.FieldType)5 ObjectTableType (org.eclipse.persistence.tools.oracleddl.metadata.ObjectTableType)5 PLSQLCollectionType (org.eclipse.persistence.tools.oracleddl.metadata.PLSQLCollectionType)4 CompositeDatabaseType (org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType)3 TYPEType (org.eclipse.persistence.tools.oracleddl.metadata.TYPEType)3 TableType (org.eclipse.persistence.tools.oracleddl.metadata.TableType)3 VArrayType (org.eclipse.persistence.tools.oracleddl.metadata.VArrayType)3 OracleObjectType (org.eclipse.persistence.platform.database.oracle.jdbc.OracleObjectType)2 Util.qNameFromString (org.eclipse.persistence.tools.dbws.Util.qNameFromString)2 DatabaseType (org.eclipse.persistence.tools.oracleddl.metadata.DatabaseType)2 ObjectType (org.eclipse.persistence.tools.oracleddl.metadata.ObjectType)2 PLSQLPackageType (org.eclipse.persistence.tools.oracleddl.metadata.PLSQLPackageType)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 Vector (java.util.Vector)1 ComplexDatabaseType (org.eclipse.persistence.internal.helper.ComplexDatabaseType)1 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)1 PLSQLParameterMetadata (org.eclipse.persistence.internal.jpa.metadata.queries.PLSQLParameterMetadata)1