Example usage for org.hibernate.mapping RootClass setEntityPersisterClass

List of usage examples for org.hibernate.mapping RootClass setEntityPersisterClass

Introduction

In this page you can find the example usage for org.hibernate.mapping RootClass setEntityPersisterClass.

Prototype

@Override
    public void setEntityPersisterClass(Class persister) 

Source Link

Usage

From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java

License:Apache License

/**
 * Binds a root class (one with no super classes) to the runtime meta model
 * based on the supplied Grails domain class
 *
 * @param domainClass The Grails domain class
 * @param mappings    The Hibernate Mappings object
 * @param sessionFactoryBeanName  the session factory bean name
 *//*from  ww  w .j av  a  2s . com*/
public void bindRoot(GrailsDomainClass domainClass, Mappings mappings, String sessionFactoryBeanName) {
    if (mappings.getClass(domainClass.getFullName()) != null) {
        LOG.info("[GrailsDomainBinder] Class [" + domainClass.getFullName()
                + "] is already mapped, skipping.. ");
        return;
    }

    RootClass root = new RootClass();
    root.setAbstract(Modifier.isAbstract(domainClass.getClazz().getModifiers()));
    if (!domainClass.hasSubClasses()) {
        root.setPolymorphic(false);
    }
    bindClass(domainClass, root, mappings);

    Mapping m = getMapping(domainClass);

    bindRootPersistentClassCommonValues(domainClass, root, mappings, sessionFactoryBeanName);

    if (!domainClass.getSubClasses().isEmpty()) {
        boolean tablePerSubclass = m != null && !m.getTablePerHierarchy();
        if (!tablePerSubclass) {
            // if the root class has children create a discriminator property
            bindDiscriminatorProperty(root.getTable(), root, mappings);
        }
        // bind the sub classes
        bindSubClasses(domainClass, root, mappings, sessionFactoryBeanName);
    }

    if (root.getEntityPersisterClass() == null) {
        root.setEntityPersisterClass(getGroovyAwareSingleTableEntityPersisterClass());
    }
    mappings.addClass(root);
}

From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.java

License:Apache License

/**
 * Binds a root class (one with no super classes) to the runtime meta model
 * based on the supplied Grails domain class
 *
 * @param domainClass The Grails domain class
 * @param mappings    The Hibernate Mappings object
 * @param sessionFactoryBeanName  the session factory bean name
 *///from   w  ww . j a  v a 2s.  c  o  m
public static void bindRoot(GrailsDomainClass domainClass, Mappings mappings, String sessionFactoryBeanName) {
    if (mappings.getClass(domainClass.getFullName()) != null) {
        LOG.info("[GrailsDomainBinder] Class [" + domainClass.getFullName()
                + "] is already mapped, skipping.. ");
        return;
    }

    RootClass root = new RootClass();
    root.setAbstract(Modifier.isAbstract(domainClass.getClazz().getModifiers()));
    if (!domainClass.hasSubClasses()) {
        root.setPolymorphic(false);
    }
    bindClass(domainClass, root, mappings);

    Mapping m = getMapping(domainClass);

    bindRootPersistentClassCommonValues(domainClass, root, mappings, sessionFactoryBeanName);

    if (!domainClass.getSubClasses().isEmpty()) {
        boolean tablePerSubclass = m != null && !m.getTablePerHierarchy();
        if (!tablePerSubclass) {
            // if the root class has children create a discriminator property
            bindDiscriminatorProperty(root.getTable(), root, mappings);
        }
        // bind the sub classes
        bindSubClasses(domainClass, root, mappings, sessionFactoryBeanName);
    }

    if (root.getEntityPersisterClass() == null) {
        root.setEntityPersisterClass(GroovyAwareSingleTableEntityPersister.class);
    }
    mappings.addClass(root);
}

From source file:org.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java

License:Apache License

/**
 * Binds a root class (one with no super classes) to the runtime meta model
 * based on the supplied Grails domain class
 *
 * @param entity The Grails domain class
 * @param mappings    The Hibernate Mappings object
 * @param sessionFactoryBeanName  the session factory bean name
 *//*ww w  .j  ava2 s  . c o m*/
public void bindRoot(HibernatePersistentEntity entity, Mappings mappings, String sessionFactoryBeanName) {
    if (mappings.getClass(entity.getName()) != null) {
        LOG.info("[GrailsDomainBinder] Class [" + entity.getName() + "] is already mapped, skipping.. ");
        return;
    }

    RootClass root = new RootClass();
    root.setAbstract(entity.isAbstract());
    final MappingContext mappingContext = entity.getMappingContext();
    final java.util.Collection<PersistentEntity> children = mappingContext.getDirectChildEntities(entity);
    if (children.isEmpty()) {
        root.setPolymorphic(false);
    }
    bindClass(entity, root, mappings);

    Mapping m = getMapping(entity);

    bindRootPersistentClassCommonValues(entity, root, mappings, sessionFactoryBeanName);

    if (!children.isEmpty()) {
        boolean tablePerSubclass = m != null && !m.getTablePerHierarchy();
        if (!tablePerSubclass) {
            // if the root class has children create a discriminator property
            bindDiscriminatorProperty(root.getTable(), root, mappings);
        }
        // bind the sub classes
        bindSubClasses(entity, root, mappings, sessionFactoryBeanName);
    }

    if (root.getEntityPersisterClass() == null) {
        root.setEntityPersisterClass(getGroovyAwareSingleTableEntityPersisterClass());
    }
    mappings.addClass(root);
}