List of usage examples for org.hibernate.mapping PersistentClass getKey
public abstract KeyValue getKey();
From source file:com.github.shyiko.rook.target.hibernate4.cache.PrimaryKey.java
License:Apache License
public PrimaryKey(PersistentClass persistentClass, Map<String, Integer> columnIndexByNameMap) { this(persistentClass.getKey(), persistentClass.getTable(), columnIndexByNameMap); final Type type = persistentClass.getIdentifier().getType(); if (type instanceof EmbeddedComponentType) { entityClass = type.getReturnedClass(); } else {/* www .ja v a 2 s. c o m*/ entityClass = persistentClass.getMappedClass(); } }
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)); }/*ww w .j a va 2 s . co 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.xpn.xwiki.store.migration.hibernate.R40000XWIKI6990DataMigration.java
License:Open Source License
/** * get column name (first one) of a property of the given pClass. * @param pClass the persistent class/*from w ww. j a va 2 s.c om*/ * @param propertyName the name of the property, or null to return the first column of the key * @return the column name of the property */ private String getColumnName(PersistentClass pClass, String propertyName) { if (propertyName != null) { return ((Column) pClass.getProperty(propertyName).getColumnIterator().next()).getName(); } return ((Column) pClass.getKey().getColumnIterator().next()).getName(); }
From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java
License:Apache License
protected Property getProperty(PersistentClass associatedClass, String propertyName) throws MappingException { try {/*from ww w. j a v a 2s . com*/ return associatedClass.getProperty(propertyName); } catch (MappingException e) { //maybe it's squirreled away in a composite primary key if (associatedClass.getKey() instanceof Component) { return ((Component) associatedClass.getKey()).getProperty(propertyName); } throw e; } }
From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.java
License:Apache License
private static Property getProperty(PersistentClass associatedClass, String propertyName) throws MappingException { try {//from w w w .j a v a 2 s .c om return associatedClass.getProperty(propertyName); } catch (MappingException e) { //maybe it's squirreled away in a composite primary key if (associatedClass.getKey() instanceof Component) { return ((Component) associatedClass.getKey()).getProperty(propertyName); } throw e; } }