Search in sources :

Example 1 with PLSQLTableMetadata

use of org.eclipse.persistence.internal.jpa.metadata.queries.PLSQLTableMetadata in project eclipselink by eclipse-ee4j.

the class ClassAccessor method processComplexMetadataTypes.

/**
 * Process PL/SQL record and table types, Oracle object array and XMLType types.
 */
public void processComplexMetadataTypes() {
    // Process the XML first.
    for (PLSQLRecordMetadata record : m_plsqlRecords) {
        getProject().addComplexMetadataType(record);
    }
    // Process the annotations.
    MetadataAnnotation records = getAnnotation(PLSQLRecords.class);
    if (records != null) {
        for (Object record : records.getAttributeArray("value")) {
            getProject().addComplexMetadataType(new PLSQLRecordMetadata((MetadataAnnotation) record, this));
        }
    }
    MetadataAnnotation record = getAnnotation(PLSQLRecord.class);
    if (record != null) {
        getProject().addComplexMetadataType(new PLSQLRecordMetadata(record, this));
    }
    // Process the XML first.
    for (PLSQLTableMetadata table : m_plsqlTables) {
        getProject().addComplexMetadataType(table);
    }
    // Process the annotations.
    MetadataAnnotation tables = getAnnotation(PLSQLTables.class);
    if (tables != null) {
        for (Object table : tables.getAttributeArray("value")) {
            getProject().addComplexMetadataType(new PLSQLTableMetadata((MetadataAnnotation) table, this));
        }
    }
    MetadataAnnotation table = getAnnotation(PLSQLTable.class);
    if (table != null) {
        getProject().addComplexMetadataType(new PLSQLTableMetadata(table, this));
    }
    // Process XML.
    for (OracleObjectTypeMetadata objectType : m_oracleObjectTypes) {
        getProject().addComplexMetadataType(objectType);
    }
    // Process the annotations.
    MetadataAnnotation objectTypes = getAnnotation(OracleObjects.class);
    if (objectTypes != null) {
        for (Object objectType : objectTypes.getAttributeArray("value")) {
            getProject().addComplexMetadataType(new OracleObjectTypeMetadata((MetadataAnnotation) objectType, this));
        }
    }
    MetadataAnnotation objectType = getAnnotation(OracleObject.class);
    if (objectType != null) {
        getProject().addComplexMetadataType(new OracleObjectTypeMetadata(objectType, this));
    }
    // Process XML.
    for (OracleArrayTypeMetadata arrayType : m_oracleArrayTypes) {
        getProject().addComplexMetadataType(arrayType);
    }
    // Process the annotations.
    MetadataAnnotation arrayTypes = getAnnotation(OracleArrays.class);
    if (arrayTypes != null) {
        for (Object arrayType : arrayTypes.getAttributeArray("value")) {
            getProject().addComplexMetadataType(new OracleArrayTypeMetadata((MetadataAnnotation) arrayType, this));
        }
    }
    MetadataAnnotation arrayType = getAnnotation(OracleArray.class);
    if (arrayType != null) {
        getProject().addComplexMetadataType(new OracleArrayTypeMetadata(arrayType, this));
    }
}
Also used : OracleArrayTypeMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.OracleArrayTypeMetadata) OracleObjectTypeMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.OracleObjectTypeMetadata) PLSQLRecordMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.PLSQLRecordMetadata) MetadataAccessibleObject(org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataAccessibleObject) OracleObject(org.eclipse.persistence.platform.database.oracle.annotations.OracleObject) PLSQLTableMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.PLSQLTableMetadata) MetadataAnnotation(org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataAnnotation)

Example 2 with PLSQLTableMetadata

use of org.eclipse.persistence.internal.jpa.metadata.queries.PLSQLTableMetadata in project eclipselink by eclipse-ee4j.

the class XMLEntityMappings method process.

/**
 * INTERNAL:
 * Process the metadata from the <entity-mappings> level except for the
 * classes themselves. They will be processed afterwards and controlled
 * by the MetadataProcessor. Note: this method does a few things of
 * interest. It not only adds metadata to the project but it will also
 * override (that is EclipseLink-ORM-XML-->JPA-XML {@literal &&} JPA-XML-->Annotation)
 * the necessary metadata and log messages to the user. A validation
 * exception could also be thrown. See the related processing methods for
 * more details.
 *
 * Any XML metadata of the types processed below should call these methods.
 * That is, as an example, a converter can be found at the entity-mappings
 * and entity level. Therefore you must ensure that those from levels other
 * than the entity-mappings call these methods as well to ensure consistent
 * metadata processing (and behavior).
 */
public void process() {
    // Add the XML converters to the project.
    for (ConverterMetadata converter : m_converters) {
        converter.initXMLObject(m_file, this);
        m_project.addConverter(converter);
    }
    // Add the XML type converters to the project.
    for (TypeConverterMetadata typeConverter : m_typeConverters) {
        typeConverter.initXMLObject(m_file, this);
        m_project.addConverter(typeConverter);
    }
    // Add the XML object type converters to the project.
    for (ObjectTypeConverterMetadata objectTypeConverter : m_objectTypeConverters) {
        objectTypeConverter.initXMLObject(m_file, this);
        m_project.addConverter(objectTypeConverter);
    }
    // Add the XML serialized converters to the project.
    for (SerializedConverterMetadata serializedConverter : m_serializedConverters) {
        serializedConverter.initXMLObject(m_file, this);
        m_project.addConverter(serializedConverter);
    }
    // Add the XML struct converters to the project.
    for (StructConverterMetadata structConverter : m_structConverters) {
        structConverter.initXMLObject(m_file, this);
        m_project.addConverter(structConverter);
    }
    // Add the XML table generators to the project.
    for (TableGeneratorMetadata tableGenerator : m_tableGenerators) {
        tableGenerator.initXMLObject(m_file, this);
        m_project.addTableGenerator(tableGenerator, getDefaultCatalog(), getDefaultSchema());
    }
    // Add the XML sequence generators to the project.
    for (SequenceGeneratorMetadata sequenceGenerator : m_sequenceGenerators) {
        sequenceGenerator.initXMLObject(m_file, this);
        m_project.addSequenceGenerator(sequenceGenerator, getDefaultCatalog(), getDefaultSchema());
    }
    // Add the XML uuid generators to the project.
    for (UuidGeneratorMetadata uuidGenerator : m_uuidGenerators) {
        uuidGenerator.initXMLObject(m_file, this);
        m_project.addUuidGenerator(uuidGenerator);
    }
    // Add the partitioning to the project.
    for (PartitioningMetadata partitioning : m_partitioning) {
        partitioning.initXMLObject(m_file, this);
        m_project.addPartitioningPolicy(partitioning);
    }
    // Add the replication partitioning to the project.
    for (ReplicationPartitioningMetadata partitioning : m_replicationPartitioning) {
        partitioning.initXMLObject(m_file, this);
        m_project.addPartitioningPolicy(partitioning);
    }
    // Add the round robin partitioning to the project.
    for (RoundRobinPartitioningMetadata partitioning : m_roundRobinPartitioning) {
        partitioning.initXMLObject(m_file, this);
        m_project.addPartitioningPolicy(partitioning);
    }
    // Add the pinned partitioning to the project.
    for (PinnedPartitioningMetadata partitioning : m_pinnedPartitioning) {
        partitioning.initXMLObject(m_file, this);
        m_project.addPartitioningPolicy(partitioning);
    }
    // Add the range partitioning to the project.
    for (RangePartitioningMetadata partitioning : m_rangePartitioning) {
        partitioning.initXMLObject(m_file, this);
        m_project.addPartitioningPolicy(partitioning);
    }
    // Add the value partitioning to the project.
    for (ValuePartitioningMetadata partitioning : m_valuePartitioning) {
        partitioning.initXMLObject(m_file, this);
        m_project.addPartitioningPolicy(partitioning);
    }
    // Add the hash partitioning to the project.
    for (HashPartitioningMetadata partitioning : m_hashPartitioning) {
        partitioning.initXMLObject(m_file, this);
        m_project.addPartitioningPolicy(partitioning);
    }
    // Add the XML named queries to the project.
    for (NamedQueryMetadata namedQuery : m_namedQueries) {
        namedQuery.initXMLObject(m_file, this);
        m_project.addQuery(namedQuery);
    }
    // Add the XML named native queries to the project.
    for (NamedNativeQueryMetadata namedNativeQuery : m_namedNativeQueries) {
        namedNativeQuery.initXMLObject(m_file, this);
        m_project.addQuery(namedNativeQuery);
    }
    // Add the XML named stored procedure queries to the project.
    for (NamedStoredProcedureQueryMetadata namedStoredProcedureQuery : m_namedStoredProcedureQueries) {
        namedStoredProcedureQuery.initXMLObject(m_file, this);
        m_project.addQuery(namedStoredProcedureQuery);
    }
    // Add the XML named stored function queries to the project.
    for (NamedStoredFunctionQueryMetadata namedStoredFunctionQuery : m_namedStoredFunctionQueries) {
        namedStoredFunctionQuery.initXMLObject(m_file, this);
        m_project.addQuery(namedStoredFunctionQuery);
    }
    // Add the XML named stored procedure queries to the project.
    for (NamedPLSQLStoredProcedureQueryMetadata namedPLSQLStoredProcedureQuery : m_namedPLSQLStoredProcedureQueries) {
        namedPLSQLStoredProcedureQuery.initXMLObject(m_file, this);
        m_project.addQuery(namedPLSQLStoredProcedureQuery);
    }
    // Add the XML named stored function queries to the project.
    for (NamedPLSQLStoredFunctionQueryMetadata namedPLSQLStoredFunctionQuery : m_namedPLSQLStoredFunctionQueries) {
        namedPLSQLStoredFunctionQuery.initXMLObject(m_file, this);
        m_project.addQuery(namedPLSQLStoredFunctionQuery);
    }
    // Add the XML sql result set mappings to the project.
    for (SQLResultSetMappingMetadata sqlResultSetMapping : m_sqlResultSetMappings) {
        sqlResultSetMapping.initXMLObject(m_file, this);
        m_project.addSQLResultSetMapping(sqlResultSetMapping);
    }
    // Add the Oracle object types to the project.
    for (OracleObjectTypeMetadata oType : m_oracleObjectTypes) {
        oType.initXMLObject(m_file, this);
        m_project.addComplexMetadataType(oType);
    }
    // Add the Oracle array types to the project.
    for (OracleArrayTypeMetadata aType : m_oracleArrayTypes) {
        aType.initXMLObject(m_file, this);
        m_project.addComplexMetadataType(aType);
    }
    // Add the PLSQL types to the project.
    for (PLSQLRecordMetadata record : m_plsqlRecords) {
        record.initXMLObject(m_file, this);
        m_project.addComplexMetadataType(record);
    }
    // Add the PLSQL tables to the project.
    for (PLSQLTableMetadata table : m_plsqlTables) {
        table.initXMLObject(m_file, this);
        m_project.addComplexMetadataType(table);
    }
}
Also used : NamedStoredFunctionQueryMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.NamedStoredFunctionQueryMetadata) RoundRobinPartitioningMetadata(org.eclipse.persistence.internal.jpa.metadata.partitioning.RoundRobinPartitioningMetadata) PLSQLRecordMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.PLSQLRecordMetadata) PinnedPartitioningMetadata(org.eclipse.persistence.internal.jpa.metadata.partitioning.PinnedPartitioningMetadata) TypeConverterMetadata(org.eclipse.persistence.internal.jpa.metadata.converters.TypeConverterMetadata) ObjectTypeConverterMetadata(org.eclipse.persistence.internal.jpa.metadata.converters.ObjectTypeConverterMetadata) ReplicationPartitioningMetadata(org.eclipse.persistence.internal.jpa.metadata.partitioning.ReplicationPartitioningMetadata) TableGeneratorMetadata(org.eclipse.persistence.internal.jpa.metadata.sequencing.TableGeneratorMetadata) HashPartitioningMetadata(org.eclipse.persistence.internal.jpa.metadata.partitioning.HashPartitioningMetadata) OracleArrayTypeMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.OracleArrayTypeMetadata) StructConverterMetadata(org.eclipse.persistence.internal.jpa.metadata.converters.StructConverterMetadata) RangePartitioningMetadata(org.eclipse.persistence.internal.jpa.metadata.partitioning.RangePartitioningMetadata) NamedStoredProcedureQueryMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.NamedStoredProcedureQueryMetadata) NamedQueryMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.NamedQueryMetadata) StructConverterMetadata(org.eclipse.persistence.internal.jpa.metadata.converters.StructConverterMetadata) SerializedConverterMetadata(org.eclipse.persistence.internal.jpa.metadata.converters.SerializedConverterMetadata) TypeConverterMetadata(org.eclipse.persistence.internal.jpa.metadata.converters.TypeConverterMetadata) ConverterMetadata(org.eclipse.persistence.internal.jpa.metadata.converters.ConverterMetadata) MixedConverterMetadata(org.eclipse.persistence.internal.jpa.metadata.converters.MixedConverterMetadata) ObjectTypeConverterMetadata(org.eclipse.persistence.internal.jpa.metadata.converters.ObjectTypeConverterMetadata) SequenceGeneratorMetadata(org.eclipse.persistence.internal.jpa.metadata.sequencing.SequenceGeneratorMetadata) OracleObjectTypeMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.OracleObjectTypeMetadata) UuidGeneratorMetadata(org.eclipse.persistence.internal.jpa.metadata.sequencing.UuidGeneratorMetadata) SQLResultSetMappingMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.SQLResultSetMappingMetadata) ObjectTypeConverterMetadata(org.eclipse.persistence.internal.jpa.metadata.converters.ObjectTypeConverterMetadata) ValuePartitioningMetadata(org.eclipse.persistence.internal.jpa.metadata.partitioning.ValuePartitioningMetadata) SerializedConverterMetadata(org.eclipse.persistence.internal.jpa.metadata.converters.SerializedConverterMetadata) PLSQLTableMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.PLSQLTableMetadata) NamedPLSQLStoredProcedureQueryMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.NamedPLSQLStoredProcedureQueryMetadata) NamedNativeQueryMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.NamedNativeQueryMetadata) PartitioningMetadata(org.eclipse.persistence.internal.jpa.metadata.partitioning.PartitioningMetadata) UnionPartitioningMetadata(org.eclipse.persistence.internal.jpa.metadata.partitioning.UnionPartitioningMetadata) ReplicationPartitioningMetadata(org.eclipse.persistence.internal.jpa.metadata.partitioning.ReplicationPartitioningMetadata) RoundRobinPartitioningMetadata(org.eclipse.persistence.internal.jpa.metadata.partitioning.RoundRobinPartitioningMetadata) HashPartitioningMetadata(org.eclipse.persistence.internal.jpa.metadata.partitioning.HashPartitioningMetadata) RangePartitioningMetadata(org.eclipse.persistence.internal.jpa.metadata.partitioning.RangePartitioningMetadata) ValuePartitioningMetadata(org.eclipse.persistence.internal.jpa.metadata.partitioning.ValuePartitioningMetadata) PinnedPartitioningMetadata(org.eclipse.persistence.internal.jpa.metadata.partitioning.PinnedPartitioningMetadata) NamedPLSQLStoredFunctionQueryMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.NamedPLSQLStoredFunctionQueryMetadata)

Example 3 with PLSQLTableMetadata

use of org.eclipse.persistence.internal.jpa.metadata.queries.PLSQLTableMetadata 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 4 with PLSQLTableMetadata

use of org.eclipse.persistence.internal.jpa.metadata.queries.PLSQLTableMetadata in project eclipselink by eclipse-ee4j.

the class XmlEntityMappingsGenerator method generateXmlEntityMappings.

/**
 * Generate an XMLEntityMappings instance based on a given OR Project's Queries and Descriptors.
 *
 * @param orProject the ORM Project instance containing Queries and Descriptors to be used to generate an XMLEntityMappings
 * @param complexTypes list of composite database types used to generate metadata for advanced Oracle and PL/SQL types
 * @param crudOperations map of maps keyed on table name - the second map are operation name to SQL string entries
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static XMLEntityMappings generateXmlEntityMappings(Project orProject, List<CompositeDatabaseType> complexTypes, Map<String, Map<String, String>> crudOperations) {
    List<ClassDescriptor> descriptors = orProject.getOrderedDescriptors();
    List<DatabaseQuery> queries = orProject.getQueries();
    XMLEntityMappings xmlEntityMappings = new XMLEntityMappings();
    xmlEntityMappings.setEmbeddables(new ArrayList<EmbeddableAccessor>());
    xmlEntityMappings.setEntities(new ArrayList<EntityAccessor>());
    xmlEntityMappings.setPLSQLRecords(new ArrayList<PLSQLRecordMetadata>());
    xmlEntityMappings.setPLSQLTables(new ArrayList<PLSQLTableMetadata>());
    xmlEntityMappings.setOracleObjectTypes(new ArrayList<OracleObjectTypeMetadata>());
    xmlEntityMappings.setOracleArrayTypes(new ArrayList<OracleArrayTypeMetadata>());
    // process PL/SQL records and collections, and Oracle advanced JDBC types
    List<PLSQLRecordMetadata> plsqlRecords = null;
    List<PLSQLTableMetadata> plsqlTables = null;
    List<OracleObjectTypeMetadata> objectTypes = null;
    List<OracleArrayTypeMetadata> arrayTypes = null;
    // generate metadata for each of the composite types
    List<ComplexTypeMetadata> complexTypeMetadata = processCompositeTypes(complexTypes, orProject);
    for (ComplexTypeMetadata cTypeMetadata : complexTypeMetadata) {
        if (cTypeMetadata.isOracleComplexTypeMetadata()) {
            OracleComplexTypeMetadata octMetadata = (OracleComplexTypeMetadata) cTypeMetadata;
            if (octMetadata.isOracleArrayTypeMetadata()) {
                if (arrayTypes == null) {
                    arrayTypes = new ArrayList<OracleArrayTypeMetadata>();
                }
                arrayTypes.add((OracleArrayTypeMetadata) octMetadata);
            } else {
                // assumes OracleObjectTypeMetadata
                if (objectTypes == null) {
                    objectTypes = new ArrayList<OracleObjectTypeMetadata>();
                }
                objectTypes.add((OracleObjectTypeMetadata) octMetadata);
            }
        } else {
            // assumes PL/SQL complex type metadata
            PLSQLComplexTypeMetadata plsqlctMetadata = (PLSQLComplexTypeMetadata) cTypeMetadata;
            if (plsqlctMetadata.isPLSQLRecordMetadata()) {
                if (plsqlRecords == null) {
                    plsqlRecords = new ArrayList<PLSQLRecordMetadata>();
                }
                plsqlRecords.add((PLSQLRecordMetadata) plsqlctMetadata);
            } else {
                // assumes PLSQLTableMetadata
                if (plsqlTables == null) {
                    plsqlTables = new ArrayList<PLSQLTableMetadata>();
                }
                plsqlTables.add((PLSQLTableMetadata) plsqlctMetadata);
            }
        }
    }
    // add generated metadata
    xmlEntityMappings.setPLSQLRecords(plsqlRecords);
    xmlEntityMappings.setPLSQLTables(plsqlTables);
    xmlEntityMappings.setOracleObjectTypes(objectTypes);
    xmlEntityMappings.setOracleArrayTypes(arrayTypes);
    // process stored procedures/functions
    List<NamedPLSQLStoredProcedureQueryMetadata> plsqlStoredProcs = null;
    List<NamedPLSQLStoredFunctionQueryMetadata> plsqlStoredFuncs = null;
    List<NamedStoredProcedureQueryMetadata> storedProcs = null;
    List<NamedStoredFunctionQueryMetadata> storedFuncs = null;
    List<NamedNativeQueryMetadata> namedNativeQueries = null;
    // process database queries set on the descriptor
    for (DatabaseQuery query : queries) {
        if (query.getCall().isStoredFunctionCall()) {
            if (query.getCall() instanceof PLSQLStoredFunctionCall) {
                PLSQLStoredFunctionCall call = (PLSQLStoredFunctionCall) query.getCall();
                NamedPLSQLStoredFunctionQueryMetadata metadata = new NamedPLSQLStoredFunctionQueryMetadata();
                metadata.setName(query.getName());
                metadata.setProcedureName(call.getProcedureName());
                List<PLSQLParameterMetadata> params = new ArrayList<PLSQLParameterMetadata>();
                if (plsqlStoredFuncs == null) {
                    plsqlStoredFuncs = new ArrayList<NamedPLSQLStoredFunctionQueryMetadata>();
                }
                PLSQLargument arg;
                PLSQLParameterMetadata param;
                List<PLSQLargument> types = call.getArguments();
                for (int i = 0; i < types.size(); i++) {
                    arg = types.get(i);
                    param = new PLSQLParameterMetadata();
                    param.setName(arg.name);
                    String dbType = arg.databaseType.getTypeName();
                    if (arg.databaseType == XMLType) {
                        dbType = XMLType.name();
                    } else if (arg.databaseType == PLSQLBoolean) {
                        dbType = PLSQLBoolean.name();
                    } else {
                        if (!(getJDBCTypeFromTypeName(dbType) == Types.OTHER)) {
                            dbType = dbType.concat(_TYPE_STR);
                        }
                    }
                    param.setDatabaseType(dbType);
                    if (i == 0) {
                        // first arg is the return arg
                        metadata.setReturnParameter(param);
                        if (arg.cursorOutput) {
                            param.setDirection(CURSOR_STR);
                        }
                    } else {
                        param.setDirection(getDirectionAsString(arg.direction));
                        params.add(param);
                    }
                }
                if (params.size() > 0) {
                    metadata.setParameters(params);
                }
                plsqlStoredFuncs.add(metadata);
            } else {
                StoredFunctionCall call = (StoredFunctionCall) query.getCall();
                NamedStoredFunctionQueryMetadata metadata = new NamedStoredFunctionQueryMetadata();
                metadata.setName(query.getName());
                metadata.setProcedureName(call.getProcedureName());
                List<StoredProcedureParameterMetadata> params = new ArrayList<StoredProcedureParameterMetadata>();
                if (storedFuncs == null) {
                    storedFuncs = new ArrayList<NamedStoredFunctionQueryMetadata>();
                }
                DatabaseField arg;
                StoredProcedureParameterMetadata param;
                List<DatabaseField> paramFields = call.getParameters();
                List<Integer> types = call.getParameterTypes();
                for (int i = 0; i < paramFields.size(); i++) {
                    arg = paramFields.get(i);
                    param = new StoredProcedureParameterMetadata();
                    param.setTypeName(arg.getTypeName());
                    if (arg.getSqlType() != DatabaseField.NULL_SQL_TYPE) {
                        param.setJdbcType(arg.getSqlType());
                    }
                    if (arg.isObjectRelationalDatabaseField()) {
                        param.setJdbcTypeName(((ObjectRelationalDatabaseField) arg).getSqlTypeName());
                    }
                    if (i == 0) {
                        // first arg is the return arg
                        metadata.setReturnParameter(param);
                        // handle CURSOR types - want name/value pairs returned
                        if (types.get(i) == 8) {
                            addQueryHint(metadata);
                        }
                    } else {
                        param.setName(arg.getName());
                        param.setMode(getParameterModeAsString(types.get(i)));
                        params.add(param);
                    }
                }
                if (params.size() > 0) {
                    metadata.setParameters(params);
                }
                storedFuncs.add(metadata);
            }
        } else if (query.getCall().isStoredProcedureCall()) {
            if (query.getCall() instanceof PLSQLStoredProcedureCall) {
                PLSQLStoredProcedureCall call = (PLSQLStoredProcedureCall) query.getCall();
                if (plsqlStoredProcs == null) {
                    plsqlStoredProcs = new ArrayList<NamedPLSQLStoredProcedureQueryMetadata>();
                }
                NamedPLSQLStoredProcedureQueryMetadata metadata = new NamedPLSQLStoredProcedureQueryMetadata();
                metadata.setName(query.getName());
                metadata.setProcedureName(call.getProcedureName());
                PLSQLParameterMetadata param;
                List<PLSQLParameterMetadata> params = new ArrayList<PLSQLParameterMetadata>();
                List<PLSQLargument> types = call.getArguments();
                for (PLSQLargument arg : types) {
                    param = new PLSQLParameterMetadata();
                    param.setName(arg.name);
                    String dbType = processTypeName(arg.databaseType.getTypeName());
                    if (arg.cursorOutput) {
                        param.setDirection(CURSOR_STR);
                    } else {
                        param.setDirection(getDirectionAsString(arg.direction));
                    }
                    if (arg.databaseType == XMLType) {
                        param.setDatabaseType(XMLType.name());
                    } else if (arg.databaseType == PLSQLBoolean) {
                        param.setDatabaseType(PLSQLBoolean.name());
                    } else {
                        param.setDatabaseType(dbType);
                    }
                    params.add(param);
                }
                if (params.size() > 0) {
                    metadata.setParameters(params);
                }
                plsqlStoredProcs.add(metadata);
            } else {
                StoredProcedureCall call = (StoredProcedureCall) query.getCall();
                NamedStoredProcedureQueryMetadata metadata = new NamedStoredProcedureQueryMetadata();
                metadata.setName(query.getName());
                metadata.setProcedureName(call.getProcedureName());
                metadata.setReturnsResultSet(false);
                List<StoredProcedureParameterMetadata> params = new ArrayList<StoredProcedureParameterMetadata>();
                DatabaseField arg;
                StoredProcedureParameterMetadata param;
                List paramFields = call.getParameters();
                List<Integer> types = call.getParameterTypes();
                for (int i = 0; i < paramFields.size(); i++) {
                    if (types.get(i) == DatabaseCall.INOUT) {
                        // for INOUT we get Object[IN, OUT]
                        arg = (DatabaseField) ((Object[]) paramFields.get(i))[1];
                    } else {
                        arg = (DatabaseField) paramFields.get(i);
                    }
                    param = new StoredProcedureParameterMetadata();
                    param.setName(arg.getName());
                    param.setTypeName(arg.getTypeName());
                    if (arg.getSqlType() != DatabaseField.NULL_SQL_TYPE) {
                        param.setJdbcType(arg.getSqlType());
                    }
                    if (arg.isObjectRelationalDatabaseField()) {
                        param.setJdbcTypeName(((ObjectRelationalDatabaseField) arg).getSqlTypeName());
                    }
                    param.setMode(getParameterModeAsString(types.get(i)));
                    // handle CURSOR types - want name/value pairs returned
                    if (types.get(i) == 8) {
                        addQueryHint(metadata);
                    }
                    params.add(param);
                }
                if (params.size() > 0) {
                    metadata.setParameters(params);
                }
                if (storedProcs == null) {
                    storedProcs = new ArrayList<NamedStoredProcedureQueryMetadata>();
                }
                storedProcs.add(metadata);
            }
        } else {
            // named native query
            NamedNativeQueryMetadata namedQuery = new NamedNativeQueryMetadata();
            namedQuery.setName(query.getName());
            namedQuery.setQuery(query.getSQLString());
            namedQuery.setResultClassName(query.getReferenceClassName());
            if (namedNativeQueries == null) {
                namedNativeQueries = new ArrayList<NamedNativeQueryMetadata>();
            }
            namedNativeQueries.add(namedQuery);
        }
    }
    // add generated metadata
    if (plsqlStoredProcs != null) {
        xmlEntityMappings.setNamedPLSQLStoredProcedureQueries(plsqlStoredProcs);
    }
    if (plsqlStoredFuncs != null) {
        xmlEntityMappings.setNamedPLSQLStoredFunctionQueries(plsqlStoredFuncs);
    }
    if (storedProcs != null) {
        xmlEntityMappings.setNamedStoredProcedureQueries(storedProcs);
    }
    if (storedFuncs != null) {
        xmlEntityMappings.setNamedStoredFunctionQueries(storedFuncs);
    }
    if (namedNativeQueries != null) {
        xmlEntityMappings.setNamedNativeQueries(namedNativeQueries);
    }
    // generate a ClassAccessor for each Descriptor, keeping track of Embeddables
    List<String> embeddables = new ArrayList<String>();
    Map<String, ClassAccessor> accessors = new HashMap<String, ClassAccessor>();
    for (ClassDescriptor cdesc : descriptors) {
        boolean embeddable = false;
        ClassAccessor classAccessor;
        if (cdesc.isAggregateDescriptor()) {
            embeddable = true;
            classAccessor = new EmbeddableAccessor();
            embeddables.add(cdesc.getJavaClassName());
        } else {
            classAccessor = new EntityAccessor();
        }
        classAccessor.setClassName(cdesc.getJavaClassName());
        classAccessor.setAccess(EL_ACCESS_VIRTUAL);
        // may need add STRUCT metadata to the classAccessor to ensure correct field ordering
        if (cdesc.isObjectRelationalDataTypeDescriptor()) {
            ObjectRelationalDataTypeDescriptor odesc = (ObjectRelationalDataTypeDescriptor) cdesc;
            if (odesc.getOrderedFields().size() > 0) {
                StructMetadata struct = new StructMetadata();
                struct.setName(odesc.getStructureName());
                struct.setFields(odesc.getOrderedFields());
                classAccessor.setStruct(struct);
            }
        }
        if (!embeddable && cdesc.getTableName() != null) {
            TableMetadata table = new TableMetadata();
            table.setName(cdesc.getTableName());
            ((EntityAccessor) classAccessor).setTable(table);
        }
        if (!embeddable) {
            List<NamedNativeQueryMetadata> namedNatQueries = new ArrayList<NamedNativeQueryMetadata>();
            NamedNativeQueryMetadata namedQuery;
            DatabaseQuery dbQuery;
            // process findAll and findByPk queries
            for (Iterator<DatabaseQuery> queryIt = cdesc.getQueryManager().getAllQueries().iterator(); queryIt.hasNext(); ) {
                dbQuery = queryIt.next();
                namedQuery = new NamedNativeQueryMetadata();
                namedQuery.setName(dbQuery.getName());
                namedQuery.setQuery(dbQuery.getSQLString());
                namedQuery.setResultClassName(dbQuery.getReferenceClassName());
                namedNatQueries.add(namedQuery);
            }
            // now create/update/delete operations
            Map<String, String> crudOps = crudOperations.get(cdesc.getTableName());
            if (!crudOps.isEmpty()) {
                for (String opName : crudOps.keySet()) {
                    String crudSql = crudOps.get(opName);
                    NamedNativeQueryMetadata crudQuery = new NamedNativeQueryMetadata();
                    crudQuery.setName(opName);
                    crudQuery.setQuery(crudSql);
                    namedNatQueries.add(crudQuery);
                }
            }
            if (namedNatQueries.size() > 0) {
                ((EntityAccessor) classAccessor).setNamedNativeQueries(namedNatQueries);
            }
        }
        classAccessor.setAttributes(new XMLAttributes());
        classAccessor.getAttributes().setIds(new ArrayList<IdAccessor>());
        classAccessor.getAttributes().setBasics(new ArrayList<BasicAccessor>());
        classAccessor.getAttributes().setArrays(new ArrayList<ArrayAccessor>());
        classAccessor.getAttributes().setStructures(new ArrayList<StructureAccessor>());
        classAccessor.getAttributes().setEmbeddeds(new ArrayList<EmbeddedAccessor>());
        if (embeddable) {
            xmlEntityMappings.getEmbeddables().add((EmbeddableAccessor) classAccessor);
        } else {
            xmlEntityMappings.getEntities().add((EntityAccessor) classAccessor);
        }
        accessors.put(cdesc.getJavaClassName(), classAccessor);
    }
    // now the we know what the embeddables are, we can process mappings
    for (ClassDescriptor cdesc : descriptors) {
        ClassAccessor classAccessor = accessors.get(cdesc.getJavaClassName());
        MappingAccessor mapAccessor;
        // generate a MappingAccessor for each mapping
        for (DatabaseMapping dbMapping : cdesc.getMappings()) {
            mapAccessor = generateMappingAccessor(dbMapping, embeddables);
            if (mapAccessor == null) {
                continue;
            }
            if (mapAccessor.isId()) {
                classAccessor.getAttributes().getIds().add((IdAccessor) mapAccessor);
            } else if (mapAccessor.isBasic()) {
                classAccessor.getAttributes().getBasics().add((BasicAccessor) mapAccessor);
            } else if (mapAccessor instanceof ArrayAccessor) {
                classAccessor.getAttributes().getArrays().add((ArrayAccessor) mapAccessor);
            } else if (mapAccessor instanceof StructureAccessor) {
                classAccessor.getAttributes().getStructures().add((StructureAccessor) mapAccessor);
            } else {
                // assumes EmbeddedAccessor
                classAccessor.getAttributes().getEmbeddeds().add((EmbeddedAccessor) mapAccessor);
            }
        }
    }
    return xmlEntityMappings;
}
Also used : EntityAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) NamedStoredFunctionQueryMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.NamedStoredFunctionQueryMetadata) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PLSQLRecordMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.PLSQLRecordMetadata) List(java.util.List) ArrayList(java.util.ArrayList) StructMetadata(org.eclipse.persistence.internal.jpa.metadata.structures.StructMetadata) PLSQLParameterMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.PLSQLParameterMetadata) OracleArrayTypeMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.OracleArrayTypeMetadata) PLSQLTableMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.PLSQLTableMetadata) TableMetadata(org.eclipse.persistence.internal.jpa.metadata.tables.TableMetadata) ObjectRelationalDatabaseField(org.eclipse.persistence.mappings.structures.ObjectRelationalDatabaseField) BasicAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.BasicAccessor) NamedStoredProcedureQueryMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.NamedStoredProcedureQueryMetadata) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) EmbeddableAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EmbeddableAccessor) StoredFunctionCall(org.eclipse.persistence.queries.StoredFunctionCall) PLSQLStoredFunctionCall(org.eclipse.persistence.platform.database.oracle.plsql.PLSQLStoredFunctionCall) OracleObjectTypeMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.OracleObjectTypeMetadata) IdAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.IdAccessor) ClassAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor) StructureAccessor(org.eclipse.persistence.internal.jpa.metadata.structures.StructureAccessor) OracleComplexTypeMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.OracleComplexTypeMetadata) ComplexTypeMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.ComplexTypeMetadata) PLSQLComplexTypeMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.PLSQLComplexTypeMetadata) NamedNativeQueryMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.NamedNativeQueryMetadata) NamedPLSQLStoredFunctionQueryMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.NamedPLSQLStoredFunctionQueryMetadata) EmbeddedAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.EmbeddedAccessor) PLSQLStoredFunctionCall(org.eclipse.persistence.platform.database.oracle.plsql.PLSQLStoredFunctionCall) PLSQLargument(org.eclipse.persistence.platform.database.oracle.plsql.PLSQLargument) PLSQLComplexTypeMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.PLSQLComplexTypeMetadata) OracleComplexTypeMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.OracleComplexTypeMetadata) ObjectRelationalDataTypeDescriptor(org.eclipse.persistence.mappings.structures.ObjectRelationalDataTypeDescriptor) DatabaseQuery(org.eclipse.persistence.queries.DatabaseQuery) PLSQLStoredProcedureCall(org.eclipse.persistence.platform.database.oracle.plsql.PLSQLStoredProcedureCall) StoredProcedureCall(org.eclipse.persistence.queries.StoredProcedureCall) XMLEntityMappings(org.eclipse.persistence.internal.jpa.metadata.xml.XMLEntityMappings) ArrayAccessor(org.eclipse.persistence.internal.jpa.metadata.structures.ArrayAccessor) PLSQLStoredProcedureCall(org.eclipse.persistence.platform.database.oracle.plsql.PLSQLStoredProcedureCall) XMLAttributes(org.eclipse.persistence.internal.jpa.metadata.accessors.classes.XMLAttributes) ObjectRelationalDatabaseField(org.eclipse.persistence.mappings.structures.ObjectRelationalDatabaseField) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) MappingAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.MappingAccessor) PLSQLTableMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.PLSQLTableMetadata) NamedPLSQLStoredProcedureQueryMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.NamedPLSQLStoredProcedureQueryMetadata) StoredProcedureParameterMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.StoredProcedureParameterMetadata)

Example 5 with PLSQLTableMetadata

use of org.eclipse.persistence.internal.jpa.metadata.queries.PLSQLTableMetadata 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)

Aggregations

PLSQLTableMetadata (org.eclipse.persistence.internal.jpa.metadata.queries.PLSQLTableMetadata)5 OracleArrayTypeMetadata (org.eclipse.persistence.internal.jpa.metadata.queries.OracleArrayTypeMetadata)3 OracleObjectTypeMetadata (org.eclipse.persistence.internal.jpa.metadata.queries.OracleObjectTypeMetadata)3 PLSQLRecordMetadata (org.eclipse.persistence.internal.jpa.metadata.queries.PLSQLRecordMetadata)3 NamedNativeQueryMetadata (org.eclipse.persistence.internal.jpa.metadata.queries.NamedNativeQueryMetadata)2 NamedPLSQLStoredFunctionQueryMetadata (org.eclipse.persistence.internal.jpa.metadata.queries.NamedPLSQLStoredFunctionQueryMetadata)2 NamedPLSQLStoredProcedureQueryMetadata (org.eclipse.persistence.internal.jpa.metadata.queries.NamedPLSQLStoredProcedureQueryMetadata)2 NamedStoredFunctionQueryMetadata (org.eclipse.persistence.internal.jpa.metadata.queries.NamedStoredFunctionQueryMetadata)2 NamedStoredProcedureQueryMetadata (org.eclipse.persistence.internal.jpa.metadata.queries.NamedStoredProcedureQueryMetadata)2 PLSQLType (org.eclipse.persistence.tools.oracleddl.metadata.PLSQLType)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)1 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)1 ClassAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor)1 EmbeddableAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EmbeddableAccessor)1 EntityAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor)1 XMLAttributes (org.eclipse.persistence.internal.jpa.metadata.accessors.classes.XMLAttributes)1 BasicAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.BasicAccessor)1