use of org.eclipse.persistence.mappings.CollectionMapping in project eclipselink by eclipse-ee4j.
the class ManyToManyAccessor method process.
/**
* INTERNAL:
* Process a many to many metadata accessor into a EclipseLink
* ManyToManyMapping.
*/
@Override
public void process() {
super.process();
// Create a M-M mapping and process common collection mapping metadata.
// Allow for different descriptor types (EIS) to create different mapping types.
CollectionMapping mapping = getDescriptor().getClassDescriptor().newManyToManyMapping();
process(mapping);
if (hasMappedBy()) {
// We are processing the non-owning side of a M-M relationship. Get
// the owning mapping from the reference descriptor metadata and
// process the keys from it.
DatabaseMapping owningMapping = getOwningMapping();
if (owningMapping.isManyToManyMapping()) {
ManyToManyMapping ownerMapping = (ManyToManyMapping) owningMapping;
processMappedByRelationTable(ownerMapping.getRelationTableMechanism(), ((ManyToManyMapping) mapping).getRelationTableMechanism());
// Set the mapping read-only.
mapping.setIsReadOnly(true);
} else {
// Invalid owning mapping type, throw an exception.
throw ValidationException.invalidMapping(getJavaClass(), getReferenceClass());
}
} else if (mapping instanceof ManyToManyMapping) {
// Processing the owning side of a M-M, process the join table.
processJoinTable(mapping, ((ManyToManyMapping) mapping).getRelationTableMechanism(), getJoinTableMetadata());
} else if (mapping instanceof EISOneToManyMapping) {
processEISOneToManyMapping((EISOneToManyMapping) mapping);
}
}
use of org.eclipse.persistence.mappings.CollectionMapping in project eclipselink by eclipse-ee4j.
the class MappingAccessor method setIndirectionPolicy.
/**
* INTERNAL:
* Set the correct indirection policy on a collection mapping. Method
* assume that the reference class has been set on the mapping before
* calling this method.
*/
protected void setIndirectionPolicy(ContainerMapping mapping, String mapKey, boolean usesIndirection) {
MetadataClass rawClass = getRawClass();
boolean containerPolicySet = false;
if (usesIndirection && (mapping instanceof ForeignReferenceMapping)) {
containerPolicySet = true;
CollectionMapping collectionMapping = (CollectionMapping) mapping;
if (rawClass.isClass(Map.class)) {
if (collectionMapping.isDirectMapMapping()) {
((DirectMapMapping) mapping).useTransparentMap();
} else {
collectionMapping.useTransparentMap(mapKey);
}
} else if (rawClass.isClass(List.class)) {
collectionMapping.useTransparentList();
} else if (rawClass.isClass(Collection.class)) {
collectionMapping.useTransparentCollection();
} else if (rawClass.isClass(Set.class)) {
collectionMapping.useTransparentSet();
} else {
getLogger().logWarningMessage(MetadataLogger.WARNING_INVALID_COLLECTION_USED_ON_LAZY_RELATION, getJavaClass(), getAnnotatedElement(), rawClass);
processIndirection((ForeignReferenceMapping) mapping);
containerPolicySet = false;
}
} else {
if (mapping instanceof CollectionMapping) {
((CollectionMapping) mapping).dontUseIndirection();
}
}
if (!containerPolicySet) {
if (rawClass.isClass(Map.class)) {
if (mapping instanceof DirectMapMapping) {
((DirectMapMapping) mapping).useMapClass(java.util.Hashtable.class);
} else {
mapping.useMapClass(java.util.Hashtable.class, mapKey);
}
} else if (rawClass.isClass(Set.class)) {
// This will cause it to use a CollectionContainerPolicy type
mapping.useCollectionClass(java.util.HashSet.class);
} else if (rawClass.isClass(List.class)) {
// This will cause a ListContainerPolicy type to be used or
// OrderedListContainerPolicy if ordering is specified.
mapping.useCollectionClass(java.util.Vector.class);
} else if (rawClass.isClass(Collection.class)) {
// Force CollectionContainerPolicy type to be used with a
// collection implementation.
mapping.setContainerPolicy(new CollectionContainerPolicy(java.util.Vector.class));
} else {
// Use the supplied collection class type if its not an interface
if (mapKey == null || mapKey.equals("")) {
if (rawClass.isList()) {
mapping.useListClassName(rawClass.getName());
} else {
mapping.useCollectionClassName(rawClass.getName());
}
} else {
mapping.useMapClassName(rawClass.getName(), mapKey);
}
}
}
}
use of org.eclipse.persistence.mappings.CollectionMapping in project eclipselink by eclipse-ee4j.
the class OneToManyAccessor method processManyToManyMapping.
/**
* INTERNAL:
* Process an many to many mapping for this accessor since a join table
* was specified.
*/
protected void processManyToManyMapping() {
// Create a M-M mapping and process common collection mapping metadata
// first followed by specific metadata.
// Allow for different descriptor types (EIS) to create different mapping types.
CollectionMapping mapping = getDescriptor().getClassDescriptor().newManyToManyMapping();
process(mapping);
if (mapping instanceof ManyToManyMapping) {
// 266912: If this 1:n accessor is different than the n:n mapping - track this
((ManyToManyMapping) mapping).setDefinedAsOneToManyMapping(true);
// Process the JoinTable metadata.
processJoinTable(mapping, ((ManyToManyMapping) mapping).getRelationTableMechanism(), getJoinTableMetadata());
} else if (mapping instanceof EISOneToManyMapping) {
processEISOneToManyMapping((EISOneToManyMapping) mapping);
}
}
use of org.eclipse.persistence.mappings.CollectionMapping in project eclipselink by eclipse-ee4j.
the class DynamicXMLMetadataSource method createJAXBProperty.
/**
* Create a JAXB property for a particular mapping.
* This will only create JAXBProperties for mappings that are virtual - either because their
* parent object is a dynamic class, or because the owning static class has virtual properties
*/
private JAXBElement<XmlElement> createJAXBProperty(DatabaseMapping mapping, ObjectFactory objectFactory, JavaType owningType, boolean isDynamic) {
if (!mapping.getAttributeAccessor().isVirtualAttributeAccessor() && !isDynamic) {
return null;
}
XmlElement xmlElement = new XmlElement();
xmlElement.setJavaAttribute(mapping.getAttributeName());
if (mapping.isObjectReferenceMapping()) {
xmlElement.setType(((ObjectReferenceMapping) mapping).getReferenceClassName());
} else if (mapping.isCollectionMapping()) {
if (mapping.isEISMapping()) {
// It will be fine for simple collections
if (mapping instanceof EISCompositeDirectCollectionMapping) {
xmlElement.setContainerType(mapping.getContainerPolicy().getContainerClassName());
} else if (mapping instanceof EISCompositeCollectionMapping) {
xmlElement.setContainerType(mapping.getContainerPolicy().getContainerClassName());
xmlElement.setType(((EISCompositeCollectionMapping) mapping).getReferenceClassName());
}
} else {
xmlElement.setType(((CollectionMapping) mapping).getReferenceClassName());
xmlElement.setContainerType(mapping.getContainerPolicy().getContainerClassName());
}
} else {
xmlElement.setType(mapping.getAttributeClassification().getName());
}
if (mapping.getAttributeAccessor().isVirtualAttributeAccessor()) {
VirtualAttributeAccessor jpaAccessor = (VirtualAttributeAccessor) mapping.getAttributeAccessor();
if (owningType.getXmlVirtualAccessMethods() == null) {
XmlVirtualAccessMethods virtualAccessMethods = new XmlVirtualAccessMethods();
virtualAccessMethods.setGetMethod(jpaAccessor.getGetMethodName());
virtualAccessMethods.setSetMethod(jpaAccessor.getSetMethodName());
owningType.setXmlVirtualAccessMethods(virtualAccessMethods);
} else if (!owningType.getXmlVirtualAccessMethods().getGetMethod().equals(jpaAccessor.getGetMethodName())) {
XmlAccessMethods accessMethods = new XmlAccessMethods();
accessMethods.setGetMethod(jpaAccessor.getGetMethodName());
accessMethods.setSetMethod(jpaAccessor.getSetMethodName());
xmlElement.setXmlAccessMethods(accessMethods);
}
}
return objectFactory.createXmlElement(xmlElement);
}
use of org.eclipse.persistence.mappings.CollectionMapping 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);
}
}
}
}
Aggregations