From: <one...@us...> - 2003-02-09 06:28:47
|
Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/collection In directory sc8-pr-cvs1:/tmp/cvs-serv20713/hibernate/collection Modified Files: ArrayHolder.java Bag.java CollectionPersister.java List.java Map.java ODMGCollection.java PersistentCollection.java Set.java SortedMap.java SortedSet.java Log Message: standardised on dom4j fixed bugs in collection caching (sometimes an exception occurred) allowed null discriminators set autocommit to true in SchemaUpdate collections now deserialize correctly Index: ArrayHolder.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/collection/ArrayHolder.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ArrayHolder.java 2 Feb 2003 04:19:51 -0000 1.6 --- ArrayHolder.java 9 Feb 2003 06:28:14 -0000 1.7 *************** *** 172,184 **** ! public void assemble(CollectionPersister persister) throws HibernateException, SQLException { ! ! Object[] cached = (Object[]) array; array = Array.newInstance( persister.getElementClass(), cached.length ); for ( int i=0; i<cached.length; i++ ) { ! Array.set(array, i, persister.getElementType().assemble( (Serializable) cached[i], session, null) ); } --- 172,184 ---- ! public ArrayHolder(SessionImplementor session, CollectionPersister persister, Serializable disassembled) throws HibernateException, SQLException { ! super(session); ! Serializable[] cached = (Serializable[]) disassembled; array = Array.newInstance( persister.getElementClass(), cached.length ); for ( int i=0; i<cached.length; i++ ) { ! Array.set(array, i, persister.getElementType().assemble(cached[i], session, null) ); } *************** *** 188,192 **** int length = temp.size(); ! Object[] result = new Object[length]; for ( int i=0; i<length; i++ ) { result[i] = persister.getElementType().disassemble( temp.get(i), session ); --- 188,192 ---- int length = temp.size(); ! Serializable[] result = new Serializable[length]; for ( int i=0; i<length; i++ ) { result[i] = persister.getElementType().disassemble( temp.get(i), session ); Index: Bag.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/collection/Bag.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Bag.java 5 Jan 2003 02:11:20 -0000 1.5 --- Bag.java 9 Feb 2003 06:28:14 -0000 1.6 *************** *** 149,155 **** int length = bag.size(); ! ArrayList result = new ArrayList(length); for ( int i=0; i<length; i++ ) { ! result.add( persister.getElementType().disassemble( bag.get(i), session ) ); } return result; --- 149,155 ---- int length = bag.size(); ! Serializable[] result = new Serializable[length]; for ( int i=0; i<length; i++ ) { ! result[i] = persister.getElementType().disassemble( bag.get(i), session ); } return result; *************** *** 159,170 **** * @see net.sf.hibernate.collections.PersistentCollection#assemble(CollectionPersister, SessionImplementor) */ ! public void assemble(CollectionPersister persister) throws HibernateException, SQLException { ! int length = bag.size(); ! java.util.List old = bag; beforeInitialize(persister); ! for ( int i=0; i<length; i++ ) { ! bag.add( persister.getElementType().assemble( (Serializable) old.get(i), session, null ) ); } } --- 159,171 ---- * @see net.sf.hibernate.collections.PersistentCollection#assemble(CollectionPersister, SessionImplementor) */ ! public Bag(SessionImplementor session, CollectionPersister persister, Serializable disassembled) throws HibernateException, SQLException { ! super(session); beforeInitialize(persister); ! Serializable[] array = (Serializable[]) disassembled; ! for ( int i=0; i<array.length; i++ ) { ! bag.add( persister.getElementType().assemble( array[i], session, null ) ); //TODO: fix the null!!! } + initialized=true; } *************** *** 306,312 **** throw new UnsupportedOperationException("Bags don't have indexes"); } - - public Bag() {} - public DBag difference(DBag arg0) { --- 307,310 ---- Index: CollectionPersister.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/collection/CollectionPersister.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** CollectionPersister.java 30 Jan 2003 13:02:29 -0000 1.8 --- CollectionPersister.java 9 Feb 2003 06:28:14 -0000 1.9 *************** *** 2,7 **** package net.sf.hibernate.collection; - import java.io.InvalidObjectException; - import java.io.ObjectStreamException; import java.io.Serializable; import java.sql.PreparedStatement; --- 2,5 ---- *************** *** 50,91 **** */ ! public final class CollectionPersister implements Serializable, CollectionMetadata { ! private transient final String sqlSelectString; ! private transient final String sqlDeleteString; ! //private transient final String sqlSelectRowString; ! private transient final String sqlInsertRowString; ! private transient final String sqlUpdateRowString; ! private transient final String sqlDeleteRowString; ! private transient final String sqlOrderByString; ! private transient final boolean hasOrder; ! private transient final boolean isSet; ! private transient final Type keyType; ! private transient final Type indexType; ! private transient final Type elementType; ! private transient final String[] keyColumnNames; ! private transient final String[] indexColumnNames; ! private transient final String[] unquotedIndexColumnNames; ! private transient final String[] elementColumnNames; ! private transient final String[] unquotedElementColumnNames; ! private transient final String[] rowSelectColumnNames; ! private transient final Type rowSelectType; ! private transient final boolean primitiveArray; ! private transient final boolean array; ! private transient final boolean isOneToMany; ! private transient final String qualifiedTableName; ! private transient final boolean hasIndex; ! private transient final boolean isLazy; ! private transient final boolean isInverse; ! private transient final Class elementClass; ! private transient final CacheConcurrencyStrategy cache; ! private transient final PersistentCollectionType collectionType; ! private transient final int enableJoinedFetch; ! private transient final Class ownerClass; ! private transient final CollectionInitializer loader; private final String role; ! private final SessionFactoryImplementor factory; private static final Log log = LogFactory.getLog(CollectionPersister.class); --- 48,88 ---- */ ! public final class CollectionPersister implements CollectionMetadata { ! private final String sqlSelectString; ! private final String sqlDeleteString; ! private final String sqlInsertRowString; ! private final String sqlUpdateRowString; ! private final String sqlDeleteRowString; ! private final String sqlOrderByString; ! private final boolean hasOrder; ! private final boolean isSet; ! private final Type keyType; ! private final Type indexType; ! private final Type elementType; ! private final String[] keyColumnNames; ! private final String[] indexColumnNames; ! private final String[] unquotedIndexColumnNames; ! private final String[] elementColumnNames; ! private final String[] unquotedElementColumnNames; ! private final String[] rowSelectColumnNames; ! private final Type rowSelectType; ! private final boolean primitiveArray; ! private final boolean array; ! private final boolean isOneToMany; ! private final String qualifiedTableName; ! private final boolean hasIndex; ! private final boolean isLazy; ! private final boolean isInverse; ! private final Class elementClass; ! private final CacheConcurrencyStrategy cache; ! private final PersistentCollectionType collectionType; ! private final int enableJoinedFetch; ! private final Class ownerClass; ! private final CollectionInitializer loader; private final String role; ! //private final SessionFactoryImplementor factory; private static final Log log = LogFactory.getLog(CollectionPersister.class); *************** *** 97,101 **** role = collection.getRole(); ownerClass = collection.getOwnerClass(); - this.factory = factory; hasOrder = collection.getOrderByString()!=null; --- 94,97 ---- *************** *** 213,217 **** public void cache(Serializable id, PersistentCollection coll, SessionImplementor s) throws HibernateException { ! if (cache!=null) cache.put( id, coll.disassemble(this), s.getTimestamp() ); } --- 209,215 ---- public void cache(Serializable id, PersistentCollection coll, SessionImplementor s) throws HibernateException { ! if (cache!=null) { ! cache.put( id, coll.disassemble(this), s.getTimestamp() ); ! } } *************** *** 226,232 **** } else { ! PersistentCollection coll = collectionType.wrap(s, cached); ! coll.assemble(this); ! return coll; } } --- 224,228 ---- } else { ! return collectionType.assembleCachedCollection(s, this, cached); } } *************** *** 656,668 **** public String getRole() { return role; - } - - Object readResolve() throws ObjectStreamException { - try { - return factory.getCollectionPersister(role); - } - catch (MappingException me) { - throw new InvalidObjectException( me.getMessage() ); - } } --- 652,655 ---- Index: List.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/collection/List.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** List.java 2 Feb 2003 04:19:51 -0000 1.6 --- List.java 9 Feb 2003 06:28:14 -0000 1.7 *************** *** 315,340 **** } } ! public void assemble(CollectionPersister persister) throws HibernateException, SQLException { ! ! int length = list.size(); ! java.util.List old = list; beforeInitialize(persister); ! for ( int i=0; i<length; i++ ) { ! list.add( persister.getElementType().assemble( (Serializable) old.get(i), session, null ) ); } ! } ! public Serializable disassemble(CollectionPersister persister) throws HibernateException { int length = list.size(); ! ArrayList result = new ArrayList(length); for ( int i=0; i<length; i++ ) { ! result.add( persister.getElementType().disassemble( list.get(i), session ) ); } return result; - } public Iterator getDeletes(Type elemType) throws HibernateException { --- 315,341 ---- } } ! ! public List(SessionImplementor session, CollectionPersister persister, Serializable disassembled) throws HibernateException, SQLException { ! super(session); beforeInitialize(persister); ! Serializable[] array = (Serializable[]) disassembled; ! for ( int i=0; i<array.length; i++ ) { ! list.add( persister.getElementType().assemble( array[i], session, null ) ); //TODO: fix the null!!! } ! initialized=true; } ! public Serializable disassemble(CollectionPersister persister) ! throws HibernateException { int length = list.size(); ! Serializable[] result = new Serializable[length]; for ( int i=0; i<length; i++ ) { ! result[i] = persister.getElementType().disassemble( list.get(i), session ); } return result; } + public Iterator getDeletes(Type elemType) throws HibernateException { *************** *** 362,367 **** return new Integer(i); } - - public List() {} /** --- 363,366 ---- Index: Map.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/collection/Map.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Map.java 2 Feb 2003 04:19:51 -0000 1.6 --- Map.java 9 Feb 2003 06:28:14 -0000 1.7 *************** *** 308,337 **** } ! public void assemble(CollectionPersister persister) throws HibernateException, SQLException { ! ! java.util.Map old = map; beforeInitialize(persister); ! Iterator iter = old.entrySet().iterator(); ! while ( iter.hasNext() ) { ! java.util.Map.Entry e = (java.util.Map.Entry) iter.next(); ! map.put( ! persister.getIndexType().assemble( (Serializable) e.getKey(), session, null), ! persister.getElementType().assemble( (Serializable) e.getValue(), session, null ) ! ); ! } ! } public Serializable disassemble(CollectionPersister persister) throws HibernateException { ! HashMap result = new HashMap(); Iterator iter = map.entrySet().iterator(); while ( iter.hasNext() ) { java.util.Map.Entry e = (java.util.Map.Entry) iter.next(); ! result.put( ! persister.getIndexType().disassemble( e.getKey(), session ), ! persister.getElementType().disassemble( e.getValue(), session ) ! ); } return result; --- 308,332 ---- } ! public Map(SessionImplementor session, CollectionPersister persister, Serializable disassembled) throws HibernateException, SQLException { ! super(session); beforeInitialize(persister); ! Serializable[] array = (Serializable[]) disassembled; ! for (int i=0; i<array.length; i+=2 ) map.put( ! persister.getIndexType().assemble( array[i], session, null ), ! persister.getElementType().assemble( array[i+1], session, null ) //TODO: fix the null!!!! ! ); ! initialized = true; } public Serializable disassemble(CollectionPersister persister) throws HibernateException { ! Serializable[] result = new Serializable[ map.size() * 2 ]; Iterator iter = map.entrySet().iterator(); + int i=0; while ( iter.hasNext() ) { java.util.Map.Entry e = (java.util.Map.Entry) iter.next(); ! result[i++] = persister.getIndexType().disassemble( e.getKey(), session); ! result[i++] = persister.getElementType().disassemble( e.getValue(), session ); } return result; *************** *** 366,371 **** return ( (java.util.Map.Entry) entry ).getKey(); } - - public Map() {} public boolean equals(Object other) { --- 361,364 ---- Index: ODMGCollection.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/collection/ODMGCollection.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ODMGCollection.java 28 Jan 2003 10:22:19 -0000 1.6 --- ODMGCollection.java 9 Feb 2003 06:28:14 -0000 1.7 *************** *** 21,31 **** /** - * Constructor for ODMGCollection. - */ - public ODMGCollection() { - super(); - } - - /** * @see org.odmg.DCollection#existsElement(String) */ --- 21,24 ---- Index: PersistentCollection.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/collection/PersistentCollection.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** PersistentCollection.java 30 Jan 2003 13:02:30 -0000 1.6 --- PersistentCollection.java 9 Feb 2003 06:28:14 -0000 1.7 *************** *** 174,178 **** public abstract Serializable disassemble(CollectionPersister persister) throws HibernateException; - public abstract void assemble(CollectionPersister persister) throws HibernateException, SQLException; public boolean needsRecreate(Type elemType) throws HibernateException { --- 174,177 ---- *************** *** 519,524 **** } - - public PersistentCollection() {} /** --- 518,521 ---- Index: Set.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/collection/Set.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Set.java 5 Jan 2003 02:11:20 -0000 1.5 --- Set.java 9 Feb 2003 06:28:14 -0000 1.6 *************** *** 78,81 **** --- 78,90 ---- initialized = true; } + public Set(SessionImplementor session, CollectionPersister persister, Serializable disassembled) throws HibernateException, SQLException { + super(session); + beforeInitialize(persister); + Serializable[] array = (Serializable[]) disassembled; + for (int i=0; i<array.length; i++ ) set.add( + persister.getElementType().assemble( array[i], session, null ) //TODO: fix the null!!!! + ); + initialized = true; + } /** *************** *** 243,271 **** } - - public void assemble(CollectionPersister persister) - throws HibernateException, SQLException { - - java.util.Set old = set; - beforeInitialize(persister); - Iterator iter = old.iterator(); - while ( iter.hasNext() ) set.add( - persister.getElementType().assemble( (Serializable) iter.next(), session, null ) - ); - - } - public Serializable disassemble(CollectionPersister persister) throws HibernateException { ! HashSet result = new HashSet(); Iterator iter = set.iterator(); ! while ( iter.hasNext() ) result.add( ! persister.getElementType().disassemble( iter.next(), session ) ! ); return result; ! } ! public Iterator getDeletes(Type elemType) throws HibernateException { --- 252,267 ---- } public Serializable disassemble(CollectionPersister persister) throws HibernateException { ! Serializable[] result = new Serializable[ set.size() ]; Iterator iter = set.iterator(); ! int i=0; ! while ( iter.hasNext() ) { ! result[i++] = persister.getElementType().disassemble( iter.next(), session ); ! } return result; ! } public Iterator getDeletes(Type elemType) throws HibernateException { *************** *** 319,324 **** throw new UnsupportedOperationException("Sets don't have indexes"); } - - public Set() {} /** --- 315,318 ---- Index: SortedMap.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/collection/SortedMap.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** SortedMap.java 5 Jan 2003 02:11:20 -0000 1.4 --- SortedMap.java 9 Feb 2003 06:28:14 -0000 1.5 *************** *** 4,7 **** --- 4,8 ---- import java.io.Serializable; + import java.sql.SQLException; import java.util.Iterator; import java.util.TreeMap; *************** *** 32,50 **** return clonedMap; } - - public Serializable disassemble(CollectionPersister persister) throws HibernateException { - - TreeMap result = new TreeMap(comparator); - Iterator iter = map.entrySet().iterator(); - while ( iter.hasNext() ) { - java.util.Map.Entry e = (java.util.Map.Entry) iter.next(); - result.put( e.getKey(), persister.getElementType().disassemble( e.getValue(), session ) ); - } - return result; } ! public SortedMap(SessionImplementor session) { super(session); } --- 33,52 ---- return clonedMap; } + public SortedMap(SessionImplementor session) { + super(session); } ! public SortedMap(SessionImplementor session, CollectionPersister persister, Comparator comparator, Serializable disassembled) ! throws HibernateException, SQLException { super(session); + this.comparator=comparator; + beforeInitialize(persister); + Serializable[] array = (Serializable[]) disassembled; + for (int i=0; i<array.length; i+=2 ) map.put( + persister.getIndexType().assemble( array[i], session, null ), + persister.getElementType().assemble( array[i+1], session, null ) //TODO: fix the null!!!! + ); + initialized = true; } *************** *** 194,199 **** } ! ! public SortedMap() {} } --- 196,200 ---- } ! } Index: SortedSet.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/collection/SortedSet.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** SortedSet.java 5 Jan 2003 02:11:20 -0000 1.4 --- SortedSet.java 9 Feb 2003 06:28:14 -0000 1.5 *************** *** 3,6 **** --- 3,7 ---- import java.io.Serializable; + import java.sql.SQLException; import java.util.Iterator; import java.util.TreeSet; *************** *** 31,46 **** } - public Serializable disassemble(CollectionPersister persister) - throws HibernateException { - - TreeSet result = new TreeSet(comparator); - Iterator iter = set.iterator(); - while ( iter.hasNext() ) result.add( - persister.getElementType().disassemble( iter.next(), session ) - ); - return result; - - } - public void setComparator(Comparator comparator) { this.comparator = comparator; --- 32,35 ---- *************** *** 142,147 **** } ! ! public SortedSet() {} } --- 131,152 ---- } ! ! public SortedSet( ! SessionImplementor session, ! CollectionPersister persister, ! Comparator comparator, ! Serializable disassembled) ! throws HibernateException, SQLException { ! ! this(session); ! this.comparator=comparator; ! beforeInitialize(persister); ! Serializable[] array = (Serializable[]) disassembled; ! for (int i=0; i<array.length; i++ ) set.add( ! persister.getElementType().assemble( array[i], session, null ) //TODO: fix the null!!!! ! ); ! initialized = true; ! } ! } |