use of org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataClass 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.internal.jpa.metadata.accessors.objects.MetadataClass in project eclipselink by eclipse-ee4j.
the class MappingAccessor method processEmbeddableMapKeyClass.
/**
* INTERNAL:
*/
protected AggregateObjectMapping processEmbeddableMapKeyClass(MappedKeyMapAccessor mappedKeyMapAccessor) {
AggregateObjectMapping keyMapping = new AggregateObjectMapping();
MetadataClass mapKeyClass = mappedKeyMapAccessor.getMapKeyClass();
keyMapping.setReferenceClassName(mapKeyClass.getName());
// The embeddable accessor must be processed by now. If it is not then
// we are in trouble since by the time we get here, we are too late in
// the cycle to process embeddable classes and their accessors. See
// MetadataProject processStage3(), processEmbeddableMappingAccessors.
// At this stage all class accessors (embeddable, entity and mapped
// superclass) have to have been processed to gather all their
// relational and embedded mappings.
EmbeddableAccessor mapKeyAccessor = getProject().getEmbeddableAccessor(mapKeyClass);
// Ensure the reference descriptor is marked as an embeddable collection.
mapKeyAccessor.getDescriptor().setIsEmbeddable();
// Process the attribute overrides for this may key embeddable.
processAttributeOverrides(mappedKeyMapAccessor.getMapKeyAttributeOverrides(), keyMapping, mapKeyAccessor.getDescriptor());
// Process the association overrides for this may key embeddable.
processAssociationOverrides(mappedKeyMapAccessor.getMapKeyAssociationOverrides(), keyMapping, mapKeyAccessor.getDescriptor());
// Process a convert key or jpa converter for the map key if specified.
processConverts(getMapKeyConverts(mappedKeyMapAccessor.getMapKeyConverts()), keyMapping, mappedKeyMapAccessor.getMapKeyClass(), true);
keyMapping.setDescriptor(getDescriptor().getClassDescriptor());
return keyMapping;
}
use of org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataClass in project eclipselink by eclipse-ee4j.
the class EmbeddableAccessor method discoverMappedSuperclassesAndInheritanceParents.
/**
* INTERNAL:
* Build a list of classes that are decorated with a MappedSuperclass
* annotation or that are tagged as a mapped-superclass in an XML document.
*
* This method will also do a couple other things as well since we are
* traversing the parent classes:
* - Build a map of generic types specified and will be used to resolve
* actual class types for mappings.
* - save mapped-superclass descriptors on the project for later use
* by the Metamodel API
*
* We don't support embeddable inheritance yet. When that is added, this
* method will need to change and in fact we may be able to re-use the
* existing discover method from EntityAccessor (with minor tweaks).
*/
protected void discoverMappedSuperclassesAndInheritanceParents(boolean addMappedSuperclassAccessors) {
// Clear any previous discovery.
clearMappedSuperclassesAndInheritanceParents();
MetadataClass parentClass = getJavaClass().getSuperclass();
List<String> genericTypes = getJavaClass().getGenericType();
while (parentClass != null && !parentClass.isObject()) {
// Our parent might be a mapped superclass, check and add as needed.
addPotentialMappedSuperclass(parentClass, addMappedSuperclassAccessors);
// Resolve any generic types from the generic parent onto the
// current entity accessor.
resolveGenericTypes(genericTypes, parentClass);
// Grab the generic types from the parent class.
genericTypes = parentClass.getGenericType();
// Finally, get the next parent and keep processing ...
parentClass = parentClass.getSuperclass();
}
}
use of org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataClass in project eclipselink by eclipse-ee4j.
the class MetadataProject method processSequencingAccessors.
/**
* INTERNAL:
* Process the sequencing information. At this point, through validation, it
* is not possible to have:
* 1 - a table generator with the generator name equal to
* DEFAULT_SEQUENCE_GENERATOR or DEFAULT_IDENTITY_GENERATOR
* 2 - a sequence generator with the name eqaul to DEFAULT_TABLE_GENERATOR
* or DEFAULT_IDENTITY_GENERATOR
* 3 - you can't have both a sequence generator and a table generator with
* the same DEFAULT_AUTO_GENERATOR name.
*
* @see addTableGenerator and addSequenceGenerator.
*/
protected void processSequencingAccessors() {
if (!m_generatedValues.isEmpty()) {
// 1 - Build our map of sequences keyed on generator names.
Hashtable<String, Sequence> sequences = new Hashtable<String, Sequence>();
for (SequenceGeneratorMetadata sequenceGenerator : m_sequenceGenerators.values()) {
sequences.put(sequenceGenerator.getName(), sequenceGenerator.process(m_logger));
}
for (UuidGeneratorMetadata uuidGenerator : m_uuidGenerators.values()) {
sequences.put(uuidGenerator.getName(), uuidGenerator.process(m_logger));
}
for (TableGeneratorMetadata tableGenerator : m_tableGenerators.values()) {
sequences.put(tableGenerator.getGeneratorName(), tableGenerator.process(m_logger));
}
// create them using the Table and Sequence generator metadata.
if (!sequences.containsKey(DEFAULT_TABLE_GENERATOR)) {
TableGeneratorMetadata tableGenerator = new TableGeneratorMetadata(DEFAULT_TABLE_GENERATOR);
// This code was attempting to use the platform default sequence name,
// however the platform has not been set yet, so it would never work,
// it was also causing the platform default sequence to be set, causing the DatabasePlatform default to be used,
// so I am removing this code, as it breaks the platform default sequence and does not work.
// Sequence seq = m_session.getDatasourcePlatform().getDefaultSequence();
// Using "" as the default should make the platform default it.
String defaultTableGeneratorName = "";
// Process the default values.
processTable(tableGenerator, defaultTableGeneratorName, getPersistenceUnitDefaultCatalog(), getPersistenceUnitDefaultSchema(), tableGenerator);
sequences.put(DEFAULT_TABLE_GENERATOR, tableGenerator.process(m_logger));
}
if (!sequences.containsKey(DEFAULT_SEQUENCE_GENERATOR)) {
sequences.put(DEFAULT_SEQUENCE_GENERATOR, new SequenceGeneratorMetadata(DEFAULT_SEQUENCE_GENERATOR, getPersistenceUnitDefaultCatalog(), getPersistenceUnitDefaultSchema()).process(m_logger));
}
if (!sequences.containsKey(DEFAULT_IDENTITY_GENERATOR)) {
sequences.put(DEFAULT_IDENTITY_GENERATOR, new SequenceGeneratorMetadata(DEFAULT_IDENTITY_GENERATOR, 1, getPersistenceUnitDefaultCatalog(), getPersistenceUnitDefaultSchema(), true).process(m_logger));
}
if (!sequences.containsKey(DEFAULT_UUID_GENERATOR)) {
sequences.put(DEFAULT_UUID_GENERATOR, new UuidGeneratorMetadata().process(m_logger));
}
// Use a temporary sequence generator to build a qualifier to set on
// the default generator. Don't use this generator as the default
// auto generator though.
SequenceGeneratorMetadata tempGenerator = new SequenceGeneratorMetadata(DEFAULT_AUTO_GENERATOR, getPersistenceUnitDefaultCatalog(), getPersistenceUnitDefaultSchema());
DatasourceLogin login = m_session.getProject().getLogin();
login.setTableQualifier(tempGenerator.processQualifier());
// 3 - Loop through generated values and set sequences for each.
for (MetadataClass entityClass : m_generatedValues.keySet()) {
// Skip setting sequences if our accessor is null, must be a mapped superclass
ClassAccessor accessor = m_allAccessors.get(entityClass.getName());
if (accessor != null) {
m_generatedValues.get(entityClass).process(accessor.getDescriptor(), sequences, login);
}
}
}
}
use of org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataClass in project eclipselink by eclipse-ee4j.
the class TransformerFactory method addClassDetailsForMappedSuperClasses.
/**
* INTERNAL:
* Look higher in the hierarchy for the mappings listed in the unMappedAttribute list.
*
* We assume that if a mapping exists, the attribute must either be mapped from the owning
* class or from a superclass.
*/
public void addClassDetailsForMappedSuperClasses(MetadataClass clz, ClassDescriptor initialDescriptor, ClassDetails classDetails, Map<String, ClassDetails> classDetailsMap, List<DatabaseMapping> unMappedAttributes, boolean weaveChangeTracking) {
MetadataClass superClz = clz.getSuperclass();
if (superClz == null || superClz.isObject()) {
return;
}
ClassDescriptor mappedSuperclassDescriptor = ((AbstractSession) session).getMappedSuperclass(superClz.getName());
if (mappedSuperclassDescriptor == null) {
ClassDescriptor descriptor = findDescriptor(session.getProject(), clz.getSuperclass().getName());
if (descriptor != null) {
return;
}
}
// If the superclass declares more mappings than there are unmapped mappings still to process, this superclass has shadowed attributes
if (mappedSuperclassDescriptor != null && unMappedAttributes.size() < mappedSuperclassDescriptor.getMappings().size()) {
List<DatabaseMapping> hiddenMappings = new ArrayList<DatabaseMapping>();
for (DatabaseMapping mapping : mappedSuperclassDescriptor.getMappings()) {
boolean contains = false;
String name = mapping.getAttributeName();
for (DatabaseMapping newmapping : unMappedAttributes) {
if (name.equals(newmapping.getAttributeName())) {
contains = true;
break;
}
}
// If the super has a mapping that wasn't processed by the subclasses, add it to be processed
if (!contains) {
hiddenMappings.add(mapping);
}
}
unMappedAttributes.addAll(hiddenMappings);
}
boolean weaveValueHolders = canWeaveValueHolders(superClz, unMappedAttributes);
List<DatabaseMapping> stillUnMappedMappings = null;
ClassDetails superClassDetails = createClassDetails(superClz, weaveValueHolders, weaveChangeTracking, weaveFetchGroups, weaveInternal, weaveRest);
superClassDetails.setIsMappedSuperClass(true);
if (mappedSuperclassDescriptor != null && !mappedSuperclassDescriptor.usesPropertyAccessForWeaving()) {
superClassDetails.useAttributeAccess();
} else if (!initialDescriptor.usesPropertyAccessForWeaving()) {
superClassDetails.useAttributeAccess();
}
if (!classDetailsMap.containsKey(superClassDetails.getClassName())) {
stillUnMappedMappings = storeAttributeMappings(superClz, superClassDetails, unMappedAttributes, weaveValueHolders);
classDetailsMap.put(superClassDetails.getClassName(), superClassDetails);
addClassDetailsForMappedSuperClasses(superClz, initialDescriptor, classDetails, classDetailsMap, stillUnMappedMappings, weaveChangeTracking);
}
}
Aggregations