From: Michael D. <mik...@us...> - 2004-09-14 17:50:07
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Persister In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11256/Persister Modified Files: EntityPersister.cs NormalizedEntityPersister.cs Log Message: Major refactoring with NDataReader and Batcher. NHibernate now uses an IDataReader returned from the Driver for as long as possible before converting to a NDataReader. This has nice perf gains on the simple performance test in the Test Fixtures. Index: NormalizedEntityPersister.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Persister/NormalizedEntityPersister.cs,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** NormalizedEntityPersister.cs 30 Aug 2004 02:49:06 -0000 1.30 --- NormalizedEntityPersister.cs 14 Sep 2004 17:49:56 -0000 1.31 *************** *** 944,947 **** --- 944,949 ---- IDbCommand st = session.Batcher.PrepareCommand( (SqlString)lockers[lockMode] ); + IDataReader rs = null; + try { *************** *** 952,967 **** } ! IDataReader rs = st.ExecuteReader(); ! try ! { if ( !rs.Read() ) { throw new StaleObjectStateException(MappedClass, id); } ! } ! finally ! { ! rs.Close(); ! } } //TODO: change this to catch a Sql Exception and log it --- 954,970 ---- } ! // IDataReader rs = st.ExecuteReader(); ! rs = session.Batcher.ExecuteReader( st ); ! // try ! // { if ( !rs.Read() ) { throw new StaleObjectStateException(MappedClass, id); } ! // } ! // finally ! // { ! // rs.Close(); ! // } } //TODO: change this to catch a Sql Exception and log it *************** *** 972,976 **** finally { ! session.Batcher.CloseCommand(st); } } --- 975,979 ---- finally { ! session.Batcher.CloseCommand(st, rs); } } *************** *** 1049,1053 **** for (int i = 0; i < tableNames.Length; i++) { ! insertCmds[i].ExecuteNonQuery(); } --- 1052,1056 ---- for (int i = 0; i < tableNames.Length; i++) { ! session.Batcher.ExecuteNonQuery( insertCmds[i] ); } *************** *** 1064,1068 **** if( insertCmds[i]!=null ) { ! session.Batcher.CloseCommand( insertCmds[i] ); } } --- 1067,1071 ---- if( insertCmds[i]!=null ) { ! session.Batcher.CloseCommand( insertCmds[i], null ); } } *************** *** 1087,1106 **** IDbCommand statement = null; IDbCommand idSelect = null; object id; - // still using the Preparer instead of Batcher because the Batcher won't work - // with 2 commands being Prepared back to back - when the second SqlString gets - // prepared that would cause it to execute the first SqlString - which is not - // what we want because no values have been put into the parameter. if(dialect.SupportsIdentitySelectInInsert) { ! statement = session.Preparer.PrepareCommand( dialect.AddIdentitySelectToInsert(sql[0]) ); idSelect = statement; } else { ! statement = session.Preparer.PrepareCommand(sql[0]); ! idSelect = session.Preparer.PrepareCommand(SqlIdentitySelect); } --- 1090,1109 ---- IDbCommand statement = null; IDbCommand idSelect = null; + IDataReader rs = null; object id; if(dialect.SupportsIdentitySelectInInsert) { ! statement = session.Batcher.PrepareCommand( dialect.AddIdentitySelectToInsert(sql[0]) ); idSelect = statement; } else { ! // do not Prepare the Command to be part of a batch. When the second command ! // is Prepared for the Batch that would cause the first one to be executed and ! // we don't want that yet. ! statement = session.Batcher.Generate( sql[0] ); ! idSelect = session.Batcher.PrepareCommand( new SqlString( SqlIdentitySelect ) ); } *************** *** 1120,1139 **** if(dialect.SupportsIdentitySelectInInsert==false) { ! statement.ExecuteNonQuery(); } ! IDataReader rs = idSelect.ExecuteReader(); ! try ! { ! if ( !rs.Read() ) ! { ! throw new HibernateException("The database returned no natively generated identity value"); ! } ! id = IdentifierGeneratorFactory.Get( rs, IdentifierType.ReturnedClass ); ! } ! finally { ! rs.Close(); } log.Debug("Natively generated identity: " + id); --- 1123,1135 ---- if(dialect.SupportsIdentitySelectInInsert==false) { ! session.Batcher.ExecuteNonQuery( statement ); } ! rs = session.Batcher.ExecuteReader( idSelect ); ! if ( !rs.Read() ) { ! throw new HibernateException("The database returned no natively generated identity value"); } + id = IdentifierGeneratorFactory.Get( rs, IdentifierType.ReturnedClass ); log.Debug("Natively generated identity: " + id); *************** *** 1147,1162 **** finally { ! // session.Batcher.CloseStatement(statement); ! // session.Batcher.CloseStatement(idselect); } for (int i=1; i<naturalOrderTableNames.Length; i++ ) { ! statement = session.Preparer.PrepareCommand(sql[i]); ! try { Dehydrate(id, fields, notNull, i, statement, session); ! statement.ExecuteNonQuery(); } //TODO: change this to SQLException and log it --- 1143,1160 ---- finally { ! if( dialect.SupportsIdentitySelectInInsert==false ) ! { ! session.Batcher.CloseCommand( statement, null ); ! } ! session.Batcher.CloseCommand( idSelect, rs ); } for (int i=1; i<naturalOrderTableNames.Length; i++ ) { ! statement = session.Batcher.PrepareCommand( sql[i] ); try { Dehydrate(id, fields, notNull, i, statement, session); ! session.Batcher.ExecuteNonQuery( statement ); } //TODO: change this to SQLException and log it *************** *** 1167,1171 **** finally { ! //session.Batcher.CloseStatement(statement); } } --- 1165,1169 ---- finally { ! session.Batcher.CloseCommand( statement, null ); } } *************** *** 1206,1210 **** IdentifierType.NullSafeSet( statements[i], id, 0, session ); ! Check( statements[i].ExecuteNonQuery(), id ); } } --- 1204,1208 ---- IdentifierType.NullSafeSet( statements[i], id, 0, session ); ! Check( session.Batcher.ExecuteNonQuery( statements[i] ), id ); } } *************** *** 1217,1221 **** for (int i=0; i<naturalOrderTableNames.Length; i++) { ! if (statements[i]!=null ) session.Batcher.CloseCommand( statements[i] ); } } --- 1215,1222 ---- for (int i=0; i<naturalOrderTableNames.Length; i++) { ! if (statements[i]!=null ) ! { ! session.Batcher.CloseCommand( statements[i], null ); ! } } } *************** *** 1303,1307 **** for (int i=0; i<tables; i++ ) { ! if ( includeTable[i] ) Check(statements[i].ExecuteNonQuery(), id ); } } --- 1304,1311 ---- for (int i=0; i<tables; i++ ) { ! if ( includeTable[i] ) ! { ! Check( session.Batcher.ExecuteNonQuery( statements[i] ), id ); ! } } } *************** *** 1316,1320 **** if ( statements[i]!=null ) { ! session.Batcher.CloseCommand( statements[i] ); } } --- 1320,1324 ---- if ( statements[i]!=null ) { ! session.Batcher.CloseCommand( statements[i], null ); } } Index: EntityPersister.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Persister/EntityPersister.cs,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** EntityPersister.cs 30 Aug 2004 02:49:06 -0000 1.27 --- EntityPersister.cs 14 Sep 2004 17:49:56 -0000 1.28 *************** *** 716,719 **** --- 716,720 ---- IDbCommand st = session.Batcher.PrepareCommand( (SqlString)lockers[lockMode] ); + IDataReader reader = null; try *************** *** 726,743 **** } ! IDataReader rs = st.ExecuteReader(); ! try ! { ! if ( rs.Read()==false ) throw new StaleObjectStateException( MappedClass, id); ! } ! finally ! { ! rs.Close(); ! } } //TODO: add something to catch a sql exception and log it here finally { ! session.Batcher.CloseCommand(st); } } --- 727,748 ---- } ! // IDataReader rs = st.ExecuteReader(); ! reader = session.Batcher.ExecuteReader( st ); ! // try ! // { ! if ( reader.Read()==false ) ! { ! throw new StaleObjectStateException( MappedClass, id); ! } ! // } ! // finally ! // { ! // rs.Close(); ! // } } //TODO: add something to catch a sql exception and log it here finally { ! session.Batcher.CloseCommand( st, reader ); } } *************** *** 832,849 **** IDbCommand statement = null; IDbCommand idSelect = null; - // still using the Preparer instead of Batcher because the Batcher won't work - // with 2 commands being Prepared back to back - when the second SqlString gets - // prepared that would cause it to execute the first SqlString - which is not - // what we want because no values have been put into the parameter. if(dialect.SupportsIdentitySelectInInsert) { ! statement = session.Preparer.PrepareCommand( dialect.AddIdentitySelectToInsert(sql) ); idSelect = statement; } else { ! statement = session.Preparer.PrepareCommand( sql ); ! idSelect = session.Preparer.PrepareCommand( SqlIdentitySelect ); } --- 837,854 ---- IDbCommand statement = null; IDbCommand idSelect = null; + IDataReader rs = null; if(dialect.SupportsIdentitySelectInInsert) { ! statement = session.Batcher.PrepareCommand( dialect.AddIdentitySelectToInsert(sql) ); idSelect = statement; } else { ! // do not Prepare the Command to be part of a batch. When the second command ! // is Prepared for the Batch that would cause the first one to be executed and ! // we don't want that yet. ! statement = session.Batcher.Generate( sql ); ! idSelect = session.Batcher.PrepareCommand( new SqlString( SqlIdentitySelect ) ); } *************** *** 863,880 **** if(dialect.SupportsIdentitySelectInInsert==false) { ! statement.ExecuteNonQuery(); } ! IDataReader rs = idSelect.ExecuteReader(); object id; ! try ! { ! if ( !rs.Read() ) throw new HibernateException("The database returned no natively generated identity value"); ! id = IdentifierGeneratorFactory.Get( rs, IdentifierType.ReturnedClass ); ! } ! finally { ! rs.Close(); } log.Debug("Natively generated identity: " + id); --- 868,882 ---- if(dialect.SupportsIdentitySelectInInsert==false) { ! session.Batcher.ExecuteNonQuery( statement ); } ! rs = session.Batcher.ExecuteReader( idSelect ); object id; ! ! if ( !rs.Read() ) { ! throw new HibernateException("The database returned no natively generated identity value"); } + id = IdentifierGeneratorFactory.Get( rs, IdentifierType.ReturnedClass ); log.Debug("Natively generated identity: " + id); *************** *** 889,894 **** finally { ! // session.Batcher.CloseStatement(statement); ! // session.Batcher.CloseStatement(idselect); } } --- 891,899 ---- finally { ! if( dialect.SupportsIdentitySelectInInsert==false ) ! { ! session.Batcher.CloseCommand( statement, null ); ! } ! session.Batcher.CloseCommand( idSelect, rs ); } } *************** *** 931,935 **** { VersionType.NullSafeSet(deleteCmd, version, IdentifierColumnNames.Length, session); ! Check(deleteCmd.ExecuteNonQuery(), id); } else --- 936,940 ---- { VersionType.NullSafeSet(deleteCmd, version, IdentifierColumnNames.Length, session); ! Check( session.Batcher.ExecuteNonQuery( deleteCmd ) , id); } else *************** *** 947,951 **** if( IsVersioned ) { ! session.Batcher.CloseCommand( deleteCmd ); } } --- 952,956 ---- if( IsVersioned ) { ! session.Batcher.CloseCommand( deleteCmd, null ); } } *************** *** 1026,1030 **** { VersionType.NullSafeSet( statement, oldVersion, versionParamIndex, session); ! Check( statement.ExecuteNonQuery(), id ); } else --- 1031,1035 ---- { VersionType.NullSafeSet( statement, oldVersion, versionParamIndex, session); ! Check( session.Batcher.ExecuteNonQuery( statement ), id ); } else *************** *** 1053,1057 **** if( IsVersioned ) { ! session.Batcher.CloseCommand( statement ); } } --- 1058,1062 ---- if( IsVersioned ) { ! session.Batcher.CloseCommand( statement, null ); } } |