List of usage examples for org.hibernate.mapping Component setComponentClassName
public void setComponentClassName(String componentClass)
From source file:com.manydesigns.portofino.persistence.hibernate.HibernateConfig.java
License:Open Source License
protected void createPKComposite(Mappings mappings, com.manydesigns.portofino.model.database.Table mdTable, String pkName, RootClass clazz, Table tab, List<com.manydesigns.portofino.model.database.Column> columnPKList) { PrimaryKey primaryKey = new PrimaryKey(); primaryKey.setName(pkName);//from w w w. ja v a 2 s . c o m primaryKey.setTable(tab); clazz.setEmbeddedIdentifier(true); Component component = new Component(mappings, clazz); component.setDynamic(mdTable.getActualJavaClass() == null); String name; name = mdTable.getQualifiedName(); component.setRoleName(name + ".id"); component.setEmbedded(true); //component.setNodeName("id"); component.setKey(true); component.setNullValue("undefined"); if (!component.isDynamic()) { component.setComponentClassName(mdTable.getJavaClass()); //TODO verificare se non si intende actualJavaClass } boolean hasErrors = false; for (com.manydesigns.portofino.model.database.Column column : columnPKList) { if (column == null) { throw new InternalError("Null column"); } Column col = createColumn(mappings, tab, column); hasErrors = col == null || hasErrors; if (col != null) { primaryKey.addColumn(col); Property prop = createProperty(column, col.getValue()); prop.setCascade("none"); //prop.setPropertyAccessorName("property"); interferisce con il generator pi sotto prop.setPersistentClass(clazz); component.addProperty(prop); //Generator not supported for embedded map identifier //See https://forum.hibernate.org/viewtopic.php?t=945273 //See Component.buildIdentifierGenerator() /*String columnName = column.getColumnName(); PrimaryKeyColumn pkCol = mdTable.getPrimaryKey().findPrimaryKeyColumnByName(columnName); if(pkCol == null) { logger.error("Column without corresponding PrimaryKeyColumn: {}", columnName); hasErrors = true; continue; } Generator generator = pkCol.getGenerator(); setPKColumnGenerator(mappings, clazz, tab, column, value, generator);*/ } } if (hasErrors) { // TODO PAOLO: se la PK non e' buona, tutta la tabella dovrebbe saltare logger.error("Skipping primary key"); return; } tab.setIdentifierValue(component); clazz.setIdentifier(component); clazz.setDiscriminatorValue(name); tab.setPrimaryKey(primaryKey); }
From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java
License:Apache License
protected void bindCompositeId(GrailsDomainClass domainClass, RootClass root, CompositeIdentity compositeIdentity, Mappings mappings, String sessionFactoryBeanName) { Component id = new Component(mappings, root); id.setNullValue("undefined"); root.setIdentifier(id);//from w ww.j a v a2 s. c om root.setEmbeddedIdentifier(true); id.setComponentClassName(domainClass.getFullName()); id.setKey(true); id.setEmbedded(true); String path = qualify(root.getEntityName(), "id"); id.setRoleName(path); String[] props = compositeIdentity.getPropertyNames(); for (String propName : props) { GrailsDomainClassProperty property = domainClass.getPropertyByName(propName); if (property == null) { throw new MappingException( "Property [" + propName + "] referenced in composite-id mapping of class [" + domainClass.getFullName() + "] is not a valid property!"); } bindComponentProperty(id, null, property, root, "", root.getTable(), mappings, sessionFactoryBeanName); } }
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// ww w. j a va 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
private static void bindCompositeId(GrailsDomainClass domainClass, RootClass root, CompositeIdentity compositeIdentity, Mappings mappings, String sessionFactoryBeanName) { Component id = new Component(mappings, root); id.setNullValue("undefined"); root.setIdentifier(id);//from www . j ava 2 s . c o m root.setEmbeddedIdentifier(true); id.setComponentClassName(domainClass.getFullName()); id.setKey(true); id.setEmbedded(true); String path = StringHelper.qualify(root.getEntityName(), "id"); id.setRoleName(path); String[] props = compositeIdentity.getPropertyNames(); for (String propName : props) { GrailsDomainClassProperty property = domainClass.getPropertyByName(propName); if (property == null) { throw new MappingException( "Property [" + propName + "] referenced in composite-id mapping of class [" + domainClass.getFullName() + "] is not a valid property!"); } bindComponentProperty(id, null, property, root, "", root.getTable(), 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//w ww. j av a2 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.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java
License:Apache License
protected void bindCompositeId(PersistentEntity domainClass, RootClass root, CompositeIdentity compositeIdentity, Mappings mappings, String sessionFactoryBeanName) { HibernatePersistentEntity hibernatePersistentEntity = (HibernatePersistentEntity) domainClass; Component id = new Component(mappings, root); id.setNullValue("undefined"); root.setIdentifier(id);/*from w w w. j av a 2 s . co m*/ root.setEmbeddedIdentifier(true); id.setComponentClassName(domainClass.getName()); id.setKey(true); id.setEmbedded(true); String path = qualify(root.getEntityName(), "id"); id.setRoleName(path); final PersistentProperty[] composite = hibernatePersistentEntity.getCompositeIdentity(); for (PersistentProperty property : composite) { if (property == null) { throw new MappingException("Property referenced in composite-id mapping of class [" + domainClass.getName() + "] is not a valid property!"); } bindComponentProperty(id, null, property, root, "", root.getTable(), mappings, sessionFactoryBeanName); } }
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// ww w .ja v a2s.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
protected void bindCompositeId(PersistentEntity domainClass, RootClass root, CompositeIdentity compositeIdentity, InFlightMetadataCollector mappings, String sessionFactoryBeanName) { HibernatePersistentEntity hibernatePersistentEntity = (HibernatePersistentEntity) domainClass; Component id = new Component(mappings, root); id.setNullValue("undefined"); root.setIdentifier(id);/*from w w w . ja va 2 s.com*/ root.setEmbeddedIdentifier(true); id.setComponentClassName(domainClass.getName()); id.setKey(true); id.setEmbedded(true); String path = qualify(root.getEntityName(), "id"); id.setRoleName(path); final PersistentProperty[] composite = hibernatePersistentEntity.getCompositeIdentity(); for (PersistentProperty property : composite) { if (property == null) { throw new MappingException("Property referenced in composite-id mapping of class [" + domainClass.getName() + "] is not a valid property!"); } bindComponentProperty(id, null, property, root, "", root.getTable(), 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/*from w w w . j ava 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, 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); } }