Search in sources :

Example 1 with ObjectTableType

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

the class JPAMetadataGenerator method processArrayType.

/**
 * Generate array type metadata based on the given VArray or ObjectTable type.
 */
protected OracleArrayTypeMetadata processArrayType(DatabaseType dbType) {
    OracleArrayTypeMetadata arrayType = new OracleArrayTypeMetadata();
    arrayType.setName(dbType.getTypeName());
    arrayType.setJavaType(getGeneratedJavaClassName(dbType.getTypeName(), defaultPackage));
    if (dbType.isVArrayType()) {
        arrayType.setNestedType(processTypeName(((VArrayType) dbType).getEnclosedType().getTypeName()));
    } else {
        // assumes ObjectTable
        arrayType.setNestedType(((ObjectTableType) dbType).getEnclosedType().getTypeName());
    }
    // avoid double-processing
    getProcessedTypes().add(arrayType.getName());
    // generate an EmbeddableAccessor for this type
    generateEmbeddable(arrayType, (CompositeDatabaseTypeWithEnclosedType) dbType);
    return arrayType;
}
Also used : OracleArrayTypeMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.OracleArrayTypeMetadata) ObjectTableType(org.eclipse.persistence.tools.oracleddl.metadata.ObjectTableType)

Example 2 with ObjectTableType

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

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

the class OracleHelper method addToOXProjectForObjectTypeArg.

/**
 * Build descriptor and mappings for an Object type argument.  The
 * newly created descriptor will be added to the given OX project.
 */
protected void addToOXProjectForObjectTypeArg(DatabaseType dbType, Project oxProject, String objectName, String objectAlias) {
    XMLDescriptor xdesc = (XMLDescriptor) oxProject.getDescriptorForAlias(objectAlias);
    if (xdesc == null) {
        xdesc = buildAndAddNewXMLDescriptor(oxProject, objectAlias, objectName, nct.generateSchemaAlias(dbType.getTypeName()), buildCustomQName(objectName, dbwsBuilder).getNamespaceURI());
    }
    ObjectType oType = (ObjectType) dbType;
    for (FieldType field : oType.getFields()) {
        // custom transformer may exclude some fields
        if (nct.styleForElement(field.getFieldName()) == ElementStyle.NONE) {
            continue;
        }
        String lFieldName = field.getFieldName().toLowerCase();
        if (xdesc.getMappingForAttributeName(lFieldName) == null) {
            if (field.isComposite()) {
                String targetTypeName2 = field.getEnclosedType().getTypeName();
                String alias = getGeneratedAlias(targetTypeName2);
                XMLDescriptor xdesc2 = (XMLDescriptor) oxProject.getDescriptorForAlias(alias);
                boolean buildDescriptor = xdesc2 == null;
                if (buildDescriptor) {
                    xdesc2 = buildAndAddNewXMLDescriptor(oxProject, alias, nct.generateSchemaAlias(targetTypeName2), buildCustomQName(targetTypeName2, dbwsBuilder).getNamespaceURI());
                }
                // handle ObjectType field
                if (field.getEnclosedType().isObjectType()) {
                    if (buildDescriptor) {
                        // need to update the java class name on the descriptor to include package (project) name
                        xdesc2.setJavaClassName(getGeneratedJavaClassName(alias, dbwsBuilder.getProjectName()));
                        addToOXProjectForObjectTypeArg(field.getEnclosedType(), oxProject, xdesc2.getJavaClassName(), alias);
                    }
                    buildAndAddXMLCompositeObjectMapping(xdesc, lFieldName, xdesc2.getJavaClassName());
                } else if (field.getEnclosedType().isVArrayType()) {
                    // handle VArray field
                    if (buildDescriptor) {
                        // need to update the java class name on the descriptor to include package (project) name
                        xdesc2.setJavaClassName(getGeneratedJavaClassName(alias, dbwsBuilder.getProjectName()));
                        addToOXProjectForVArrayArg(field.getEnclosedType(), oxProject, xdesc2.getJavaClassName(), alias);
                    }
                    buildAndAddXMLCompositeDirectCollectionMapping(xdesc, lFieldName, lFieldName + SLASH + TEXT, getAttributeClassForDatabaseType(field.getEnclosedType()));
                } else if (field.getEnclosedType().isObjectTableType()) {
                    // handle ObjectTableType field
                    if (buildDescriptor) {
                        // need to update the java class name on the descriptor to include package (project) name
                        xdesc2.setJavaClassName(getGeneratedJavaClassName(alias, dbwsBuilder.getProjectName()));
                        // make sure the descriptor is built for the enclosed ObjectType
                        addToOXProjectForObjectTableTypeArg(field.getEnclosedType(), oxProject, targetTypeName2, alias);
                    }
                    ObjectTableType tableType = (ObjectTableType) field.getEnclosedType();
                    if (tableType.getEnclosedType().isComposite()) {
                        String nestedTypeAlias = getGeneratedAlias(((ObjectTableType) field.getEnclosedType()).getEnclosedType().getTypeName());
                        String nestedTypeName = getGeneratedJavaClassName(nestedTypeAlias, dbwsBuilder.getProjectName());
                        buildAndAddXMLCompositeCollectionMapping(xdesc, lFieldName, lFieldName + SLASH + ITEM_MAPPING_NAME, nestedTypeName);
                    } else {
                        buildAndAddXMLCompositeDirectCollectionMapping(xdesc, lFieldName, lFieldName + SLASH + TEXT, getAttributeClassForDatabaseType(tableType));
                    }
                }
            } else {
                // direct mapping
                addDirectMappingForFieldType(xdesc, lFieldName, field);
            }
        }
    }
}
Also used : ObjectType(org.eclipse.persistence.tools.oracleddl.metadata.ObjectType) OracleObjectType(org.eclipse.persistence.platform.database.oracle.jdbc.OracleObjectType) ObjectTableType(org.eclipse.persistence.tools.oracleddl.metadata.ObjectTableType) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) Util.qNameFromString(org.eclipse.persistence.tools.dbws.Util.qNameFromString) FieldType(org.eclipse.persistence.tools.oracleddl.metadata.FieldType)

Example 4 with ObjectTableType

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

the class OracleHelper method addToOXProjectForObjectTableTypeArg.

/**
 * Build descriptor and mappings for an OracleTableType argument.  The
 * newly created descriptor will be added to the given OX project.
 */
protected void addToOXProjectForObjectTableTypeArg(DatabaseType dbType, Project oxProject, String objectTableName, String objectTableAlias) {
    XMLDescriptor xdesc = (XMLDescriptor) oxProject.getDescriptorForAlias(objectTableAlias);
    if (xdesc == null) {
        xdesc = buildAndAddNewXMLDescriptor(oxProject, objectTableAlias, objectTableName + COLLECTION_WRAPPER_SUFFIX, nct.generateSchemaAlias(dbType.getTypeName()), buildCustomQName(objectTableName, dbwsBuilder).getNamespaceURI());
    }
    boolean itemsMappingFound = xdesc.getMappingForAttributeName(ITEMS_MAPPING_ATTRIBUTE_NAME) == null ? false : true;
    if (!itemsMappingFound) {
        DatabaseType nType = ((ObjectTableType) dbType).getEnclosedType();
        if (nType.isObjectType()) {
            ObjectType oType = (ObjectType) nType;
            String nestedTypeAlias = getGeneratedAlias(oType.getTypeName());
            String nestedTypeName = getGeneratedJavaClassName(nestedTypeAlias, dbwsBuilder.getProjectName());
            addToOXProjectForObjectTypeArg(oType, oxProject, nestedTypeName, nestedTypeAlias);
            // ObjectType is composite
            buildAndAddXMLCompositeCollectionMapping(xdesc, nestedTypeName);
        } else {
            buildAndAddXMLCompositeDirectCollectionMapping(xdesc, ITEMS_MAPPING_ATTRIBUTE_NAME, ITEM_MAPPING_NAME + SLASH + TEXT, getAttributeClassForDatabaseType(nType));
        }
    }
}
Also used : 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) 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 5 with ObjectTableType

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

ObjectTableType (org.eclipse.persistence.tools.oracleddl.metadata.ObjectTableType)7 Util.qNameFromString (org.eclipse.persistence.tools.dbws.Util.qNameFromString)5 OracleObjectType (org.eclipse.persistence.platform.database.oracle.jdbc.OracleObjectType)4 FieldType (org.eclipse.persistence.tools.oracleddl.metadata.FieldType)4 ObjectType (org.eclipse.persistence.tools.oracleddl.metadata.ObjectType)4 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)3 CompositeDatabaseType (org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType)3 DatabaseType (org.eclipse.persistence.tools.oracleddl.metadata.DatabaseType)3 ROWTYPEType (org.eclipse.persistence.tools.oracleddl.metadata.ROWTYPEType)3 TYPEType (org.eclipse.persistence.tools.oracleddl.metadata.TYPEType)3 ComplexDatabaseType (org.eclipse.persistence.internal.helper.ComplexDatabaseType)2 ObjectRelationalDataTypeDescriptor (org.eclipse.persistence.mappings.structures.ObjectRelationalDataTypeDescriptor)2 Util.getAttributeClassForDatabaseType (org.eclipse.persistence.tools.dbws.Util.getAttributeClassForDatabaseType)2 PLSQLCollectionType (org.eclipse.persistence.tools.oracleddl.metadata.PLSQLCollectionType)2 PLSQLRecordType (org.eclipse.persistence.tools.oracleddl.metadata.PLSQLRecordType)2 VArrayType (org.eclipse.persistence.tools.oracleddl.metadata.VArrayType)2 Iterator (java.util.Iterator)1 Vector (java.util.Vector)1 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)1 BasicAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.BasicAccessor)1