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; }
public static void bindSubclass(Element node, Subclass subclass, Mappings mappings, java.util.Map inheritedMetas) throws MappingException { bindClass( node, subclass, mappings, inheritedMetas ); inheritedMetas = getMetas( node, inheritedMetas, true ); // get meta's from <subclass> if ( subclass.getEntityPersisterClass() == null ) { subclass.getRootClass() .setEntityPersisterClass( SingleTableEntityPersister.class ); } log.info( "Mapping subclass: " + subclass.getEntityName() + " -> " + subclass.getTable().getName() ); // properties createClassProperties( node, subclass, mappings, inheritedMetas ); }
public static void bindSubclass(Element node, Subclass subclass, Mappings mappings, java.util.Map inheritedMetas) throws MappingException { bindClass( node, subclass, mappings, inheritedMetas ); inheritedMetas = getMetas( node, inheritedMetas, true ); // get meta's from <subclass> if ( LOG.isDebugEnabled() ) { LOG.debugf( "Mapping subclass: %s -> %s", subclass.getEntityName(), subclass.getTable().getName() ); } // properties createClassProperties( node, subclass, mappings, inheritedMetas ); }
private static void handleSubclass(PersistentClass model, Mappings mappings, Element subnode, java.util.Map inheritedMetas) throws MappingException { Subclass subclass = new SingleTableSubclass( model ); bindSubclass( subnode, subclass, mappings, inheritedMetas ); model.addSubclass( subclass ); mappings.addClass( subclass ); }
public void testProperCallbacks() { PersistentClassVisitorValidator vv = new PersistentClassVisitorValidator(); new RootClass().accept(vv); new Subclass(new RootClass()).accept(vv); new JoinedSubclass(new RootClass()).accept(vv); new SingleTableSubclass(new RootClass()).accept(vv); new UnionSubclass(new RootClass()).accept(vv); }
public Object getClassDiscriminatorValue(String classname) throws TypesInformationException { Object identifier = discriminators.get(classname); if (identifier == null) { PersistentClass clazz = configuration.getClassMapping(classname); if (clazz != null) { if (clazz instanceof Subclass) { Subclass sub = (Subclass) clazz; if (sub.isJoinedSubclass()) { identifier = Integer.valueOf(sub.getSubclassId()); } else { identifier = getShortClassName(classname); } } else if (clazz instanceof RootClass) { RootClass root = (RootClass) clazz; if (root.getDiscriminator() == null) { identifier = Integer.valueOf(root.getSubclassId()); } else { identifier = getShortClassName(classname); } } } else { throw new TypesInformationException("Class " + classname + " not found in hibernate configuration"); } discriminators.put(classname, identifier); } return identifier; }
public Object getClassDiscriminatorValue(String classname) throws TypesInformationException { LOG.debug("Getting class discriminator value for " + classname); Object identifier = discriminators.get(classname); if (identifier == null) { PersistentClass clazz = configuration.getClassMapping(classname); if (clazz != null) { if (clazz instanceof Subclass) { Subclass sub = (Subclass) clazz; if (sub.isJoinedSubclass()) { LOG.debug("\t" + classname + " is a joined subclass"); identifier = Integer.valueOf(sub.getSubclassId()); } else { LOG.debug("\t" + classname + " is a named subclass"); identifier = getShortClassName(classname); } } else if (clazz instanceof RootClass) { LOG.debug("\t" + classname + " is a root class"); RootClass root = (RootClass) clazz; if (root.getDiscriminator() == null) { identifier = Integer.valueOf(root.getSubclassId()); } else { identifier = getShortClassName(classname); } } } else { throw new TypesInformationException("Class " + classname + " not found in hibernate configuration"); } discriminators.put(classname, identifier); } return identifier; }
@Override protected ProxyFactory buildProxyFactory(PersistentClass thePersistentClass, Getter idGetter, Setter idSetter) { final Class<?> mappedClass = thePersistentClass.getMappedClass(); Check.isNotNull(mappedClass, "Mapped class of entity " + thePersistentClass.getEntityName() + " is null"); // determine the id getter and setter methods from the proxy interface // (if // any) // determine all interfaces needed by the resulting proxy final HashSet<Object> proxyInterfaces = new HashSet<Object>(); proxyInterfaces.add(HibernateProxy.class); final Class<?> proxyInterface = thePersistentClass.getProxyInterface(); if (proxyInterface != null && !mappedClass.equals(proxyInterface)) { if (!proxyInterface.isInterface()) { throw new MappingException("proxy must be either an interface, or the class itself: " + getEntityName()); } proxyInterfaces.add(proxyInterface); } if (mappedClass.isInterface()) { proxyInterfaces.add(mappedClass); } final Iterator<?> iter = thePersistentClass.getSubclassIterator(); while (iter.hasNext()) { final Subclass subclass = (Subclass) iter.next(); final Class<?> subclassProxy = subclass.getProxyInterface(); final Class<?> subclassClass = subclass.getMappedClass(); if (subclassProxy != null && !subclassClass.equals(subclassProxy)) { if (proxyInterface == null || !proxyInterface.isInterface()) { throw new MappingException("proxy must be either an interface, or the class itself: " + subclass.getEntityName()); } proxyInterfaces.add(subclassProxy); } } final Method idGetterMethod = idGetter == null ? null : idGetter.getMethod(); final Method idSetterMethod = idSetter == null ? null : idSetter.getMethod(); final Method proxyGetIdentifierMethod = idGetterMethod == null || proxyInterface == null ? null : ReflectHelper.getMethod(proxyInterface, idGetterMethod); final Method proxySetIdentifierMethod = idSetterMethod == null || proxyInterface == null ? null : ReflectHelper.getMethod(proxyInterface, idSetterMethod); ProxyFactory pf = buildProxyFactoryInternal(thePersistentClass, idGetter, idSetter); try { pf.postInstantiate(getEntityName(), mappedClass, proxyInterfaces, proxyGetIdentifierMethod, proxySetIdentifierMethod, thePersistentClass.hasEmbeddedIdentifier() ? (CompositeType) thePersistentClass .getIdentifier().getType() : null); } catch (final HibernateException he) { log.warn("could not create proxy factory for:" + getEntityName(), he); pf = null; } return pf; }
public Object accept(Subclass subclass) { return validate(Subclass.class, subclass); }