Example usage for org.hibernate.mapping RootClass setAbstract

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

Introduction

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

Prototype

public void setAbstract(Boolean isAbstract) 

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
 *//*w  w w  . jav a 2s.  c o  m*/
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
 *///  ww  w  . j a  v a 2 s. 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
 *//*from  ww w  .j  a v a 2 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);
}

From source file:org.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 entity The Grails domain class
 * @param mappings    The Hibernate Mappings object
 * @param sessionFactoryBeanName  the session factory bean name
 *//*w ww .  j a  v a 2  s. c  o m*/
public void bindRoot(HibernatePersistentEntity entity, InFlightMetadataCollector mappings,
        String sessionFactoryBeanName) {
    if (mappings.getEntityBinding(entity.getName()) != null) {
        LOG.info("[GrailsDomainBinder] Class [" + entity.getName() + "] is already mapped, skipping.. ");
        return;
    }

    RootClass root = new RootClass(this.metadataBuildingContext);
    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 (entity.isMultiTenant()) {
        TenantId tenantId = entity.getTenantId();
        if (tenantId != null) {
            String filterCondition = getMultiTenantFilterCondition(sessionFactoryBeanName, entity);
            root.addFilter(GormProperties.TENANT_IDENTITY, filterCondition, true,
                    Collections.<String, String>emptyMap(), Collections.<String, String>emptyMap());
            mappings.addFilterDefinition(new FilterDefinition(GormProperties.TENANT_IDENTITY, filterCondition,
                    Collections.singletonMap(GormProperties.TENANT_IDENTITY,
                            root.getProperty(tenantId.getName()).getType())));
        }

    }
    mappings.addEntityBinding(root);
}