use of org.hibernate.mapping.MappedSuperclass in project hibernate-orm by hibernate.
the class JoinedSubclassEntityPersister method processPersistentClassHierarchy.
private Set<String> processPersistentClassHierarchy(PersistentClass persistentClass, boolean isBase, SessionFactoryImplementor factory, String[][] mapping) {
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// collect all the class names that indicate that the "main table" of the given PersistentClass should be
// included when one of the collected class names is used in TREAT
final Set<String> classNames = new HashSet<String>();
final Iterator itr = persistentClass.getDirectSubclasses();
while (itr.hasNext()) {
final Subclass subclass = (Subclass) itr.next();
final Set<String> subclassSubclassNames = processPersistentClassHierarchy(subclass, false, factory, mapping);
classNames.addAll(subclassSubclassNames);
}
classNames.add(persistentClass.getEntityName());
if (!isBase) {
MappedSuperclass msc = persistentClass.getSuperMappedSuperclass();
while (msc != null) {
classNames.add(msc.getMappedClass().getName());
msc = msc.getSuperMappedSuperclass();
}
associateSubclassNamesToSubclassTableIndexes(persistentClass, classNames, mapping, factory);
}
return classNames;
}
use of org.hibernate.mapping.MappedSuperclass in project hibernate-orm by hibernate.
the class MetamodelImpl method buildMappedSuperclassType.
// TODO remove / reduce @SW scope
@SuppressWarnings("unchecked")
private static MappedSuperclassTypeImpl<?> buildMappedSuperclassType(MappedSuperclass mappedSuperclass, MetadataContext context) {
final MappedSuperclass superMappedSuperclass = mappedSuperclass.getSuperMappedSuperclass();
AbstractIdentifiableType<?> superType = superMappedSuperclass == null ? null : locateOrBuildMappedsuperclassType(superMappedSuperclass, context);
// no mappedSuperclass, check for a super entity
if (superType == null) {
final PersistentClass superPersistentClass = mappedSuperclass.getSuperPersistentClass();
superType = superPersistentClass == null ? null : locateOrBuildEntityType(superPersistentClass, context);
}
final Class javaType = mappedSuperclass.getMappedClass();
MappedSuperclassTypeImpl mappedSuperclassType = new MappedSuperclassTypeImpl(javaType, mappedSuperclass, superType);
context.registerMappedSuperclassType(mappedSuperclass, mappedSuperclassType);
return mappedSuperclassType;
}
use of org.hibernate.mapping.MappedSuperclass in project hibernate-orm by hibernate.
the class MetamodelImpl method handleUnusedMappedSuperclasses.
private static void handleUnusedMappedSuperclasses(MetadataContext context) {
final Set<MappedSuperclass> unusedMappedSuperclasses = context.getUnusedMappedSuperclasses();
if (!unusedMappedSuperclasses.isEmpty()) {
for (MappedSuperclass mappedSuperclass : unusedMappedSuperclasses) {
log.unusedMappedSuperclass(mappedSuperclass.getMappedClass().getName());
locateOrBuildMappedsuperclassType(mappedSuperclass, context);
}
}
}
use of org.hibernate.mapping.MappedSuperclass in project hibernate-orm by hibernate.
the class MetadataContext method wrapUp.
@SuppressWarnings({ "unchecked" })
public void wrapUp() {
final boolean traceEnabled = LOG.isTraceEnabled();
if (traceEnabled) {
LOG.trace("Wrapping up metadata context...");
}
boolean staticMetamodelScanEnabled = JpaStaticMetaModelPopulationSetting.determineJpaMetaModelPopulationSetting(sessionFactory.getProperties()) != JpaStaticMetaModelPopulationSetting.DISABLED;
// we need to process types from superclasses to subclasses
for (Object mapping : orderedMappings) {
if (PersistentClass.class.isAssignableFrom(mapping.getClass())) {
@SuppressWarnings("unchecked") final PersistentClass safeMapping = (PersistentClass) mapping;
if (traceEnabled) {
LOG.trace("Starting entity [" + safeMapping.getEntityName() + ']');
}
try {
final EntityTypeImpl<?> jpa2Mapping = entityTypesByPersistentClass.get(safeMapping);
applyIdMetadata(safeMapping, jpa2Mapping);
applyVersionAttribute(safeMapping, jpa2Mapping);
Iterator<Property> properties = safeMapping.getDeclaredPropertyIterator();
while (properties.hasNext()) {
final Property property = properties.next();
if (property.getValue() == safeMapping.getIdentifierMapper()) {
// #buildIdClassAttributes
continue;
}
if (safeMapping.isVersioned() && property == safeMapping.getVersion()) {
// skip the version property, it was already handled previously.
continue;
}
final Attribute attribute = attributeFactory.buildAttribute(jpa2Mapping, property);
if (attribute != null) {
jpa2Mapping.getBuilder().addAttribute(attribute);
}
}
jpa2Mapping.lock();
if (staticMetamodelScanEnabled) {
populateStaticMetamodel(jpa2Mapping);
}
} finally {
if (traceEnabled) {
LOG.trace("Completed entity [" + safeMapping.getEntityName() + ']');
}
}
} else if (MappedSuperclass.class.isAssignableFrom(mapping.getClass())) {
@SuppressWarnings("unchecked") final MappedSuperclass safeMapping = (MappedSuperclass) mapping;
if (traceEnabled) {
LOG.trace("Starting mapped superclass [" + safeMapping.getMappedClass().getName() + ']');
}
try {
final MappedSuperclassTypeImpl<?> jpa2Mapping = mappedSuperclassByMappedSuperclassMapping.get(safeMapping);
applyIdMetadata(safeMapping, jpa2Mapping);
applyVersionAttribute(safeMapping, jpa2Mapping);
Iterator<Property> properties = safeMapping.getDeclaredPropertyIterator();
while (properties.hasNext()) {
final Property property = properties.next();
if (safeMapping.isVersioned() && property == safeMapping.getVersion()) {
// skip the version property, it was already handled previously.
continue;
}
final Attribute attribute = attributeFactory.buildAttribute(jpa2Mapping, property);
if (attribute != null) {
jpa2Mapping.getBuilder().addAttribute(attribute);
}
}
jpa2Mapping.lock();
if (staticMetamodelScanEnabled) {
populateStaticMetamodel(jpa2Mapping);
}
} finally {
if (traceEnabled) {
LOG.trace("Completed mapped superclass [" + safeMapping.getMappedClass().getName() + ']');
}
}
} else {
throw new AssertionFailure("Unexpected mapping type: " + mapping.getClass());
}
}
if (staticMetamodelScanEnabled) {
for (EmbeddableTypeImpl embeddable : embeddables.values()) {
populateStaticMetamodel(embeddable);
}
}
}
use of org.hibernate.mapping.MappedSuperclass in project hibernate-orm by hibernate.
the class ClassPropertyHolder method addPropertyToMappedSuperclass.
private void addPropertyToMappedSuperclass(Property prop, XClass declaringClass) {
final Class type = getContext().getBootstrapContext().getReflectionManager().toClass(declaringClass);
MappedSuperclass superclass = getContext().getMetadataCollector().getMappedSuperclass(type);
superclass.addDeclaredProperty(prop);
}
Aggregations