Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/persister In directory sc8-pr-cvs1:/tmp/cvs-serv13138/persister Modified Files: AbstractEntityPersister.java EntityPersister.java NormalizedEntityPersister.java Queryable.java Log Message: added CompositeUserType refactored handling of component path expressions PersistentIdentifierGenerators now aware of schema Index: AbstractEntityPersister.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/persister/AbstractEntityPersister.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** AbstractEntityPersister.java 4 Apr 2003 13:51:59 -0000 1.17 --- AbstractEntityPersister.java 6 Apr 2003 02:28:57 -0000 1.18 *************** *** 19,23 **** import net.sf.hibernate.MappingException; import net.sf.hibernate.PropertyAccessException; - import net.sf.hibernate.QueryException; import net.sf.hibernate.StaleObjectStateException; import net.sf.hibernate.Validatable; --- 19,22 ---- *************** *** 32,36 **** import net.sf.hibernate.id.IdentityGenerator; import net.sf.hibernate.mapping.Column; - import net.sf.hibernate.mapping.Component; import net.sf.hibernate.mapping.PersistentClass; import net.sf.hibernate.mapping.Property; --- 31,34 ---- *************** *** 39,43 **** import net.sf.hibernate.metadata.ClassMetadata; import net.sf.hibernate.proxy.HibernateProxy; - import net.sf.hibernate.hql.PathExpressionParser; import net.sf.hibernate.dialect.Dialect; import net.sf.hibernate.sql.SelectFragment; --- 37,40 ---- *************** *** 92,97 **** private transient final Cascades.IdentifierValue unsavedIdentifierValue; - private transient final HashMap idTypesByPropertyPath = new HashMap(); - private transient final HashMap idColumnNamesByPropertyPath = new HashMap(); protected transient final HashMap columnNamesByPropertyPath = new HashMap(); protected transient final HashMap typesByPropertyPath = new HashMap(); --- 89,92 ---- *************** *** 143,214 **** } - public String[] toColumns(String name, String path) throws QueryException { - - final String[] cols; - - if ( path.equals(PathExpressionParser.ENTITY_CLASS) ) { - cols = new String[] { getDiscriminatorColumnName() }; - } - else { - - String idprop = getIdentifierPropertyName(); - - if ( - PathExpressionParser.ENTITY_ID.equals(path) || - ( idprop!=null && path.equals(idprop) ) - ){ - cols = getIdentifierColumnNames(); - - } - else if ( - path.startsWith(PathExpressionParser.ENTITY_ID + StringHelper.DOT) || - ( idprop!=null && path.startsWith(idprop + StringHelper.DOT) ) - ) { - - int loc = path.indexOf("."); - String componentPath = path.substring(loc+1); - - if ( getIdentifierType().isComponentType() ) { - cols = getIdentifierPropertyColumnNames(componentPath); - if (cols==null) throw new QueryException("composite id path not found (or dereferenced a <key-many-to-one>)"); - } - else { - throw new QueryException("unresolved id property: " + path); - } - } - else { - return null; - } - } - - return StringHelper.prefix(cols, name + StringHelper.DOT); - - } - public Type getPropertyType(String path) { ! ! if ( path.equals(PathExpressionParser.ENTITY_CLASS) ) { ! return getDiscriminatorType(); ! } ! else { ! ! String idprop = getIdentifierPropertyName(); ! ! if ( ! PathExpressionParser.ENTITY_ID.equals(path) || ! ( idprop!=null && path.equals(idprop) ) ! ){ ! return getIdentifierType(); ! } ! else if ( ! path.startsWith(PathExpressionParser.ENTITY_ID + StringHelper.DOT) || ! ( idprop!=null && path.startsWith(idprop + StringHelper.DOT) ) ! ) { ! return getIdentifierPropertyType( path.substring( PathExpressionParser.ENTITY_ID.length()+1 ) ); ! } ! else { ! return (Type) typesByPropertyPath.get(path); ! } ! } } --- 138,143 ---- } public Type getPropertyType(String path) { ! return (Type) typesByPropertyPath.get(path); } *************** *** 421,430 **** } - public final String[] getIdentifierPropertyColumnNames(String path) { - return (String[]) idColumnNamesByPropertyPath.get(path); - } - public final Type getIdentifierPropertyType(String path) { - return (Type) idTypesByPropertyPath.get(path); - } public final String[] getPropertyColumnNames(String path) { return (String[]) columnNamesByPropertyPath.get(path); --- 350,353 ---- *************** *** 559,589 **** i++; } - - - if ( idValue.isComposite() ) { - - iter = ( (Component) idValue ).getPropertyIterator(); - while ( iter.hasNext() ) { - - Property prop = (Property) iter.next(); - idTypesByPropertyPath.put( prop.getName(), prop.getType() ); - - String[] cols = new String[ prop.getColumnSpan() ]; - Iterator colIter= prop.getColumnIterator(); - int j=0; - while ( colIter.hasNext() ) { - Column col = (Column) colIter.next(); - cols[j++] = col.getName(); - } - idColumnNamesByPropertyPath.put( prop.getName(), cols ); - if ( model.hasEmbeddedIdentifier() ) { - columnNamesByPropertyPath.put( prop.getName(), cols ); - typesByPropertyPath.put( prop.getName(), prop.getType() ); - } - - } - } - // GENERATOR --- 482,486 ---- *************** *** 772,776 **** ( (ReflectHelper.Setter) settersByPropertyName.get(propertyName) ).set(object, value); } ! } --- 669,676 ---- ( (ReflectHelper.Setter) settersByPropertyName.get(propertyName) ).set(object, value); } ! ! protected boolean hasEmbeddedIdentifier() { ! return hasEmbeddedIdentifier; ! } } Index: EntityPersister.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/persister/EntityPersister.java,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** EntityPersister.java 2 Apr 2003 13:10:36 -0000 1.23 --- EntityPersister.java 6 Apr 2003 02:28:57 -0000 1.24 *************** *** 7,13 **** import net.sf.hibernate.loader.SimpleEntityLoader; import net.sf.hibernate.loader.UniqueEntityLoader; - import net.sf.hibernate.mapping.Any; import net.sf.hibernate.mapping.Column; - import net.sf.hibernate.mapping.Component; import net.sf.hibernate.mapping.PersistentClass; import net.sf.hibernate.mapping.Property; --- 7,11 ---- *************** *** 30,34 **** import org.apache.commons.logging.LogFactory; - import net.sf.hibernate.Hibernate; import net.sf.hibernate.HibernateException; import net.sf.hibernate.LockMode; --- 28,31 ---- *************** *** 48,51 **** --- 45,49 ---- import net.sf.hibernate.type.EntityType; import net.sf.hibernate.type.Type; + import net.sf.hibernate.engine.Mapping; import net.sf.hibernate.engine.SessionFactoryImplementor; import net.sf.hibernate.engine.SessionImplementor; *************** *** 99,102 **** --- 97,103 ---- public void postInstantiate(SessionFactoryImplementor factory) throws MappingException { + initPropertyPaths(factory); + + //TODO: move into initPropertyPaths HashMap mods = new HashMap(); Iterator iter = typesByPropertyPath.entrySet().iterator(); *************** *** 687,697 **** propertyColumnAliases[i] = colAliases; ! initPropertyPaths(prop, StringHelper.EMPTY_STRING); i++; } ! if ( model.hasIdentifierProperty() && model.getIdentifierProperty().isComposite() ) { ! initPropertyPaths( model.getIdentifierProperty(), StringHelper.EMPTY_STRING ); ! } hasUpdateableColumns = foundColumn; --- 688,698 ---- propertyColumnAliases[i] = colAliases; ! //initPropertyPaths(prop, StringHelper.EMPTY_STRING, factory); i++; } ! /*if ( model.hasIdentifierProperty() && model.getIdentifierProperty().isComposite() ) { ! initPropertyPaths( model.getIdentifierProperty(), StringHelper.EMPTY_STRING, factory ); ! }*/ hasUpdateableColumns = foundColumn; *************** *** 790,835 **** } ! ! private void initPropertyPaths(Property prop, String path) { ! ! path += prop.getName(); ! if ( prop.isComposite() ) { ! Iterator iter = ( (Component) prop.getValue() ).getPropertyIterator(); ! while ( iter.hasNext() ) { ! initPropertyPaths( (Property) iter.next(), path + "." ) ; ! } ! } ! Iterator iter = prop.getColumnIterator(); ! String[] names = new String[ prop.getColumnSpan() ]; ! int k=0; ! while ( iter.hasNext() ) { ! names[k] = ( (Column) iter.next() ).getName(); ! k++; } ! Type type = prop.getType(); ! typesByPropertyPath.put(path, type); ! columnNamesByPropertyPath.put(path, names); ! if ( prop.getValue().isAny() ) { ! String idpath = path + ".id"; ! String clpath = path + ".class"; ! ! Any any = (Any) prop.getValue(); ! typesByPropertyPath.put( idpath, any.getIdentifierType() ); ! typesByPropertyPath.put( clpath, Hibernate.CLASS ); ! ! iter = any.getColumnIterator(); ! columnNamesByPropertyPath.put( clpath, new String[] { ( (Column) iter.next() ).getName() } ); ! names = new String[ any.getColumnSpan() - 1 ]; ! k=0; ! while ( iter.hasNext() ) { ! names[k++] = ( (Column) iter.next() ).getName(); } - columnNamesByPropertyPath.put(idpath, names); } - } --- 791,835 ---- } ! private void initPropertyPaths(Mapping mapping) throws MappingException { ! Type[] propertyTypes = getPropertyTypes(); ! String[] propertyNames = getPropertyNames(); ! for ( int i=0; i<propertyNames.length; i++ ) { ! initPropertyPaths( propertyNames[i], propertyTypes[i], propertyColumnNames[i], mapping ); } ! String idProp = getIdentifierPropertyName(); ! if (idProp!=null) initPropertyPaths( idProp, getIdentifierType(), getIdentifierColumnNames(), mapping ); ! if ( hasEmbeddedIdentifier() ) initPropertyPaths( null, getIdentifierType(), getIdentifierColumnNames(), mapping ); ! initPropertyPaths( PathExpressionParser.ENTITY_ID, getIdentifierType(), getIdentifierColumnNames(), mapping ); ! if ( isPolymorphic() ) { ! typesByPropertyPath.put( PathExpressionParser.ENTITY_CLASS, getDiscriminatorType() ); ! columnNamesByPropertyPath.put( PathExpressionParser.ENTITY_CLASS, new String[] { getDiscriminatorColumnName() } ); ! } ! } ! ! private void initPropertyPaths(String propertyName, Type propertyType, String[] columns, Mapping mapping) throws MappingException { ! if (propertyName!=null) { ! typesByPropertyPath.put(propertyName, propertyType); ! columnNamesByPropertyPath.put(propertyName, columns); ! } ! ! if ( propertyType.isComponentType() ) { ! AbstractComponentType compType = (AbstractComponentType) propertyType; ! String[] props = compType.getPropertyNames(); ! Type[] types = compType.getSubtypes(); ! int count=0; ! for ( int k=0; k<props.length; k++ ) { ! int len = types[k].getColumnSpan(mapping); ! String[] slice = new String[len]; ! for ( int j=0; j<len; j++ ) { ! slice[j] = columns[count++]; ! } ! String path = (propertyName==null) ? props[k] : propertyName + '.' + props[k]; ! initPropertyPaths(path, types[k], slice, mapping); } } } *************** *** 862,868 **** public String[] toColumns(String name, String property) throws QueryException { - - String[] idcols = super.toColumns(name, property); - if (idcols!=null) return idcols; String[] cols = getPropertyColumnNames(property); --- 862,865 ---- Index: NormalizedEntityPersister.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/persister/NormalizedEntityPersister.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** NormalizedEntityPersister.java 29 Mar 2003 04:08:48 -0000 1.15 --- NormalizedEntityPersister.java 6 Apr 2003 02:28:57 -0000 1.16 *************** *** 7,13 **** import net.sf.hibernate.loader.EntityLoader; import net.sf.hibernate.loader.UniqueEntityLoader; - import net.sf.hibernate.mapping.Any; import net.sf.hibernate.mapping.Column; - import net.sf.hibernate.mapping.Component; import net.sf.hibernate.mapping.PersistentClass; import net.sf.hibernate.mapping.Property; --- 7,11 ---- *************** *** 49,52 **** --- 47,51 ---- import net.sf.hibernate.type.EntityType; import net.sf.hibernate.type.Type; + import net.sf.hibernate.engine.Mapping; import net.sf.hibernate.engine.SessionFactoryImplementor; import net.sf.hibernate.engine.SessionImplementor; *************** *** 112,115 **** --- 111,117 ---- public void postInstantiate(SessionFactoryImplementor factory) throws MappingException { + initPropertyPaths(factory); + + //TODO: move into initPropertyPaths HashMap mods = new HashMap(); Iterator iter = typesByPropertyPath.entrySet().iterator(); *************** *** 765,776 **** propertyColumnNameAliases[i] = propAliases; - initPropertyPaths(prop, StringHelper.EMPTY_STRING); i++; } - if ( model.hasIdentifierProperty() && model.getIdentifierProperty().isComposite() ) { - initPropertyPaths( model.getIdentifierProperty(), StringHelper.EMPTY_STRING ); - } - ArrayList columns = new ArrayList(); ArrayList types = new ArrayList(); --- 767,773 ---- *************** *** 889,944 **** } ! ! ! private void initPropertyPaths(Property prop, String path) { ! ! path += prop.getName(); ! if ( prop.isComposite() ) { ! Iterator iter = ( (Component) prop.getValue() ).getPropertyIterator(); ! while ( iter.hasNext() ) { ! initPropertyPaths( (Property) iter.next(), path + "." ) ; ! } ! } ! Iterator iter = prop.getColumnIterator(); ! String[] names = new String[ prop.getColumnSpan() ]; ! int k=0; ! while ( iter.hasNext() ) { ! names[k++] = ( (Column) iter.next() ).getName(); } ! Integer tabno = new Integer( getTableId( ! prop.getValue().getTable().getQualifiedName( factory.getDefaultSchema() ), ! subclassTableNameClosure ! ) ); ! Type type = prop.getType(); ! ! typesByPropertyPath.put(path, type); ! tableNumberByPropertyPath.put(path, tabno); ! columnNamesByPropertyPath.put(path, names); ! if ( prop.getValue().isAny() ) { ! String idpath = path + ".id"; ! String clpath = path + ".class"; ! ! Any any = (Any) prop.getValue(); ! typesByPropertyPath.put( idpath, any.getIdentifierType() ); ! typesByPropertyPath.put( clpath, Hibernate.CLASS ); ! ! iter = any.getColumnIterator(); ! columnNamesByPropertyPath.put( clpath, new String[] { ( (Column) iter.next() ).getName() } ); ! names = new String[ any.getColumnSpan() - 1 ]; ! k=0; ! while ( iter.hasNext() ) { ! names[k++] = ( (Column) iter.next() ).getName(); } - columnNamesByPropertyPath.put(idpath, names); - tableNumberByPropertyPath.put(idpath, tabno); - tableNumberByPropertyPath.put(clpath, tabno); } - } public String fromTableFragment(String alias) { return subclassTableNameClosure[0] + ' ' + alias; --- 886,934 ---- } ! ! private void initPropertyPaths(Mapping mapping) throws MappingException { ! Type[] propertyTypes = getPropertyTypes(); ! String[] propertyNames = getPropertyNames(); ! for ( int i=0; i<propertyNames.length; i++ ) { ! initPropertyPaths( propertyNames[i], propertyTypes[i], propertyColumnNames[i], propertyTables[i], mapping ); } ! String idProp = getIdentifierPropertyName(); ! if (idProp!=null) initPropertyPaths( idProp, getIdentifierType(), getIdentifierColumnNames(), 0, mapping ); ! if ( hasEmbeddedIdentifier() ) initPropertyPaths( null, getIdentifierType(), getIdentifierColumnNames(), 0, mapping ); ! initPropertyPaths( PathExpressionParser.ENTITY_ID, getIdentifierType(), getIdentifierColumnNames(), 0, mapping ); ! typesByPropertyPath.put( PathExpressionParser.ENTITY_CLASS, getDiscriminatorType() ); ! columnNamesByPropertyPath.put( PathExpressionParser.ENTITY_CLASS, new String[] { getDiscriminatorColumnName() } ); ! tableNumberByPropertyPath.put( PathExpressionParser.ENTITY_CLASS, new Integer(0) ); ! } ! ! private void initPropertyPaths(String propertyName, Type propertyType, String[] columns, int table, Mapping mapping) throws MappingException { ! if (propertyName!=null) { ! typesByPropertyPath.put(propertyName, propertyType); ! columnNamesByPropertyPath.put(propertyName, columns); ! tableNumberByPropertyPath.put( propertyName, new Integer(table) ); ! } ! ! if ( propertyType.isComponentType() ) { ! AbstractComponentType compType = (AbstractComponentType) propertyType; ! String[] props = compType.getPropertyNames(); ! Type[] types = compType.getSubtypes(); ! int count=0; ! for ( int k=0; k<props.length; k++ ) { ! int len = types[k].getColumnSpan(mapping); ! String[] slice = new String[len]; ! for ( int j=0; j<len; j++ ) { ! slice[j] = columns[count++]; ! } ! String path = (propertyName==null) ? props[k] : propertyName + '.' + props[k]; ! initPropertyPaths(path, types[k], slice, table, mapping); } } } + public String fromTableFragment(String alias) { return subclassTableNameClosure[0] + ' ' + alias; *************** *** 968,976 **** } - public String[] toColumns(String alias, String property) throws QueryException { - - String[] idcols = super.toColumns(alias, property); - if (idcols!=null) return idcols; String[] cols = getPropertyColumnNames(property); --- 958,962 ---- Index: Queryable.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/persister/Queryable.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Queryable.java 2 Mar 2003 06:58:53 -0000 1.6 --- Queryable.java 6 Apr 2003 02:28:58 -0000 1.7 *************** *** 35,43 **** */ public Type getPropertyType(String path); - /** - * Given a component path expression, get the type of the composite - * identifier property - */ - public Type getIdentifierPropertyType(String path); /** --- 35,38 ---- |