Search in sources :

Example 1 with RelationalDescriptor

use of org.eclipse.persistence.descriptors.RelationalDescriptor in project eclipselink by eclipse-ee4j.

the class AbstractEntityResource method checkIdempotenceOnRelationships.

/**
 * This method maintains idempotence on PUT by disallowing sequencing in relationships.
 *
 * @param descriptor    descriptor of the entity passed in 'entity' parameter.
 * @param entity        entity to process.
 * @return true if check is passed (no sequencing)
 */
private boolean checkIdempotenceOnRelationships(ClassDescriptor descriptor, Object entity) {
    final List<DatabaseMapping> mappings = descriptor.getMappings();
    if ((mappings != null) && (!mappings.isEmpty())) {
        for (DatabaseMapping mapping : mappings) {
            if (mapping instanceof ForeignReferenceMapping) {
                final ForeignReferenceMapping fkMapping = (ForeignReferenceMapping) mapping;
                if ((fkMapping.isCascadePersist()) || (fkMapping.isCascadeMerge())) {
                    final ClassDescriptor referenceDescriptor = fkMapping.getReferenceDescriptor();
                    if (referenceDescriptor != null) {
                        if (referenceDescriptor instanceof RelationalDescriptor) {
                            final RelationalDescriptor relDesc = (RelationalDescriptor) referenceDescriptor;
                            final AbstractDirectMapping relSequenceMapping = relDesc.getObjectBuilder().getSequenceMapping();
                            if (relSequenceMapping != null) {
                                final Object value = mapping.getAttributeAccessor().getAttributeValueFromObject(entity);
                                if (value != null) {
                                    if (value instanceof ValueHolder) {
                                        final ValueHolder<?> holder = (ValueHolder<?>) value;
                                        if (holder.getValue() != null) {
                                            return false;
                                        }
                                    } else if (value instanceof Collection) {
                                        if (!(((Collection<?>) value).isEmpty())) {
                                            return false;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return true;
}
Also used : RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) ForeignReferenceMapping(org.eclipse.persistence.mappings.ForeignReferenceMapping) AbstractDirectMapping(org.eclipse.persistence.mappings.foundation.AbstractDirectMapping) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) Collection(java.util.Collection) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) ValueHolder(org.eclipse.persistence.indirection.ValueHolder)

Example 2 with RelationalDescriptor

use of org.eclipse.persistence.descriptors.RelationalDescriptor in project eclipselink by eclipse-ee4j.

the class BaseDBWSBuilderHelper method addToOROXProjectsForBuildSql.

protected void addToOROXProjectsForBuildSql(ModelWithBuildSql modelWithBuildSql, Project orProject, Project oxProject, NamingConventionTransformer nct) {
    List<DbColumn> columns = buildDbColumns(dbwsBuilder.getConnection(), modelWithBuildSql.getBuildSql());
    String schemaAlias = modelWithBuildSql.getReturnType();
    String tableName = schemaAlias;
    NamingConventionTransformer customNct = setUpCustomTransformer(tableName, nct);
    RelationalDescriptor desc = buildORDescriptor(tableName, dbwsBuilder.getProjectName(), null, customNct);
    createdORDescriptors.put(desc.getJavaClassName(), desc);
    desc.descriptorIsAggregate();
    orProject.addDescriptor(desc);
    XMLDescriptor xdesc = buildOXDescriptor(desc.getAlias(), schemaAlias, desc.getJavaClassName(), dbwsBuilder.getTargetNamespace());
    oxProject.addDescriptor(xdesc);
    List<String> columnsAlreadyProcessed = new ArrayList<String>();
    for (DbColumn dbColumn : columns) {
        String columnName = dbColumn.getFieldName();
        if (!columnsAlreadyProcessed.contains(columnName)) {
            columnsAlreadyProcessed.add(columnName);
            ElementStyle style = nct.styleForElement(columnName);
            if (style == NONE) {
                continue;
            }
            dbwsBuilder.logMessage(FINE, "Building mappings for " + columnName);
            DirectToFieldMapping orFieldMapping = buildORFieldMappingFromColumn(dbColumn, desc, dbwsBuilder.getDatabasePlatform(), nct);
            desc.addMapping(orFieldMapping);
            XMLDirectMapping oxFieldMapping = buildOXFieldMappingFromColumn(dbColumn, dbwsBuilder.getDatabasePlatform(), nct);
            if (oxFieldMapping instanceof XMLBinaryDataMapping) {
                xdesc.getNamespaceResolver().put(XML_MIME_PREFIX, XML_MIME_URL);
            }
            xdesc.addMapping(oxFieldMapping);
        } else {
            dbwsBuilder.logMessage(SEVERE, "Duplicate ResultSet columns not supported '" + columnName + "'");
            throw new RuntimeException("Duplicate ResultSet columns not supported");
        }
    }
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) DbColumn(org.eclipse.persistence.tools.dbws.jdbc.DbColumn) ArrayList(java.util.ArrayList) ElementStyle(org.eclipse.persistence.tools.dbws.NamingConventionTransformer.ElementStyle) XMLBinaryDataMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping)

Example 3 with RelationalDescriptor

use of org.eclipse.persistence.descriptors.RelationalDescriptor in project eclipselink by eclipse-ee4j.

the class BaseDBWSBuilderHelper method buildOROXProjects.

/**
 * Builds OR/OX projects, descriptors {@literal &} mappings, based on a given list
 * of types, as well as table(s) and secondary SQL.
 */
public void buildOROXProjects(NamingConventionTransformer nct, List<CompositeDatabaseType> types) {
    // save for later
    this.nct = nct;
    String projectName = dbwsBuilder.getProjectName();
    Project orProject = new Project();
    orProject.setName(projectName + UNDERSCORE + DBWS_OR_LABEL);
    Project oxProject = null;
    if (dbTables.isEmpty() && !dbwsBuilder.hasBuildSqlOperations()) {
        dbwsBuilder.logMessage(FINEST, "No tables specified");
        oxProject = new SimpleXMLFormatProject();
    } else {
        oxProject = new Project();
    }
    oxProject.setName(projectName + UNDERSCORE + DBWS_OX_LABEL);
    for (TableType dbTable : dbTables) {
        String tableName = dbTable.getTableName();
        RelationalDescriptor desc = buildORDescriptor(tableName, dbwsBuilder.getProjectName(), dbwsBuilder.requireCRUDOperations, nct);
        orProject.addDescriptor(desc);
        XMLDescriptor xdesc = buildOXDescriptor(tableName, dbwsBuilder.getProjectName(), dbwsBuilder.getTargetNamespace(), nct);
        oxProject.addDescriptor(xdesc);
        for (FieldType dbColumn : dbTable.getColumns()) {
            String columnName = dbColumn.getFieldName();
            ElementStyle style = nct.styleForElement(columnName);
            if (style == NONE) {
                continue;
            }
            dbwsBuilder.logMessage(FINE, "Building mappings for " + tableName + DOT + columnName);
            DirectToFieldMapping orFieldMapping = buildORFieldMappingFromColumn(dbColumn, desc, dbwsBuilder.getDatabasePlatform(), nct);
            desc.addMapping(orFieldMapping);
            XMLDirectMapping oxFieldMapping = buildOXFieldMappingFromColumn(dbColumn, dbwsBuilder.getDatabasePlatform(), nct);
            if (oxFieldMapping instanceof XMLBinaryDataMapping) {
                xdesc.getNamespaceResolver().put(XML_MIME_PREFIX, XML_MIME_URL);
            }
            xdesc.addMapping(oxFieldMapping);
            // check for switch from Byte[] to byte[]
            if (oxFieldMapping.getAttributeClassificationName() == APBYTE.getName()) {
                orFieldMapping.setAttributeClassificationName(APBYTE.getName());
            }
        }
        setUpFindQueries(nct, tableName, desc);
    }
    finishUpProjects(orProject, oxProject, types);
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) XMLBinaryDataMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping) Project(org.eclipse.persistence.sessions.Project) SchemaModelProject(org.eclipse.persistence.internal.oxm.schema.SchemaModelProject) DBWSModelProject(org.eclipse.persistence.dbws.DBWSModelProject) ObjectPersistenceWorkbenchXMLProject(org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceWorkbenchXMLProject) SimpleXMLFormatProject(org.eclipse.persistence.internal.xr.sxf.SimpleXMLFormatProject) SimpleXMLFormatProject(org.eclipse.persistence.internal.xr.sxf.SimpleXMLFormatProject) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) TableType(org.eclipse.persistence.tools.oracleddl.metadata.TableType) ObjectTableType(org.eclipse.persistence.tools.oracleddl.metadata.ObjectTableType) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) ElementStyle(org.eclipse.persistence.tools.dbws.NamingConventionTransformer.ElementStyle) FieldType(org.eclipse.persistence.tools.oracleddl.metadata.FieldType)

Example 4 with RelationalDescriptor

use of org.eclipse.persistence.descriptors.RelationalDescriptor in project eclipselink by eclipse-ee4j.

the class Util method buildORDescriptor.

/**
 * Build a RelationalDescriptor for a given table.
 */
public static RelationalDescriptor buildORDescriptor(String tableName, String projectName, List<String> requireCRUDOperations, NamingConventionTransformer nct) {
    RelationalDescriptor desc = new RelationalDescriptor();
    desc.addTableName(tableName);
    String tableAlias = getGeneratedAlias(tableName);
    desc.setAlias(tableAlias);
    desc.setJavaClassName(getGeneratedJavaClassName(tableName, projectName));
    desc.useWeakIdentityMap();
    // keep track of which tables require CRUD operations
    if (requireCRUDOperations != null) {
        requireCRUDOperations.add(tableAlias);
    }
    return desc;
}
Also used : RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor)

Example 5 with RelationalDescriptor

use of org.eclipse.persistence.descriptors.RelationalDescriptor in project eclipselink by eclipse-ee4j.

the class MappingProject method buildCubicleDescriptor.

protected void buildCubicleDescriptor() {
    RelationalDescriptor descriptor = new RelationalDescriptor();
    // SECTION: DESCRIPTOR
    descriptor.setJavaClass(Cubicle.class);
    Vector vector = new Vector();
    vector.addElement("MAP_CUB");
    descriptor.setTableNames(vector);
    descriptor.addPrimaryKeyFieldName("MAP_CUB.C_ID");
    // SECTION: PROPERTIES
    descriptor.setSequenceNumberName("SEQ_ID");
    descriptor.setSequenceNumberFieldName("C_ID");
    // SECTION: COPY POLICY
    descriptor.createCopyPolicy("constructor");
    // SECTION: INSTANTIATION POLICY
    descriptor.createInstantiationPolicy("constructor");
    // SECTION: DIRECTTOFIELDMAPPING
    DirectToFieldMapping typeConversionMapping = new DirectToFieldMapping();
    TypeConversionConverter typeConversionConverter = new TypeConversionConverter();
    typeConversionMapping.setAttributeName("id");
    typeConversionMapping.setIsReadOnly(false);
    typeConversionMapping.setFieldName("MAP_CUB.C_ID");
    typeConversionConverter.setObjectClass(java.math.BigDecimal.class);
    typeConversionConverter.setDataClass(String.class);
    typeConversionMapping.setConverter(typeConversionConverter);
    descriptor.addMapping(typeConversionMapping);
    // SECTION: DIRECTTOFIELDMAPPING
    DirectToFieldMapping directtofieldmapping1 = new DirectToFieldMapping();
    directtofieldmapping1.setAttributeName("location");
    directtofieldmapping1.setIsReadOnly(false);
    directtofieldmapping1.setFieldName("MAP_CUB.LOCATION");
    descriptor.addMapping(directtofieldmapping1);
    // SECTION: MANYTOMANYMAPPING
    ManyToManyMapping manytomanymapping = new ManyToManyMapping();
    manytomanymapping.setAttributeName("emergencyExits");
    manytomanymapping.setIsReadOnly(false);
    manytomanymapping.setUsesIndirection(false);
    manytomanymapping.setReferenceClass(EmergencyExit.class);
    manytomanymapping.setIsPrivateOwned(false);
    manytomanymapping.setRelationTableName("CUBICLE_EMERGENCYEXIT");
    manytomanymapping.addSourceRelationKeyFieldName("CUBICLE_EMERGENCYEXIT.CUBICLE_LOCATION", "MAP_CUB.LOCATION");
    manytomanymapping.addTargetRelationKeyFieldName("CUBICLE_EMERGENCYEXIT.EXIT_ID", "MAP_EMERGENCYEXIT.EXIT_ID");
    descriptor.addMapping(manytomanymapping);
    addDescriptor(descriptor);
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) ManyToManyMapping(org.eclipse.persistence.mappings.ManyToManyMapping) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) TypeConversionConverter(org.eclipse.persistence.mappings.converters.TypeConversionConverter) Vector(java.util.Vector)

Aggregations

RelationalDescriptor (org.eclipse.persistence.descriptors.RelationalDescriptor)306 DirectToFieldMapping (org.eclipse.persistence.mappings.DirectToFieldMapping)122 OneToOneMapping (org.eclipse.persistence.mappings.OneToOneMapping)43 EclipseLinkException (org.eclipse.persistence.exceptions.EclipseLinkException)26 DescriptorException (org.eclipse.persistence.exceptions.DescriptorException)19 OneToManyMapping (org.eclipse.persistence.mappings.OneToManyMapping)18 Vector (java.util.Vector)17 TransparentIndirectionPolicy (org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy)15 MappedKeyMapContainerPolicy (org.eclipse.persistence.internal.queries.MappedKeyMapContainerPolicy)15 TransformationMapping (org.eclipse.persistence.mappings.TransformationMapping)13 IntegrityChecker (org.eclipse.persistence.exceptions.IntegrityChecker)12 ManyToManyMapping (org.eclipse.persistence.mappings.ManyToManyMapping)10 java.util (java.util)9 AggregateObjectMapping (org.eclipse.persistence.mappings.AggregateObjectMapping)8 org.eclipse.persistence.mappings (org.eclipse.persistence.mappings)7 UnidirectionalOneToManyMapping (org.eclipse.persistence.mappings.UnidirectionalOneToManyMapping)6 ObjectTypeConverter (org.eclipse.persistence.mappings.converters.ObjectTypeConverter)6 DatabaseRecord (org.eclipse.persistence.sessions.DatabaseRecord)6 DirectCollectionMapping (org.eclipse.persistence.mappings.DirectCollectionMapping)5 DirectMapMapping (org.eclipse.persistence.mappings.DirectMapMapping)4