Search in sources :

Example 1 with CompositeDatabaseType

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

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

the class JPAMetadataGenerator method generateXmlEntityMappings.

/**
 * Generate an XMLEntityMappings instance based on a given list of meta-model database types.
 *
 * @param databaseTypes the list of meta-model database types to be used to generate an XMLEntityMappings
 * @see org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType
 */
public XMLEntityMappings generateXmlEntityMappings(List<CompositeDatabaseType> databaseTypes) {
    List<ProcedureType> procedures = new ArrayList<ProcedureType>();
    List<TableType> tables = new ArrayList<TableType>();
    // populate lists of TableTypes and ProcedureTypes
    for (CompositeDatabaseType dbType : databaseTypes) {
        if (dbType.isTableType()) {
            tables.add((TableType) dbType);
        } else if (dbType.isProcedureType()) {
            procedures.add((ProcedureType) dbType);
        }
    }
    // handle stored procedure overloading
    handleOverloading(procedures);
    // process TableTypes
    for (TableType table : tables) {
        EntityAccessor entity = processTableType(table);
        xmlEntityMappings.getEntities().add(entity);
    }
    // process ProcedureTypes
    for (ProcedureType procedure : procedures) {
        // PL/SQL stored procedures and functions will have a PLSQLPackageType as its parent
        PLSQLPackageType pkgType = procedure.getParentType();
        if (pkgType != null) {
            // handle PL/SQL
            if (procedure.isFunctionType()) {
                xmlEntityMappings.getNamedPLSQLStoredFunctionQueries().add(processPLSQLFunctionType((FunctionType) procedure, pkgType));
            } else {
                xmlEntityMappings.getNamedPLSQLStoredProcedureQueries().add(processPLSQLProcedureType(procedure, pkgType));
            }
        } else {
            // handle top-level (non-PL/SQL) functions and procedures
            if (procedure.isFunctionType()) {
                xmlEntityMappings.getNamedStoredFunctionQueries().add(processFunctionType((FunctionType) procedure));
            } else {
                xmlEntityMappings.getNamedStoredProcedureQueries().add(processProcedureType(procedure));
            }
        }
    }
    return xmlEntityMappings;
}
Also used : EntityAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor) ProcedureType(org.eclipse.persistence.tools.oracleddl.metadata.ProcedureType) TableType(org.eclipse.persistence.tools.oracleddl.metadata.TableType) ObjectTableType(org.eclipse.persistence.tools.oracleddl.metadata.ObjectTableType) PLSQLPackageType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLPackageType) FunctionType(org.eclipse.persistence.tools.oracleddl.metadata.FunctionType) ArrayList(java.util.ArrayList) CompositeDatabaseType(org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType)

Example 3 with CompositeDatabaseType

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

the class XmlEntityMappingsGenerator method processCompositeTypes.

/**
 * Returns a list of ComplexTypeMetadata instances generated based on a list of
 * CompositeDatabaseTypes.  The given non-empty list should contain one or
 * more of the following types:
 * <ul>
 * <li>PLSQLCollectionType
 * <li>PLSQLRecordType
 * <li>ObjectTableType
 * <li>ObjectType
 * <li>VArrayType
 * </ul>
 */
protected static List<ComplexTypeMetadata> processCompositeTypes(List<CompositeDatabaseType> complexTypes, Project orProject) {
    List<String> processedTypeNames = new ArrayList<String>();
    List<ComplexTypeMetadata> processedTypes = new ArrayList<ComplexTypeMetadata>();
    // process composite types
    for (CompositeDatabaseType cdbType : complexTypes) {
        ComplexTypeMetadata complexTypeMetadata = processDatabaseType(cdbType, orProject);
        if (complexTypeMetadata != null) {
            processedTypeNames.add(complexTypeMetadata.getName());
            processedTypes.add(complexTypeMetadata);
        }
    }
    // now handle processing composite enclosed types
    for (CompositeDatabaseType cdbType : complexTypes) {
        if (cdbType.getEnclosedType() != null && cdbType.getEnclosedType().isComposite()) {
            CompositeDatabaseType enclosedType = (CompositeDatabaseType) cdbType.getEnclosedType();
            ComplexTypeMetadata complexTypeMetadata = processDatabaseType(enclosedType, orProject, processedTypeNames);
            if (complexTypeMetadata != null) {
                processedTypeNames.add(complexTypeMetadata.getName());
                processedTypes.add(complexTypeMetadata);
                if (enclosedType.isObjectType()) {
                    for (FieldType ft : ((ObjectType) enclosedType).getFields()) {
                        if (ft.isComposite()) {
                            complexTypeMetadata = processDatabaseType(ft, orProject, processedTypeNames);
                            if (complexTypeMetadata != null) {
                                processedTypeNames.add(complexTypeMetadata.getName());
                                processedTypes.add(complexTypeMetadata);
                            }
                        }
                    }
                } else if (enclosedType.isVArrayType()) {
                    VArrayType vType = (VArrayType) enclosedType;
                    if (vType.getEnclosedType().isComposite()) {
                        complexTypeMetadata = processDatabaseType((CompositeDatabaseType) vType.getEnclosedType(), orProject, processedTypeNames);
                        if (complexTypeMetadata != null) {
                            processedTypeNames.add(complexTypeMetadata.getName());
                            processedTypes.add(complexTypeMetadata);
                        }
                    }
                }
            }
        }
    }
    return processedTypes;
}
Also used : ObjectType(org.eclipse.persistence.tools.oracleddl.metadata.ObjectType) VArrayType(org.eclipse.persistence.tools.oracleddl.metadata.VArrayType) ArrayList(java.util.ArrayList) OracleComplexTypeMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.OracleComplexTypeMetadata) ComplexTypeMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.ComplexTypeMetadata) PLSQLComplexTypeMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.PLSQLComplexTypeMetadata) CompositeDatabaseType(org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType) FieldType(org.eclipse.persistence.tools.oracleddl.metadata.FieldType)

Example 4 with CompositeDatabaseType

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

the class OracleHelper method addToOROXProjectsForComplexTypes.

/**
 * Create OR/OX projects for complex types, i.e. PLSQLTypes, VArray, etc.
 */
@Override
public void addToOROXProjectsForComplexTypes(List<CompositeDatabaseType> types, Project orProject, Project oxProject) {
    for (DatabaseType dbType : types) {
        String name;
        String alias;
        if (dbType.isPLSQLType()) {
            // set type name to upper case to avoid runtime SQLException
            dbType.setTypeName(dbType.getTypeName().toUpperCase());
            String catalogPattern = ((PLSQLType) dbType).getParentType().getPackageName();
            String targetTypeName;
            // for types enclosed in a ROWTYPEType, package doesn't apply
            if (catalogPattern == null) {
                name = dbType.getTypeName();
                targetTypeName = dbType.getTypeName();
            } else {
                name = catalogPattern + DOT + dbType.getTypeName();
                targetTypeName = catalogPattern + UNDERSCORE + dbType.getTypeName();
            }
            alias = targetTypeName.toLowerCase();
            // remove '%' from target, alias, and name
            name = name.replace(PERCENT, UNDERSCORE);
            targetTypeName = targetTypeName.replace(PERCENT, UNDERSCORE);
            alias = alias.replace(PERCENT, UNDERSCORE);
            // handle PL/SQL record type
            if (dbType.isPLSQLRecordType()) {
                addToOXProjectForPLSQLRecordArg(dbType, oxProject, name, alias, targetTypeName, catalogPattern);
                addToORProjectForPLSQLRecordArg(dbType, orProject, name, alias, targetTypeName, catalogPattern);
            } else // handle PL/SQL collection type
            {
                addToOXProjectForPLSQLTableArg(dbType, oxProject, name, alias, targetTypeName, catalogPattern);
                addToORProjectForPLSQLTableArg(dbType, orProject, name, alias, targetTypeName, catalogPattern);
            }
        } else {
            // Advanced JDBC types need the (Java) package name prepended to the type name
            if (Util.isTypeComplex(dbType)) {
                name = getGeneratedJavaClassName(dbType.getTypeName(), dbwsBuilder.getProjectName());
            } else {
                name = dbType.getTypeName();
            }
            alias = getGeneratedAlias(dbType.getTypeName());
            // handle VArray type
            if (dbType.isVArrayType()) {
                addToOXProjectForVArrayArg(dbType, oxProject, name, alias);
                addToORProjectForVArrayArg(dbType, orProject, name, alias);
            } else // handle ObjectType type
            if (dbType.isObjectType()) {
                addToOXProjectForObjectTypeArg(dbType, oxProject, name, alias);
                addToORProjectForObjectTypeArg(dbType, orProject, name, alias);
            } else // handle ObjectTable type
            if (dbType.isObjectTableType()) {
                addToOXProjectForObjectTableTypeArg(dbType, oxProject, name, alias);
                addToORProjectForObjectTableTypeArg(dbType, orProject, name, alias);
            }
        }
    }
}
Also used : 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)

Aggregations

CompositeDatabaseType (org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType)4 ArrayList (java.util.ArrayList)3 FieldType (org.eclipse.persistence.tools.oracleddl.metadata.FieldType)2 ObjectTableType (org.eclipse.persistence.tools.oracleddl.metadata.ObjectTableType)2 PLSQLPackageType (org.eclipse.persistence.tools.oracleddl.metadata.PLSQLPackageType)2 ProcedureType (org.eclipse.persistence.tools.oracleddl.metadata.ProcedureType)2 TableType (org.eclipse.persistence.tools.oracleddl.metadata.TableType)2 ComplexDatabaseType (org.eclipse.persistence.internal.helper.ComplexDatabaseType)1 EntityAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor)1 ComplexTypeMetadata (org.eclipse.persistence.internal.jpa.metadata.queries.ComplexTypeMetadata)1 OracleComplexTypeMetadata (org.eclipse.persistence.internal.jpa.metadata.queries.OracleComplexTypeMetadata)1 PLSQLComplexTypeMetadata (org.eclipse.persistence.internal.jpa.metadata.queries.PLSQLComplexTypeMetadata)1 Util.getAttributeClassForDatabaseType (org.eclipse.persistence.tools.dbws.Util.getAttributeClassForDatabaseType)1 Util.qNameFromString (org.eclipse.persistence.tools.dbws.Util.qNameFromString)1 ArgumentType (org.eclipse.persistence.tools.oracleddl.metadata.ArgumentType)1 DatabaseType (org.eclipse.persistence.tools.oracleddl.metadata.DatabaseType)1 FunctionType (org.eclipse.persistence.tools.oracleddl.metadata.FunctionType)1 ObjectType (org.eclipse.persistence.tools.oracleddl.metadata.ObjectType)1 PLSQLRecordType (org.eclipse.persistence.tools.oracleddl.metadata.PLSQLRecordType)1 ROWTYPEType (org.eclipse.persistence.tools.oracleddl.metadata.ROWTYPEType)1