Search in sources :

Example 11 with DatabaseType

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

the class OracleHelper method getStructureNameForField.

/**
 * Return the structure name to be set on a mapping based on a given
 * FieldType and packageName.
 */
protected String getStructureNameForField(FieldType fType, String packageName) {
    DatabaseType type = fType.getEnclosedType();
    String structureName = type.getTypeName();
    if (packageName != null && packageName.length() > 0 && !packageName.equals(TOPLEVEL)) {
        structureName = packageName + UNDERSCORE + structureName;
    }
    return structureName;
}
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)

Example 12 with DatabaseType

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

the class OracleHelper method addToOXProjectForPLSQLTableArg.

/**
 * Build descriptor and mappings for a PL/SQL collection argument.  The newly
 * created descriptor will be added to the given OX project.
 */
protected void addToOXProjectForPLSQLTableArg(DatabaseType dbType, Project oxProject, String tableName, String tableAlias, String targetTypeName, String catalogPattern) {
    XMLDescriptor xdesc = (XMLDescriptor) oxProject.getDescriptorForAlias(tableAlias);
    if (xdesc == null) {
        xdesc = buildAndAddNewXMLDescriptor(oxProject, tableAlias, tableName.toLowerCase() + COLLECTION_WRAPPER_SUFFIX, nct.generateSchemaAlias(targetTypeName), buildCustomQName(targetTypeName, dbwsBuilder).getNamespaceURI());
    }
    boolean itemsMappingFound = xdesc.getMappingForAttributeName(ITEMS_MAPPING_ATTRIBUTE_NAME) == null ? false : true;
    if (!itemsMappingFound) {
        DatabaseType nestedType = ((PLSQLCollectionType) dbType).getEnclosedType();
        if (nestedType.isPLSQLRecordType()) {
            String referenceClassName = (catalogPattern + DOT + ((PLSQLRecordType) nestedType).getTypeName()).toLowerCase();
            buildAndAddXMLCompositeCollectionMapping(xdesc, referenceClassName);
            if (oxProject.getDescriptorForAlias(referenceClassName) == null) {
                String refTypeName = catalogPattern + UNDERSCORE + ((PLSQLRecordType) nestedType).getTypeName();
                addToOXProjectForPLSQLRecordArg(nestedType, oxProject, referenceClassName, refTypeName.toLowerCase(), refTypeName, catalogPattern);
            }
        } else if (nestedType.isObjectType()) {
            buildAndAddXMLCompositeCollectionMapping(xdesc, getGeneratedJavaClassName(nestedType.getTypeName(), dbwsBuilder.getProjectName()));
        } else {
            if (nestedType.isComposite()) {
                buildAndAddXMLCompositeCollectionMapping(xdesc, tableName.toLowerCase() + COLLECTION_WRAPPER_SUFFIX);
            } else {
                buildAndAddXMLCompositeDirectCollectionMapping(xdesc, ITEMS_MAPPING_ATTRIBUTE_NAME, ITEM_MAPPING_NAME + SLASH + TEXT, getAttributeClassForDatabaseType(nestedType));
            }
        }
    }
}
Also used : PLSQLCollectionType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLCollectionType) 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 13 with DatabaseType

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

Example 14 with DatabaseType

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

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

the class OracleHelper method addToORProjectForPLSQLTableArg.

/**
 * Build descriptor and mappings for a PL/SQL collection argument.  The newly
 * created descriptor will be added to the given OR project.
 */
protected void addToORProjectForPLSQLTableArg(DatabaseType dbType, Project orProject, String tableName, String tableAlias, String targetTypeName, String catalogPattern) {
    ObjectRelationalDataTypeDescriptor ordt = (ObjectRelationalDataTypeDescriptor) orProject.getDescriptorForAlias(tableAlias);
    if (ordt == null) {
        ordt = buildAndAddNewObjectRelationalDataTypeDescriptor(orProject, tableAlias, tableName.toLowerCase() + COLLECTION_WRAPPER_SUFFIX);
    }
    boolean itemsMappingFound = ordt.getMappingForAttributeName(ITEMS_MAPPING_ATTRIBUTE_NAME) == null ? false : true;
    if (!itemsMappingFound) {
        DatabaseType nestedType = ((PLSQLCollectionType) dbType).getEnclosedType();
        if (nestedType.isPLSQLRecordType()) {
            String referenceClassName = (catalogPattern + DOT + ((PLSQLRecordType) nestedType).getTypeName()).toLowerCase();
            buildAndAddObjectArrayMapping(ordt, ITEMS_MAPPING_ATTRIBUTE_NAME, ITEMS_MAPPING_FIELD_NAME, referenceClassName, targetTypeName);
            if (orProject.getDescriptorForAlias(referenceClassName) == null) {
                String refTypeName = catalogPattern + UNDERSCORE + ((PLSQLRecordType) nestedType).getTypeName();
                addToORProjectForPLSQLRecordArg(nestedType, orProject, referenceClassName, refTypeName.toLowerCase(), refTypeName, catalogPattern);
            }
        } else if (nestedType.isObjectType()) {
            buildAndAddObjectArrayMapping(ordt, ITEMS_MAPPING_ATTRIBUTE_NAME, ITEMS_MAPPING_FIELD_NAME, getGeneratedJavaClassName(nestedType.getTypeName(), dbwsBuilder.getProjectName()), targetTypeName);
        } else {
            buildAndAddArrayMapping(ordt, ITEMS_MAPPING_ATTRIBUTE_NAME, ITEMS_MAPPING_FIELD_NAME, targetTypeName);
        }
    }
}
Also used : PLSQLCollectionType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLCollectionType) 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) ObjectRelationalDataTypeDescriptor(org.eclipse.persistence.mappings.structures.ObjectRelationalDataTypeDescriptor)

Aggregations

CompositeDatabaseType (org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType)20 DatabaseType (org.eclipse.persistence.tools.oracleddl.metadata.DatabaseType)20 ComplexDatabaseType (org.eclipse.persistence.internal.helper.ComplexDatabaseType)15 Util.getAttributeClassForDatabaseType (org.eclipse.persistence.tools.dbws.Util.getAttributeClassForDatabaseType)12 Util.qNameFromString (org.eclipse.persistence.tools.dbws.Util.qNameFromString)11 PLSQLType (org.eclipse.persistence.tools.oracleddl.metadata.PLSQLType)5 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)4 OracleObjectType (org.eclipse.persistence.platform.database.oracle.jdbc.OracleObjectType)4 FieldType (org.eclipse.persistence.tools.oracleddl.metadata.FieldType)4 ObjectTableType (org.eclipse.persistence.tools.oracleddl.metadata.ObjectTableType)4 VArrayType (org.eclipse.persistence.tools.oracleddl.metadata.VArrayType)4 ObjectRelationalDataTypeDescriptor (org.eclipse.persistence.mappings.structures.ObjectRelationalDataTypeDescriptor)3 Util.getAttributeTypeNameForFieldType (org.eclipse.persistence.tools.metadata.generation.Util.getAttributeTypeNameForFieldType)3 ArgumentType (org.eclipse.persistence.tools.oracleddl.metadata.ArgumentType)3 ObjectType (org.eclipse.persistence.tools.oracleddl.metadata.ObjectType)3 PLSQLCollectionType (org.eclipse.persistence.tools.oracleddl.metadata.PLSQLCollectionType)3 ROWTYPEType (org.eclipse.persistence.tools.oracleddl.metadata.ROWTYPEType)3 ArrayList (java.util.ArrayList)2 QName (javax.xml.namespace.QName)2 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)2