Search in sources :

Example 6 with FieldType

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

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

the class JPAMetadataGenerator method processTableType.

/**
 * Generate an EntityAccessor based on the given TableType.
 */
protected EntityAccessor processTableType(TableType tType) {
    EntityAccessor entity = new EntityAccessor();
    entity.setAccess(EL_ACCESS_VIRTUAL);
    entity.setClassName(getEntityName(tType.getTableName(), defaultPackage));
    // initialize the various lists - some used, some not
    initializeXMLAttributeLists(entity);
    // set the table name on the entity
    TableMetadata table = new TableMetadata();
    table.setName(tType.getTableName());
    entity.setTable(table);
    // process the table columns
    for (FieldType fType : tType.getColumns()) {
        BasicAccessor attribute;
        // handle primary key
        if (fType.pk()) {
            attribute = new IdAccessor();
            entity.getAttributes().getIds().add((IdAccessor) attribute);
        } else {
            attribute = new BasicAccessor();
            entity.getAttributes().getBasics().add(attribute);
        }
        attribute.setName(fType.getFieldName().toLowerCase());
        attribute.setAttributeType(getAttributeTypeNameForFieldType(fType, dbPlatform));
        // set the column name
        ColumnMetadata column = new ColumnMetadata();
        column.setName(fType.getFieldName());
        attribute.setColumn(column);
    }
    // may need to generated NamedNativeQueryMetadata for CRUD operations
    generateCRUDMetadata(entity);
    return entity;
}
Also used : EntityAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor) PLSQLTableMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.PLSQLTableMetadata) TableMetadata(org.eclipse.persistence.internal.jpa.metadata.tables.TableMetadata) BasicAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.BasicAccessor) TenantDiscriminatorColumnMetadata(org.eclipse.persistence.internal.jpa.metadata.columns.TenantDiscriminatorColumnMetadata) ColumnMetadata(org.eclipse.persistence.internal.jpa.metadata.columns.ColumnMetadata) IdAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.IdAccessor) FieldType(org.eclipse.persistence.tools.oracleddl.metadata.FieldType) Util.getAttributeTypeNameForFieldType(org.eclipse.persistence.tools.metadata.generation.Util.getAttributeTypeNameForFieldType)

Example 8 with FieldType

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

the class JPAMetadataGenerator method processPLSQLRecordType.

/**
 * Process the given PLSQLRecordType and return a PLSQLRecordMetadata instance.
 */
protected PLSQLRecordMetadata processPLSQLRecordType(PLSQLRecordType plsqlRecordType) {
    // for %ROWTYPE we create a 'place holder' PL/SQL Record - in this case there is no package name
    String typeName = getQualifiedTypeName(plsqlRecordType);
    String compatibleName = getQualifiedCompatibleTypeName(plsqlRecordType);
    if (compatibleName.contains(PERCENT)) {
        compatibleName = compatibleName.replace(PERCENT, UNDERSCORE);
    }
    PLSQLRecordMetadata plsqlRecord = new PLSQLRecordMetadata();
    plsqlRecord.setName(typeName);
    plsqlRecord.setCompatibleType(compatibleName);
    if (typeName.endsWith(ROWTYPE_STR)) {
        plsqlRecord.setJavaType(getGeneratedJavaClassName(compatibleName));
    } else {
        plsqlRecord.setJavaType(getGeneratedJavaClassName(typeName));
    }
    List<PLSQLParameterMetadata> fields = new ArrayList<PLSQLParameterMetadata>();
    PLSQLParameterMetadata field;
    for (FieldType fld : plsqlRecordType.getFields()) {
        field = new PLSQLParameterMetadata();
        field.setName(fld.getFieldName());
        String dbType = processTypeName(fld.getTypeName());
        if (fld.isComposite()) {
            DatabaseType enclosedType = fld.getEnclosedType();
            // may need to prepend package name
            if (enclosedType.isPLSQLType()) {
                dbType = ((PLSQLType) fld.getEnclosedType()).getParentType().getPackageName() + DOT + dbType;
            }
            processCompositeType(enclosedType, dbType);
        }
        field.setDatabaseType(dbType);
        fields.add(field);
    }
    plsqlRecord.setFields(fields);
    // avoid double-processing
    getProcessedTypes().add(plsqlRecord.getName());
    // generate an EmbeddableAccessor for this type
    generateEmbeddable(plsqlRecord, plsqlRecordType);
    return plsqlRecord;
}
Also used : CompositeDatabaseType(org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType) DatabaseType(org.eclipse.persistence.tools.oracleddl.metadata.DatabaseType) ArrayList(java.util.ArrayList) PLSQLRecordMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.PLSQLRecordMetadata) PLSQLType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLType) 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 9 with FieldType

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

the class XmlEntityMappingsGenerator method processObjectType.

/**
 * Process the given ObjectType and return an OracleObjectTypeMetadata instance.
 */
protected static ComplexTypeMetadata processObjectType(ObjectType oType, Project orProject) {
    ClassDescriptor cDesc = orProject.getDescriptorForAlias(getGeneratedAlias(oType.getTypeName()));
    OracleObjectTypeMetadata ootMetadata = new OracleObjectTypeMetadata();
    ootMetadata.setName(oType.getTypeName());
    ootMetadata.setJavaType(cDesc.getJavaClassName());
    List<PLSQLParameterMetadata> fields = new ArrayList<PLSQLParameterMetadata>();
    for (FieldType ft : oType.getFields()) {
        PLSQLParameterMetadata fieldMetadata = new PLSQLParameterMetadata();
        fieldMetadata.setName(ft.getFieldName());
        fieldMetadata.setDatabaseType(processTypeName(ft.getTypeName()));
        fields.add(fieldMetadata);
    }
    ootMetadata.setFields(fields);
    return ootMetadata;
}
Also used : OracleObjectTypeMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.OracleObjectTypeMetadata) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) ArrayList(java.util.ArrayList) PLSQLParameterMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.PLSQLParameterMetadata) FieldType(org.eclipse.persistence.tools.oracleddl.metadata.FieldType)

Example 10 with FieldType

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

Aggregations

FieldType (org.eclipse.persistence.tools.oracleddl.metadata.FieldType)15 ObjectTableType (org.eclipse.persistence.tools.oracleddl.metadata.ObjectTableType)7 ArrayList (java.util.ArrayList)6 CompositeDatabaseType (org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType)6 ROWTYPEType (org.eclipse.persistence.tools.oracleddl.metadata.ROWTYPEType)6 PLSQLParameterMetadata (org.eclipse.persistence.internal.jpa.metadata.queries.PLSQLParameterMetadata)5 Util.getAttributeTypeNameForFieldType (org.eclipse.persistence.tools.metadata.generation.Util.getAttributeTypeNameForFieldType)5 ObjectType (org.eclipse.persistence.tools.oracleddl.metadata.ObjectType)5 PLSQLRecordType (org.eclipse.persistence.tools.oracleddl.metadata.PLSQLRecordType)5 OracleObjectType (org.eclipse.persistence.platform.database.oracle.jdbc.OracleObjectType)4 Util.qNameFromString (org.eclipse.persistence.tools.dbws.Util.qNameFromString)4 DatabaseType (org.eclipse.persistence.tools.oracleddl.metadata.DatabaseType)4 PLSQLType (org.eclipse.persistence.tools.oracleddl.metadata.PLSQLType)4 TYPEType (org.eclipse.persistence.tools.oracleddl.metadata.TYPEType)4 VArrayType (org.eclipse.persistence.tools.oracleddl.metadata.VArrayType)4 DirectToFieldMapping (org.eclipse.persistence.mappings.DirectToFieldMapping)3 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)3 PLSQLCollectionType (org.eclipse.persistence.tools.oracleddl.metadata.PLSQLCollectionType)3 Iterator (java.util.Iterator)2 Vector (java.util.Vector)2