List of usage examples for org.hibernate.mapping Property getColumnIterator
public Iterator getColumnIterator()
From source file:com.ah.ui.actions.BaseAction.java
public int getAttributeLength(String name) { /*- hibernate annotation doesn't work after hibernate upgraded to 3.5.x, use JPA annotation instead try {//ww w . ja v a2 s .c o m Field field = boClass.getDeclaredField(name); Length length = field.getAnnotation(Length.class); if (length != null) { log.debug("getAttributeLength", "Attribute '" + name + "' length: " + length.max()); return length.max(); } } catch (NoSuchFieldException e) { log.error("getAttributeLength", "Attribute '" + name + "' does not exist in class '" + boClass.getName() + "'."); }*/ if (boPersistentClass == null) { log.error("getAttributeLength", "boPersistentClass has not been initialized."); return 0; } Property property = boPersistentClass.getProperty(name); if (property == null) { log.error("getAttributeLength", "Attribute '" + name + "' does not exist in class '" + boClass.getName() + "'."); return 0; } if (property.getColumnIterator().hasNext()) { Column column = (Column) property.getColumnIterator().next(); log.debug("getAttributeLength", "Attribute '" + name + "' length is: " + column.getLength()); return column.getLength(); } else { log.error("getAttributeLength", "Attribute '" + name + "' in class '" + boClass.getName() + "' does not map to a column."); return 0; } }
From source file:com.clueride.rest.MemberWebService.java
License:Apache License
private void dumpEntities() { Metadata metadata = MetadataExtractorIntegrator.INSTANCE.getMetadata(); for (PersistentClass persistentClass : metadata.getEntityBindings()) { Table table = persistentClass.getTable(); LOGGER.info(String.format("Entity: {} is mapped to table: {}", persistentClass.getClassName(), table.getName()));//from w w w . j a v a 2 s . c om for (Iterator propertyIterator = persistentClass.getPropertyIterator(); propertyIterator.hasNext();) { Property property = (Property) propertyIterator.next(); for (Iterator columnIterator = property.getColumnIterator(); columnIterator.hasNext();) { Column column = (Column) columnIterator.next(); LOGGER.info(String.format("Property: {} is mapped on table column: {} of type: {}", property.getName(), column.getName(), column.getSqlType())); } } } }
From source file:com.fiveamsolutions.nci.commons.audit.AuditLogInterceptor.java
License:Open Source License
/** * Retrieves the column name for the given PersistentClass and fieldName. * * @param pc/* www . j a v a 2 s .co m*/ * @param fieldName * @return columnName */ private static String getColumnName(PersistentClass pc, String fieldName) { if (pc == null) { return null; } String columnName = null; Property property = pc.getProperty(fieldName); for (Iterator<?> it3 = property.getColumnIterator(); it3.hasNext();) { Object o = it3.next(); if (!(o instanceof Column)) { LOG.debug("Skipping non-column (probably a formula"); continue; } Column column = (Column) o; columnName = column.getName(); break; } if (columnName == null) { try { columnName = getColumnName(pc.getSuperclass(), fieldName); } catch (MappingException e) { // in this case the annotation / mapping info was at the current class and not the base class // but for some reason the column name could not be determined. // This will happen when a subclass of an entity uses a joined subclass. // in this case just set column Name to null and let the caller default to the property name. columnName = null; } } return columnName; }
From source file:com.github.shyiko.rook.target.hibernate4.cache.PrimaryKey.java
License:Apache License
private PrimaryKey(KeyValue keyValue, Table table, Map<String, Integer> columnIndexByNameMap) { KeyColumn[] positionWithinRow = new KeyColumn[keyValue.getColumnSpan()]; int index = 0; if (keyValue instanceof Component) { Iterator propertyIterator = ((Component) keyValue).getPropertyIterator(); while (propertyIterator.hasNext()) { Property property = (Property) propertyIterator.next(); String columnName = ((Column) property.getColumnIterator().next()).getName(); positionWithinRow[index++] = new KeyColumn(property.getName(), columnIndexByNameMap.get(columnName)); }// w w w . j ava 2 s. c o m } else { Iterator columnIterator = keyValue.getColumnIterator(); while (columnIterator.hasNext()) { String columnName = ((Column) columnIterator.next()).getName(); positionWithinRow[index++] = new KeyColumn(columnName, columnIndexByNameMap.get(columnName)); } } if (positionWithinRow.length == 0) { throw new IllegalStateException("Unable to determine PK for " + table.getName()); } this.positionWithinRow = positionWithinRow; }
From source file:com.github.shyiko.rook.target.hibernate4.fulltextindex.PrimaryKey.java
License:Apache License
public PrimaryKey(PersistentClass persistentClass) { this.entityClass = persistentClass.getMappedClass(); KeyValue keyValue = persistentClass.getKey(); Table table = persistentClass.getTable(); Map<String, Integer> columnIndexByNameMap = getColumnIndexByNameMap(table); KeyColumn[] positionWithinRow = new KeyColumn[keyValue.getColumnSpan()]; int index = 0; if (keyValue instanceof Component) { Iterator propertyIterator = ((Component) keyValue).getPropertyIterator(); while (propertyIterator.hasNext()) { Property property = (Property) propertyIterator.next(); String columnName = ((Column) property.getColumnIterator().next()).getName(); positionWithinRow[index++] = new KeyColumn(property.getName(), columnIndexByNameMap.get(columnName)); }/* w ww . ja va2s .c o m*/ } else { Iterator columnIterator = keyValue.getColumnIterator(); while (columnIterator.hasNext()) { String columnName = ((Column) columnIterator.next()).getName(); positionWithinRow[index++] = new KeyColumn(columnName, columnIndexByNameMap.get(columnName)); } } if (positionWithinRow.length == 0) { throw new IllegalStateException("Unable to determine PK for " + table.getName()); } Property identifierProperty = persistentClass.getIdentifierProperty(); this.getter = identifierProperty.getGetter(this.entityClass); this.positionWithinRow = positionWithinRow; }
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 ww . j a va 2 s .co m*/ 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.tomitribe.reveng.codegen.FreemarkerObject.java
License:Apache License
public String generateManyToOneAnnotation(final BasicPOJOClass pojo, final Property p, String table) { // @ForeignKey(name="FK_recipe_tree_node") final Value value = p.getValue(); final int span; final Iterator columnIterator; if (value != null && value instanceof Collection) { final Collection collection = (Collection) value; span = collection.getKey().getColumnSpan(); columnIterator = collection.getKey().getColumnIterator(); } else {// ww w. j a v a 2 s . co m span = p.getColumnSpan(); columnIterator = p.getColumnIterator(); } final Selectable selectable = (Selectable) columnIterator.next(); final Column column = (Column) selectable; table += "_" + column.getName(); // id_tree_node table = "FK_" + table.replace("_id_", "_"); String s = EntityPOJOClass.class.cast(pojo).generateManyToOneAnnotation(p); s += "\n@ForeignKey(name=\"" + table + "\")"; // log.info(s); return s; }
From source file:com.vecna.maven.hibernate.HibernateDocMojo.java
License:Apache License
/** * set a comment on Hibernate columns mapped to a property *//*from ww w. ja va 2 s .c o m*/ private void setComment(String comment, Property prop) { @SuppressWarnings("unchecked") Iterator<Column> columnIterator = prop.getColumnIterator(); setComment(comment, columnIterator); }
From source file:com.wavemaker.runtime.data.task.AbstractReadTask.java
License:Open Source License
protected boolean isNulleable(Class<?> rootType, String propertyPath, String dbName) { Property p = getProperty(rootType, propertyPath, NOOP_PROPERTY_TRAVERSAL, dbName); if (isRelatedMany(p.getType().getReturnedClass())) { return true; }//from w w w . j av a 2 s . c om return ((Column) p.getColumnIterator().next()).isNullable(); }
From source file:com.wm.framework.sh.dao.impl.BaseDaoImpl.java
License:Open Source License
protected String getColumnName(Class<?> clazz, String propertyName) { PersistentClass persistentClass = getPersistentClass(clazz); Property property = persistentClass.getProperty(propertyName); Iterator<?> it = property.getColumnIterator(); if (it.hasNext()) { Column column = (Column) it.next(); return column.getName(); }/*from w w w. j a va 2 s .co m*/ return null; }