List of usage examples for org.hibernate.mapping MetaAttribute addValue
public void addValue(String value)
From source file:alma.acs.tmcdb.translator.AbstractReverseEngineeringStrategy.java
License:Open Source License
@SuppressWarnings("unchecked") @Override// w w w . j av a 2 s. c o m public Map tableToMetaAttributes(TableIdentifier tableIdentifier) { Map map = super.tableToMetaAttributes(tableIdentifier); if (map == null) map = new HashMap<String, MetaAttribute>(); // Check if table contains a XMLCLOB column for (int i = 0; i < inheritanceTranslators.length; i++) { String tableName = tableIdentifier.getName(); if (inheritanceTranslators[i].hasXmlClobType(tableName)) { MetaAttribute mattr = new MetaAttribute(HAS_XML_CLOB_TYPE); mattr.addValue("true"); map.put(HAS_XML_CLOB_TYPE, mattr); break; } } // Check if table has a generated ID, necessary to generate the GenericGenerator custom annotation for (int i = 0; i < inheritanceTranslators.length; i++) { String tableName = tableIdentifier.getName(); String sequence = inheritanceTranslators[i].getSequenceForTable(tableName); if (sequence != null) { MetaAttribute mattr = new MetaAttribute(ORACLE_SEQUENCE); mattr.addValue(sequence); map.put(ORACLE_SEQUENCE, mattr); break; } } // Check all CHECK constraints for this table for (int i = 0; i < inheritanceTranslators.length; i++) { String tableName = tableIdentifier.getName().toLowerCase(); if (inheritanceTranslators[i].getEnumTypesForTable(tableName) != null) { Map<String, String> typesForTable = inheritanceTranslators[i].getEnumTypesForTable(tableName); if (typesForTable == null) continue; MetaAttribute mattr2 = new MetaAttribute(HAS_ENUM_TYPES); mattr2.addValue("true"); map.put(HAS_ENUM_TYPES, mattr2); mattr2 = new MetaAttribute(ENUM_TYPES); Iterator<Map.Entry<String, String>> it = typesForTable.entrySet().iterator(); StringBuilder sb = new StringBuilder(); while (it.hasNext()) { Map.Entry<String, String> entry = it.next(); sb.append(entry.getKey()); sb.append("|"); sb.append(entry.getValue()); if (it.hasNext()) sb.append(","); } mattr2.addValue(sb.toString()); map.put(ENUM_TYPES, mattr2); } } // Check if table is superclass or child class for (int i = 0; i < inheritanceTranslators.length; i++) { String tableName = tableIdentifier.getName().toLowerCase(); String superClass = inheritanceTranslators[i].getSuperTable(tableName); if (superClass != null) { MetaAttribute mattr = new MetaAttribute(MetaAttributeConstants.EXTENDS); mattr.addValue(superClass); map.put("extends", mattr); return map; } else { MetaAttribute mattr = new MetaAttribute(MetaAttributeConstants.EXTENDS); mattr.addValue("alma.acs.tmcdb.translator.TmcdbObject"); map.put("extends", mattr); for (int j = 0; j != inheritanceTranslators.length; j++) { if (inheritanceTranslators[j].isSuperClass(tableName)) { mattr = new MetaAttribute(IS_SUPER_CLASS); mattr.addValue("true"); map.put(IS_SUPER_CLASS, mattr); return map; } } } } return map; }
From source file:alma.acs.tmcdb.translator.AbstractReverseEngineeringStrategy.java
License:Open Source License
@SuppressWarnings("unchecked") @Override// w w w .jav a 2 s . c o m public Map columnToMetaAttributes(TableIdentifier identifier, String column) { Map map = super.columnToMetaAttributes(identifier, column); if (map == null) map = new HashMap<String, MetaAttribute>(); String tableName = identifier.getName().toLowerCase(); // Don't generate getter/setters for inheritance-related fields MetaAttribute mattr = new MetaAttribute(MetaAttributeConstants.GEN_PROPERTY); for (int i = 0; i < inheritanceTranslators.length; i++) { List<String> columns = inheritanceTranslators[i].getPkFkCombinationColumns(tableName); if (columns != null && columns.contains(column.toLowerCase())) { mattr.addValue("false"); map.put("gen-property", mattr); return map; } } // Make everything protected mattr.addValue("protected"); map.put("scope-field", mattr); // Check for special XMLCLOB types, they get a specific annotation generated for (int i = 0; i < inheritanceTranslators.length; i++) { if (inheritanceTranslators[i].hasXmlClobType(tableName)) { if (inheritanceTranslators[i].isXmlClobType(tableName, column)) { MetaAttribute mattr2 = new MetaAttribute(IS_XML_CLOB_TYPE); mattr2.addValue("true"); map.put(IS_XML_CLOB_TYPE, mattr2); break; } } } for (int i = 0; i < inheritanceTranslators.length; i++) { if (inheritanceTranslators[i].isKeyPiece(tableName, column)) { MetaAttribute mattr2 = new MetaAttribute("use-in-equals"); mattr2.addValue("true"); map.put("use-in-equals", mattr2); break; } } return map; }
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 ww w .j av a 2 s. c o m * 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); } } } } } }