Search in sources :

Example 6 with MappingAccessor

use of org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.MappingAccessor in project eclipselink by eclipse-ee4j.

the class NamedEntityGraphMetadata method process.

/**
 * INTERNAL:
 * Process the entity graph metadata.
 */
public void process(EntityAccessor entityAccessor) {
    String entityGraphName;
    if (hasName()) {
        entityGraphName = getName();
    } else {
        entityGraphName = entityAccessor.getEntityName();
        getLogger().logConfigMessage(MetadataLogger.NAMED_ENTITY_GRAPH_NAME, entityGraphName, entityAccessor.getJavaClassName());
    }
    // Check for an existing entity graph and throw an exception if there is one.
    if (getProject().hasEntityGraph(entityGraphName)) {
        throw new IllegalStateException(ExceptionLocalization.buildMessage("named_entity_graph_exists", new Object[] { entityGraphName, entityAccessor.getJavaClassName() }));
    } else {
        AttributeGroup entityGraph = new AttributeGroup(entityGraphName, entityAccessor.getJavaClassName(), true);
        Map<String, Map<String, AttributeGroup>> attributeGraphs = new HashMap<String, Map<String, AttributeGroup>>();
        // Process the subgraph metadata (build attribute graphs for each).
        for (NamedSubgraphMetadata subgraph : getSubgraphs()) {
            subgraph.process(attributeGraphs);
        }
        // Process the include all attributes flag.
        if (includeAllAttributes()) {
            for (MappingAccessor accessor : entityAccessor.getDescriptor().getMappingAccessors()) {
                entityGraph.addAttribute(accessor.getAttributeName());
            }
        }
        // Process the attribute nodes.
        for (NamedAttributeNodeMetadata attributeNode : getNamedAttributeNodes()) {
            attributeNode.process(attributeGraphs, entityGraph, entityGraph);
        }
        // Process the subgraphs attribute nodes (into the groups built previously).
        for (NamedSubgraphMetadata subgraph : getSubgraphs()) {
            subgraph.processAttributeNodes(attributeGraphs, attributeGraphs.get(subgraph.getName()).get(subgraph.getTypeClassName()), entityGraph);
        }
        for (NamedSubgraphMetadata subclassSubgraph : getSubclassSubgraphs()) {
            AttributeGroup group = new AttributeGroup(subclassSubgraph.getName(), subclassSubgraph.getTypeClassName(), true);
            subclassSubgraph.processAttributeNodes(attributeGraphs, group, entityGraph);
            entityGraph.getSubClassGroups().put(group.getTypeName(), group);
        }
        // Finally, add the entity graph to the project.
        getProject().addEntityGraph(entityGraph);
    }
}
Also used : HashMap(java.util.HashMap) MappingAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.MappingAccessor) AttributeGroup(org.eclipse.persistence.queries.AttributeGroup) MetadataAccessibleObject(org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataAccessibleObject) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with MappingAccessor

use of org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.MappingAccessor in project eclipselink by eclipse-ee4j.

the class ConvertMetadata method verify.

/**
 * INTERNAL:
 * Verify mapping passed to register {@code AttributeConverter} class.
 * @param mapping        Database attribute mapping.
 * @param referenceClass JPA annotated class.
 * @param accessor       Class accessor.
 * @param embeddedAttributeName Content of {@code <name>}
 *        from {@code attributeName="value.<name>"}. This value shall never
 *        be {@code null} when {@code @ElementCollection} mapping is being
 *        processed.
 */
private MetadataClass verify(final DatabaseMapping mapping, final MetadataClass referenceClass, final ClassAccessor accessor, final String embeddedAttributeName) throws ValidationException {
    // Validate the attribute name first if there is one.
    if (hasAttributeName()) {
        String attributeName;
        // Aggregate object mapping
        if (mapping.isAggregateObjectMapping()) {
            attributeName = getAttributeName();
        // Coming from @ElementCollection mapping with value.<name> attributeName.
        } else if (mapping.isAggregateCollectionMapping() && embeddedAttributeName != null && embeddedAttributeName.length() > 0) {
            attributeName = embeddedAttributeName;
        // Unsupported mapping, throw an exception
        } else {
            throw ValidationException.invalidMappingForConvertWithAttributeName(accessor.getJavaClassName(), mapping.getAttributeName());
        }
        // Validate the attribute name existing on the embeddable and update
        // the reference class.
        final ClassAccessor embeddableAccessor = getProject().getEmbeddableAccessor(referenceClass);
        final MappingAccessor mappingAccessor = embeddableAccessor.getDescriptor().getMappingAccessor(attributeName);
        if (mappingAccessor == null) {
            throw ValidationException.embeddableAttributeNameForConvertNotFound(accessor.getJavaClassName(), mapping.getAttributeName(), embeddableAccessor.getJavaClassName(), getAttributeName());
        }
        return mappingAccessor.getReferenceClass();
    } else {
        // In an aggregate object case, the attribute name must be specified.
        if (mapping.isAggregateObjectMapping()) {
            throw ValidationException.missingMappingConvertAttributeName(accessor.getJavaClassName(), mapping.getAttributeName());
        }
    }
    return referenceClass;
}
Also used : ClassAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor) MappingAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.MappingAccessor)

Example 8 with MappingAccessor

use of org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.MappingAccessor in project eclipselink by eclipse-ee4j.

the class JPAMetadataGenerator method generateCRUDMetadata.

/**
 * Generates NamedNativeQueryMetadata for CRUD operations (create,
 * findAll, findByPk, update and delete) for a given Entity if
 * required, i.e. generateCRUDOps is true.
 */
protected void generateCRUDMetadata(EntityAccessor entity) {
    if (generateCRUDOps) {
        // don't blow away the Entity's query metadata
        if (entity.getNamedNativeQueries() == null) {
            entity.setNamedNativeQueries(new ArrayList<NamedNativeQueryMetadata>());
        }
        String tableName = entity.getTable().getName();
        String entityType = getUnqualifiedEntityName(tableName) + TYPE_STR;
        List<IdAccessor> ids = entity.getAttributes().getIds();
        List<BasicAccessor> basics = entity.getAttributes().getBasics();
        // list of all mappings (ids and basics)
        List<MappingAccessor> mappings = new ArrayList<MappingAccessor>();
        mappings.addAll(ids);
        mappings.addAll(basics);
        // process primary keys
        String pks = null;
        int pkCount = 0;
        for (IdAccessor pk : ids) {
            if (pkCount++ == 0) {
                pks = OPEN_BRACKET + pk.getName().toUpperCase() + EQUALS_BINDING1_STR;
            } else {
                pks = pks.concat(AND_STR + pk.getName().toUpperCase() + EQUALS_BINDING_STR + pkCount++);
            }
        }
        if (pks != null) {
            pks = pks.concat(CLOSE_BRACKET);
        }
        // find by PK
        NamedNativeQueryMetadata crudQuery = new NamedNativeQueryMetadata();
        crudQuery.setName(PK_QUERYNAME + UNDERSCORE + entityType);
        crudQuery.setQuery(SELECT_FROM_STR + tableName + WHERE_STR + pks);
        crudQuery.setResultClassName(entity.getClassName());
        entity.getNamedNativeQueries().add(crudQuery);
        // find all
        crudQuery = new NamedNativeQueryMetadata();
        crudQuery.setName(ALL_QUERYNAME + UNDERSCORE + entityType);
        crudQuery.setQuery(SELECT_FROM_STR + tableName);
        crudQuery.setResultClassName(entity.getClassName());
        entity.getNamedNativeQueries().add(crudQuery);
        // create
        StringBuilder sqlStmt = new StringBuilder(128);
        sqlStmt.append(INSERT_STR).append(tableName).append(SINGLE_SPACE).append(OPEN_BRACKET);
        MetadataHelper.buildColsFromMappings(sqlStmt, mappings, COMMA_SPACE_STR);
        sqlStmt.append(CLOSE_BRACKET).append(VALUES_STR).append(OPEN_BRACKET);
        MetadataHelper.buildValuesAsQMarksFromMappings(sqlStmt, mappings, COMMA_SPACE_STR);
        sqlStmt.append(CLOSE_BRACKET);
        crudQuery = new NamedNativeQueryMetadata();
        crudQuery.setName(CREATE_OPERATION_NAME + UNDERSCORE + entityType);
        crudQuery.setQuery(sqlStmt.toString());
        entity.getNamedNativeQueries().add(crudQuery);
        // update
        sqlStmt = new StringBuilder(128);
        sqlStmt.append(UPDATE_STR).append(tableName).append(SET_STR);
        MetadataHelper.buildColsAndValuesBindingsFromMappings(sqlStmt, basics, pkCount, EQUALS_BINDING_STR, COMMA_SPACE_STR);
        sqlStmt.append(WHERE_STR).append(pks);
        crudQuery = new NamedNativeQueryMetadata();
        crudQuery.setName(UPDATE_OPERATION_NAME + UNDERSCORE + entityType);
        crudQuery.setQuery(sqlStmt.toString());
        entity.getNamedNativeQueries().add(crudQuery);
        // delete
        crudQuery = new NamedNativeQueryMetadata();
        crudQuery.setName(REMOVE_OPERATION_NAME + UNDERSCORE + entityType);
        crudQuery.setQuery(DELETE_STR + tableName + WHERE_STR + pks);
        entity.getNamedNativeQueries().add(crudQuery);
    }
}
Also used : BasicAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.BasicAccessor) IdAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.IdAccessor) MappingAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.MappingAccessor) ArrayList(java.util.ArrayList) NamedNativeQueryMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.NamedNativeQueryMetadata)

Example 9 with MappingAccessor

use of org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.MappingAccessor 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 10 with MappingAccessor

use of org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.MappingAccessor in project eclipselink by eclipse-ee4j.

the class MetadataDescriptor method addMappingAccessor.

/**
 * INTERNAL:
 * If the accessor is an IdAccessor we store it in a separate map for use
 * during MappedSuperclass processing.
 */
public void addMappingAccessor(MappingAccessor accessor) {
    // accessor does not show up in the mapping accessors list.
    if (accessor.isRelationship() && ((RelationshipAccessor) accessor).isValueHolderInterface()) {
        return;
    }
    // Log a warning message if we are overriding a mapping accessor.
    if (m_mappingAccessors.containsKey(accessor.getAttributeName())) {
        MappingAccessor existingAccessor = m_mappingAccessors.get(accessor.getAttributeName());
        String existingAccessType = existingAccessor.usesPropertyAccess() ? JPA_ACCESS_PROPERTY : JPA_ACCESS_FIELD;
        String accessType = accessor.usesPropertyAccess() ? JPA_ACCESS_PROPERTY : JPA_ACCESS_FIELD;
        getLogger().logWarningMessage(MetadataLogger.INVERSE_ACCESS_TYPE_MAPPING_OVERRIDE, accessor.getJavaClass().getName(), existingAccessor.getAnnotatedElementName(), existingAccessType, accessor.getAnnotatedElementName(), accessType);
    }
    m_mappingAccessors.put(accessor.getAttributeName(), accessor);
    // Store IdAccessors in a separate map for use by hasIdAccessor()
    if (accessor.isId()) {
        m_idAccessors.put(accessor.getAttributeName(), (IdAccessor) accessor);
    }
    // Check if we already processed an EmbeddedId for this Entity or MappedSuperclass.
    if (accessor.isEmbeddedId() && hasEmbeddedId()) {
        throw ValidationException.multipleEmbeddedIdAnnotationsFound(getJavaClass(), accessor.getAttributeName(), this.getEmbeddedIdAttributeName());
    }
    // 300051: store the single EmbeddedIdAccessor for use by hasEmbeddedId in MetadataProject.addMetamodelMappedSuperclass()
    if (accessor.isEmbeddedId()) {
        setEmbeddedIdAccessor((EmbeddedIdAccessor) accessor);
    }
}
Also used : MappingAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.MappingAccessor)

Aggregations

MappingAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.MappingAccessor)11 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ClassAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor)3 EmbeddableAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EmbeddableAccessor)2 BasicAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.BasicAccessor)2 IdAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.IdAccessor)2 MappedKeyMapAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.MappedKeyMapAccessor)2 MetadataAccessibleObject (org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataAccessibleObject)2 NamedNativeQueryMetadata (org.eclipse.persistence.internal.jpa.metadata.queries.NamedNativeQueryMetadata)2 Writer (java.io.Writer)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 List (java.util.List)1 Map (java.util.Map)1 StringTokenizer (java.util.StringTokenizer)1 JavaFileObject (javax.tools.JavaFileObject)1 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)1 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)1 EntityAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor)1