Example usage for org.hibernate.mapping Component getOwner

List of usage examples for org.hibernate.mapping Component getOwner

Introduction

In this page you can find the example usage for org.hibernate.mapping Component getOwner.

Prototype

public PersistentClass getOwner() 

Source Link

Usage

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

License:Apache License

/**
 * Binds a Hibernate component type using the given GrailsDomainClassProperty instance
 *
 * @param component  The component to bind
 * @param property   The property//from   w w w  . ja v  a 2s  . c  o m
 * @param isNullable Whether it is nullable or not
 * @param mappings   The Hibernate Mappings object
 * @param sessionFactoryBeanName  the session factory bean name
 */
protected void bindComponent(Component component, GrailsDomainClassProperty property, boolean isNullable,
        Mappings mappings, String sessionFactoryBeanName) {
    component.setEmbedded(true);
    Class<?> type = property.getType();
    String role = qualify(type.getName(), property.getName());
    component.setRoleName(role);
    component.setComponentClassName(type.getName());

    GrailsDomainClass domainClass = property.getReferencedDomainClass() != null
            ? property.getReferencedDomainClass()
            : property.getComponent();

    evaluateMapping(domainClass);
    GrailsDomainClassProperty[] properties = domainClass.getPersistentProperties();
    Table table = component.getOwner().getTable();
    PersistentClass persistentClass = component.getOwner();
    String path = property.getName();
    Class<?> propertyType = property.getDomainClass().getClazz();

    for (GrailsDomainClassProperty currentGrailsProp : properties) {
        if (currentGrailsProp.isIdentity())
            continue;
        if (currentGrailsProp.getName().equals(GrailsDomainClassProperty.VERSION))
            continue;

        if (currentGrailsProp.getType().equals(propertyType)) {
            component.setParentProperty(currentGrailsProp.getName());
            continue;
        }

        bindComponentProperty(component, property, currentGrailsProp, persistentClass, path, table, mappings,
                sessionFactoryBeanName);
    }
}

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

License:Apache License

/**
 * Binds a Hibernate component type using the given GrailsDomainClassProperty instance
 *
 * @param component  The component to bind
 * @param property   The property/*  ww w.  j av  a  2  s  .  c  o  m*/
 * @param isNullable Whether it is nullable or not
 * @param mappings   The Hibernate Mappings object
 * @param sessionFactoryBeanName  the session factory bean name
 */
private static void bindComponent(Component component, GrailsDomainClassProperty property,
        @SuppressWarnings("unused") boolean isNullable, Mappings mappings, String sessionFactoryBeanName) {
    component.setEmbedded(true);
    Class<?> type = property.getType();
    String role = StringHelper.qualify(type.getName(), property.getName());
    component.setRoleName(role);
    component.setComponentClassName(type.getName());

    GrailsDomainClass domainClass = property.getReferencedDomainClass() != null
            ? property.getReferencedDomainClass()
            : property.getComponent();

    evaluateMapping(domainClass);
    GrailsDomainClassProperty[] properties = domainClass.getPersistentProperties();
    Table table = component.getOwner().getTable();
    PersistentClass persistentClass = component.getOwner();
    String path = property.getName();
    Class<?> propertyType = property.getDomainClass().getClazz();

    for (GrailsDomainClassProperty currentGrailsProp : properties) {
        if (currentGrailsProp.isIdentity())
            continue;
        if (currentGrailsProp.getName().equals(GrailsDomainClassProperty.VERSION))
            continue;

        if (currentGrailsProp.getType().equals(propertyType)) {
            component.setParentProperty(currentGrailsProp.getName());
            continue;
        }

        bindComponentProperty(component, property, currentGrailsProp, persistentClass, path, table, mappings,
                sessionFactoryBeanName);
    }
}

From source file:org.eclipse.emf.teneo.hibernate.mapping.elist.FeatureMapEntryComponentTuplizer.java

License:Open Source License

protected PropertyAccessor getPropertyAccessor(Property mappedProperty, Component component) {
    final HbDataStore hds = HbHelper.INSTANCE.getDataStore(component.getOwner());
    if (mappedProperty.getMetaAttribute(HbMapperConstants.VERSION_META) != null) {
        return hds.getHbContext().createVersionAccessor();
    } else if (mappedProperty.getName().compareToIgnoreCase(HbMapperConstants.PROPERTY_FEATURE) == 0) {
        return hds.getHbContext().createFeatureMapEntryFeatureURIAccessor();
    } else if (mappedProperty.getName().compareToIgnoreCase(HbMapperConstants.PROPERTY_MIXED_CDATA) == 0) {
        return hds.getHbContext().createFeatureMapEntryAccessor(Constants.CDATA);
    } else if (mappedProperty.getName().compareToIgnoreCase(HbMapperConstants.PROPERTY_MIXED_COMMENT) == 0) {
        return hds.getHbContext().createFeatureMapEntryAccessor(Constants.COMMENT);
    } else if (mappedProperty.getName().compareToIgnoreCase(HbMapperConstants.PROPERTY_MIXED_TEXT) == 0) {
        return hds.getHbContext().createFeatureMapEntryAccessor(Constants.TEXT);
    } else if (mappedProperty.getName().endsWith(HbMapperConstants.PROPERTY_ANY_PRIMITIVE)) {
        return hds.getExtensionManager().getExtension(WildCardAttributePropertyHandler.class);
    } else if (mappedProperty.getName().endsWith(HbMapperConstants.PROPERTY_ANY_REFERENCE)) {
        return hds.getExtensionManager().getExtension(WildCardReferencePropertyHandler.class);
    }//from   w  ww .j  ava  2 s  .  com

    final MetaAttribute ma = component.getMetaAttribute(HbMapperConstants.FEATUREMAP_META);
    final String eclassUri = ma.getValue();
    final EClass eClass = hds.getEntityNameStrategy().toEClass(eclassUri);
    final EStructuralFeature efeature = StoreUtil.getEStructuralFeature(eClass, mappedProperty.getName());

    if (efeature == null) {
        throw new HbMapperException("Feature not found for property " + mappedProperty.getName());
    }

    if (log.isDebugEnabled()) {
        log.debug("Creating property accessor for " + mappedProperty.getName() + "/" + eclassUri + "/"
                + efeature.getName());
    }

    return hds.getHbContext().createFeatureMapEntryAccessor(efeature);
}

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

License:Apache License

/**
 * Binds a Hibernate component type using the given GrailsDomainClassProperty instance
 *
 * @param component  The component to bind
 * @param property   The property//w  w w  .j a  v  a2  s.  c om
 * @param isNullable Whether it is nullable or not
 * @param mappings   The Hibernate Mappings object
 * @param sessionFactoryBeanName  the session factory bean name
 */
protected void bindComponent(Component component, Embedded property, boolean isNullable, Mappings mappings,
        String sessionFactoryBeanName) {
    component.setEmbedded(true);
    Class<?> type = property.getType();
    String role = qualify(type.getName(), property.getName());
    component.setRoleName(role);
    component.setComponentClassName(type.getName());

    PersistentEntity domainClass = property.getAssociatedEntity();
    evaluateMapping(domainClass, defaultMapping);
    final List<PersistentProperty> properties = domainClass.getPersistentProperties();
    Table table = component.getOwner().getTable();
    PersistentClass persistentClass = component.getOwner();
    String path = property.getName();
    Class<?> propertyType = property.getOwner().getJavaClass();

    for (PersistentProperty currentGrailsProp : properties) {
        if (currentGrailsProp.equals(domainClass.getIdentity()))
            continue;
        if (currentGrailsProp.getName().equals(GormProperties.VERSION))
            continue;

        if (currentGrailsProp.getType().equals(propertyType)) {
            component.setParentProperty(currentGrailsProp.getName());
            continue;
        }

        bindComponentProperty(component, property, currentGrailsProp, persistentClass, path, table, mappings,
                sessionFactoryBeanName);
    }
}

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

License:Apache License

/**
 * Binds a Hibernate component type using the given GrailsDomainClassProperty instance
 *
 * @param component  The component to bind
 * @param property   The property/*w  w  w.ja v a 2s .co  m*/
 * @param isNullable Whether it is nullable or not
 * @param mappings   The Hibernate Mappings object
 * @param sessionFactoryBeanName  the session factory bean name
 */
protected void bindComponent(Component component, Embedded property, boolean isNullable,
        InFlightMetadataCollector mappings, String sessionFactoryBeanName) {
    component.setEmbedded(true);
    Class<?> type = property.getType();
    String role = qualify(type.getName(), property.getName());
    component.setRoleName(role);
    component.setComponentClassName(type.getName());

    PersistentEntity domainClass = property.getAssociatedEntity();
    evaluateMapping(domainClass, defaultMapping);
    final List<PersistentProperty> properties = domainClass.getPersistentProperties();
    Table table = component.getOwner().getTable();
    PersistentClass persistentClass = component.getOwner();
    String path = property.getName();
    Class<?> propertyType = property.getOwner().getJavaClass();

    for (PersistentProperty currentGrailsProp : properties) {
        if (currentGrailsProp.equals(domainClass.getIdentity()))
            continue;
        if (currentGrailsProp.getName().equals(GormProperties.VERSION))
            continue;

        if (currentGrailsProp.getType().equals(propertyType)) {
            component.setParentProperty(currentGrailsProp.getName());
            continue;
        }

        bindComponentProperty(component, property, currentGrailsProp, persistentClass, path, table, mappings,
                sessionFactoryBeanName);
    }
}

From source file:org.jboss.tools.hibernate.ui.diagram.editors.model.SpecialRootClass.java

License:Open Source License

@SuppressWarnings("unchecked")
private void generate() {
    if (property == null) {
        return;/*from  w w  w . ja  v a 2 s  .  c  o  m*/
    }
    Component component = null;
    if (property.getValue() instanceof Collection) {
        Collection collection = (Collection) property.getValue();
        component = (Component) collection.getElement();
    } else if (property.getValue() instanceof Component) {
        component = (Component) property.getValue();
    }
    if (component != null) {
        setClassName(component.getComponentClassName());
        setEntityName(component.getComponentClassName());
        PersistentClass ownerClass = component.getOwner();
        if (component.getParentProperty() != null) {
            parentProperty = new Property();
            parentProperty.setName(component.getParentProperty());
            parentProperty.setPersistentClass(ownerClass);
        }
        Iterator<Property> iterator = component.getPropertyIterator();
        while (iterator.hasNext()) {
            Property property = iterator.next();
            if (property != null) {
                addProperty(property);
            }
        }
    }
}