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;
}
use of org.eclipse.persistence.mappings.foundation.AbstractDirectMapping in project eclipselink by eclipse-ee4j.
the class DynamicTypeBuilder method addEnum.
public DynamicEnumBuilder addEnum(String fieldName, String className, String columnName, DynamicClassLoader dcl) {
dcl.addEnum(className, (Object) null);
AbstractDirectMapping adm = addDirectMappingForEnum(fieldName, className, columnName);
return new DynamicEnumBuilder(className, adm, dcl);
}
use of org.eclipse.persistence.mappings.foundation.AbstractDirectMapping in project eclipselink by eclipse-ee4j.
the class ClassDescriptor method addDirectMapping.
/**
* PUBLIC:
* Add a direct to field mapping to the receiver. The new mapping specifies that
* an instance variable of the class of objects which the receiver describes maps in
* the default manner for its type to the indicated database field.
*
* @param attributeName is the name of an instance variable of the
* class which the receiver describes.
* @param fieldName is the name of the database column which corresponds
* with the designated instance variable.
* @return The newly created DatabaseMapping is returned.
*/
public DatabaseMapping addDirectMapping(String attributeName, String fieldName) {
AbstractDirectMapping mapping = newDirectMapping();
mapping.setAttributeName(attributeName);
mapping.setField(new DatabaseField(fieldName));
return addMapping(mapping);
}
use of org.eclipse.persistence.mappings.foundation.AbstractDirectMapping in project eclipselink by eclipse-ee4j.
the class MappedKeyMapContainerPolicy method setKeyField.
/**
* INTERNAL:
* Set the DatabaseField that will represent the key in a DirectMapMapping.
*/
public void setKeyField(DatabaseField keyField, ClassDescriptor descriptor) {
if (keyMapping == null) {
AbstractDirectMapping newKeyMapping = new DirectToFieldMapping();
newKeyMapping.setField(keyField);
newKeyMapping.setDescriptor(descriptor);
setKeyMapping(newKeyMapping);
}
if (((DatabaseMapping) keyMapping).isDirectToFieldMapping()) {
((AbstractDirectMapping) keyMapping).setField(keyField);
}
}
Aggregations