List of usage examples for org.hibernate.mapping Property getName
public String getName()
From source file:lucee.runtime.orm.hibernate.tuplizer.AbstractEntityTuplizerImpl.java
License:Open Source License
@Override protected Setter buildPropertySetter(Property mappedProperty, PersistentClass mappedEntity) { return buildPropertyAccessor(mappedProperty).getSetter(null, mappedProperty.getName()); }
From source file:net.chrisrichardson.ormunit.hibernate.ComponentFieldMapping.java
License:Apache License
public Property findProperty(String fieldName) { for (Iterator it = componentValue.getPropertyIterator(); it.hasNext();) { Property subProperty = (Property) it.next(); if (subProperty.getName().equals(fieldName)) { return subProperty; }//w w w . j a v a 2 s . c om } return null; }
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); }/* w ww .java 2 s . co m*/ } }
From source file:net.chrisrichardson.ormunit.hibernate.HibernateMappingTests.java
License:Apache License
private void assertNoOtherUnmappedFields(Class type, Set nonPersistentFields, boolean includeSuper) throws MappingException { Property idProperty = classMapping.getIdentifierProperty(); Set unmappedFields = new HashSet(); Set fieldsToIgnore = new HashSet(nonPersistentFields); if (idProperty != null) { fieldsToIgnore.add(idProperty.getName()); }// w ww .j a va2 s. c om for (Iterator it = HibernateAssertUtil.getPersistableFields(type, includeSuper).iterator(); it.hasNext();) { String fieldName = (String) it.next(); if (!fieldsToIgnore.contains(fieldName)) try { classMapping.getProperty(fieldName); } catch (MappingException e) { unmappedFields.add(fieldName); } } if (!unmappedFields.isEmpty()) throw new UnmappedFieldsException(type, unmappedFields); }
From source file:net.chrisrichardson.ormunit.hibernate.HibernateMappingTests.java
License:Apache License
private void assertNoMappingForFields(Class type, Set fieldNames) { for (Iterator iter = fieldNames.iterator(); iter.hasNext();) { String fieldName = (String) iter.next(); try {//from w w w . j a v a 2 s. c om Property r = classMapping.getProperty(fieldName); if (r.getName().equals(fieldName)) throw new NonPersistentFieldException(type, Collections.singleton(fieldName)); } catch (MappingException e) { } } }
From source file:net.chrisrichardson.ormunit.hibernate.HibernateMappingTests.java
License:Apache License
protected void assertVersionField(String fieldName, String columnName) { Property versionProperty = classMapping.getVersion(); assertEquals(fieldName, versionProperty.getName()); HibernateAssertUtil.assertPropertyColumn(columnName, versionProperty); }
From source file:org.babyfish.hibernate.cfg.Configuration.java
License:Open Source License
private static void replaceUserCollectionType(Property mappingProperty, Class<? extends org.hibernate.mapping.Collection> hibernateCollectionType, Class<? extends AbstractMACollectionType> babyfishCollectionType) { /*// ww w . j a v a 2s .c o m * Don't invoke property.getType() or property.getValue().getType() * that will cause the creating of original collection-type before the replacement. * that is is slow */ Value value = mappingProperty.getValue(); if (!(value instanceof org.hibernate.mapping.Collection)) { throw new MappingException('"' + mappingProperty.getPersistentClass().getEntityName() + '.' + mappingProperty.getName() + "\" must be mapped as collection."); } org.hibernate.mapping.Collection collection = (org.hibernate.mapping.Collection) value; String typeName = collection.getTypeName(); if (typeName == null) { if (!hibernateCollectionType.isAssignableFrom(value.getClass())) { throw new MappingException('"' + mappingProperty.getPersistentClass().getEntityName() + '.' + mappingProperty.getName() + "\" must be mapped collection whose hibernate type is \"" + hibernateCollectionType.getName() + "\"."); } collection.setTypeName(babyfishCollectionType.getName()); } else { Class<?> userCollctionType; try { userCollctionType = ReflectHelper.classForName(typeName); } catch (ClassNotFoundException ex) { throw new MappingException( '"' + mappingProperty.getPersistentClass().getEntityName() + '.' + mappingProperty.getName() + "\" must be mapped as collection whose attribute \"collection-type\" is \"" + typeName + "\", but the there is no java type names\"" + typeName + "\"."); } if (!babyfishCollectionType.isAssignableFrom(userCollctionType)) { throw new MappingException( '"' + mappingProperty.getPersistentClass().getEntityName() + '.' + mappingProperty.getName() + "\" must be mapped as collection whose attribut \"collection-type\" is \"" + typeName + "\", but the there class \"" + typeName + "\" is not \"" + babyfishCollectionType.getName() + "\" or its derived class."); } } }
From source file:org.beangle.orm.hibernate.tool.DdlGenerator.java
License:Open Source License
@SuppressWarnings("unchecked") private void commentProperty(Class<?> clazz, Table table, Property p) { if (null == p) return;/*from w ww. jav a 2 s . co m*/ if (p.getColumnSpan() == 1) { Column column = (Column) p.getColumnIterator().next(); if (isForeignColumn(table, column)) { column.setComment(messages.get(clazz, p.getName()) + " ID"); } else { column.setComment(messages.get(clazz, p.getName())); } } else if (p.getColumnSpan() > 1) { Component pc = ((Component) p.getValue()); Class<?> columnOwnerClass = pc.getComponentClass(); commentProperties(columnOwnerClass, table, pc.getPropertyIterator()); } }
From source file:org.beangle.orm.hibernate.tool.HbmGenerator.java
License:Open Source License
@SuppressWarnings("unchecked") public void gen(String file) throws Exception { hbconfig = new OverrideConfiguration(); hbconfig.getProperties().put(Environment.DIALECT, new Oracle10gDialect()); ConfigBuilder.build(hbconfig);/*ww w. j ava 2 s.c om*/ freemarkerConfig = new freemarker.template.Configuration(); freemarkerConfig.setTemplateLoader(new ClassTemplateLoader(getClass(), "/")); Iterator<PersistentClass> iter = hbconfig.getClassMappings(); List<PersistentClass> pcs = CollectUtils.newArrayList(); while (iter.hasNext()) { PersistentClass pc = iter.next(); Class<?> cls = pc.getMappedClass(); Iterator<Property> pi = pc.getPropertyIterator(); // For AnnotationBinder don't set column'length and nullable in ,let's we do it. while (pi.hasNext()) { Property p = pi.next(); if (p.getColumnSpan() != 1) continue; Column column = (Column) p.getColumnIterator().next(); if (column.getLength() == Column.DEFAULT_LENGTH) { Size size = findAnnotation(cls, Size.class, p.getName()); if (null != size) column.setLength(size.max()); } if (column.isNullable()) { NotNull notnull = findAnnotation(cls, NotNull.class, p.getName()); if (null != notnull) column.setNullable(false); } } if (!pc.getClassName().contains(".example.")) pcs.add(pc); } Map<String, Object> data = CollectUtils.newHashMap(); data.put("classes", pcs); data.put("generator", this); Template freemarkerTemplate = freemarkerConfig.getTemplate("/hbm.ftl"); FileWriter fw = new FileWriter("/tmp/hibernate.hbm.xml"); freemarkerTemplate.process(data, fw); }
From source file:org.broadleafcommerce.openadmin.server.dao.DynamicEntityDaoImpl.java
License:Apache License
protected FieldMetadata getFieldMetadata(String prefix, String propertyName, List<Property> componentProperties, SupportedFieldType type, SupportedFieldType secondaryType, Type entityType, Class<?> targetClass, FieldPresentationAttributes presentationAttribute, MergedPropertyType mergedPropertyType) throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { FieldMetadata fieldMetadata = new FieldMetadata(); fieldMetadata.setFieldType(type);/*from ww w . j a v a2s . c o m*/ fieldMetadata.setSecondaryType(secondaryType); if (entityType != null && !entityType.isCollectionType()) { Column column = null; for (Property property : componentProperties) { if (property.getName().equals(propertyName)) { column = (Column) property.getColumnIterator().next(); break; } } if (column != null) { fieldMetadata.setLength(column.getLength()); fieldMetadata.setScale(column.getScale()); fieldMetadata.setPrecision(column.getPrecision()); fieldMetadata.setRequired(!column.isNullable()); fieldMetadata.setUnique(column.isUnique()); } fieldMetadata.setCollection(false); } else { fieldMetadata.setCollection(true); } fieldMetadata.setMutable(true); fieldMetadata.setInheritedFromType(targetClass.getName()); fieldMetadata.setAvailableToTypes(new String[] { targetClass.getName() }); if (presentationAttribute != null) { fieldMetadata.setPresentationAttributes(presentationAttribute); } fieldMetadata.setMergedPropertyType(mergedPropertyType); if (SupportedFieldType.BROADLEAF_ENUMERATION.equals(type)) { setupBroadleafEnumeration(presentationAttribute.getBroadleafEnumeration(), fieldMetadata); } return fieldMetadata; }