List of usage examples for org.hibernate.mapping Component getComponentClass
public Class getComponentClass() throws MappingException
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/*from w w w . java 2 s .com*/ * @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:gr.interamerican.bo2.impl.open.hibernate.tuple.Bo2PojoComponentTuplizer.java
License:Open Source License
@Override protected Instantiator buildInstantiator(Component component) { if (ReflectionUtils.isConcreteClass(component.getComponentClass())) { return super.buildInstantiator(component); }/*from w w w . j a v a 2 s.c o m*/ return new Bo2PojoComponentInstantiator(component); }
From source file:gr.interamerican.bo2.impl.open.hibernate.tuple.instantiator.Bo2PojoComponentInstantiator.java
License:Open Source License
/** * Creates a new Bo2PojoInstantiator object. * //from ww w .j a v a2 s .co m * @param component */ public Bo2PojoComponentInstantiator(Component component) { this.componentClass = component.getComponentClass(); }
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 ww. ja v a 2 s . c o m*/ } }
From source file:net.chrisrichardson.ormunit.hibernate.HibernateMappingTests.java
License:Apache License
private void assertAllFieldsMapped(Component cv, Set fieldsToIgnore) { Set unmappedFields = new HashSet(); Set mappedFields = new HashSet(); for (Iterator it = HibernateAssertUtil.getPersistableFields(cv.getComponentClass(), false).iterator(); it .hasNext();) {/*from w w w . j a va 2s. co m*/ String fieldName = (String) it.next(); try { cv.getProperty(fieldName); mappedFields.add(fieldName); } catch (MappingException e) { unmappedFields.add(fieldName); } } unmappedFields.removeAll(fieldsToIgnore); if (!unmappedFields.isEmpty()) throw new UnmappedFieldsException(cv.getComponentClass(), unmappedFields); Set x = intersection(mappedFields, fieldsToIgnore); if (!x.isEmpty()) { throw new NonPersistentFieldException(cv.getComponentClass(), x); } }
From source file:org.beangle.orm.hibernate.tool.DdlGenerator.java
License:Open Source License
/** * Generate sql scripts/* w ww. j av a2 s. co m*/ * * @param fileName * @param packageName * @throws Exception */ @SuppressWarnings("unchecked") public void gen(String fileName, String packageName) throws Exception { configuration = ConfigBuilder.build(new OverrideConfiguration()); mapping = configuration.buildMapping(); defaultCatalog = configuration.getProperties().getProperty(Environment.DEFAULT_CATALOG); defaultSchema = configuration.getProperties().getProperty(Environment.DEFAULT_SCHEMA); configuration.getProperties().put(Environment.DIALECT, dialect); // 1. first process class mapping Iterator<PersistentClass> iterpc = configuration.getClassMappings(); while (iterpc.hasNext()) { PersistentClass pc = iterpc.next(); Class<?> clazz = pc.getMappedClass(); if (isNotBlank(packageName) && !clazz.getPackage().getName().startsWith(packageName)) continue; // add comment to table and column pc.getTable().setComment(messages.get(clazz, clazz.getSimpleName())); commentProperty(clazz, pc.getTable(), pc.getIdentifierProperty()); commentProperties(clazz, pc.getTable(), pc.getPropertyIterator()); // generator sequence sql if (pc instanceof RootClass) { IdentifierGenerator ig = pc.getIdentifier().createIdentifierGenerator( configuration.getIdentifierGeneratorFactory(), dialect, defaultCatalog, defaultSchema, (RootClass) pc); if (ig instanceof PersistentIdentifierGenerator) { String[] lines = ((PersistentIdentifierGenerator) ig).sqlCreateStrings(dialect); sequences.addAll(Arrays.asList(lines)); } } // generater table sql generateTableSql(pc.getTable()); } // 2. process collection mapping Iterator<Collection> itercm = configuration.getCollectionMappings(); while (itercm.hasNext()) { Collection col = itercm.next(); if (isNotBlank(packageName) && !col.getRole().startsWith(packageName)) continue; // collection sequences if (col.isIdentified()) { IdentifierGenerator ig = ((IdentifierCollection) col).getIdentifier().createIdentifierGenerator( configuration.getIdentifierGeneratorFactory(), dialect, defaultCatalog, defaultSchema, null); if (ig instanceof PersistentIdentifierGenerator) { String[] lines = ((PersistentIdentifierGenerator) ig).sqlCreateStrings(dialect); sequences.addAll(Arrays.asList(lines)); } } // collection table if (!col.isOneToMany()) { Table table = col.getCollectionTable(); String owner = col.getTable().getComment(); Class<?> ownerClass = col.getOwner().getMappedClass(); // resolved nested compoent name in collection's role String colName = substringAfter(col.getRole(), col.getOwnerEntityName() + "."); if (colName.contains(".")) ownerClass = getPropertyType(col.getOwner(), substringBeforeLast(colName, ".")); table.setComment(owner + "-" + messages.get(ownerClass, substringAfterLast(col.getRole(), "."))); Column keyColumn = table.getColumn((Column) col.getKey().getColumnIterator().next()); if (null != keyColumn) keyColumn.setComment(owner + " ID"); if (col instanceof IndexedCollection) { IndexedCollection idxCol = (IndexedCollection) col; Value idx = idxCol.getIndex(); if (idx instanceof ToOne) commentToOne((ToOne) idx, (Column) idx.getColumnIterator().next()); } if (col.getElement() instanceof ManyToOne) { Column valueColumn = (Column) col.getElement().getColumnIterator().next(); commentToOne((ManyToOne) col.getElement(), valueColumn); } else if (col.getElement() instanceof Component) { Component cp = (Component) col.getElement(); commentProperties(cp.getComponentClass(), table, cp.getPropertyIterator()); } generateTableSql(col.getCollectionTable()); } } Set<String> commentSet = CollectUtils.newHashSet(comments); comments.clear(); comments.addAll(commentSet); // 3. export to files for (String key : files.keySet()) { List<List<String>> sqls = files.get(key); FileWriter writer = new FileWriter(fileName + "/" + key, false); writes(writer, sqls); writer.flush(); writer.close(); } }
From source file:org.beangle.orm.hibernate.tool.DdlGenerator.java
License:Open Source License
/** * get component class by component property string * // w w w . ja va2s.c o m * @param pc * @param propertyString * @return */ private Class<?> getPropertyType(PersistentClass pc, String propertyString) { String[] properties = split(propertyString, '.'); Property p = pc.getProperty(properties[0]); Component cp = ((Component) p.getValue()); int i = 1; for (; i < properties.length; i++) { p = cp.getProperty(properties[i]); cp = ((Component) p.getValue()); } return cp.getComponentClass(); }
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;/* w ww . j av a 2s .c o 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.eclipse.emf.cdo.server.internal.hibernate.tuplizer.FeatureMapEntryTuplizer.java
License:Open Source License
@Override protected Getter buildGetter(Component component, Property prop) { return getPropertyAccessor(prop, component).getGetter(component.getComponentClass(), prop.getName()); }
From source file:org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.FeatureMapEntryTuplizer.java
License:Open Source License
@Override protected Setter buildSetter(Component component, Property prop) { return getPropertyAccessor(prop, component).getSetter(component.getComponentClass(), prop.getName()); }