Search in sources :

Example 1 with SizedType

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

the class BaseDBWSBuilderHelper method buildOXFieldMappingFromColumn.

protected XMLDirectMapping buildOXFieldMappingFromColumn(FieldType dbColumn, DatabasePlatform databasePlatform, NamingConventionTransformer nct) {
    String columnName = dbColumn.getFieldName();
    DatabaseType dataType = dbColumn.getEnclosedType();
    String typeName = getTypeNameForDatabaseType(dataType);
    int jdbcType = getJDBCTypeFromTypeName(typeName);
    String dmdTypeName = getJDBCTypeNameFromType(jdbcType);
    QName qName = getXMLTypeFromJDBCType(jdbcType);
    Class<?> attributeClass;
    if (CHAR_STR.equalsIgnoreCase(dmdTypeName) && dbColumn.getEnclosedType().isSizedType()) {
        SizedType sizedType = (SizedType) dbColumn.getEnclosedType();
        if (sizedType.getSize() == 1) {
            attributeClass = Character.class;
        } else {
            attributeClass = String.class;
        }
    } else {
        attributeClass = getClassFromJDBCType(dmdTypeName.toUpperCase(), databasePlatform);
    }
    // problem with conversion and Oracle11 platform
    if (attributeClass.getName().contains(TIMESTAMP_CLASS)) {
        attributeClass = java.sql.Timestamp.class;
    } else if (attributeClass.getName().contains(java.lang.Character[].class.getName())) {
        attributeClass = java.lang.String.class;
    }
    XMLDirectMapping xdm = setUpXMLDirectMapping(columnName, qName, nct, attributeClass, jdbcType, dbColumn.pk());
    return xdm;
}
Also used : ScalarDatabaseType(org.eclipse.persistence.tools.oracleddl.metadata.ScalarDatabaseType) CompositeDatabaseType(org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType) ComplexDatabaseType(org.eclipse.persistence.internal.helper.ComplexDatabaseType) DatabaseType(org.eclipse.persistence.tools.oracleddl.metadata.DatabaseType) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) QName(javax.xml.namespace.QName) SizedType(org.eclipse.persistence.tools.oracleddl.metadata.SizedType)

Example 2 with SizedType

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

the class Util method getAttributeTypeNameForFieldType.

/**
 * Return the attribute-type name for a given FieldType.
 *
 * For CHAR sized type, java.lang.Character will be returned.
 * For CHAR non-sized type, java.lang.String will be returned.
 * For non-CHAR type, the database platform will be used to get the type name.
 * If the type to be returned is oracle.sql.Timestamp, java.sql.Timestamp will be
 * returned instead (to handle conversion issue with Oracle11Platform)
 */
protected static String getAttributeTypeNameForFieldType(FieldType fldType, DatabasePlatform dbPlatform) {
    String typeName = getJDBCTypeName(fldType.getTypeName());
    String attributeType;
    if (CHAR_STR.equalsIgnoreCase(typeName) && fldType.getEnclosedType().isSizedType()) {
        SizedType sizedType = (SizedType) fldType.getEnclosedType();
        if (sizedType.getSize() == 1) {
            attributeType = ClassConstants.CHAR.getName();
        } else {
            attributeType = ClassConstants.STRING.getName();
        }
    } else {
        attributeType = getClassNameFromJDBCTypeName(typeName.toUpperCase(), dbPlatform);
    }
    // handle issue with java.sql.Timestamp conversion and Oracle11 platform
    if (attributeType.contains(ORACLE_TIMESTAMP_CLS_STR)) {
        attributeType = ClassConstants.TIMESTAMP.getName();
    } else if (attributeType.contains(ClassConstants.ABYTE.getName())) {
        attributeType = ClassConstants.APBYTE.getName();
    }
    return attributeType;
}
Also used : SizedType(org.eclipse.persistence.tools.oracleddl.metadata.SizedType)

Example 3 with SizedType

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

the class BaseDBWSBuilderHelper method buildDatabaseTypeFromMetadataType.

/**
 * Build a org.eclipse.persistence.internal.helper.DatabaseType  instance  from an
 * org.eclipse.persistence.tools.oracleddl.metadata.DatabaseType instance.  In the
 * the case of PLSQL Packages, the catalog (package) name can be passed in as well.
 */
@SuppressWarnings("rawtypes")
protected org.eclipse.persistence.internal.helper.DatabaseType buildDatabaseTypeFromMetadataType(DatabaseType dType, String catalog) {
    // argument could be from a different package
    if (dType.isPLSQLType()) {
        PLSQLType pType = (PLSQLType) dType;
        catalog = pType.getParentType().getPackageName();
    }
    // handle cursors
    if (dType.isPLSQLCursorType()) {
        if (dType.isArgumentType()) {
            dType = ((ArgumentType) dType).getEnclosedType();
        }
        PLSQLCursorType pType = (PLSQLCursorType) dType;
        return new PLSQLCursor(pType.getParentType().getPackageName() + DOT + pType.getCursorName());
    }
    if (dType.isArgumentType()) {
        dType = ((ArgumentType) dType).getEnclosedType();
    } else if (dType.isTYPEType()) {
        dType = ((TYPEType) dType).getEnclosedType();
    }
    // composite types
    if (dType.isComposite()) {
        String typeName = dType.getTypeName();
        // for %ROWTYPE, the compatible JDBC type name cannot contain '%'
        String compatibleType = typeName.contains(PERCENT) ? typeName.replace(PERCENT, UNDERSCORE) : typeName;
        String javaTypeName = compatibleType.toLowerCase();
        // handle PL/SQL types
        if (dType.isPLSQLType()) {
            // for %ROWTYPE we don't want the catalog name prepended even if non-null
            if (catalog != null && !typeName.contains(ROWTYPE_STR)) {
                typeName = (catalog + DOT).concat(typeName);
                compatibleType = (catalog + UNDERSCORE).concat(compatibleType);
                javaTypeName = (catalog.toLowerCase() + DOT).concat(javaTypeName);
            }
            // handle PL/SQL record
            if (dType.isPLSQLRecordType()) {
                PLSQLrecord plsqlRec = new PLSQLrecord();
                plsqlRec.setTypeName(typeName);
                plsqlRec.setCompatibleType(compatibleType);
                plsqlRec.setJavaTypeName(javaTypeName);
                // process fields
                for (FieldType fld : ((PLSQLRecordType) dType).getFields()) {
                    if (fld.getEnclosedType().isPrecisionType()) {
                        PrecisionType precisionType = (PrecisionType) fld.getEnclosedType();
                        plsqlRec.addField(fld.getFieldName(), buildDatabaseTypeFromMetadataType(precisionType), (int) precisionType.getPrecision(), (int) precisionType.getScale());
                    } else if (fld.getEnclosedType().isSizedType()) {
                        SizedType sizedType = (SizedType) fld.getEnclosedType();
                        plsqlRec.addField(fld.getFieldName(), buildDatabaseTypeFromMetadataType(sizedType), (int) sizedType.getSize());
                    } else {
                        plsqlRec.addField(fld.getFieldName(), buildDatabaseTypeFromMetadataType(fld.getEnclosedType(), catalog));
                    }
                }
                return plsqlRec;
            }
            // assumes PL/SQL collection
            PLSQLCollection plsqlCollection = new PLSQLCollection();
            plsqlCollection.setTypeName(typeName);
            plsqlCollection.setCompatibleType(compatibleType);
            plsqlCollection.setJavaTypeName(javaTypeName + COLLECTION_WRAPPER_SUFFIX);
            plsqlCollection.setNestedType(buildDatabaseTypeFromMetadataType(((PLSQLCollectionType) dType).getEnclosedType(), catalog));
            return plsqlCollection;
        }
        // handle advanced Oracle types
        if (dType.isVArrayType()) {
            OracleArrayType varray = new OracleArrayType();
            varray.setTypeName(typeName);
            varray.setCompatibleType(compatibleType);
            varray.setJavaTypeName(getGeneratedWrapperClassName(javaTypeName, dbwsBuilder.getProjectName()));
            varray.setNestedType(buildDatabaseTypeFromMetadataType(((VArrayType) dType).getEnclosedType(), null));
            return varray;
        }
        if (dType.isObjectType()) {
            OracleObjectType objType = new OracleObjectType();
            objType.setTypeName(typeName);
            objType.setCompatibleType(compatibleType);
            objType.setJavaTypeName(getGeneratedJavaClassName(javaTypeName, dbwsBuilder.getProjectName()));
            objType.setJavaType(getWrapperClass(objType.getJavaTypeName()));
            Map<String, org.eclipse.persistence.internal.helper.DatabaseType> fields = objType.getFields();
            ObjectType oType = (ObjectType) dType;
            for (FieldType field : oType.getFields()) {
                fields.put(field.getFieldName(), buildDatabaseTypeFromMetadataType(field.getEnclosedType()));
            }
            return objType;
        }
        if (dType.isObjectTableType()) {
            OracleArrayType tableType = new OracleArrayType();
            tableType.setTypeName(typeName);
            tableType.setCompatibleType(compatibleType);
            tableType.setJavaTypeName(getGeneratedWrapperClassName(javaTypeName, dbwsBuilder.getProjectName()));
            org.eclipse.persistence.internal.helper.DatabaseType nestedType = buildDatabaseTypeFromMetadataType(((ObjectTableType) dType).getEnclosedType(), null);
            // need to set the Java Type on the nested type
            Class wrapper = getWrapperClass(nestedType);
            if (wrapper != null) {
                ((ComplexDatabaseType) nestedType).setJavaType(wrapper);
            }
            tableType.setNestedType(nestedType);
            return tableType;
        }
        return null;
    } else if (dType.isScalar()) {
        org.eclipse.persistence.internal.helper.DatabaseType theType = OraclePLSQLTypes.getDatabaseTypeForCode(dType.getTypeName());
        if (theType != null) {
            return theType;
        }
    }
    // scalar types
    return JDBCTypes.getDatabaseTypeForCode(org.eclipse.persistence.tools.dbws.Util.getJDBCTypeFromTypeName(dType.getTypeName()));
}
Also used : ScalarDatabaseType(org.eclipse.persistence.tools.oracleddl.metadata.ScalarDatabaseType) CompositeDatabaseType(org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType) ComplexDatabaseType(org.eclipse.persistence.internal.helper.ComplexDatabaseType) DatabaseType(org.eclipse.persistence.tools.oracleddl.metadata.DatabaseType) PLSQLCursorType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLCursorType) PrecisionType(org.eclipse.persistence.tools.oracleddl.metadata.PrecisionType) ObjectType(org.eclipse.persistence.tools.oracleddl.metadata.ObjectType) OracleObjectType(org.eclipse.persistence.platform.database.oracle.jdbc.OracleObjectType) VArrayType(org.eclipse.persistence.tools.oracleddl.metadata.VArrayType) OracleObjectType(org.eclipse.persistence.platform.database.oracle.jdbc.OracleObjectType) PLSQLrecord(org.eclipse.persistence.platform.database.oracle.plsql.PLSQLrecord) PLSQLCursor(org.eclipse.persistence.platform.database.oracle.plsql.PLSQLCursor) PLSQLRecordType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLRecordType) FieldType(org.eclipse.persistence.tools.oracleddl.metadata.FieldType) ComplexDatabaseType(org.eclipse.persistence.internal.helper.ComplexDatabaseType) ROWTYPEType(org.eclipse.persistence.tools.oracleddl.metadata.ROWTYPEType) TYPEType(org.eclipse.persistence.tools.oracleddl.metadata.TYPEType) PLSQLCollectionType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLCollectionType) PLSQLCollection(org.eclipse.persistence.platform.database.oracle.plsql.PLSQLCollection) SizedType(org.eclipse.persistence.tools.oracleddl.metadata.SizedType) PLSQLType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLType) OracleArrayType(org.eclipse.persistence.platform.database.oracle.jdbc.OracleArrayType)

Example 4 with SizedType

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

the class BaseDBWSBuilderHelper method buildORFieldMappingFromColumn.

protected DirectToFieldMapping buildORFieldMappingFromColumn(FieldType dbColumn, RelationalDescriptor desc, DatabasePlatform databasePlatform, NamingConventionTransformer nct) {
    String columnName = dbColumn.getFieldName();
    DatabaseType dataType = dbColumn.getEnclosedType();
    String typeName = getTypeNameForDatabaseType(dataType);
    int jdbcType = getJDBCTypeFromTypeName(typeName);
    String dmdTypeName = getJDBCTypeNameFromType(jdbcType);
    Class<?> attributeClass = null;
    if (CHAR_STR.equalsIgnoreCase(dmdTypeName) && dbColumn.getEnclosedType().isSizedType()) {
        SizedType sizedType = (SizedType) dbColumn.getEnclosedType();
        if (sizedType.getSize() == 1) {
            attributeClass = Character.class;
        } else {
            attributeClass = String.class;
        }
    } else {
        attributeClass = getClassFromJDBCType(dmdTypeName.toUpperCase(), databasePlatform);
    }
    // problem with java.sql.Timestamp conversion and Oracle11 platform
    if (attributeClass.getName().contains(TIMESTAMP_CLASS)) {
        attributeClass = java.sql.Timestamp.class;
    }
    DirectToFieldMapping dtfm = setUpDirectToFieldMapping(desc, columnName, nct, attributeClass, jdbcType, dbColumn.pk());
    return dtfm;
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) ScalarDatabaseType(org.eclipse.persistence.tools.oracleddl.metadata.ScalarDatabaseType) CompositeDatabaseType(org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType) ComplexDatabaseType(org.eclipse.persistence.internal.helper.ComplexDatabaseType) DatabaseType(org.eclipse.persistence.tools.oracleddl.metadata.DatabaseType) SizedType(org.eclipse.persistence.tools.oracleddl.metadata.SizedType)

Aggregations

SizedType (org.eclipse.persistence.tools.oracleddl.metadata.SizedType)4 ComplexDatabaseType (org.eclipse.persistence.internal.helper.ComplexDatabaseType)3 CompositeDatabaseType (org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType)3 DatabaseType (org.eclipse.persistence.tools.oracleddl.metadata.DatabaseType)3 ScalarDatabaseType (org.eclipse.persistence.tools.oracleddl.metadata.ScalarDatabaseType)3 QName (javax.xml.namespace.QName)1 DirectToFieldMapping (org.eclipse.persistence.mappings.DirectToFieldMapping)1 XMLDirectMapping (org.eclipse.persistence.oxm.mappings.XMLDirectMapping)1 OracleArrayType (org.eclipse.persistence.platform.database.oracle.jdbc.OracleArrayType)1 OracleObjectType (org.eclipse.persistence.platform.database.oracle.jdbc.OracleObjectType)1 PLSQLCollection (org.eclipse.persistence.platform.database.oracle.plsql.PLSQLCollection)1 PLSQLCursor (org.eclipse.persistence.platform.database.oracle.plsql.PLSQLCursor)1 PLSQLrecord (org.eclipse.persistence.platform.database.oracle.plsql.PLSQLrecord)1 FieldType (org.eclipse.persistence.tools.oracleddl.metadata.FieldType)1 ObjectType (org.eclipse.persistence.tools.oracleddl.metadata.ObjectType)1 PLSQLCollectionType (org.eclipse.persistence.tools.oracleddl.metadata.PLSQLCollectionType)1 PLSQLCursorType (org.eclipse.persistence.tools.oracleddl.metadata.PLSQLCursorType)1 PLSQLRecordType (org.eclipse.persistence.tools.oracleddl.metadata.PLSQLRecordType)1 PLSQLType (org.eclipse.persistence.tools.oracleddl.metadata.PLSQLType)1 PrecisionType (org.eclipse.persistence.tools.oracleddl.metadata.PrecisionType)1