Search in sources :

Example 6 with PLSQLType

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

the class XmlEntityMappingsGenerator method processPLSQLRecordType.

/**
 * Process the given PLSQLRecordType and return a PLSQLRecordMetadata instance.
 */
protected static ComplexTypeMetadata processPLSQLRecordType(PLSQLRecordType plsqlRecordType) {
    // for %ROWTYPE we create a 'place holder' PL/SQL Record - in this case there is no package name
    String packageName = plsqlRecordType.getParentType().getPackageName();
    String typeName = packageName != null ? plsqlRecordType.getParentType().getPackageName() + DOT + plsqlRecordType.getTypeName() : plsqlRecordType.getTypeName();
    String compatiableName = packageName != null ? plsqlRecordType.getParentType().getPackageName() + UNDERSCORE + plsqlRecordType.getTypeName() : plsqlRecordType.getTypeName();
    if (compatiableName.contains(PERCENT)) {
        compatiableName = compatiableName.replace(PERCENT, UNDERSCORE);
    }
    PLSQLRecordMetadata plsqlRecordMetadata = new PLSQLRecordMetadata();
    plsqlRecordMetadata.setName(typeName);
    plsqlRecordMetadata.setCompatibleType(compatiableName);
    if (typeName.endsWith(ROWTYPE_STR)) {
        plsqlRecordMetadata.setJavaType(compatiableName.toLowerCase());
    } else {
        plsqlRecordMetadata.setJavaType(typeName.toLowerCase());
    }
    List<PLSQLParameterMetadata> fields = new ArrayList<PLSQLParameterMetadata>();
    PLSQLParameterMetadata field;
    for (FieldType fld : plsqlRecordType.getFields()) {
        field = new PLSQLParameterMetadata();
        field.setName(fld.getFieldName());
        String pkg = null;
        if (fld.getEnclosedType() != null && fld.getEnclosedType().isPLSQLType()) {
            PLSQLType pType = (PLSQLType) fld.getEnclosedType();
            pkg = pType.getParentType().getPackageName();
        }
        String dbType = fld.getTypeName();
        if (!(getJDBCTypeFromTypeName(dbType) == Types.OTHER)) {
            // OR Metadata doesn't handle VARCHAR2
            if (dbType.equals(VARCHAR2_STR)) {
                dbType = VARCHAR_STR;
            }
            if (!dbType.equals(BOOLEAN_STR)) {
                dbType = dbType.concat(_TYPE_STR);
            }
        }
        dbType = pkg == null ? dbType : pkg + DOT + dbType;
        field.setDatabaseType(dbType);
        fields.add(field);
    }
    plsqlRecordMetadata.setFields(fields);
    return plsqlRecordMetadata;
}
Also used : 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)

Example 7 with PLSQLType

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

the class OracleHelper method buildResultForStoredFunction.

/**
 * Build and return a Result instance based on a given ProcedureType
 * and return type name.
 */
protected Result buildResultForStoredFunction(ArgumentType returnArgument, String returnType) {
    Result result = null;
    DatabaseType rargDataType = returnArgument.getEnclosedType();
    // handle ref cursor
    if (rargDataType.isPLSQLCursorType() || returnArgument.getTypeName().contains(CURSOR_STR)) {
        result = new CollectionResult();
        result.setType(SXF_QNAME_CURSOR);
    } else {
        result = new Result();
        int rargJdbcType = OTHER;
        if (rargDataType.isComposite()) {
            if (rargDataType.isObjectType()) {
                rargJdbcType = STRUCT;
            } else if (rargDataType.isVArrayType() || rargDataType.isObjectTableType()) {
                rargJdbcType = ARRAY;
            }
        } else {
            rargJdbcType = Util.getJDBCTypeFromTypeName(returnArgument.getTypeName());
        }
        switch(rargJdbcType) {
            case OTHER:
                String returnTypeName;
                // if user overrides returnType, assume they're right
                if (returnType != null && returnType.length() > 0) {
                    returnTypeName = returnType;
                } else {
                    returnType = rargDataType.getTypeName();
                    // packages only apply to PL/SQL types
                    String packageName = null;
                    if (rargDataType.isPLSQLType()) {
                        packageName = ((PLSQLType) rargDataType).getParentType().getPackageName();
                    }
                    // may need to prepend a package name
                    returnTypeName = (packageName != null && packageName.length() > 0) ? packageName + UNDERSCORE + returnType : returnType;
                    // may need to strip off %
                    returnTypeName = returnTypeName.contains(PERCENT) ? returnTypeName.replace(PERCENT, UNDERSCORE) : returnTypeName;
                    returnTypeName = nct.generateSchemaAlias(returnTypeName);
                }
                result.setType(buildCustomQName(returnTypeName, dbwsBuilder));
                break;
            case STRUCT:
            case ARRAY:
                // if user overrides returnType, assume they're right
                if (returnType == null || returnType.length() == 0) {
                    returnType = rargDataType.getTypeName().toLowerCase().concat(TYPE_STR);
                }
                result.setType(buildCustomQName(returnType, dbwsBuilder));
                break;
            default:
                // scalar types
                result.setType(getXMLTypeFromJDBCType(rargJdbcType));
                break;
        }
    }
    // for XMLType, we want the type code to be 'OPAQUE' (2007)
    if (rargDataType == ScalarDatabaseTypeEnum.XMLTYPE_TYPE) {
        result.setJdbcType(getJDBCTypeForTypeName(XMLTYPE_STR));
    }
    return result;
}
Also used : CollectionResult(org.eclipse.persistence.internal.xr.CollectionResult) 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) PLSQLType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLType) CollectionResult(org.eclipse.persistence.internal.xr.CollectionResult) Result(org.eclipse.persistence.internal.xr.Result)

Example 8 with PLSQLType

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

the class Util method getQualifiedCompatibleTypeName.

/**
 * Return a qualified compatible type name for the given DatabaseType. If the type is a
 * PLSQLType, and there is a package name available on the type's parent, a string will
 * be returned in the format 'package_typename'. Otherwise the type name will be
 * returned. A compatible type is the JDBC type equivalent of a PL/SQL type.
 */
public static String getQualifiedCompatibleTypeName(DatabaseType dbType) {
    String packageName = null;
    if (dbType.isPLSQLType()) {
        PLSQLType plsqlType = (PLSQLType) dbType;
        packageName = plsqlType.getParentType().getPackageName();
    }
    return packageName != null ? packageName + UNDERSCORE + dbType.getTypeName() : dbType.getTypeName();
}
Also used : PLSQLType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLType)

Example 9 with PLSQLType

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

Aggregations

PLSQLType (org.eclipse.persistence.tools.oracleddl.metadata.PLSQLType)9 CompositeDatabaseType (org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType)6 DatabaseType (org.eclipse.persistence.tools.oracleddl.metadata.DatabaseType)6 FieldType (org.eclipse.persistence.tools.oracleddl.metadata.FieldType)4 ComplexDatabaseType (org.eclipse.persistence.internal.helper.ComplexDatabaseType)3 ArrayList (java.util.ArrayList)2 PLSQLParameterMetadata (org.eclipse.persistence.internal.jpa.metadata.queries.PLSQLParameterMetadata)2 PLSQLRecordMetadata (org.eclipse.persistence.internal.jpa.metadata.queries.PLSQLRecordMetadata)2 PLSQLTableMetadata (org.eclipse.persistence.internal.jpa.metadata.queries.PLSQLTableMetadata)2 Util.getAttributeClassForDatabaseType (org.eclipse.persistence.tools.dbws.Util.getAttributeClassForDatabaseType)2 Util.getAttributeTypeNameForFieldType (org.eclipse.persistence.tools.metadata.generation.Util.getAttributeTypeNameForFieldType)2 ROWTYPEType (org.eclipse.persistence.tools.oracleddl.metadata.ROWTYPEType)2 TYPEType (org.eclipse.persistence.tools.oracleddl.metadata.TYPEType)2 HashSet (java.util.HashSet)1 BasicAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.BasicAccessor)1 EmbeddedAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.EmbeddedAccessor)1 ArrayAccessor (org.eclipse.persistence.internal.jpa.metadata.structures.ArrayAccessor)1 StructureAccessor (org.eclipse.persistence.internal.jpa.metadata.structures.StructureAccessor)1 CollectionResult (org.eclipse.persistence.internal.xr.CollectionResult)1 Result (org.eclipse.persistence.internal.xr.Result)1