List of usage examples for org.hibernate.mapping Property getName
public String getName()
From source file:edu.wustl.dao.util.HibernateMetaData.java
License:BSD License
/** *This method will iterate the Identified property file and returns the column name. * @param classObj : Class of the object * @param attributeName :attribute of the given class * @return returns the Column Name mapped to the attribute. *//* w w w. ja v a2 s. co m*/ private static String getColumName(Class classObj, String attributeName) { String columnName = DAOConstants.TAILING_SPACES; Property property = cfg.getClassMapping(classObj.getName()).getIdentifierProperty(); if (property.getName().equals(attributeName)) { Iterator<Object> colIt = property.getColumnIterator();//y("id").getColumnIterator(); if (colIt.hasNext()) { Column col = (Column) colIt.next(); columnName = col.getName(); } } return columnName; }
From source file:edu.wustl.dao.util.HibernateMetaData.java
License:BSD License
/** * This method will be called to obtained column width of attribute field of given class. * @param classObj Name of the class.// ww w . ja v a 2 s. co m * @param attributeName Name of the attribute. * @return The width of the column. Returns width of the column or zero. */ public static int getColumnWidth(Class classObj, String attributeName) { Iterator iterator = cfg.getClassMapping(classObj.getName()).getPropertyClosureIterator(); int colLength = 50; while (iterator.hasNext()) { Property property = (Property) iterator.next(); if (property != null && property.getName().equals(attributeName)) { Iterator colIt = property.getColumnIterator(); while (colIt.hasNext()) { Column col = (Column) colIt.next(); colLength = col.getLength(); } } } // if attribute is not found than the default width will be 50. return colLength; }
From source file:gov.nih.nci.system.dao.impl.orm.ORMDAOImpl.java
License:Open Source License
private void getFieldList(PersistentClass pclass, List<Field> fieldList) throws Exception { Iterator<Property> properties = pclass.getPropertyIterator(); while (properties.hasNext()) { Property prop = properties.next(); if (!prop.getType().isAssociationType()) { String fieldName = prop.getName(); Field field = pclass.getMappedClass().getDeclaredField(fieldName); field.setAccessible(true);/* w ww . j a v a2 s . c o m*/ fieldList.add(field); } } }
From source file:gov.nih.nci.system.util.ClassCache.java
License:BSD License
private Map<String, List<Object>> getISOIdentifierFieldsMap(PersistentClass pclass, Configuration cfg) { Map<String, List<Object>> isoIdentifierMap = new HashMap<String, List<Object>>(); Property identifierProperty = pclass.getIdentifierProperty(); if (identifierProperty != null) { List<Object> identifierSearchFields = getPersistentFieldsForISOObject(identifierProperty); isoIdentifierMap.put(identifierProperty.getName(), identifierSearchFields); }/*from www . ja v a2 s . c o m*/ return isoIdentifierMap; }
From source file:gov.nih.nci.system.util.ClassCache.java
License:BSD License
@SuppressWarnings("unchecked") private Map<String, List<Object>> getISOPropertiesForObject(PersistentClass pclass, Configuration cfg) { Map<String, List<Object>> isoFieldsMap = new HashMap<String, List<Object>>(); if (pclass.getEntityName().startsWith("_xxEntityxx_gov_nih_nci_cacoresdk_domain_other_datatype")) { Iterator<? extends Object> properties = pclass.getPropertyIterator(); while (properties != null && properties.hasNext()) { Property prop = (Property) properties.next(); List<Object> searchableFields = getPersistentFieldsForISOObject(prop, cfg); isoFieldsMap.put(prop.getName(), searchableFields); }// w w w . j a va2 s . co m } else { Class klass; try { klass = Class.forName(pclass.getClassName()); } catch (ClassNotFoundException e) { log.error("Error: Class not found for: " + pclass.getClassName(), e); return isoFieldsMap; } while (!klass.getName().equals("java.lang.Object")) { pclass = cfg.getClassMapping(klass.getName()); if (pclass != null) { Iterator<? extends Object> properties = pclass.getPropertyIterator(); while (properties != null && properties.hasNext()) { Property prop = (Property) properties.next(); List<Object> searchableFields = getPersistentFieldsForISOObject(prop, cfg); isoFieldsMap.put(prop.getName(), searchableFields); } } klass = klass.getSuperclass(); } } return isoFieldsMap; }
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 ww w . j a v a 2s. c o m 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(); 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 {/*w w w . j av a 2 s.co m*/ 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.j a v a 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:lucee.runtime.orm.hibernate.tuplizer.AbstractEntityTuplizerImpl.java
License:Open Source License
private Serializable toIdentifier(Serializable id) { if (id instanceof Component) { HashMap<String, Object> map = new HashMap<String, Object>(); Component cfc = (Component) id; ComponentScope scope = cfc.getComponentScope(); lucee.runtime.component.Property[] props = HibernateUtil.getIDProperties(cfc, true, true); lucee.runtime.component.Property p; String name;/*w ww .j av a 2 s . c o m*/ Object value; for (int i = 0; i < props.length; i++) { p = props[i]; name = p.getName(); value = scope.get(CommonUtil.createKey(name), null); String type = p.getType(); if (Decision.isAnyType(type)) { type = "string"; try { Object o = p.getMetaData(); if (o instanceof Struct) { Struct meta = (Struct) o; String gen = Caster.toString(meta.get(KeyConstants._generator, null), null); if (!StringUtil.isEmpty(gen)) { type = HBMCreator.getDefaultTypeForGenerator(gen, "string"); } } } catch (Throwable t) { } } try { value = HibernateCaster.toHibernateValue(ThreadLocalPageContext.get(), value, type); } catch (PageException pe) { } map.put(name, value); } return map; } return id; }
From source file:lucee.runtime.orm.hibernate.tuplizer.AbstractEntityTuplizerImpl.java
License:Open Source License
@Override protected Getter buildPropertyGetter(Property mappedProperty, PersistentClass mappedEntity) { return buildPropertyAccessor(mappedProperty).getGetter(null, mappedProperty.getName()); }