use of org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy in project eclipselink by eclipse-ee4j.
the class MappingAccessor method processMapKeyClass.
/**
* INTERNAL:
* Process a map key class for the given map key map accessor.
*/
protected void processMapKeyClass(ContainerMapping mapping, MappedKeyMapAccessor mappedKeyMapAccessor) {
MapKeyMapping keyMapping;
MetadataClass mapKeyClass = mappedKeyMapAccessor.getMapKeyClass();
if (getProject().hasEntity(mapKeyClass)) {
keyMapping = processEntityMapKeyClass(mappedKeyMapAccessor);
} else if (getProject().hasEmbeddable(mapKeyClass)) {
keyMapping = processEmbeddableMapKeyClass(mappedKeyMapAccessor);
} else {
keyMapping = processDirectMapKeyClass(mappedKeyMapAccessor);
}
Class<?> containerClass;
if (mapping instanceof ForeignReferenceMapping) {
if (usesIndirection()) {
containerClass = ClassConstants.IndirectMap_Class;
((ForeignReferenceMapping) mapping).setIndirectionPolicy(new TransparentIndirectionPolicy());
} else {
containerClass = java.util.Hashtable.class;
((ForeignReferenceMapping) mapping).dontUseIndirection();
}
} else {
containerClass = java.util.Hashtable.class;
}
MappedKeyMapContainerPolicy policy = new MappedKeyMapContainerPolicy(containerClass);
policy.setKeyMapping(keyMapping);
policy.setValueMapping((MapComponentMapping) mapping);
mapping.setContainerPolicy(policy);
}
use of org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy in project eclipselink by eclipse-ee4j.
the class TransparentIndirectionPolicyInstanceTest method setup.
@Override
protected void setup() {
getSession().getIdentityMapAccessor().initializeAllIdentityMaps();
descriptorToModify = project.getDescriptors().get(Employee.class);
for (Enumeration<DatabaseMapping> mappingsEnum = (descriptorToModify.getMappings()).elements(); mappingsEnum.hasMoreElements(); ) {
mappingToModify = mappingsEnum.nextElement();
if (mappingToModify.isForeignReferenceMapping()) {
((ForeignReferenceMapping) mappingToModify).setIndirectionPolicy(new TransparentIndirectionPolicy());
}
}
}
use of org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy in project eclipselink by eclipse-ee4j.
the class UseTransparentMapOnCollectionMapping method setup.
@Override
protected void setup() {
getSession().getIdentityMapAccessor().initializeAllIdentityMaps();
descriptorToModify = project.getDescriptors().get(Employee.class);
policy = new TransparentIndirectionPolicy();
mapPolicy = new MapContainerPolicy();
for (Enumeration<DatabaseMapping> mappingsEnum = (descriptorToModify.getMappings()).elements(); mappingsEnum.hasMoreElements(); ) {
mappingToModify = mappingsEnum.nextElement();
if (mappingToModify.isForeignReferenceMapping()) {
if (mappingToModify.isCollectionMapping()) {
CollectionMapping collectionMapping = (CollectionMapping) mappingToModify;
collectionMapping.setContainerPolicy(mapPolicy);
mapPolicy.setKeyName("testMethod");
collectionMapping.getContainerPolicy().setContainerClass(Vector.class);
((ForeignReferenceMapping) mappingToModify).setIndirectionPolicy(policy);
}
}
}
}
use of org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy in project eclipselink by eclipse-ee4j.
the class DirectMapMapping method useTransparentMap.
/**
* PUBLIC:
* Configure the mapping to use an instance of the specified container class
* to hold the target objects.
* <p>The container class must implement (directly or indirectly) the Map interface.
* <p>Note: Do not use both useMapClass(Class concreteClass), useTransparentMap(). The last use of one of the two methods will override the previous one.
*/
public void useTransparentMap() {
setIndirectionPolicy(new TransparentIndirectionPolicy());
useMapClass(ClassConstants.IndirectMap_Class);
}
use of org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy in project eclipselink by eclipse-ee4j.
the class MapCollectionsProject method buildAggregateDirectMapHolderDescriptor.
protected void buildAggregateDirectMapHolderDescriptor() {
RelationalDescriptor descriptor = new RelationalDescriptor();
// SECTION: DESCRIPTOR
descriptor.setJavaClass(AggregateDirectMapHolder.class);
Vector vector = new Vector();
vector.addElement("AGG_DIR_MAP_HOLDER");
descriptor.setTableNames(vector);
descriptor.addPrimaryKeyFieldName("AGG_DIR_MAP_HOLDER.ID");
// SECTION: PROPERTIES
descriptor.setIdentityMapClass(org.eclipse.persistence.internal.identitymaps.FullIdentityMap.class);
descriptor.setExistenceChecking("Check cache");
descriptor.setIdentityMapSize(100);
descriptor.setSequenceNumberName("AGG_DIR_MAP_HOLDER_ID");
descriptor.setSequenceNumberFieldName("ID");
// SECTION: DIRECTTOFIELDMAPPING
org.eclipse.persistence.mappings.DirectToFieldMapping directtofieldmapping = new org.eclipse.persistence.mappings.DirectToFieldMapping();
directtofieldmapping.setAttributeName("id");
directtofieldmapping.setIsReadOnly(false);
directtofieldmapping.setGetMethodName("getId");
directtofieldmapping.setSetMethodName("setId");
directtofieldmapping.setFieldName("AGG_DIR_MAP_HOLDER.ID");
descriptor.addMapping(directtofieldmapping);
DirectMapMapping directMapMapping = new DirectMapMapping();
directMapMapping.setAttributeName("aggregateToDirectMap");
directMapMapping.setGetMethodName("getAggregateToDirectMap");
directMapMapping.setSetMethodName("setAggregateToDirectMap");
directMapMapping.setReferenceTableName("AGG_DIR_MAP_REL");
directMapMapping.setDirectFieldName("AGG_DIR_MAP_REL.MAP_VALUE");
directMapMapping.addReferenceKeyFieldName("AGG_DIR_MAP_REL.HOLDER_ID", "AGG_DIR_MAP_HOLDER.ID");
directMapMapping.setDirectFieldClassification(Integer.class);
directMapMapping.setIndirectionPolicy(new TransparentIndirectionPolicy());
AggregateObjectMapping keyMapping = new AggregateObjectMapping();
keyMapping.setReferenceClass(AggregateMapKey.class);
keyMapping.addFieldNameTranslation("AGG_DIR_MAP_REL.MAP_KEY", "key->DIRECT");
keyMapping.setDescriptor(descriptor);
MappedKeyMapContainerPolicy policy = new MappedKeyMapContainerPolicy(IndirectMap.class);
policy.setKeyMapping(keyMapping);
policy.setValueMapping(directMapMapping);
directMapMapping.setContainerPolicy(policy);
descriptor.addMapping(directMapMapping);
addDescriptor(descriptor);
}
Aggregations