List of usage examples for org.hibernate.mapping Property setName
public void setName(String name)
From source file:com.javaetmoi.core.persistence.hibernate.TestReflectionUtil.java
License:Apache License
@Before public void setUp() { Configuration configuration = new Configuration(); Mappings mappings = configuration.createMappings(); Component component = new Component(mappings, new RootClass()); Property p1 = new Property(); p1.setName("client"); SimpleValue p1val = new SimpleValue(mappings); p1val.setTypeName("java.lang.Integer"); p1.setValue(p1val); component.addProperty(p1);//w w w . j a v a 2 s . c o m Property p2 = new Property(); p2.setName("user"); SimpleValue p2val = new SimpleValue(mappings); p2val.setTypeName("java.lang.String"); p2.setValue(p2val); component.addProperty(p2); metadata = new ComponentMetamodel(component); }
From source file:com.manydesigns.portofino.persistence.hibernate.HibernateConfig.java
License:Open Source License
protected Property createProperty(com.manydesigns.portofino.model.database.Column column, Value value) { Property prop = new Property(); prop.setName(column.getActualPropertyName()); //prop.setNodeName(column.getActualPropertyName()); prop.setValue(value);//from w w w. ja v a2 s.com return prop; }
From source file:com.manydesigns.portofino.persistence.hibernate.HibernateConfig.java
License:Open Source License
protected void createO2M(Configuration config, Mappings mappings, ForeignKey relationship) { com.manydesigns.portofino.model.database.Table manyMDTable = relationship.getFromTable(); com.manydesigns.portofino.model.database.Table oneMDTable = relationship.getToTable(); //Se la classe One non e' dinamica e // non ha la proprieta' non inserisco la relazione if (oneMDTable.getJavaClass() != null) { try {//from ww w.j a v a2s .c om Class oneClass = oneMDTable.getActualJavaClass(); JavaClassAccessor accessor = JavaClassAccessor.getClassAccessor(oneClass); PropertyAccessor[] propertyAccessors = accessor.getProperties(); boolean found = false; for (PropertyAccessor propertyAccessor : propertyAccessors) { if (propertyAccessor.getName().equals(relationship.getActualManyPropertyName())) { found = true; } } if (!found) { logger.warn("Property '{}' not found, skipping relationship {}", relationship.getActualManyPropertyName(), relationship.getQualifiedName()); return; } } catch (Exception e) { //se non c'e' non inserisco la relazione logger.warn("Property not found, skipping relationship ", e); return; } } //relazione virtuali fra Database differenti if (!manyMDTable.getDatabaseName().equalsIgnoreCase(oneMDTable.getDatabaseName())) { logger.warn("Relationship crosses databases, skipping: {}", relationship.getQualifiedName()); return; } String manyMDQualifiedTableName = manyMDTable.getActualEntityName(); String oneMDQualifiedTableName = oneMDTable.getActualEntityName(); PersistentClass clazzOne = config.getClassMapping(oneMDQualifiedTableName); if (clazzOne == null) { logger.error("Cannot find table '{}' as 'one' side of foreign key '{}'. Skipping relationship.", oneMDQualifiedTableName, relationship.getName()); return; } PersistentClass clazzMany = config.getClassMapping(manyMDQualifiedTableName); if (clazzMany == null) { logger.error("Cannot find table '{}' as 'many' side of foreign key '{}'. Skipping relationship.", manyMDQualifiedTableName, relationship.getName()); return; } //Uso i Bag perche' i set non funzionano con i componenti dinamici Bag set = new Bag(mappings, clazzOne); // Mettere Lazy in debug a false per ottenere subito eventuali errori // nelle relazioni set.setLazy(LAZY); set.setRole( relationship.getToTable().getActualEntityName() + "." + relationship.getActualManyPropertyName()); //set.setNodeName(relationship.getActualManyPropertyName()); set.setCollectionTable(clazzMany.getTable()); OneToMany oneToMany = new OneToMany(mappings, set.getOwner()); set.setElement(oneToMany); oneToMany.setReferencedEntityName(manyMDQualifiedTableName); oneToMany.setAssociatedClass(clazzMany); oneToMany.setEmbedded(true); set.setSorted(false); set.setFetchMode(FetchMode.DEFAULT); //Riferimenti alle colonne DependantValue dv; Table tableMany = clazzMany.getTable(); Table tableOne = clazzOne.getTable(); List<Column> oneColumns = new ArrayList<Column>(); List<Column> manyColumns = new ArrayList<Column>(); //Chiave multipla final List<Reference> refs = relationship.getReferences(); if (refs.size() > 1) { dv = createFKComposite(mappings, relationship, manyMDTable, clazzOne, clazzMany, set, tableMany, tableOne, oneColumns, manyColumns); } else { //chiave straniera singola dv = createFKSingle(mappings, clazzOne, clazzMany, tableOne, oneColumns, manyColumns, refs); } tableMany.createForeignKey(relationship.getName(), manyColumns, oneMDQualifiedTableName, oneColumns); dv.setNullable(false); set.setKey(dv); mappings.addCollection(set); Property prop = new Property(); prop.setName(relationship.getActualManyPropertyName()); //prop.setNodeName(relationship.getActualManyPropertyName()); prop.setValue(set); if (ForeignKeyConstraintType.importedKeyCascade.name().equalsIgnoreCase(relationship.getOnDelete())) { prop.setCascade("delete"); } else { prop.setCascade("none"); } clazzOne.addProperty(prop); //if(!StringUtils.) }
From source file:com.manydesigns.portofino.persistence.hibernate.HibernateConfig.java
License:Open Source License
protected void createM2O(Configuration config, Mappings mappings, ForeignKey relationship) { com.manydesigns.portofino.model.database.Table manyMDTable = relationship.getFromTable(); com.manydesigns.portofino.model.database.Table oneMDTable = relationship.getToTable(); String manyMDQualifiedTableName = manyMDTable.getActualEntityName(); String oneMDQualifiedTableName = oneMDTable.getActualEntityName(); RootClass clazz = (RootClass) mappings.getClass(manyMDQualifiedTableName); if (clazz == null) { logger.error("Cannot find table '{}' as 'many' side of foreign key '{}'. Skipping relationship.", manyMDQualifiedTableName, relationship.getName()); return;// www.j a va 2 s .co m } Table tab = clazz.getTable(); List<String> columnNames = new ArrayList<String>(); for (Reference ref : relationship.getReferences()) { if (ref.getActualFromColumn() == null) { logger.error("Missing from column {}, skipping relationship", ref.getFromColumn()); return; } columnNames.add(ref.getFromColumn()); } ManyToOne m2o = new ManyToOne(mappings, tab); m2o.setLazy(LAZY); final HashMap<String, PersistentClass> persistentClasses = new HashMap<String, PersistentClass>(); persistentClasses.put(oneMDQualifiedTableName, config.getClassMapping(oneMDQualifiedTableName)); m2o.setReferencedEntityName(oneMDQualifiedTableName); m2o.createPropertyRefConstraints(persistentClasses); PersistentClass manyClass = config.getClassMapping(manyMDQualifiedTableName); for (String columnName : columnNames) { Column col = new Column(); col.setName(escapeName(columnName)); //Recupero la colonna precedentemente associata alla tabella: //essa ha uno uniqueIdentifier generato al momento dell'associazione alla tabella; //questo viene utilizzato per disambiguare l'alias della colonna nelle query //SQL generate da Hibernate. col = manyClass.getTable().getColumn(col); if (col == null) { logger.error("Column not found in 'many' entity {}: {}, " + "skipping relationship", manyClass.getEntityName(), columnName); return; } m2o.addColumn(col); } Property prop = new Property(); prop.setName(relationship.getActualOnePropertyName()); //prop.setNodeName(relationship.getActualOnePropertyName()); prop.setValue(m2o); prop.setCascade("none"); //TODO era "all", capire prop.setInsertable(false); prop.setUpdateable(false); clazz.addProperty(prop); }
From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java
License:Apache License
/** * Binds a property to Hibernate runtime meta model. Deals with cascade strategy based on the Grails domain model * * @param grailsProperty The grails property instance * @param prop The Hibernate property * @param mappings The Hibernate mappings */// ww w. j ava 2 s. com protected void bindProperty(GrailsDomainClassProperty grailsProperty, Property prop, Mappings mappings) { // set the property name prop.setName(grailsProperty.getName()); if (isBidirectionalManyToOneWithListMapping(grailsProperty, prop)) { prop.setInsertable(false); prop.setUpdateable(false); } else { prop.setInsertable(getInsertableness(grailsProperty)); prop.setUpdateable(getUpdateableness(grailsProperty)); } prop.setPropertyAccessorName(mappings.getDefaultAccess()); prop.setOptional(grailsProperty.isOptional()); setCascadeBehaviour(grailsProperty, prop); // lazy to true boolean isLazyable = grailsProperty.isOneToOne() || grailsProperty.isManyToOne() || grailsProperty.isEmbedded() || grailsProperty.isPersistent() && !grailsProperty.isAssociation() && !grailsProperty.isIdentity(); if (isLazyable) { final boolean isLazy = getLaziness(grailsProperty); prop.setLazy(isLazy); if (isLazy && (grailsProperty.isManyToOne() || grailsProperty.isOneToOne())) { handleLazyProxy(grailsProperty.getDomainClass(), grailsProperty); } } }
From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.java
License:Apache License
/** * Binds a property to Hibernate runtime meta model. Deals with cascade strategy based on the Grails domain model * * @param grailsProperty The grails property instance * @param prop The Hibernate property * @param mappings The Hibernate mappings *//*from w ww . j av a 2s. co m*/ private static void bindProperty(GrailsDomainClassProperty grailsProperty, Property prop, Mappings mappings) { // set the property name prop.setName(grailsProperty.getName()); if (isBidirectionalManyToOneWithListMapping(grailsProperty, prop)) { prop.setInsertable(false); prop.setUpdateable(false); } else { prop.setInsertable(getInsertableness(grailsProperty)); prop.setUpdateable(getUpdateableness(grailsProperty)); } prop.setPropertyAccessorName(mappings.getDefaultAccess()); prop.setOptional(grailsProperty.isOptional()); setCascadeBehaviour(grailsProperty, prop); // lazy to true boolean isLazyable = grailsProperty.isOneToOne() || grailsProperty.isManyToOne() || grailsProperty.isEmbedded() || grailsProperty.isPersistent() && !grailsProperty.isAssociation() && !grailsProperty.isIdentity(); if (isLazyable) { final boolean isLazy = getLaziness(grailsProperty); prop.setLazy(isLazy); if (isLazy && (grailsProperty.isManyToOne() || grailsProperty.isOneToOne())) { HibernatePluginSupport.handleLazyProxy(grailsProperty.getDomainClass(), grailsProperty); } } }
From source file:org.eclipse.emf.teneo.hibernate.HbDataStore.java
License:Open Source License
/** * Extra lazy mapping for lists needs a real property for the list index and * a real inverse for the other side as well. * //from w w w. j a va 2s .c om * This method iterates over all associations and adds an inverse for the * list and set mappings. */ protected void addExtraLazyInverseProperties() { final Map<String, PersistentClass> persistentClasses = new HashMap<String, PersistentClass>(); for (Iterator<?> pcs = getClassMappings(); pcs.hasNext();) { final PersistentClass pc = (PersistentClass) pcs.next(); if (isClassOrSuperClassEAVMapped(pc)) { continue; } persistentClasses.put(pc.getEntityName(), pc); } for (Iterator<?> pcs = getClassMappings(); pcs.hasNext();) { final PersistentClass pc = (PersistentClass) pcs.next(); // copy to prevent concurrent modification final Iterator<?> propIt = pc.getPropertyIterator(); final List<Property> props = new ArrayList<Property>(); while (propIt.hasNext()) { final Property prop = (Property) propIt.next(); props.add(prop); } for (Property prop : props) { EClass eClass = null; if (pc.getMetaAttribute(HbMapperConstants.FEATUREMAP_META) == null) { if (pc.getEntityName() != null) { eClass = getEntityNameStrategy().toEClass(pc.getEntityName()); } else { eClass = EModelResolver.instance().getEClass(pc.getMappedClass()); } } final EStructuralFeature ef = eClass == null ? null : StoreUtil.getEStructuralFeature(eClass, prop.getName()); if (ef != null && ef instanceof EReference && prop.getValue() instanceof Collection) { final Collection collection = (Collection) prop.getValue(); final EReference eReference = (EReference) ef; // only work for extra lazy if (!collection.isExtraLazy()) { continue; } final Value elementValue = collection.getElement(); final PersistentClass elementPC; if (elementValue instanceof OneToMany) { final OneToMany oneToMany = (OneToMany) elementValue; elementPC = oneToMany.getAssociatedClass(); } else if (elementValue instanceof ManyToOne) { final ManyToOne mto = (ManyToOne) elementValue; elementPC = persistentClasses.get(mto.getReferencedEntityName()); } else { continue; } if (isClassOrSuperClassEAVMapped(elementPC)) { continue; } collection.setInverse(true); // and add an eopposite if (eReference.getEOpposite() == null) { final Table collectionTable = collection.getCollectionTable(); if (isClassOrSuperClassEAVMapped(elementPC)) { continue; } final Property inverseRefProperty = new Property(); inverseRefProperty.setName(StoreUtil.getExtraLazyInversePropertyName(ef)); final Map<Object, Object> metas = new HashMap<Object, Object>(); final MetaAttribute metaAttribute = new MetaAttribute( HbConstants.SYNTHETIC_PROPERTY_INDICATOR); metaAttribute.addValue("true"); metas.put(HbConstants.SYNTHETIC_PROPERTY_INDICATOR, metaAttribute); inverseRefProperty.setMetaAttributes(metas); inverseRefProperty.setNodeName(inverseRefProperty.getName()); inverseRefProperty.setPropertyAccessorName(SyntheticPropertyHandler.class.getName()); inverseRefProperty.setLazy(false); final ManyToOne mto = new ManyToOne(getMappings(), collectionTable); mto.setReferencedEntityName(pc.getEntityName()); mto.setLazy(false); mto.setFetchMode(FetchMode.SELECT); inverseRefProperty.setValue(mto); final Iterator<?> it = collection.getKey().getColumnIterator(); while (it.hasNext()) { final Column originalColumn = (Column) it.next(); // final Column newColumn = new // Column(originalColumn.getName()); mto.addColumn(originalColumn); } mto.createForeignKey(); // now determine if a join should be created if (collectionTable.getName().equalsIgnoreCase(elementPC.getTable().getName())) { elementPC.addProperty(inverseRefProperty); } else { // create a join final Join join = new Join(); join.setPersistentClass(elementPC); join.setTable(collectionTable); join.addProperty(inverseRefProperty); final ManyToOne keyValue = new ManyToOne(getMappings(), collectionTable); join.setKey(keyValue); @SuppressWarnings("unchecked") final Iterator<Column> keyColumns = collection.getElement().getColumnIterator(); while (keyColumns.hasNext()) { keyValue.addColumn(keyColumns.next()); } keyValue.setReferencedEntityName(elementPC.getEntityName()); keyValue.setTable(collectionTable); keyValue.createForeignKey(); elementPC.addJoin(join); } } // add an opposite index if (collection.isIndexed() && !collection.isMap()) { Table collectionTable = collection.getCollectionTable(); IndexedCollection indexedCollection = (IndexedCollection) collection; final Column column = (Column) indexedCollection.getIndex().getColumnIterator().next(); final Property indexProperty = new Property(); indexProperty.setName(StoreUtil.getExtraLazyInverseIndexPropertyName(ef)); final Map<Object, Object> metas = new HashMap<Object, Object>(); final MetaAttribute metaAttribute = new MetaAttribute( HbConstants.SYNTHETIC_PROPERTY_INDICATOR); metaAttribute.addValue("true"); metas.put(HbConstants.SYNTHETIC_PROPERTY_INDICATOR, metaAttribute); indexProperty.setMetaAttributes(metas); indexProperty.setNodeName(indexProperty.getName()); indexProperty.setPropertyAccessorName(SyntheticPropertyHandler.class.getName()); // always make this nullable, nullability is controlled // by the main property indexProperty.setOptional(true); Join join = null; @SuppressWarnings("unchecked") final Iterator<Join> it = (Iterator<Join>) elementPC.getJoinIterator(); while (it.hasNext()) { final Join foundJoin = it.next(); if (foundJoin.getTable().getName().equalsIgnoreCase(collectionTable.getName())) { join = foundJoin; collectionTable = join.getTable(); break; } } final SimpleValue sv = new SimpleValue(getMappings(), indexedCollection.getIndex().getTable()); sv.setTypeName("integer"); // final Column svColumn = new Column(column.getName()); sv.addColumn(column); // checkColumnExists(collectionTable, // svColumn)); indexProperty.setValue(sv); if (join != null) { join.addProperty(indexProperty); } else { elementPC.addProperty(indexProperty); } } } } } }
From source file:org.eclipse.emf.teneo.hibernate.HbDataStore.java
License:Open Source License
protected void addContainerMappingToPC(PersistentClass pc) { if (log.isDebugEnabled()) { log.debug("Adding eContainer and econtainerfeatureid properties to " + pc.getClassName()); }//from w ww. j a v a 2s. c o m final EContainerFeaturePersistenceStrategy featurePersistenceStrategy = getPersistenceOptions() .getEContainerFeaturePersistenceStrategy(); final Property eContainer = new Property(); eContainer.setName(HbConstants.PROPERTY_ECONTAINER); eContainer.setMetaAttributes(new HashMap<Object, Object>()); eContainer.setNodeName(eContainer.getName()); eContainer.setPropertyAccessorName(EContainerAccessor.class.getName()); final SimpleValue sv = new SimpleValue(getMappings(), pc.getTable()); sv.setTypeName(EContainerUserType.class.getName()); final Column eccColumn = new Column(getPersistenceOptions().getSQLColumnNamePrefix() + getPersistenceOptions().getEContainerClassColumn()); sv.addColumn(checkColumnExists(pc.getTable(), eccColumn)); final Column ecColumn = new Column( getPersistenceOptions().getSQLColumnNamePrefix() + getPersistenceOptions().getEContainerColumn()); sv.addColumn(checkColumnExists(pc.getTable(), ecColumn)); eContainer.setValue(sv); pc.addProperty(eContainer); if (featurePersistenceStrategy.equals(EContainerFeaturePersistenceStrategy.FEATUREID) || featurePersistenceStrategy.equals(EContainerFeaturePersistenceStrategy.BOTH)) { final Property ecFID = new Property(); ecFID.setName(HbConstants.PROPERTY_ECONTAINER_FEATURE_ID); ecFID.setMetaAttributes(new HashMap<Object, Object>()); ecFID.setNodeName(ecFID.getName()); ecFID.setPropertyAccessorName(EContainerFeatureIDAccessor.class.getName()); final SimpleValue svfid = new SimpleValue(getMappings(), pc.getTable()); svfid.setTypeName("integer"); final Column ecfColumn = new Column( getPersistenceOptions().getSQLColumnNamePrefix() + HbConstants.COLUMN_ECONTAINER_FEATUREID); svfid.addColumn(checkColumnExists(pc.getTable(), ecfColumn)); ecFID.setValue(svfid); pc.addProperty(ecFID); } if (featurePersistenceStrategy.equals(EContainerFeaturePersistenceStrategy.FEATURENAME) || featurePersistenceStrategy.equals(EContainerFeaturePersistenceStrategy.BOTH)) { final Property ecFID = new Property(); ecFID.setName(HbConstants.PROPERTY_ECONTAINER_FEATURE_NAME); ecFID.setMetaAttributes(new HashMap<Object, Object>()); ecFID.setNodeName(ecFID.getName()); ecFID.setPropertyAccessorName(NewEContainerFeatureIDPropertyHandler.class.getName()); final SimpleValue svfid = new SimpleValue(getMappings(), pc.getTable()); svfid.setTypeName(EContainerFeatureIDUserType.class.getName()); final Column ecfColumn = new Column(getPersistenceOptions().getSQLColumnNamePrefix() + getPersistenceOptions().getEContainerFeatureNameColumn()); ecfColumn.setLength(getEContainerFeatureNameColumnLength()); svfid.addColumn(checkColumnExists(pc.getTable(), ecfColumn)); ecFID.setValue(svfid); pc.addProperty(ecFID); } }
From source file:org.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java
License:Apache License
/** * Binds a property to Hibernate runtime meta model. Deals with cascade strategy based on the Grails domain model * * @param grailsProperty The grails property instance * @param prop The Hibernate property * @param mappings The Hibernate mappings *///from ww w.j av a 2 s . c o m protected void bindProperty(PersistentProperty grailsProperty, Property prop, Mappings mappings) { // set the property name prop.setName(grailsProperty.getName()); if (isBidirectionalManyToOneWithListMapping(grailsProperty, prop)) { prop.setInsertable(false); prop.setUpdateable(false); } else { prop.setInsertable(getInsertableness(grailsProperty)); prop.setUpdateable(getUpdateableness(grailsProperty)); } prop.setPropertyAccessorName(mappings.getDefaultAccess()); prop.setOptional(grailsProperty.isNullable()); setCascadeBehaviour(grailsProperty, prop); // lazy to true final boolean isToOne = grailsProperty instanceof ToOne; boolean isLazyable = isToOne || !(grailsProperty instanceof Association) && !grailsProperty.equals(grailsProperty.getOwner().getIdentity()); if (isLazyable) { final boolean isLazy = getLaziness(grailsProperty); prop.setLazy(isLazy); if (isLazy && isToOne) { handleLazyProxy(grailsProperty.getOwner(), grailsProperty); } } }
From source file:org.grails.orm.hibernate.cfg.GrailsDomainBinder.java
License:Apache License
/** * Binds a property to Hibernate runtime meta model. Deals with cascade strategy based on the Grails domain model * * @param grailsProperty The grails property instance * @param prop The Hibernate property * @param mappings The Hibernate mappings *//*from w ww . jav a 2s . c o m*/ protected void bindProperty(PersistentProperty grailsProperty, Property prop, InFlightMetadataCollector mappings) { // set the property name prop.setName(grailsProperty.getName()); if (isBidirectionalManyToOneWithListMapping(grailsProperty, prop)) { prop.setInsertable(false); prop.setUpdateable(false); } else { prop.setInsertable(getInsertableness(grailsProperty)); prop.setUpdateable(getUpdateableness(grailsProperty)); } AccessType accessType = AccessType .getAccessStrategy(grailsProperty.getMapping().getMappedForm().getAccessType()); prop.setPropertyAccessorName(accessType.getType()); prop.setOptional(grailsProperty.isNullable()); setCascadeBehaviour(grailsProperty, prop); // lazy to true final boolean isToOne = grailsProperty instanceof ToOne; PersistentEntity propertyOwner = grailsProperty.getOwner(); boolean isLazyable = isToOne || !(grailsProperty instanceof Association) && !grailsProperty.equals(propertyOwner.getIdentity()); if (isLazyable) { final boolean isLazy = getLaziness(grailsProperty); prop.setLazy(isLazy); if (isLazy && isToOne && !(PersistentAttributeInterceptable.class.isAssignableFrom(propertyOwner.getJavaClass()))) { handleLazyProxy(propertyOwner, grailsProperty); } } }