List of usage examples for org.hibernate.mapping Subclass getEntityName
public String getEntityName()
From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java
License:Apache License
/** * Binds a sub-class using table-per-hierarchy inheritance mapping * * @param sub The Grails domain class instance representing the sub-class * @param subClass The Hibernate SubClass instance * @param mappings The mappings instance */// w ww. ja v a 2s . c o m protected void bindSubClass(GrailsDomainClass sub, Subclass subClass, Mappings mappings, String sessionFactoryBeanName) { bindClass(sub, subClass, mappings); if (subClass.getEntityPersisterClass() == null) { subClass.getRootClass().setEntityPersisterClass(getGroovyAwareSingleTableEntityPersisterClass()); } if (LOG.isDebugEnabled()) LOG.debug("Mapping subclass: " + subClass.getEntityName() + " -> " + subClass.getTable().getName()); // properties createClassProperties(sub, subClass, mappings, sessionFactoryBeanName); }
From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.java
License:Apache License
/** * Binds a sub-class using table-per-hierarchy inheritance mapping * * @param sub The Grails domain class instance representing the sub-class * @param subClass The Hibernate SubClass instance * @param mappings The mappings instance *//*ww w. j a v a2 s . com*/ private static void bindSubClass(GrailsDomainClass sub, Subclass subClass, Mappings mappings, String sessionFactoryBeanName) { bindClass(sub, subClass, mappings); if (subClass.getEntityPersisterClass() == null) { subClass.getRootClass().setEntityPersisterClass(GroovyAwareSingleTableEntityPersister.class); // .setEntityPersisterClass(SingleTableEntityPersister.class); } if (LOG.isDebugEnabled()) LOG.debug("Mapping subclass: " + subClass.getEntityName() + " -> " + subClass.getTable().getName()); // properties createClassProperties(sub, subClass, mappings, sessionFactoryBeanName); }
From source file:org.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java
License:Apache License
/** * Binds a sub-class using table-per-hierarchy inheritance mapping * * @param sub The Grails domain class instance representing the sub-class * @param subClass The Hibernate SubClass instance * @param mappings The mappings instance *///from www .ja v a2s . com protected void bindSubClass(HibernatePersistentEntity sub, Subclass subClass, Mappings mappings, String sessionFactoryBeanName) { bindClass(sub, subClass, mappings); if (subClass.getEntityPersisterClass() == null) { subClass.getRootClass().setEntityPersisterClass(getGroovyAwareSingleTableEntityPersisterClass()); } if (LOG.isDebugEnabled()) LOG.debug("Mapping subclass: " + subClass.getEntityName() + " -> " + subClass.getTable().getName()); // properties createClassProperties(sub, subClass, mappings, sessionFactoryBeanName); }
From source file:org.grails.orm.hibernate.cfg.GrailsDomainBinder.java
License:Apache License
/** * Binds a sub-class using table-per-hierarchy inheritance mapping * * @param sub The Grails domain class instance representing the sub-class * @param subClass The Hibernate SubClass instance * @param mappings The mappings instance *//*from ww w . jav a 2s .co m*/ protected void bindSubClass(HibernatePersistentEntity sub, Subclass subClass, InFlightMetadataCollector mappings, String sessionFactoryBeanName) { bindClass(sub, subClass, mappings); if (LOG.isDebugEnabled()) LOG.debug("Mapping subclass: " + subClass.getEntityName() + " -> " + subClass.getTable().getName()); // properties createClassProperties(sub, subClass, mappings, sessionFactoryBeanName); }
From source file:org.openbravo.dal.core.OBTuplizer.java
License:Open Source License
@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/*from w ww.j a v a 2 s . c o m*/ // 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; }
From source file:org.web4thejob.orm.EntityMetadataImpl.java
License:Open Source License
@SuppressWarnings("unchecked") public EntityMetadataImpl(ClassMetadata classMetadata) { this.classMetadata = classMetadata; this.persistentClass = ContextUtil.getBean(HibernateConfiguration.class).getConfiguration() .getClassMapping(classMetadata.getEntityName()); entityType = getEntityType(classMetadata.getEntityName()); identifier = classMetadata.getIdentifierPropertyName(); identifierType = classMetadata.getIdentifierType(); versioned = classMetadata.getVersionProperty() >= 0; if (MetaUtil.hasMetaAttribute(this.persistentClass, META_FRIENDLY_NAME)) { friendlyName = MetaUtil.getMetaAttribute(this.persistentClass, META_FRIENDLY_NAME); } else {/*from w ww. ja v a 2 s.co m*/ friendlyName = classMetadata.getEntityName(); } if (MetaUtil.hasMetaAttribute(this.persistentClass, META_TABLE_SUBSET)) { tableSubset = Boolean.parseBoolean(MetaUtil.getMetaAttribute(this.persistentClass, META_TABLE_SUBSET)); } else { tableSubset = false; } if (MetaUtil.hasMetaAttribute(this.persistentClass, META_TABLE_CACHED)) { cached = Boolean.parseBoolean(MetaUtil.getMetaAttribute(this.persistentClass, META_TABLE_CACHED)); } else { cached = false; } boolean isAbstract = persistentClass.isAbstract() != null ? persistentClass.isAbstract() : false; if (MetaUtil.hasMetaAttribute(this.persistentClass, META_DENY_ADDNEW)) { denyAddNew = isAbstract || Boolean.parseBoolean(MetaUtil.getMetaAttribute(this.persistentClass, META_DENY_ADDNEW)); } else { denyAddNew = isAbstract; } if (MetaUtil.hasMetaAttribute(this.persistentClass, META_DENY_UPDATE)) { denyUpdate = Boolean.parseBoolean(MetaUtil.getMetaAttribute(this.persistentClass, META_DENY_UPDATE)); } else { denyUpdate = false; } if (MetaUtil.hasMetaAttribute(this.persistentClass, META_DENY_DELETE)) { denyDelete = Boolean.parseBoolean(MetaUtil.getMetaAttribute(this.persistentClass, META_DENY_DELETE)); } else { denyDelete = false; } // id PropertyMetadata propertyMetadata = new PropertyMetadataImpl(this, classMetadata.getIdentifierPropertyName()); propertySet.add(propertyMetadata); propertyMap.put(propertyMetadata.getName(), propertyMetadata); // properties int i = 0; for (final String propertyName : classMetadata.getPropertyNames()) { if (!isBackref(propertyName) && !isVersionProperty(i) && !isDiscriminatorDuplicate(propertyName)) { propertyMetadata = new PropertyMetadataImpl(this, propertyName); propertySet.add(propertyMetadata); propertyMap.put(propertyMetadata.getName(), propertyMetadata); } else { logger.debug("ignoring property of " + classMetadata.getEntityName() + ": " + propertyName); } i++; } // subclasses if (persistentClass.hasSubclasses()) { subclasses = new ArrayList<Class<? extends Entity>>(); for (final Iterator<?> iter = persistentClass.getSubclassIterator(); iter.hasNext();) { Subclass subclass = (Subclass) iter.next(); try { subclasses.add((Class<? extends Entity>) Class.forName(subclass.getEntityName())); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } } } else { subclasses = Collections.emptyList(); } }