use of org.eclipse.persistence.mappings.DirectMapMapping 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.DirectMapMapping 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.DirectMapMapping in project eclipselink by eclipse-ee4j.
the class DirectCollectionAccessor method processDirectMapMapping.
/**
* INTERNAL:
*/
protected void processDirectMapMapping() {
// Initialize and process common direct collection metadata. This must
// be done before any field processing since field processing requires
// that the collection table be processed before hand.
DirectMapMapping mapping = new DirectMapMapping();
process(mapping);
// Process the container and indirection policies.
processContainerPolicyAndIndirection(mapping);
// Process the key column (we must process this field before the
// call to processConverter, since it may set a field classification)
mapping.setDirectKeyField(getDatabaseField(getReferenceDatabaseTable(), MetadataLogger.MAP_KEY_COLUMN));
// in the processContainerPolicyAndIndirection call above.
if (isBasicMap()) {
// mapping to ensure we do the right conversions.
if (hasAttributeType() || getAccessibleObject().isGenericCollectionType()) {
mapping.setDirectKeyFieldClassificationName(getJavaClassName(getMapKeyReferenceClass()));
}
// Process a converter for the key column of this mapping.
processMappingKeyConverter(mapping, getKeyConverter(), null, getMapKeyReferenceClass(), getMapKeyReferenceClassWithGenerics());
}
// Process the value column (we must process this field before the call
// to processConverter, since it may set a field classification)
mapping.setDirectField(getDatabaseField(getReferenceDatabaseTable(), MetadataLogger.VALUE_COLUMN));
// mapping to ensure we do the right conversions.
if (hasAttributeType() || getAccessibleObject().isGenericCollectionType()) {
mapping.setDirectFieldClassificationName(getJavaClassName(getReferenceClass()));
}
// Process a converter for value column of this mapping.
processMappingValueConverter(mapping, getValueConverter(), getConverts(), getReferenceClass(), getReferenceClassWithGenerics());
}
use of org.eclipse.persistence.mappings.DirectMapMapping in project eclipselink by eclipse-ee4j.
the class ConverterClass method initialize.
/**
* INTERNAL:
*/
@Override
public void initialize(DatabaseMapping mapping, Session session) {
// Ensure the mapping has the correct field classification set.
if (mapping.isDirectToFieldMapping()) {
DirectToFieldMapping m = (DirectToFieldMapping) mapping;
if (disableConversion) {
m.setConverter(null);
} else {
m.setConverter(this);
m.setFieldClassification(fieldClassification);
m.setFieldClassificationClassName(fieldClassificationName);
}
} else if (mapping.isDirectMapMapping() && isForMapKey) {
DirectMapMapping m = (DirectMapMapping) mapping;
if (disableConversion) {
m.setKeyConverter(null);
} else {
m.setKeyConverter(this);
m.setDirectKeyFieldClassification(fieldClassification);
m.setDirectKeyFieldClassificationName(fieldClassificationName);
}
} else if (mapping.isDirectCollectionMapping()) {
DirectCollectionMapping m = (DirectCollectionMapping) mapping;
if (disableConversion) {
m.setValueConverter(null);
} else {
m.setValueConverter(this);
m.setDirectFieldClassification(fieldClassification);
m.setDirectFieldClassificationName(fieldClassificationName);
}
} else {
// TODO: what else could it be???
}
}
use of org.eclipse.persistence.mappings.DirectMapMapping 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