Search in sources :

Example 1 with FieldType

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

the class BaseDBWSBuilderHelper method buildOROXProjects.

/**
 * Builds OR/OX projects, descriptors {@literal &} mappings, based on a given list
 * of types, as well as table(s) and secondary SQL.
 */
public void buildOROXProjects(NamingConventionTransformer nct, List<CompositeDatabaseType> types) {
    // save for later
    this.nct = nct;
    String projectName = dbwsBuilder.getProjectName();
    Project orProject = new Project();
    orProject.setName(projectName + UNDERSCORE + DBWS_OR_LABEL);
    Project oxProject = null;
    if (dbTables.isEmpty() && !dbwsBuilder.hasBuildSqlOperations()) {
        dbwsBuilder.logMessage(FINEST, "No tables specified");
        oxProject = new SimpleXMLFormatProject();
    } else {
        oxProject = new Project();
    }
    oxProject.setName(projectName + UNDERSCORE + DBWS_OX_LABEL);
    for (TableType dbTable : dbTables) {
        String tableName = dbTable.getTableName();
        RelationalDescriptor desc = buildORDescriptor(tableName, dbwsBuilder.getProjectName(), dbwsBuilder.requireCRUDOperations, nct);
        orProject.addDescriptor(desc);
        XMLDescriptor xdesc = buildOXDescriptor(tableName, dbwsBuilder.getProjectName(), dbwsBuilder.getTargetNamespace(), nct);
        oxProject.addDescriptor(xdesc);
        for (FieldType dbColumn : dbTable.getColumns()) {
            String columnName = dbColumn.getFieldName();
            ElementStyle style = nct.styleForElement(columnName);
            if (style == NONE) {
                continue;
            }
            dbwsBuilder.logMessage(FINE, "Building mappings for " + tableName + DOT + columnName);
            DirectToFieldMapping orFieldMapping = buildORFieldMappingFromColumn(dbColumn, desc, dbwsBuilder.getDatabasePlatform(), nct);
            desc.addMapping(orFieldMapping);
            XMLDirectMapping oxFieldMapping = buildOXFieldMappingFromColumn(dbColumn, dbwsBuilder.getDatabasePlatform(), nct);
            if (oxFieldMapping instanceof XMLBinaryDataMapping) {
                xdesc.getNamespaceResolver().put(XML_MIME_PREFIX, XML_MIME_URL);
            }
            xdesc.addMapping(oxFieldMapping);
            // check for switch from Byte[] to byte[]
            if (oxFieldMapping.getAttributeClassificationName() == APBYTE.getName()) {
                orFieldMapping.setAttributeClassificationName(APBYTE.getName());
            }
        }
        setUpFindQueries(nct, tableName, desc);
    }
    finishUpProjects(orProject, oxProject, types);
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) XMLBinaryDataMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping) Project(org.eclipse.persistence.sessions.Project) SchemaModelProject(org.eclipse.persistence.internal.oxm.schema.SchemaModelProject) DBWSModelProject(org.eclipse.persistence.dbws.DBWSModelProject) ObjectPersistenceWorkbenchXMLProject(org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceWorkbenchXMLProject) SimpleXMLFormatProject(org.eclipse.persistence.internal.xr.sxf.SimpleXMLFormatProject) SimpleXMLFormatProject(org.eclipse.persistence.internal.xr.sxf.SimpleXMLFormatProject) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) TableType(org.eclipse.persistence.tools.oracleddl.metadata.TableType) ObjectTableType(org.eclipse.persistence.tools.oracleddl.metadata.ObjectTableType) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) ElementStyle(org.eclipse.persistence.tools.dbws.NamingConventionTransformer.ElementStyle) FieldType(org.eclipse.persistence.tools.oracleddl.metadata.FieldType)

Example 2 with FieldType

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

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

the class OracleHelper method addToORProjectForObjectTypeArg.

/**
 * Build descriptor and mappings for an Object type argument.  The
 * newly created descriptor will be added to the given OX project.
 */
@SuppressWarnings("rawtypes")
protected void addToORProjectForObjectTypeArg(DatabaseType dbType, Project orProject, String objectName, String objectAlias) {
    ObjectRelationalDataTypeDescriptor ordt = (ObjectRelationalDataTypeDescriptor) orProject.getDescriptorForAlias(objectAlias);
    if (ordt == null) {
        ordt = buildAndAddNewObjectRelationalDataTypeDescriptor(orProject, objectAlias, objectName);
    }
    ObjectType oType = (ObjectType) dbType;
    for (FieldType fType : oType.getFields()) {
        String fieldName = fType.getFieldName();
        String lFieldName = fieldName.toLowerCase();
        // handle field ordering
        boolean found = false;
        Vector orderedFields = ordt.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) {
            ordt.addFieldOrdering(fieldName);
        }
        if (ordt.getMappingForAttributeName(lFieldName) == null) {
            if (fType.isComposite()) {
                String targetTypeName2 = fType.getEnclosedType().getTypeName();
                String alias = getGeneratedAlias(targetTypeName2);
                ObjectRelationalDataTypeDescriptor ordt2 = (ObjectRelationalDataTypeDescriptor) orProject.getDescriptorForAlias(alias);
                boolean buildDescriptor = ordt2 == null;
                if (buildDescriptor) {
                    ordt2 = buildAndAddNewObjectRelationalDataTypeDescriptor(orProject, alias);
                }
                // handle ObjectType field
                if (fType.getEnclosedType().isObjectType()) {
                    if (buildDescriptor) {
                        // need to update the java class name on the descriptor to include package (project) name
                        ordt2.setJavaClassName(getGeneratedJavaClassName(alias, dbwsBuilder.getProjectName()));
                        addToORProjectForObjectTypeArg(fType.getEnclosedType(), orProject, ordt2.getJavaClassName(), alias);
                    }
                    buildAndAddStructureMapping(ordt, lFieldName, fieldName, ordt2.getJavaClassName());
                } else if (fType.getEnclosedType().isVArrayType()) {
                    // handle VArray field
                    if (buildDescriptor) {
                        // need to update the java class name on the descriptor to include package (project) name
                        ordt2.setJavaClassName(getGeneratedJavaClassName(alias, dbwsBuilder.getProjectName()));
                        addToORProjectForVArrayArg(fType.getEnclosedType(), orProject, ordt2.getJavaClassName(), alias);
                    }
                    buildAndAddArrayMapping(ordt, lFieldName, fieldName, getStructureNameForField(fType, null));
                } else if (fType.getEnclosedType().isObjectTableType()) {
                    if (buildDescriptor) {
                        // need to update the java class name on the descriptor to include package (project) name
                        ordt2.setJavaClassName(getGeneratedJavaClassName(alias, dbwsBuilder.getProjectName()));
                        // make sure the descriptor is built for the enclosed ObjectType
                        addToORProjectForObjectTableTypeArg(fType.getEnclosedType(), orProject, targetTypeName2, alias);
                    }
                    if (((ObjectTableType) fType.getEnclosedType()).getEnclosedType().isComposite()) {
                        ObjectType nestedType = (ObjectType) ((ObjectTableType) fType.getEnclosedType()).getEnclosedType();
                        String nestedTypeAlias = getGeneratedAlias(nestedType.getTypeName());
                        String nestedTypeName = getGeneratedJavaClassName(nestedTypeAlias, dbwsBuilder.getProjectName());
                        buildAndAddObjectArrayMapping(ordt, lFieldName, fieldName, nestedTypeName, nestedTypeAlias.toUpperCase());
                    } else {
                        buildAndAddArrayMapping(ordt, lFieldName, fieldName, alias.toUpperCase());
                    }
                }
            } else {
                // direct mapping
                DirectToFieldMapping dfm = new DirectToFieldMapping();
                dfm.setFieldName(fieldName);
                dfm.setAttributeName(lFieldName);
                dfm.setAttributeClassification(getAttributeClassForDatabaseType(fType.getEnclosedType()));
                ordt.addMapping(dfm);
            }
        }
    }
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) ObjectType(org.eclipse.persistence.tools.oracleddl.metadata.ObjectType) OracleObjectType(org.eclipse.persistence.platform.database.oracle.jdbc.OracleObjectType) ObjectRelationalDatabaseField(org.eclipse.persistence.mappings.structures.ObjectRelationalDatabaseField) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) Iterator(java.util.Iterator) Util.qNameFromString(org.eclipse.persistence.tools.dbws.Util.qNameFromString) Vector(java.util.Vector) ObjectRelationalDataTypeDescriptor(org.eclipse.persistence.mappings.structures.ObjectRelationalDataTypeDescriptor) FieldType(org.eclipse.persistence.tools.oracleddl.metadata.FieldType)

Example 4 with FieldType

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

the class JPAMetadataGenerator method addEmbeddableAttributes.

/**
 * Process a list of FieldTypes, creating an attribute for each - the created
 * XMLAttributes are set on the given EmbeddableAccessor.
 *
 * @see org.eclipse.persistence.internal.jpa.metadata.accessors.classes.XMLAttributes
 */
protected void addEmbeddableAttributes(EmbeddableAccessor embeddable, List<FieldType> fields) {
    for (FieldType fld : fields) {
        DatabaseType enclosedType = fld.getEnclosedType();
        if (!enclosedType.isComposite() || enclosedType.isTYPEType()) {
            // basic
            String typeName = enclosedType.isTYPEType() ? enclosedType.getTypeName() : fld.getTypeName();
            BasicAccessor basic = generateBasicAccessor(fld.getFieldName().toLowerCase(), fld.getFieldName(), getClassNameFromJDBCTypeName(typeName, dbPlatform));
            embeddable.getAttributes().getBasics().add(basic);
        } else if (enclosedType.isPLSQLType()) {
            // record or collection
            PLSQLType plsqlType = (PLSQLType) enclosedType;
            String typeName = getQualifiedTypeName(plsqlType);
            EmbeddedAccessor embedded = new EmbeddedAccessor();
            embedded.setName(fld.getFieldName().toLowerCase());
            embedded.setAttributeType(getGeneratedJavaClassName(typeName));
            embeddable.getAttributes().getEmbeddeds().add(embedded);
        } else if (enclosedType.isVArrayType() || enclosedType.isObjectTableType()) {
            // array
            ArrayAccessor array = null;
            // target class is reference class name for Object Table, and structure name for Varray
            if (enclosedType.isVArrayType()) {
                array = generateArrayAccessor(fld.getFieldName().toLowerCase(), fld.getFieldName(), enclosedType.getTypeName());
            } else {
                ObjectTableType otType = (ObjectTableType) enclosedType;
                array = generateArrayAccessor(fld.getFieldName().toLowerCase(), fld.getFieldName(), otType.getEnclosedType().getTypeName(), getGeneratedJavaClassName(otType.getEnclosedType().getTypeName(), defaultPackage));
            }
            embeddable.getAttributes().getArrays().add(array);
        } else if (enclosedType.isObjectType()) {
            // struct
            StructureAccessor structure = generateStructureAccessor(fld.getFieldName().toLowerCase(), fld.getFieldName(), getGeneratedJavaClassName(enclosedType.getTypeName(), defaultPackage));
            embeddable.getAttributes().getStructures().add(structure);
        } else if (enclosedType.isTYPEType()) {
            TYPEType tType = (TYPEType) enclosedType;
            BasicAccessor basic = generateBasicAccessor(fld.getFieldName().toLowerCase(), fld.getFieldName(), getClassNameFromJDBCTypeName(tType.getTypeName(), dbPlatform));
            embeddable.getAttributes().getBasics().add(basic);
        }
    }
}
Also used : BasicAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.BasicAccessor) ObjectTableType(org.eclipse.persistence.tools.oracleddl.metadata.ObjectTableType) ROWTYPEType(org.eclipse.persistence.tools.oracleddl.metadata.ROWTYPEType) TYPEType(org.eclipse.persistence.tools.oracleddl.metadata.TYPEType) CompositeDatabaseType(org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType) DatabaseType(org.eclipse.persistence.tools.oracleddl.metadata.DatabaseType) StructureAccessor(org.eclipse.persistence.internal.jpa.metadata.structures.StructureAccessor) PLSQLType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLType) EmbeddedAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.EmbeddedAccessor) ArrayAccessor(org.eclipse.persistence.internal.jpa.metadata.structures.ArrayAccessor) FieldType(org.eclipse.persistence.tools.oracleddl.metadata.FieldType) Util.getAttributeTypeNameForFieldType(org.eclipse.persistence.tools.metadata.generation.Util.getAttributeTypeNameForFieldType)

Example 5 with FieldType

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

the class JPAMetadataGenerator method processObjectType.

/**
 * Generate object type metadata based on the given ObjectType.
 */
protected OracleObjectTypeMetadata processObjectType(ObjectType oType) {
    OracleObjectTypeMetadata objectType = new OracleObjectTypeMetadata();
    objectType.setName(oType.getTypeName());
    objectType.setJavaType(getGeneratedJavaClassName(oType.getTypeName(), defaultPackage));
    // process the object type's fields
    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);
        if (ft.isComposite()) {
            processCompositeType(ft.getEnclosedType());
        }
    }
    objectType.setFields(fields);
    // avoid double-processing
    getProcessedTypes().add(objectType.getName());
    // generate an EmbeddableAccessor for this type
    generateEmbeddable(objectType, oType);
    return objectType;
}
Also used : OracleObjectTypeMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.OracleObjectTypeMetadata) ArrayList(java.util.ArrayList) 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)

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