use of org.eclipse.persistence.internal.queries.MappedKeyMapContainerPolicy in project eclipselink by eclipse-ee4j.
the class EntityGraphImpl method addKeySubgraph.
@Override
public <X> Subgraph<X> addKeySubgraph(String attributeName, Class<X> type) {
if (!this.isMutable) {
throw new IllegalStateException(ExceptionLocalization.buildMessage("immutable_entitygraph"));
}
AttributeNodeImpl node = null;
if (this.attributeNodes != null) {
node = this.attributeNodes.get(attributeName);
}
if (node == null) {
node = new AttributeNodeImpl<X>(attributeName);
addAttributeNodeImpl(node);
}
AttributeGroup localGroup = null;
DatabaseMapping mapping = descriptor.getMappingForAttributeName(attributeName);
if (mapping == null) {
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("metamodel_managed_type_attribute_not_present", new Object[] { this.descriptor.getJavaClassName(), attributeName }));
}
if (!mapping.getContainerPolicy().isMappedKeyMapPolicy() && !((MappedKeyMapContainerPolicy) mapping.getContainerPolicy()).isMapKeyAttribute()) {
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("attribute_is_not_map_with_managed_key", new Object[] { attributeName, descriptor.getJavaClassName() }));
}
localGroup = new AttributeGroup(attributeName, type, true);
ClassDescriptor targetDesc = mapping.getContainerPolicy().getDescriptorForMapKey();
if (type != null && targetDesc.hasInheritance()) {
targetDesc = targetDesc.getInheritancePolicy().getDescriptor(type);
if (targetDesc == null) {
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("type_unkown_for_this_attribute", new Object[] { type.getName(), attributeName }));
}
}
EntityGraphImpl entityGraph = new EntityGraphImpl(localGroup, targetDesc, attributeName);
node.addKeySubgraph(entityGraph);
// order is important here, must add entity graph to node list before adding to group or it will appear in node list twice.
this.attributeGroup.addAttributeKey(attributeName, localGroup);
return entityGraph;
}
use of org.eclipse.persistence.internal.queries.MappedKeyMapContainerPolicy 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.queries.MappedKeyMapContainerPolicy in project eclipselink by eclipse-ee4j.
the class TestUpdateEntityAggregateMapMapping method setup.
@Override
public void setup() {
AggregateCollectionMapping mapping = (AggregateCollectionMapping) getSession().getProject().getDescriptor(EntityAggregateMapHolder.class).getMappingForAttributeName("entityToAggregateMap");
keyMapping = (ForeignReferenceMapping) ((MappedKeyMapContainerPolicy) mapping.getContainerPolicy()).getKeyMapping();
oldKeyPrivateOwnedValue = keyMapping.isPrivateOwned();
keyMapping.setIsPrivateOwned(usePrivateOwned);
super.setup();
}
use of org.eclipse.persistence.internal.queries.MappedKeyMapContainerPolicy in project eclipselink by eclipse-ee4j.
the class TestUpdateEntityEntityMapMapping method setup.
@Override
public void setup() {
mapping = (ManyToManyMapping) getSession().getProject().getDescriptor(EntityEntityMapHolder.class).getMappingForAttributeName("entityToEntityMap");
oldPrivateOwnedValue = mapping.isPrivateOwned();
mapping.setIsPrivateOwned(usePrivateOwned);
keyMapping = (ForeignReferenceMapping) ((MappedKeyMapContainerPolicy) mapping.getContainerPolicy()).getKeyMapping();
oldKeyPrivateOwnedValue = keyMapping.isPrivateOwned();
keyMapping.setIsPrivateOwned(usePrivateOwned);
UnitOfWork uow = getSession().acquireUnitOfWork();
holder = new EntityEntityMapHolder();
EntityMapValue value = new EntityMapValue();
value.setId(1);
EntityMapKey key = new EntityMapKey();
key.setId(11);
key.setData("data1");
holder.addEntityToEntityMapItem(key, value);
uow.registerObject(key);
EntityMapValue value2 = new EntityMapValue();
value2.setId(2);
key = new EntityMapKey();
key.setId(22);
holder.addEntityToEntityMapItem(key, value2);
uow.registerObject(holder);
uow.registerObject(key);
uow.registerObject(value);
uow.registerObject(value2);
uow.commit();
getSession().getIdentityMapAccessor().initializeAllIdentityMaps();
}
use of org.eclipse.persistence.internal.queries.MappedKeyMapContainerPolicy 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