From: Paul H. <pha...@us...> - 2005-03-30 16:30:16
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21350/nhibernate/src/NHibernate/Impl Modified Files: AbstractQueryImpl.cs SessionFactoryImpl.cs SessionImpl.cs Log Message: Implemented Copy, enhanced versioning, support named query/sql-query Index: SessionImpl.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl/SessionImpl.cs,v retrieving revision 1.79 retrieving revision 1.80 diff -C2 -d -r1.79 -r1.80 *** SessionImpl.cs 28 Mar 2005 15:20:28 -0000 1.79 --- SessionImpl.cs 30 Mar 2005 16:28:54 -0000 1.80 *************** *** 853,858 **** if ( persister.IsVersioned ) ! substitute = Versioning.SeedVersion( ! values, persister.VersionProperty, persister.VersionType ) || substitute; if ( persister.HasCollections ) --- 853,857 ---- if ( persister.IsVersioned ) ! substitute = Versioning.SeedVersion( values, persister.VersionProperty, persister.VersionType, persister.IsDefaultVersion( obj ) ) || substitute; if ( persister.HasCollections ) *************** *** 1007,1011 **** if ( persister.IsVersioned ) { ! substitute = Versioning.SeedVersion( values, persister.VersionProperty, persister.VersionType ) || substitute; } } --- 1006,1010 ---- if ( persister.IsVersioned ) { ! substitute = Versioning.SeedVersion( values, persister.VersionProperty, persister.VersionType, persister.IsDefaultVersion( obj ) ) || substitute; } } *************** *** 1257,1294 **** // id is not "unsaved" (that is, we rely on foreign keys to keep // database integrity) - EntityEntry e = GetEntry( obj ); if( e == null ) { ! IClassPersister persister = GetPersister( obj ); ! if( persister.HasIdentifierProperty ) ! { ! object id = persister.GetIdentifier( obj ); ! if( id != null ) ! { ! // see if theres another object that *is* associated with the sesison for that id ! e = GetEntry( GetEntity( new Key( id, persister ) ) ); ! ! if( e == null ) ! { ! // look at the id value ! return persister.IsUnsaved( id ); ! } ! // else use the other object's entry... ! } ! else ! { ! // null id, so have to assume transient (because that's safer) ! return true; ! } ! } ! else ! { ! //can't determine the id, so assume transient (because that's safer) ! return true; ! } } - return e.Status == Status.Saving || ( earlyInsert ? !e.ExistsInDatabase : nullifiables.Contains( new Key( e.Id, e.Persister ) ) --- 1256,1265 ---- // id is not "unsaved" (that is, we rely on foreign keys to keep // database integrity) EntityEntry e = GetEntry( obj ); if( e == null ) { ! return GetPersister( obj ).IsUnsaved( obj ); } return e.Status == Status.Saving || ( earlyInsert ? !e.ExistsInDatabase : nullifiables.Contains( new Key( e.Id, e.Persister ) ) *************** *** 1621,1625 **** } ! object theObj = UnproxyAndReassociate( obj ); EntityEntry e = GetEntry( theObj ); --- 1592,1596 ---- } ! object theObj = UnproxyAndReassociate( obj ); //a proxy is always "update", never "save" EntityEntry e = GetEntry( theObj ); *************** *** 1643,1672 **** { // use unsaved-value ! if( persister.HasIdentifierPropertyOrEmbeddedCompositeIdentifier ) { ! object id = persister.GetIdentifier( theObj ); ! ! if( persister.IsUnsaved( id ) ) ! { ! if( log.IsDebugEnabled ) ! { ! log.Debug( "SaveOrUpdate() unsaved instance with id: " + id ); ! } ! Save( obj ); ! } ! else { ! if( log.IsDebugEnabled ) ! { ! log.Debug( "SaveOrUpdate() previously saved instance with id: " + id ); ! } ! DoUpdate( theObj, id, persister ); } } else { ! // no identifier property ... default to save() ! log.Debug( "SaveOrUpdate() unsaved instance with no identifier property" ); ! Save( obj ); } } --- 1614,1633 ---- { // use unsaved-value ! if( persister.IsUnsaved( theObj ) ) { ! if( log.IsDebugEnabled ) { ! log.Debug( "SaveOrUpdate() unsaved instance" ); } + Save( obj ); } else { ! object id = persister.GetIdentifier( theObj ); ! if( log.IsDebugEnabled ) ! { ! log.Debug( "SaveOrUpdate() previously saved instance with id: " + id ); ! } ! DoUpdate( theObj, id, persister ); } } *************** *** 3612,3626 **** } ! IClassPersister persister = GetPersister( obj ); ! if( !persister.HasIdentifierPropertyOrEmbeddedCompositeIdentifier ) ! { ! return false; ! } // I _think_ that this is reasonable! ! ! object id = persister.GetIdentifier( obj ); ! return !persister.IsUnsaved( id ); } - /// <summary> /// Used by OneToOneType and ManyToOneType to determine what id value --- 3573,3579 ---- } ! return !GetPersister( obj ).IsUnsaved( obj ); } /// <summary> /// Used by OneToOneType and ManyToOneType to determine what id value *************** *** 3659,3674 **** IClassPersister persister = GetPersister( obj ); ! if( !persister.HasIdentifierPropertyOrEmbeddedCompositeIdentifier ) ! { ! ThrowTransientObjectException( obj ); ! } ! ! object id = persister.GetIdentifier( obj ); ! if( persister.IsUnsaved( id ) ) { ThrowTransientObjectException( obj ); } ! return id; } --- 3612,3621 ---- IClassPersister persister = GetPersister( obj ); ! if( persister.IsUnsaved( obj ) ) { ThrowTransientObjectException( obj ); } ! return persister.GetIdentifier( obj ); } Index: AbstractQueryImpl.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl/AbstractQueryImpl.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** AbstractQueryImpl.cs 26 Mar 2005 12:30:23 -0000 1.3 --- AbstractQueryImpl.cs 30 Mar 2005 16:28:49 -0000 1.4 *************** *** 87,90 **** --- 87,117 ---- } + /// <summary> + /// + /// </summary> + /// <returns></returns> + public object UniqueResult() + { + return UniqueElement( List() ); + } + + static object UniqueElement( IList list ) + { + int size = list.Count; + if ( size == 0 ) + { + return null; + } + object first = list[ 0 ]; + for ( int i = 1; i < size; i++ ) + { + if ( list[ i ] != first ) + { + throw new NonUniqueResultException( size ); + } + } + return first; + } + protected virtual IType[] TypeArray() { Index: SessionFactoryImpl.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl/SessionFactoryImpl.cs,v retrieving revision 1.43 retrieving revision 1.44 diff -C2 -d -r1.43 -r1.44 *** SessionFactoryImpl.cs 6 Mar 2005 12:44:42 -0000 1.43 --- SessionFactoryImpl.cs 30 Mar 2005 16:28:51 -0000 1.44 *************** *** 188,197 **** namedQueries = new Hashtable( cfg.NamedQueries ); namedSqlQueries = new Hashtable( cfg.NamedSQLQueries.Count ); ! foreach ( NamedSQLQuery nsq in cfg.NamedSQLQueries ) { ! namedSqlQueries[ nsq.QueryString ] = new InternalNamedSQLQuery( nsq.QueryString, nsq.ReturnAliases, nsq.ReturnClasses, nsq.SynchronizedTables ); } - imports = new Hashtable( cfg.Imports ); --- 188,197 ---- namedQueries = new Hashtable( cfg.NamedQueries ); namedSqlQueries = new Hashtable( cfg.NamedSQLQueries.Count ); ! foreach ( DictionaryEntry de in cfg.NamedSQLQueries ) { ! NamedSQLQuery nsq = (NamedSQLQuery) de.Value; ! namedSqlQueries[ de.Key ] = new InternalNamedSQLQuery( nsq.QueryString, nsq.ReturnAliases, nsq.ReturnClasses, nsq.SynchronizedTables ); } imports = new Hashtable( cfg.Imports ); |