Search in sources :

Example 1 with PLSQLType

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

the class OracleHelper method buildDbArtifacts.

@Override
public void buildDbArtifacts() {
    super.buildDbArtifacts();
    // list of all directly-referenced packages
    Set<PLSQLPackageType> directPackages = new HashSet<PLSQLPackageType>();
    for (ProcedureType procedureType : dbStoredProcedures) {
        for (ArgumentType argumentType : procedureType.getArguments()) {
            DatabaseType argumentDataType = argumentType.getEnclosedType();
            if (argumentDataType.isPLSQLType()) {
                PLSQLType plsqlType = (PLSQLType) argumentDataType;
                directPackages.add(plsqlType.getParentType());
            }
        }
    }
    // any indirectly-referenced packages?
    final Set<PLSQLPackageType> indirectPackages = new HashSet<PLSQLPackageType>();
    DatabaseTypeVisitor indirectVisitor = new BaseDatabaseTypeVisitor() {

        @Override
        public void beginVisit(PLSQLPackageType databaseType) {
            indirectPackages.add(databaseType);
        }
    };
    for (PLSQLPackageType pckage : directPackages) {
        pckage.accept(indirectVisitor);
    }
    Set<PLSQLPackageType> packages = new HashSet<PLSQLPackageType>();
    packages.addAll(directPackages);
    packages.addAll(indirectPackages);
    for (PLSQLPackageType pckage : packages) {
        ShadowDDLGenerator ddlGenerator = new ShadowDDLGenerator(pckage);
        dbwsBuilder.getTypeDDL().addAll(ddlGenerator.getAllCreateDDLs());
        dbwsBuilder.getTypeDropDDL().addAll(ddlGenerator.getAllDropDDLs());
    }
}
Also used : BaseDatabaseTypeVisitor(org.eclipse.persistence.tools.oracleddl.metadata.visit.BaseDatabaseTypeVisitor) ProcedureType(org.eclipse.persistence.tools.oracleddl.metadata.ProcedureType) PLSQLPackageType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLPackageType) 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) BaseDatabaseTypeVisitor(org.eclipse.persistence.tools.oracleddl.metadata.visit.BaseDatabaseTypeVisitor) DatabaseTypeVisitor(org.eclipse.persistence.tools.oracleddl.metadata.visit.DatabaseTypeVisitor) ArgumentType(org.eclipse.persistence.tools.oracleddl.metadata.ArgumentType) PLSQLType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLType) HashSet(java.util.HashSet)

Example 2 with PLSQLType

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

the class XmlEntityMappingsGenerator method processPLSQLCollectionType.

/**
 * Process the given PLSQLCollectionType and return a PLSQLTableMetadata instance.
 */
protected static ComplexTypeMetadata processPLSQLCollectionType(PLSQLCollectionType plsqlCollectionType) {
    String typeName = plsqlCollectionType.getParentType().getPackageName() + DOT + plsqlCollectionType.getTypeName();
    String compatiableName = plsqlCollectionType.getParentType().getPackageName() + UNDERSCORE + plsqlCollectionType.getTypeName();
    PLSQLTableMetadata plsqlTable = new PLSQLTableMetadata();
    plsqlTable.setName(typeName);
    plsqlTable.setCompatibleType(compatiableName);
    // handle Nested Table (i.e. non-Varray)
    plsqlTable.setNestedTable(!plsqlCollectionType.isIndexed());
    String dbType = plsqlCollectionType.getEnclosedType().getTypeName();
    if (!(getJDBCTypeFromTypeName(dbType) == Types.OTHER)) {
        // need special handling for nested PL/SQL scalar types
        if (isArgPLSQLScalar(dbType)) {
            plsqlTable.setNestedType(getOraclePLSQLTypeForName(dbType));
        } else {
            // OR Metadata doesn't handle VARCHAR2
            if (dbType.equals(VARCHAR2_STR)) {
                dbType = VARCHAR_STR;
            }
            plsqlTable.setNestedType(dbType + _TYPE_STR);
        }
    } else {
        // may need to prepend package name
        String pkg = null;
        if (plsqlCollectionType.getEnclosedType() != null && plsqlCollectionType.getEnclosedType().isPLSQLType()) {
            PLSQLType pType = (PLSQLType) plsqlCollectionType.getEnclosedType();
            pkg = pType.getParentType().getPackageName();
        }
        plsqlTable.setNestedType(pkg == null ? dbType : pkg + DOT + dbType);
    }
    plsqlTable.setJavaType(typeName.toLowerCase() + COLLECTION_WRAPPER_SUFFIX);
    return plsqlTable;
}
Also used : PLSQLTableMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.PLSQLTableMetadata) PLSQLType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLType)

Example 3 with PLSQLType

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

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

the class JPAMetadataGenerator method processPLSQLCollectionType.

/**
 * Process the given PLSQLCollectionType and return a PLSQLTableMetadata instance.
 */
protected PLSQLTableMetadata processPLSQLCollectionType(PLSQLCollectionType plsqlCollectionType) {
    String typeName = getQualifiedTypeName(plsqlCollectionType);
    String compatiableName = getQualifiedCompatibleTypeName(plsqlCollectionType);
    String targetClassName = compatiableName;
    PLSQLTableMetadata plsqlTable = new PLSQLTableMetadata();
    plsqlTable.setName(typeName);
    plsqlTable.setCompatibleType(compatiableName);
    plsqlTable.setJavaType(getGeneratedJavaClassName(typeName));
    // handle Nested Table (i.e. non-Varray)
    plsqlTable.setNestedTable(!plsqlCollectionType.isIndexed());
    String dbType = plsqlCollectionType.getEnclosedType().getTypeName();
    if (!(getJDBCTypeFromTypeName(dbType) == Types.OTHER)) {
        // need special handling for nested PL/SQL scalar types
        if (isArgPLSQLScalar(dbType)) {
            plsqlTable.setNestedType(getOraclePLSQLTypeForName(dbType));
        } else {
            plsqlTable.setNestedType(processTypeName(dbType));
        }
    } else {
        if (plsqlCollectionType.isComposite()) {
            DatabaseType enclosedType = plsqlCollectionType.getEnclosedType();
            // may need to prepend package name
            if (enclosedType.isPLSQLType()) {
                dbType = ((PLSQLType) enclosedType).getParentType().getPackageName() + DOT + dbType;
                targetClassName = getGeneratedJavaClassName(dbType);
            } else {
                // advanced JDBC
                targetClassName = getGeneratedJavaClassName(dbType, defaultPackage);
            }
            processCompositeType(enclosedType, dbType);
        }
        plsqlTable.setNestedType(dbType);
    }
    // avoid double-processing
    getProcessedTypes().add(plsqlTable.getName());
    // generate an EmbeddableAccessor for this type
    generateEmbeddable(plsqlTable, targetClassName);
    return plsqlTable;
}
Also used : CompositeDatabaseType(org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType) DatabaseType(org.eclipse.persistence.tools.oracleddl.metadata.DatabaseType) PLSQLTableMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.PLSQLTableMetadata) PLSQLType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLType)

Example 5 with PLSQLType

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

the class JPAMetadataGenerator method processPLSQLRecordType.

/**
 * Process the given PLSQLRecordType and return a PLSQLRecordMetadata instance.
 */
protected PLSQLRecordMetadata processPLSQLRecordType(PLSQLRecordType plsqlRecordType) {
    // for %ROWTYPE we create a 'place holder' PL/SQL Record - in this case there is no package name
    String typeName = getQualifiedTypeName(plsqlRecordType);
    String compatibleName = getQualifiedCompatibleTypeName(plsqlRecordType);
    if (compatibleName.contains(PERCENT)) {
        compatibleName = compatibleName.replace(PERCENT, UNDERSCORE);
    }
    PLSQLRecordMetadata plsqlRecord = new PLSQLRecordMetadata();
    plsqlRecord.setName(typeName);
    plsqlRecord.setCompatibleType(compatibleName);
    if (typeName.endsWith(ROWTYPE_STR)) {
        plsqlRecord.setJavaType(getGeneratedJavaClassName(compatibleName));
    } else {
        plsqlRecord.setJavaType(getGeneratedJavaClassName(typeName));
    }
    List<PLSQLParameterMetadata> fields = new ArrayList<PLSQLParameterMetadata>();
    PLSQLParameterMetadata field;
    for (FieldType fld : plsqlRecordType.getFields()) {
        field = new PLSQLParameterMetadata();
        field.setName(fld.getFieldName());
        String dbType = processTypeName(fld.getTypeName());
        if (fld.isComposite()) {
            DatabaseType enclosedType = fld.getEnclosedType();
            // may need to prepend package name
            if (enclosedType.isPLSQLType()) {
                dbType = ((PLSQLType) fld.getEnclosedType()).getParentType().getPackageName() + DOT + dbType;
            }
            processCompositeType(enclosedType, dbType);
        }
        field.setDatabaseType(dbType);
        fields.add(field);
    }
    plsqlRecord.setFields(fields);
    // avoid double-processing
    getProcessedTypes().add(plsqlRecord.getName());
    // generate an EmbeddableAccessor for this type
    generateEmbeddable(plsqlRecord, plsqlRecordType);
    return plsqlRecord;
}
Also used : CompositeDatabaseType(org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType) DatabaseType(org.eclipse.persistence.tools.oracleddl.metadata.DatabaseType) 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) Util.getAttributeTypeNameForFieldType(org.eclipse.persistence.tools.metadata.generation.Util.getAttributeTypeNameForFieldType)

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