From: Paul H. <pha...@us...> - 2005-03-18 23:33:33
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv439/nhibernate/src/NHibernate/Impl Modified Files: SessionImpl.cs Log Message: Revised ISession to comply with 2.1 Index: SessionImpl.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl/SessionImpl.cs,v retrieving revision 1.74 retrieving revision 1.75 diff -C2 -d -r1.74 -r1.75 *** SessionImpl.cs 16 Mar 2005 15:10:47 -0000 1.74 --- SessionImpl.cs 18 Mar 2005 23:33:19 -0000 1.75 *************** *** 5111,5114 **** --- 5111,5135 ---- /// /// </summary> + /// <param name="obj"></param> + /// <returns></returns> + public object SavOrUpdateCopy( object obj ) + { + return SaveOrUpdateCopy( obj, null ); + } + + /// <summary> + /// + /// </summary> + /// <param name="obj"></param> + /// <param name="id"></param> + /// <returns></returns> + public object SaveOrUpdateCopy( object obj, object id ) + { + return DoCopy( obj, id, new Hashtable( 10 ) ); + } + + /// <summary> + /// + /// </summary> /// <param name="collectionPersister"></param> /// <param name="id"></param> *************** *** 5290,5293 **** --- 5311,5386 ---- /// /// </summary> + /// <param name="obj"></param> + /// <param name="replicationMode"></param> + public void Replicate( object obj, ReplicationMode replicationMode ) + { + if ( obj == null ) + { + throw new NullReferenceException( "attempt to replicate null" ); + } + + if ( ReassociateIfUninitializedProxy( obj ) ) + { + return; + } + + object theObj = UnproxyAndReassociate( obj ); + + if ( IsEntryFor( theObj ) ) + { + return; + } + + IClassPersister persister = GetPersister( theObj ); + if ( persister.IsUnsaved( theObj ) ) + { + //TODO: generate a new id value for brand new objects + throw new TransientObjectException( "unsaved object passed to Replicate()" ); + } + + object id = persister.GetIdentifier( theObj ); + object oldVersion; + if ( replicationMode == ReplicationMode.Exception ) + { + //always do an INSERT, and let it fail by constraint violation + oldVersion = null; + } + else + { + //what is the version on the database? + oldVersion = persister.CurrentVersion( id, this ); + } + + if( oldVersion != null ) + { + // existing row - do an update if appropriate + if ( replicationMode.ShouldOverwriteCurrentVersion( theObj, oldVersion, persister.GetVersion( obj ), persister.VersionType ) ) + { + //will result in a SQL UPDATE: + DoReplicate( theObj, id, oldVersion, replicationMode, persister ); + } + //else do nothing (don't even reassociate object!) + //TODO: would it be better to do a refresh from db? + } + else + { + // no existing row - do an insert + bool regenerate = persister.IsIdentifierAssignedByInsert; // prefer re-generation of identity! + DoSave( + theObj, + regenerate ? null : new Key( id, persister ), + persister, + true, //!persister.isUnsaved(object), //TODO: Do an ordinary save in the case of an "unsaved" object + // TODO: currently ignores interceptor definition of isUnsaved() + regenerate, + Cascades.CascadingAction.ActionReplicate, // not quite an ordinary save(), since we cascade back to replicate() + replicationMode + ); + } + } + + /// <summary> + /// + /// </summary> /// <param name="key"></param> public void AddNonExist( Key key ) |