List of usage examples for org.hibernate.mapping Component getPropertyIterator
public Iterator getPropertyIterator()
From source file:com.mysema.query.jpa.codegen.HibernateDomainExporter.java
License:Apache License
private void collectTypes() throws IOException, XMLStreamException, ClassNotFoundException, SecurityException, NoSuchMethodException {/*from w w w. j a v a2 s . c o m*/ // super classes Iterator<?> superClassMappings = configuration.getMappedSuperclassMappings(); while (superClassMappings.hasNext()) { MappedSuperclass msc = (MappedSuperclass) superClassMappings.next(); EntityType entityType = createSuperType(msc.getMappedClass()); if (msc.getDeclaredIdentifierProperty() != null) { handleProperty(entityType, msc.getMappedClass(), msc.getDeclaredIdentifierProperty()); } Iterator<?> properties = msc.getDeclaredPropertyIterator(); while (properties.hasNext()) { handleProperty(entityType, msc.getMappedClass(), (org.hibernate.mapping.Property) properties.next()); } } // entity classes Iterator<?> classMappings = configuration.getClassMappings(); while (classMappings.hasNext()) { PersistentClass pc = (PersistentClass) classMappings.next(); EntityType entityType = createEntityType(pc.getMappedClass()); if (pc.getDeclaredIdentifierProperty() != null) { handleProperty(entityType, pc.getMappedClass(), pc.getDeclaredIdentifierProperty()); } else if (!pc.isInherited() && pc.hasIdentifierProperty()) { logger.info(entityType.toString() + pc.getIdentifierProperty()); handleProperty(entityType, pc.getMappedClass(), pc.getIdentifierProperty()); } else if (pc.getIdentifier() != null) { KeyValue identifier = pc.getIdentifier(); if (identifier instanceof Component) { Component component = (Component) identifier; Iterator<?> properties = component.getPropertyIterator(); if (component.isEmbedded()) { while (properties.hasNext()) { handleProperty(entityType, pc.getMappedClass(), (org.hibernate.mapping.Property) properties.next()); } } else { String name = component.getNodeName(); Class<?> clazz = component.getType().getReturnedClass(); Type propertyType = getType(pc.getMappedClass(), clazz, name); AnnotatedElement annotated = getAnnotatedElement(pc.getMappedClass(), name); Property property = createProperty(entityType, name, propertyType, annotated); entityType.addProperty(property); // handle component properties EntityType embeddedType = createEmbeddableType(propertyType); while (properties.hasNext()) { handleProperty(embeddedType, clazz, (org.hibernate.mapping.Property) properties.next()); } } } // TODO handle other KeyValue subclasses such as Any, DependentValue and ToOne } Iterator<?> properties = pc.getDeclaredPropertyIterator(); while (properties.hasNext()) { handleProperty(entityType, pc.getMappedClass(), (org.hibernate.mapping.Property) properties.next()); } } // go through supertypes Set<Supertype> additions = Sets.newHashSet(); for (Map.Entry<String, EntityType> entry : allTypes.entrySet()) { EntityType entityType = entry.getValue(); if (entityType.getSuperType() != null && !allTypes.containsKey(entityType.getSuperType().getType().getFullName())) { additions.add(entityType.getSuperType()); } } for (Supertype type : additions) { type.setEntityType(createEntityType(type.getType(), superTypes)); } }
From source file:com.mysema.query.jpa.codegen.HibernateDomainExporter.java
License:Apache License
private void handleProperty(EntityType entityType, Class<?> cl, org.hibernate.mapping.Property p) throws NoSuchMethodException, ClassNotFoundException { if (p.isBackRef()) { return;//from w w w. j a v a 2 s . c o m } Class<?> clazz = Object.class; try { clazz = p.getType().getReturnedClass(); } catch (MappingException e) { // ignore } Type propertyType = getType(cl, clazz, p.getName()); if (p.isComposite()) { EntityType embeddedType = createEmbeddableType(propertyType); Iterator<?> properties = ((Component) p.getValue()).getPropertyIterator(); while (properties.hasNext()) { handleProperty(embeddedType, embeddedType.getJavaClass(), (org.hibernate.mapping.Property) properties.next()); } propertyType = embeddedType; } else if (propertyType.getCategory() == TypeCategory.ENTITY || p.getValue() instanceof ManyToOne) { propertyType = createEntityType(propertyType); } else if (propertyType.getCategory() == TypeCategory.CUSTOM) { propertyType = createEmbeddableType(propertyType); } else if (p.getValue() instanceof org.hibernate.mapping.Collection) { org.hibernate.mapping.Collection collection = (org.hibernate.mapping.Collection) p.getValue(); if (collection.getElement() instanceof OneToMany) { String entityName = ((OneToMany) collection.getElement()).getReferencedEntityName(); if (entityName != null) { Type componentType = typeFactory.create(Class.forName(entityName)); propertyType = new SimpleType(propertyType, componentType); } } else if (collection.getElement() instanceof Component) { Component component = (Component) collection.getElement(); Class<?> embeddedClass = Class.forName(component.getComponentClassName()); EntityType embeddedType = createEmbeddableType(embeddedClass); Iterator<?> properties = component.getPropertyIterator(); while (properties.hasNext()) { handleProperty(embeddedType, embeddedClass, (org.hibernate.mapping.Property) properties.next()); } } } AnnotatedElement annotated = getAnnotatedElement(cl, p.getName()); Property property = createProperty(entityType, p.getName(), propertyType, annotated); entityType.addProperty(property); }
From source file:com.querydsl.jpa.codegen.HibernateDomainExporter.java
License:Apache License
@Override protected void collectTypes() throws IOException, XMLStreamException, ClassNotFoundException, NoSuchMethodException { // super classes Iterator<?> superClassMappings = configuration.getMappedSuperclassMappings(); while (superClassMappings.hasNext()) { MappedSuperclass msc = (MappedSuperclass) superClassMappings.next(); EntityType entityType = createSuperType(msc.getMappedClass()); if (msc.getDeclaredIdentifierProperty() != null) { handleProperty(entityType, msc.getMappedClass(), msc.getDeclaredIdentifierProperty()); }//from ww w.ja va 2s. c o m Iterator<?> properties = msc.getDeclaredPropertyIterator(); while (properties.hasNext()) { handleProperty(entityType, msc.getMappedClass(), (org.hibernate.mapping.Property) properties.next()); } } // entity classes Iterator<?> classMappings = configuration.getClassMappings(); while (classMappings.hasNext()) { PersistentClass pc = (PersistentClass) classMappings.next(); EntityType entityType = createEntityType(pc.getMappedClass()); if (pc.getDeclaredIdentifierProperty() != null) { handleProperty(entityType, pc.getMappedClass(), pc.getDeclaredIdentifierProperty()); } else if (!pc.isInherited() && pc.hasIdentifierProperty()) { logger.info(entityType.toString() + pc.getIdentifierProperty()); handleProperty(entityType, pc.getMappedClass(), pc.getIdentifierProperty()); } else if (pc.getIdentifier() != null) { KeyValue identifier = pc.getIdentifier(); if (identifier instanceof Component) { Component component = (Component) identifier; Iterator<?> properties = component.getPropertyIterator(); if (component.isEmbedded()) { while (properties.hasNext()) { handleProperty(entityType, pc.getMappedClass(), (org.hibernate.mapping.Property) properties.next()); } } else { String name = component.getNodeName(); Class<?> clazz = component.getType().getReturnedClass(); Type propertyType = getType(pc.getMappedClass(), clazz, name); AnnotatedElement annotated = getAnnotatedElement(pc.getMappedClass(), name); Property property = createProperty(entityType, name, propertyType, annotated); entityType.addProperty(property); // handle component properties EntityType embeddedType = createEmbeddableType(propertyType); while (properties.hasNext()) { handleProperty(embeddedType, clazz, (org.hibernate.mapping.Property) properties.next()); } } } // TODO handle other KeyValue subclasses such as Any, DependentValue and ToOne } Iterator<?> properties = pc.getDeclaredPropertyIterator(); while (properties.hasNext()) { handleProperty(entityType, pc.getMappedClass(), (org.hibernate.mapping.Property) properties.next()); } } }
From source file:com.querydsl.jpa.codegen.HibernateDomainExporter.java
License:Apache License
private void handleProperty(EntityType entityType, Class<?> cl, org.hibernate.mapping.Property p) throws NoSuchMethodException, ClassNotFoundException { if (p.isBackRef()) { return;//from ww w . j a v a 2 s . c o m } Class<?> clazz = Object.class; try { clazz = p.getType().getReturnedClass(); } catch (MappingException e) { // ignore } Type propertyType = getType(cl, clazz, p.getName()); try { propertyType = getPropertyType(p, propertyType); } catch (MappingException e) { // ignore } AnnotatedElement annotated = getAnnotatedElement(cl, p.getName()); propertyType = getTypeOverride(propertyType, annotated); if (propertyType == null) { return; } if (p.isComposite()) { EntityType embeddedType = createEmbeddableType(propertyType); Iterator<?> properties = ((Component) p.getValue()).getPropertyIterator(); while (properties.hasNext()) { handleProperty(embeddedType, embeddedType.getJavaClass(), (org.hibernate.mapping.Property) properties.next()); } propertyType = embeddedType; } else if (propertyType.getCategory() == TypeCategory.ENTITY || p.getValue() instanceof ManyToOne) { propertyType = createEntityType(propertyType); } else if (propertyType.getCategory() == TypeCategory.CUSTOM) { propertyType = createEmbeddableType(propertyType); } else if (p.getValue() instanceof org.hibernate.mapping.Collection) { org.hibernate.mapping.Collection collection = (org.hibernate.mapping.Collection) p.getValue(); if (collection.getElement() instanceof OneToMany) { String entityName = ((OneToMany) collection.getElement()).getReferencedEntityName(); if (entityName != null) { if (collection.isMap()) { Type keyType = typeFactory .get(Class.forName(propertyType.getParameters().get(0).getFullName())); Type valueType = typeFactory.get(Class.forName(entityName)); propertyType = new SimpleType(propertyType, normalize(propertyType.getParameters().get(0), keyType), normalize(propertyType.getParameters().get(1), valueType)); } else { Type componentType = typeFactory.get(Class.forName(entityName)); propertyType = new SimpleType(propertyType, normalize(propertyType.getParameters().get(0), componentType)); } } } else if (collection.getElement() instanceof Component) { Component component = (Component) collection.getElement(); Class<?> embeddedClass = Class.forName(component.getComponentClassName()); EntityType embeddedType = createEmbeddableType(embeddedClass); Iterator<?> properties = component.getPropertyIterator(); while (properties.hasNext()) { handleProperty(embeddedType, embeddedClass, (org.hibernate.mapping.Property) properties.next()); } } } Property property = createProperty(entityType, p.getName(), propertyType, annotated); entityType.addProperty(property); }
From source file:com.siemens.scr.avt.ad.query.common.DicomMappingDictionaryLoadingStrategy.java
License:Open Source License
private void loadProperty(DicomMappingDictionary dict, Property prop, Table table, String classPrefix) { String key = classPrefix + "." + prop.getName(); Type type = prop.getType();// w w w . java 2 s . c om String tableName = table.getSchema() + "." + table.getName(); if (type.isAssociationType() || type.isCollectionType()) { // do nothing } else if (type.isComponentType()) { Component component = (Component) prop.getValue(); Iterator<Property> it = component.getPropertyIterator(); while (it.hasNext()) { Property subProp = it.next(); loadProperty(dict, subProp, table, component.getRoleName()); } } else { int sqltype = sqlTypes(type); assert prop.getColumnSpan() == 1; Iterator<Column> it = prop.getColumnIterator(); String column = it.next().getName(); dict.addMappingEntry(key, tableName, column, sqltype); loadTag(dict, prop, key); loadDicomHeaderMetadata(dict, tableName, column, prop); } }
From source file:com.vecna.maven.hibernate.HibernateDocMojo.java
License:Apache License
/** * Process a component (embedded property) and populate its properties (including nested ones) with javadoc comments. * @param component component model/* www . jav a2s . co m*/ * @param javaDocs javadocs * @param accumulatedJavadoc comments accumulated so far (for nested components) */ private void processComponent(Component component, JavaDocBuilder javaDocs, String accumulatedJavadoc) { @SuppressWarnings("unchecked") Iterator<Property> propertyIterator = component.getPropertyIterator(); processProperties(propertyIterator, component.getComponentClass(), javaDocs, accumulatedJavadoc); }
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();//from w w w .j a v a 2 s. co m 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(); initProperty(s, p2, propertiesMap); } }
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();/* w w w . ja va2 s . com*/ 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 ww .j a 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.HibernateMappingTests.java
License:Apache License
private void walkComponentProperties(Iterator propertyIterator, Set fieldNames) { for (Iterator it = propertyIterator; it.hasNext();) { Property property = (Property) it.next(); String name = property.getName(); if (property.getValue() instanceof Component) { Component cv = (Component) property.getValue(); Set mungedFieldNames = mungePaths(name, fieldNames); assertAllFieldsMapped(cv, mungedFieldNames); assertFieldsExists(cv.getComponentClass(), getRoots(mungedFieldNames), false); walkComponentProperties(cv.getPropertyIterator(), mungedFieldNames); } else if (isListOfComponents(property)) { List value = (List) property.getValue(); Component cv = (Component) value.getElement(); // Duplicate Set mungedFieldNames = mungePaths(name, fieldNames); assertAllFieldsMapped(cv, mungedFieldNames); assertFieldsExists(cv.getComponentClass(), getRoots(mungedFieldNames), false); walkComponentProperties(cv.getPropertyIterator(), mungedFieldNames); }//from w w w .j a v a 2 s . c o m } }