List of usage examples for org.hibernate.mapping RootClass setIdentifier
public void setIdentifier(KeyValue identifier)
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 ww. java 2s . c om 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:com.manydesigns.portofino.persistence.hibernate.HibernateConfig.java
License:Open Source License
protected void createPKSingle(Mappings mappings, com.manydesigns.portofino.model.database.Table mdTable, String pkName, RootClass clazz, Table tab, List<com.manydesigns.portofino.model.database.Column> columnPKList) { PrimaryKeyColumn pkcol = mdTable.getPrimaryKey().getPrimaryKeyColumns().get(0); com.manydesigns.portofino.model.database.Column column = columnPKList.get(0); final PrimaryKey primaryKey = new PrimaryKey(); primaryKey.setName(pkName);//w w w . ja v a 2s.c om primaryKey.setTable(tab); tab.setPrimaryKey(primaryKey); Column col = createColumn(mappings, tab, column); if (col == null) { // TODO PAOLO: se la PK non e' buona, tutta la tabella dovrebbe saltare logger.error("Skipping primary key"); return; } SimpleValue id = (SimpleValue) col.getValue(); //Make the defaults explicit. See section 5.1.4.5. Assigned identifiers in the Hibernate reference //(http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html) id.setIdentifierGeneratorStrategy("assigned"); id.setNullValue("undefined"); tab.getPrimaryKey().addColumn(col); Property prop = createProperty(column, id); clazz.addProperty(prop); prop.setPropertyAccessorName(mappings.getDefaultAccess()); //PropertyGeneration generation = PropertyGeneration.parse(null); //prop.setGeneration(generation); prop.setInsertable(false); prop.setUpdateable(false); Generator generator = pkcol.getGenerator(); setPKColumnGenerator(mappings, clazz, tab, column, id, generator); tab.setIdentifierValue(id); clazz.setIdentifier(id); clazz.setIdentifierProperty(prop); clazz.setDiscriminatorValue(mdTable.getQualifiedName()); }
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); root.setEmbeddedIdentifier(true);//from w ww.j a va2 s.co m 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
@SuppressWarnings("unchecked") protected void bindSimpleId(GrailsDomainClassProperty identifier, RootClass entity, Mappings mappings, Identity mappedId, String sessionFactoryBeanName) { Mapping mapping = getMapping(identifier.getDomainClass()); boolean useSequence = mapping != null && mapping.isTablePerConcreteClass(); // create the id value SimpleValue id = new SimpleValue(mappings, entity.getTable()); // set identifier on entity Properties params = new Properties(); entity.setIdentifier(id); if (mappedId == null) { // configure generator strategy id.setIdentifierGeneratorStrategy(useSequence ? "sequence-identity" : "native"); } else {/*w w w . j a v a2 s. c o m*/ String generator = mappedId.getGenerator(); if ("native".equals(generator) && useSequence) { generator = "sequence-identity"; } id.setIdentifierGeneratorStrategy(generator); params.putAll(mappedId.getParams()); if ("assigned".equals(generator)) { id.setNullValue("undefined"); } } params.put(PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER, mappings.getObjectNameNormalizer()); if (mappings.getSchemaName() != null) { params.setProperty(PersistentIdentifierGenerator.SCHEMA, mappings.getSchemaName()); } if (mappings.getCatalogName() != null) { params.setProperty(PersistentIdentifierGenerator.CATALOG, mappings.getCatalogName()); } id.setIdentifierGeneratorProperties(params); // bind value bindSimpleValue(identifier, null, id, EMPTY_PATH, mappings, sessionFactoryBeanName); // create property Property prop = new Property(); prop.setValue(id); // bind property bindProperty(identifier, prop, mappings); // set identifier property entity.setIdentifierProperty(prop); id.getTable().setIdentifierValue(id); }
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); root.setEmbeddedIdentifier(true);//from w ww .ja v a2 s . c o m 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
@SuppressWarnings("unchecked") private static void bindSimpleId(GrailsDomainClassProperty identifier, RootClass entity, Mappings mappings, Identity mappedId, String sessionFactoryBeanName) { // create the id value SimpleValue id = new SimpleValue(mappings, entity.getTable()); // set identifier on entity Properties params = new Properties(); entity.setIdentifier(id); if (mappedId != null) { id.setIdentifierGeneratorStrategy(mappedId.getGenerator()); params.putAll(mappedId.getParams()); if ("assigned".equals(mappedId.getGenerator())) { id.setNullValue("undefined"); }/*w ww . j ava 2 s .com*/ } else { // configure generator strategy id.setIdentifierGeneratorStrategy("native"); } params.put(PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER, mappings.getObjectNameNormalizer()); if (mappings.getSchemaName() != null) { params.setProperty(PersistentIdentifierGenerator.SCHEMA, mappings.getSchemaName()); } if (mappings.getCatalogName() != null) { params.setProperty(PersistentIdentifierGenerator.CATALOG, mappings.getCatalogName()); } id.setIdentifierGeneratorProperties(params); // bind value bindSimpleValue(identifier, null, id, EMPTY_PATH, mappings, sessionFactoryBeanName); // create property Property prop = new Property(); prop.setValue(id); // bind property bindProperty(identifier, prop, mappings); // set identifier property entity.setIdentifierProperty(prop); id.getTable().setIdentifierValue(id); }
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); root.setEmbeddedIdentifier(true);/*from w w w.j a v a 2 s. c o m*/ 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
@SuppressWarnings("unchecked") protected void bindSimpleId(PersistentProperty identifier, RootClass entity, Mappings mappings, Identity mappedId, String sessionFactoryBeanName) { Mapping mapping = getMapping(identifier.getOwner()); boolean useSequence = mapping != null && mapping.isTablePerConcreteClass(); // create the id value SimpleValue id = new SimpleValue(mappings, entity.getTable()); // set identifier on entity Properties params = new Properties(); entity.setIdentifier(id); if (mappedId == null) { // configure generator strategy id.setIdentifierGeneratorStrategy(useSequence ? "sequence-identity" : "native"); } else {//from w ww . j a v a 2 s . co m String generator = mappedId.getGenerator(); if ("native".equals(generator) && useSequence) { generator = "sequence-identity"; } id.setIdentifierGeneratorStrategy(generator); params.putAll(mappedId.getParams()); if ("assigned".equals(generator)) { id.setNullValue("undefined"); } } params.put(PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER, mappings.getObjectNameNormalizer()); if (mappings.getSchemaName() != null) { params.setProperty(PersistentIdentifierGenerator.SCHEMA, mappings.getSchemaName()); } if (mappings.getCatalogName() != null) { params.setProperty(PersistentIdentifierGenerator.CATALOG, mappings.getCatalogName()); } id.setIdentifierGeneratorProperties(params); // bind value bindSimpleValue(identifier, null, id, EMPTY_PATH, mappings, sessionFactoryBeanName); // create property Property prop = new Property(); prop.setValue(id); // bind property bindProperty(identifier, prop, mappings); // set identifier property entity.setIdentifierProperty(prop); id.getTable().setIdentifierValue(id); }
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); root.setEmbeddedIdentifier(true);// ww w . j ava 2 s . c o m 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
@SuppressWarnings("unchecked") protected void bindSimpleId(PersistentProperty identifier, RootClass entity, InFlightMetadataCollector mappings, Identity mappedId, String sessionFactoryBeanName) { Mapping mapping = getMapping(identifier.getOwner()); boolean useSequence = mapping != null && mapping.isTablePerConcreteClass(); // create the id value SimpleValue id = new SimpleValue(mappings, entity.getTable()); // set identifier on entity Properties params = new Properties(); entity.setIdentifier(id); if (mappedId == null) { // configure generator strategy id.setIdentifierGeneratorStrategy(useSequence ? "sequence-identity" : "native"); } else {//from w ww. ja va2s . com String generator = mappedId.getGenerator(); if ("native".equals(generator) && useSequence) { generator = "sequence-identity"; } id.setIdentifierGeneratorStrategy(generator); params.putAll(mappedId.getParams()); if (params.containsKey(SEQUENCE_KEY)) { params.put(SequenceStyleGenerator.SEQUENCE_PARAM, params.getProperty(SEQUENCE_KEY)); } if ("assigned".equals(generator)) { id.setNullValue("undefined"); } } String schemaName = getSchemaName(mappings); String catalogName = getCatalogName(mappings); params.put(PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER, this.metadataBuildingContext.getObjectNameNormalizer()); if (schemaName != null) { params.setProperty(PersistentIdentifierGenerator.SCHEMA, schemaName); } if (catalogName != null) { params.setProperty(PersistentIdentifierGenerator.CATALOG, catalogName); } id.setIdentifierGeneratorProperties(params); // bind value bindSimpleValue(identifier, null, id, EMPTY_PATH, mappings, sessionFactoryBeanName); // create property Property prop = new Property(); prop.setValue(id); // bind property bindProperty(identifier, prop, mappings); // set identifier property entity.setIdentifierProperty(prop); id.getTable().setIdentifierValue(id); }