List of usage examples for org.hibernate.mapping Property getValue
public Value getValue()
From source file:com.wavemaker.runtime.data.hibernate.DataServiceMetaData_Hib.java
License:Open Source License
private void addComponentProperties(Property p) { String s = p.getType().getReturnedClass().getName(); this.componentClassNames.add(s); Value v = p.getValue(); Component comp = (Component) v; Map<String, Property> propertiesMap = new HashMap<String, Property>(); this.allPropertiesMap.put(s, propertiesMap); for (Iterator<Property> iter = CastUtils.cast(comp.getPropertyIterator()); iter.hasNext();) { Property p2 = iter.next();//from w w w . j a va 2 s. c o m initProperty(s, p2, propertiesMap); } }
From source file:com.xpn.xwiki.store.migration.hibernate.R40000XWIKI6990DataMigration.java
License:Open Source License
/** * Retrieve the list of collection properties of the provided persisted class. * @param pClass the persisted class to analyse * @return a list of hibernate collections *///from ww w . jav a 2 s . com private List<org.hibernate.mapping.Collection> getCollection(PersistentClass pClass) { List<org.hibernate.mapping.Collection> list = new ArrayList<org.hibernate.mapping.Collection>(); if (pClass != null) { @SuppressWarnings("unchecked") Iterator<Property> it = pClass.getPropertyIterator(); while (it.hasNext()) { Property property = it.next(); if (property.getType().isCollectionType()) { list.add((org.hibernate.mapping.Collection) property.getValue()); } } } return list; }
From source file:com.xpn.xwiki.store.migration.hibernate.R40000XWIKI6990DataMigration.java
License:Open Source License
/** * Retrieve a list of tables used to store the given persistent class, that need to be processed for FK constraints. * The list include the main table use to persist the class, if this table has FK, as well as, all the collection * table used for storing this persisted class properties. * * @param pClass the persistent class to analyze * @return a list of table/*from w w w .j a v a 2 s . co m*/ */ private List<Table> getForeignKeyTables(PersistentClass pClass) { List<Table> list = new ArrayList<Table>(); if (pClass != null) { Table table = pClass.getTable(); if (checkFKtoPKinTable(table)) { list.add(table); } @SuppressWarnings("unchecked") Iterator<Property> it = pClass.getPropertyIterator(); while (it.hasNext()) { Property property = it.next(); if (property.getType().isCollectionType()) { org.hibernate.mapping.Collection coll = (org.hibernate.mapping.Collection) property.getValue(); Table collTable = coll.getCollectionTable(); if (checkFKtoPKinTable(collTable)) { list.add(collTable); } } } } return list; }
From source file:com.xpn.xwiki.store.XWikiHibernateStore.java
License:Open Source License
private boolean isValidCustomMapping(String className, Configuration hibconfig, BaseClass bclass) { PersistentClass mapping = hibconfig.getClassMapping(className); if (mapping == null) { return true; }/*from w ww.j av a2 s.c om*/ Iterator it = mapping.getPropertyIterator(); while (it.hasNext()) { Property hibprop = (Property) it.next(); String propname = hibprop.getName(); PropertyClass propclass = (PropertyClass) bclass.getField(propname); if (propclass == null) { log.warn("Mapping contains invalid field name " + propname); return false; } boolean result = isValidColumnType(hibprop.getValue().getType().getName(), propclass.getClassName()); if (result == false) { log.warn("Mapping contains invalid type in field " + propname); return false; } } return true; }
From source file:gov.nih.nci.system.util.ClassCache.java
License:BSD License
private List<Object> getPersistentFieldsForISOObject(Property prop, Configuration cfg) { List<Object> isoObjectPsFields = new ArrayList<Object>(); String idUserType = prop.getType().getName(); String identifierUserType = "gov.nih.nci.iso21090.hibernate.usertype.IiUserType"; if (identifierUserType.equals(idUserType)) { isoObjectPsFields.add("extension"); } else if ("id".equals(prop.getName())) { isoObjectPsFields.add(prop.getName()); } else if (prop.getType().isComponentType() && !(prop.getValue() instanceof Any)) { processIfComponentMapping(prop, isoObjectPsFields, cfg); String componentClassName = ((Component) prop.getValue()).getComponentClassName(); if (componentClassName != null && (componentClassName.indexOf("Adxp") > 0)) { String adxpType = componentClassName.substring(componentClassName.indexOf("Adxp") + 4) .toUpperCase();//from w w w . j a v a 2 s .com Map<String, List<Object>> nestedComponent = new HashMap<String, List<Object>>(); List<Object> adxpTypeList = new ArrayList<Object>(); adxpTypeList.add(adxpType); nestedComponent.put("type", adxpTypeList); isoObjectPsFields.add(nestedComponent); } else if (componentClassName != null && (componentClassName.indexOf("Enxp") > 0)) { String roleName = ((Component) prop.getValue()).getRoleName(); String rootKlassAttr = roleName.substring(0, roleName.lastIndexOf('.')); ComplexNode complexNode = tuplizerHelper.getComplexNodeBean(rootKlassAttr); List<Node> nodes = complexNode.getInnerNodes(); Map<String, List<Object>> nestedComponent = new HashMap<String, List<Object>>(); List<Object> enxpTypeList = new ArrayList<Object>(); // String value=null; for (Node node : nodes) { if (node instanceof ConstantNode) { continue; } ComplexNode innerComplexNode = (ComplexNode) node; // value = innerComplexNode.getName(); String key = null; List<Node> innerNodes = innerComplexNode.getInnerNodes(); for (Node innerNode : innerNodes) { if (innerNode instanceof ConstantNode && innerNode.getName().equals("type")) { ConstantNode constantNode = (ConstantNode) innerNode; key = constantNode.getConstantValue(); enxpTypeList.add(key); break; } } } nestedComponent.put("type", enxpTypeList); isoObjectPsFields.add(nestedComponent); } } else if (prop.getType().isAssociationType() && (prop.getValue() instanceof ManyToOne)) { ManyToOne manyToOne = (ManyToOne) prop.getValue(); String many2OnePClassName = manyToOne.getReferencedEntityName(); if (!many2OnePClassName.startsWith("_xxEntityxx_gov_nih_nci_cacoresdk_domain_other_datatype")) { return isoObjectPsFields; } PersistentClass many2OnePClass = cfg.getClassMapping(many2OnePClassName); Map<String, List<Object>> map = getISOPropertiesForObject(many2OnePClass, cfg); Iterator<String> keyItr = map.keySet().iterator(); while (keyItr.hasNext()) { String key = keyItr.next(); Map<String, List<Object>> tempMap = new HashMap<String, List<Object>>(); tempMap.put(key, map.get(key)); isoObjectPsFields.add(tempMap); } } else { String fieldName = prop.getName(); isoObjectPsFields.add(fieldName); } return isoObjectPsFields; }
From source file:gov.nih.nci.system.util.ClassCache.java
License:BSD License
@SuppressWarnings("unchecked") private void processIfComponentMapping(Property prop, List<Object> isoObjectPsFields, Configuration cfg) { Component isoComponent = (Component) prop.getValue(); Iterator<Property> itr = isoComponent.getPropertyIterator(); while (itr.hasNext()) { Property property = itr.next();//from w ww . ja v a2 s . c om String fieldName = property.getName(); if (property.getType().isComponentType()) { List<Object> innerPersistentFields = getPersistentFieldsForISOObject(property); Map<String, List<Object>> nestedComponent = new HashMap<String, List<Object>>(); nestedComponent.put(fieldName, innerPersistentFields); isoObjectPsFields.add(nestedComponent); } else if (property.getType().isAssociationType()) { Map<String, List<Object>> nestedComponent = processIfAssociationType(property, fieldName, cfg); isoObjectPsFields.add(nestedComponent); } else { isoObjectPsFields.add(fieldName); } } }
From source file:gov.nih.nci.system.util.ClassCache.java
License:BSD License
@SuppressWarnings("unchecked") private Map<String, List<Object>> processIfAssociationType(Property property, String fieldName, Configuration cfg) {/*from w w w. ja va 2 s . c o m*/ Map<String, List<Object>> associationPsFields = new HashMap<String, List<Object>>(); org.hibernate.mapping.Set childAssociationType = (org.hibernate.mapping.Set) property.getValue(); Object element = childAssociationType.getElement(); Class<? extends Value> elementClass = childAssociationType.getElement().getClass(); if (Component.class.isAssignableFrom(elementClass)) { Component associationComponent = (Component) element; Iterator<Property> propertiesIterator = associationComponent.getPropertyIterator(); String assoChildCompClassName = associationComponent.getComponentClassName(); String key = fieldName + "<" + assoChildCompClassName + ">"; List<Object> isoPersistentFields = new ArrayList<Object>(); while (propertiesIterator.hasNext()) { Property tempProperty = propertiesIterator.next(); List<Object> tempPersistentFields = getPersistentFieldsForISOObject(tempProperty); Class<? extends Value> tempPropertyClass = tempProperty.getValue().getClass(); if (Component.class.isAssignableFrom(tempPropertyClass)) { Map<String, List<Object>> nestedComponent = new HashMap<String, List<Object>>(); nestedComponent.put(tempProperty.getName(), tempPersistentFields); isoPersistentFields.add(nestedComponent); } else { isoPersistentFields.addAll(tempPersistentFields); } } associationPsFields.put(key, isoPersistentFields); } else if (element instanceof ManyToOne) { ManyToOne manyToOne = (ManyToOne) childAssociationType.getElement(); String many2OnePClassName = manyToOne.getReferencedEntityName(); if (!many2OnePClassName.startsWith("_xxEntityxx_gov_nih_nci_cacoresdk_domain_other_datatype")) { return associationPsFields; } PersistentClass many2OnePClass = cfg.getClassMapping(many2OnePClassName); Map<String, List<Object>> map = getISOPropertiesForObject(many2OnePClass, cfg); Iterator<String> keyItr = map.keySet().iterator(); String key = fieldName + "<" + many2OnePClass.getClassName() + ">"; List<Object> isoPersistentFields = new ArrayList<Object>(); isoPersistentFields.add(map); associationPsFields.put(key, isoPersistentFields); } else if (element instanceof OneToMany) { OneToMany oneToMany = (OneToMany) element;//prop.getValue(); String oneToManyPClassName = oneToMany.getReferencedEntityName(); if (!oneToManyPClassName.startsWith("_xxEntityxx_gov_nih_nci_cacoresdk_domain_other_datatype")) { return associationPsFields; } PersistentClass oneToManyPClass = cfg.getClassMapping(oneToManyPClassName); Map<String, List<Object>> map = getISOPropertiesForObject(oneToManyPClass, cfg); Iterator<String> keyItr = map.keySet().iterator(); String key = fieldName + "<" + oneToMany.getAssociatedClass().getClassName() + ">"; List<Object> isoPersistentFields = new ArrayList<Object>(); isoPersistentFields.add(map); associationPsFields.put(key, isoPersistentFields); } else { log.info("ignoring :::" + elementClass.getName()); } return associationPsFields; }
From source file:net.chrisrichardson.ormunit.hibernate.ComponentFieldMapping.java
License:Apache License
public void assertManyToOneField(String fieldName, String foreignKeyColumnName) { Property subProperty = findProperty(fieldName); ManyToOne value = (ManyToOne) subProperty.getValue(); HibernateAssertUtil.assertColumn(foreignKeyColumnName, value); }
From source file:net.chrisrichardson.ormunit.hibernate.ComponentFieldMapping.java
License:Apache License
public void assertCompositeSetField(String fieldName) { Property property = findProperty(fieldName); Value v = property.getValue(); org.hibernate.mapping.Set value = (org.hibernate.mapping.Set) v; }
From source file:net.chrisrichardson.ormunit.hibernate.ComponentFieldMapping.java
License:Apache License
public CompositeSetFieldMapping getCompositeSetFieldMapping(String fieldName) { Property property = findProperty(fieldName); Value v = property.getValue(); org.hibernate.mapping.Set value = (org.hibernate.mapping.Set) v; return new CompositeSetFieldMapping(property, value); }