From: <one...@us...> - 2003-02-02 04:19:55
|
Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/type In directory sc8-pr-cvs1:/tmp/cvs-serv29352/sf/hibernate/type Modified Files: AbstractType.java ComponentType.java DynaBeanType.java EntityType.java OneToOneType.java PersistentCollectionType.java Type.java TypeFactory.java Log Message: smarter dirty-checking for EntityType Index: AbstractType.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/type/AbstractType.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** AbstractType.java 27 Jan 2003 12:12:41 -0000 1.4 --- AbstractType.java 2 Feb 2003 04:19:52 -0000 1.5 *************** *** 7,11 **** import net.sf.hibernate.HibernateException; - import net.sf.hibernate.engine.SessionFactoryImplementor; import net.sf.hibernate.engine.SessionImplementor; --- 7,10 ---- *************** *** 52,56 **** } ! public boolean isDirty(Object old, Object current, Object owner,SessionFactoryImplementor pc) throws HibernateException { return !equals(old, current); } --- 51,55 ---- } ! public boolean isDirty(Object old, Object current, SessionImplementor session) throws HibernateException { return !equals(old, current); } Index: ComponentType.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/type/ComponentType.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ComponentType.java 31 Jan 2003 08:26:38 -0000 1.5 --- ComponentType.java 2 Feb 2003 04:19:52 -0000 1.6 *************** *** 103,111 **** } ! public boolean isDirty(Object x, Object y, Object owner, SessionFactoryImplementor factory) throws HibernateException { if (x==y) return false; if (x==null || y==null) return true; for ( int i=0; i<getters.length; i++ ) { ! if ( types[i].isDirty( getters[i].get(x), getters[i].get(y), owner, factory ) ) return true; } return false; --- 103,111 ---- } ! public boolean isDirty(Object x, Object y, SessionImplementor session) throws HibernateException { if (x==y) return false; if (x==null || y==null) return true; for ( int i=0; i<getters.length; i++ ) { ! if ( types[i].isDirty( getters[i].get(x), getters[i].get(y), session ) ) return true; } return false; Index: DynaBeanType.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/type/DynaBeanType.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DynaBeanType.java 19 Jan 2003 11:48:39 -0000 1.1 --- DynaBeanType.java 2 Feb 2003 04:19:52 -0000 1.2 *************** *** 144,147 **** --- 144,158 ---- } + public boolean isDirty(Object x, Object y, SessionImplementor session) throws HibernateException { + if (x==y) return false; + if (x==null || y==null) return true; + DynaBean xbean = (DynaBean) x; + DynaBean ybean = (DynaBean) y; + for ( int i=0; i<propertySpan; i++ ) { + if ( propertyTypes[i].isDirty( xbean.get( propertyNames[i] ), ybean.get( propertyNames[i] ), session ) ) return true; + } + return false; + } + /** * @see net.sf.hibernate.type.Type#getColumnSpan(net.sf.hibernate.engine.Mapping) Index: EntityType.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/type/EntityType.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** EntityType.java 19 Jan 2003 11:47:08 -0000 1.4 --- EntityType.java 2 Feb 2003 04:19:52 -0000 1.5 *************** *** 63,70 **** } catch (HibernateException he) { ! throw new HibernateException( ! "object references a transient instance - save the transient instance first" ! ); } } return id; --- 63,71 ---- } catch (HibernateException he) { ! // transient instance with no identifier property } + if (id==null) throw new HibernateException( + "object references a transient instance - save the transient instance first" + ); } return id; *************** *** 124,128 **** --- 125,139 ---- throws HibernateException, SQLException; + public boolean isDirty(Object old, Object current, SessionImplementor session) throws HibernateException { + + if ( equals(old, current) ) return false; + + Serializable oldid = getIdentifier(old, session); + Serializable newid = getIdentifier(current, session); + return !session.getFactory().getIdentifierType(persistentClass).equals(oldid, newid); + } + + } Index: OneToOneType.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/type/OneToOneType.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** OneToOneType.java 27 Jan 2003 07:12:04 -0000 1.4 --- OneToOneType.java 2 Feb 2003 04:19:52 -0000 1.5 *************** *** 10,14 **** import net.sf.hibernate.MappingException; import net.sf.hibernate.engine.Mapping; - import net.sf.hibernate.engine.SessionFactoryImplementor; import net.sf.hibernate.engine.SessionImplementor; --- 10,13 ---- *************** *** 45,49 **** ! public boolean isDirty(Object old, Object current, Object owner, SessionFactoryImplementor pc) throws HibernateException { return false; } --- 44,48 ---- ! public boolean isDirty(Object old, Object current, SessionImplementor session) throws HibernateException { return false; } Index: PersistentCollectionType.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/type/PersistentCollectionType.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** PersistentCollectionType.java 19 Jan 2003 11:47:08 -0000 1.5 --- PersistentCollectionType.java 2 Feb 2003 04:19:52 -0000 1.6 *************** *** 114,126 **** } ! public boolean isDirty(Object old, Object current, Object owner, SessionFactoryImplementor factory) throws HibernateException { ! if ( !factory.getPersister( owner.getClass() ).isVersioned() ) { ! //nested collections don't dirty the unversioned parent entity return false; } else { ! return super.isDirty(old, current, owner, factory); } } --- 114,130 ---- } ! public boolean isDirty(Object old, Object current, SessionImplementor session) throws HibernateException { ! ! Class ownerClass = session.getFactory().getCollectionPersister(role).getOwnerClass(); ! ! if ( !session.getFactory().getPersister(ownerClass).isVersioned() ) { ! // collections don't dirty an unversioned parent entity return false; } else { ! return super.isDirty(old, current, session); } + } Index: Type.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/type/Type.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Type.java 26 Jan 2003 03:16:32 -0000 1.5 --- Type.java 2 Feb 2003 04:19:52 -0000 1.6 *************** *** 91,99 **** * @param old the old value * @param current the current value ! * @param owner the parent entity ! * @param factory * @return true if the field is dirty */ ! public boolean isDirty(Object old, Object current, Object owner, SessionFactoryImplementor factory) throws HibernateException; /** --- 91,98 ---- * @param old the old value * @param current the current value ! * @param session * @return true if the field is dirty */ ! public boolean isDirty(Object old, Object current, SessionImplementor session) throws HibernateException; /** Index: TypeFactory.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/type/TypeFactory.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** TypeFactory.java 24 Jan 2003 16:16:03 -0000 1.5 --- TypeFactory.java 2 Feb 2003 04:19:52 -0000 1.6 *************** *** 22,26 **** import net.sf.hibernate.PersistentEnum; import net.sf.hibernate.UserType; ! import net.sf.hibernate.engine.SessionFactoryImplementor; import net.sf.hibernate.util.ReflectHelper; --- 22,26 ---- import net.sf.hibernate.PersistentEnum; import net.sf.hibernate.UserType; ! import net.sf.hibernate.engine.SessionImplementor; import net.sf.hibernate.util.ReflectHelper; *************** *** 194,202 **** * the dirty fields or <tt>null</tt> if no fields are dirty. */ ! public static int[] findDirty(Type[] types, Object[] x, Object[] y, boolean[] check, Object owner, SessionFactoryImplementor factory) throws HibernateException { int[] results = null; int count = 0; for (int i=0; i<types.length; i++) { ! if ( check[i] && types[i].isDirty( x[i], y[i], owner, factory ) ) { if (results==null) results = new int[ types.length ]; results[count++]=i; --- 194,202 ---- * the dirty fields or <tt>null</tt> if no fields are dirty. */ ! public static int[] findDirty(Type[] types, Object[] x, Object[] y, boolean[] check, SessionImplementor session) throws HibernateException { int[] results = null; int count = 0; for (int i=0; i<types.length; i++) { ! if ( check[i] && types[i].isDirty( x[i], y[i], session ) ) { if (results==null) results = new int[ types.length ]; results[count++]=i; |