Example usage for org.hibernate.mapping RootClass getProperty

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

Introduction

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

Prototype

public Property getProperty(String propertyName) throws MappingException 

Source Link

Usage

From source file:com.wavemaker.runtime.data.hibernate.DataServiceMetaData_Hib.java

License:Open Source License

@Override
public boolean isCompositeProperty(Class<?> c, String propertyName) {

    if (!isEntity(c)) {
        throw new DataServiceRuntimeException(c + " is not an entity");
    }//from   w  w w  .j av a2s  .c om

    RootClass rc = getRootClass(c);

    Property p = rc.getProperty(propertyName);

    return p.isComposite();
}

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
 *//*www .j  a va 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);
}