use of org.eclipse.persistence.mappings.foundation.AbstractDirectMapping in project eclipselink by eclipse-ee4j.
the class ConverterAccessor method process.
/**
* INTERNAL:
* Process this converter for the given mapping.
*/
public void process(DatabaseMapping mapping, boolean isForMapKey, String attributeName, boolean disableConversion) {
ConverterClass converterClass = new ConverterClass(getJavaClassName(), isForMapKey, fieldClassification.getName(), disableConversion);
converterClass.setSession(getProject().getSession());
if (mapping.isDirectMapMapping() && isForMapKey) {
((DirectMapMapping) mapping).setKeyConverter(converterClass);
} else if (mapping.isDirectCollectionMapping()) {
((DirectCollectionMapping) mapping).setValueConverter(converterClass);
} else if (mapping.isDirectToFieldMapping()) {
((AbstractDirectMapping) mapping).setConverter(converterClass);
} else if (mapping.isAggregateObjectMapping()) {
((AggregateObjectMapping) mapping).addConverter(converterClass, attributeName);
} else if (mapping.isAggregateCollectionMapping()) {
((AggregateCollectionMapping) mapping).addConverter(converterClass, attributeName);
}
}
use of org.eclipse.persistence.mappings.foundation.AbstractDirectMapping in project eclipselink by eclipse-ee4j.
the class BasicAccessor method process.
/**
* INTERNAL:
* Process a basic accessor.
*/
@Override
public void process() {
// Process a DirectToFieldMapping, that is a Basic that could
// be used in conjunction with a Lob, Temporal, Enumerated
// or inferred to be used with a serialized mapping.
AbstractDirectMapping mapping = getOwningDescriptor().getClassDescriptor().newDirectMapping();
setMapping(mapping);
// Process the @Column or column element if there is one.
// A number of methods depend on this field so it must be
// initialized before any further processing can take place.
m_databaseField = getDatabaseField(getDescriptor().getPrimaryTable(), MetadataLogger.COLUMN);
// mapping to ensure we do the right conversions.
if (hasAttributeType() || getAccessibleObject().isGenericType()) {
mapping.setAttributeClassificationName(getReferenceClassName());
}
mapping.setField(m_databaseField);
mapping.setIsReadOnly(m_databaseField.isReadOnly());
mapping.setAttributeName(getAttributeName());
mapping.setIsOptional(isOptional());
mapping.setIsLazy(usesIndirection());
// Will check for PROPERTY access.
setAccessorMethods(mapping);
// Process a converter for this mapping. We will look for an eclipselink
// convert value first. If none is found then we'll look for a JPA
// converter, that is, Convert, Enumerated, Lob and Temporal. With
// everything falling into a serialized mapping if no converter
// whatsoever is found.
processMappingValueConverter(mapping, getConvert(), getConverts(), getReferenceClass(), getReferenceClassWithGenerics());
// Process a mutable setting.
if (m_mutable != null) {
mapping.setIsMutable(m_mutable);
}
// Process the @ReturnInsert and @ReturnUpdate annotations.
processReturnInsertAndUpdate();
// Process a generated value setting.
processGeneratedValue();
// Add the table generator to the project if one is set.
if (m_tableGenerator != null) {
getProject().addTableGenerator(m_tableGenerator, getDescriptor().getDefaultCatalog(), getDescriptor().getDefaultSchema());
}
// Add the sequence generator to the project if one is set.
if (m_sequenceGenerator != null) {
getProject().addSequenceGenerator(m_sequenceGenerator, getDescriptor().getDefaultCatalog(), getDescriptor().getDefaultSchema());
}
// Add the uuid generator to the project if one is set.
if (m_uuidGenerator != null) {
getProject().addUuidGenerator(m_uuidGenerator);
}
// Process the index metadata.
processIndex();
processCacheIndex();
}
use of org.eclipse.persistence.mappings.foundation.AbstractDirectMapping in project eclipselink by eclipse-ee4j.
the class MappingAccessor method processDirectMapKeyClass.
/**
* INTERNAL:
*/
protected AbstractDirectMapping processDirectMapKeyClass(MappedKeyMapAccessor mappedKeyMapAccessor) {
AbstractDirectMapping keyMapping = new DirectToFieldMapping();
// Get the map key field, defaulting and looking for attribute
// overrides. Set the field before applying a converter.
DatabaseField mapKeyField = getDatabaseField(getReferenceDatabaseTable(), MetadataLogger.MAP_KEY_COLUMN);
keyMapping.setField(mapKeyField);
keyMapping.setIsReadOnly(mapKeyField.isReadOnly());
keyMapping.setAttributeClassificationName(mappedKeyMapAccessor.getMapKeyClass().getName());
keyMapping.setDescriptor(getDescriptor().getClassDescriptor());
// Process a convert key or jpa converter for the map key if specified.
processMappingKeyConverter(keyMapping, mappedKeyMapAccessor.getMapKeyConvert(), mappedKeyMapAccessor.getMapKeyConverts(), mappedKeyMapAccessor.getMapKeyClass(), mappedKeyMapAccessor.getMapKeyClassWithGenerics());
return keyMapping;
}
use of org.eclipse.persistence.mappings.foundation.AbstractDirectMapping in project eclipselink by eclipse-ee4j.
the class ObjectAccessor method processMapsId.
/**
* INTERNAL:
* Process the mapping keys from the maps id value.
*/
protected void processMapsId(OneToOneMapping oneToOneMapping) {
EmbeddedIdAccessor embeddedIdAccessor = getDescriptor().getEmbeddedIdAccessor();
if (embeddedIdAccessor == null) {
// Case #4: a simple id association
MappingAccessor idAccessor = getDescriptor().getMappingAccessor(getDescriptor().getIdAttributeName());
DatabaseMapping idMapping = idAccessor.getMapping();
// Grab the foreign key field and set it as the descriptor's id field.
DatabaseField foreignKeyField = oneToOneMapping.getForeignKeyFields().elementAt(0);
updatePrimaryKeyField(idAccessor, foreignKeyField);
// Update the field on the mapping.
((AbstractDirectMapping) idMapping).setField(foreignKeyField);
// Set the primary key mapping as read only.
idMapping.setIsReadOnly(true);
// Set the maps id mapping.
oneToOneMapping.setDerivedIdMapping(idMapping);
} else {
if (embeddedIdAccessor.getReferenceClassName().equals(getReferenceDescriptor().getPKClassName())) {
// Case #5: Parent's id class is the same as dependent's embedded id class
// Case #6: Both parent and dependent use same embedded id class.
processMapsIdFields(oneToOneMapping, embeddedIdAccessor, embeddedIdAccessor);
} else {
if (m_mapsId.equals("")) {
// User didn't specify a mapsId value. By default the attribute name from this object accessor is used.
m_mapsId = getAttributeName();
}
// Set the maps id value on the mapping.
oneToOneMapping.setMapsIdValue(m_mapsId);
MappingAccessor mappingAccessor = embeddedIdAccessor.getReferenceDescriptor().getMappingAccessor(m_mapsId);
if (mappingAccessor == null) {
throw ValidationException.invalidMappedByIdValue(m_mapsId, getAnnotatedElementName(), embeddedIdAccessor.getReferenceClass());
} else {
// Case #1: Dependent's embedded id maps a basic mapping to parent entity.
// Case #2: Dependent's embedded id maps the parent's id class
// Case #3: Dependent's embedded if maps the parent's embedded id class
processMapsIdFields(oneToOneMapping, embeddedIdAccessor, mappingAccessor);
}
}
// Set the maps id mapping.
oneToOneMapping.setDerivedIdMapping(embeddedIdAccessor.getMapping());
}
}
use of org.eclipse.persistence.mappings.foundation.AbstractDirectMapping 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;
}
Aggregations