public object Generate(ISessionImplementor session, object obj) { try { IDbCommand cmd = session.Batcher.PrepareCommand(CommandType.Text, _sql, SqlTypeFactory.NoTypes); IDataReader reader = null; try { reader = session.Batcher.ExecuteReader(cmd); try { reader.Read(); object result = IdentifierGeneratorFactory.Get(reader, NHibernateUtil.String, session); return(result); } finally { reader.Close(); } } finally { session.Batcher.CloseCommand(cmd, reader); } } catch (DbException sqle) { throw ADOExceptionHelper.Convert(session.Factory.SQLExceptionConverter, sqle, "could not get next sequence value"); } }
/// <summary> /// 获取主键 /// </summary> /// <param name="session">session</param> /// <param name="obj">obj</param> /// <returns>object</returns> public object Generate(ISessionImplementor session, object obj) { try { IDbCommand cmd = session.Connection.CreateCommand(); cmd.CommandText = _sql; IDataReader reader = null; try { reader = session.Batcher.ExecuteReader(cmd); try { reader.Read(); object result = IdentifierGeneratorFactory.Get(reader, _identifierType, session); if (_log.IsDebugEnabled) { _log.Debug("Sequence identifier generated: " + result); } return(result); } finally { reader.Close(); } } finally { session.Batcher.CloseCommand(cmd, reader); } } catch (DbException sqle) { _log.Error("error generating sequence", sqle); throw ADOExceptionHelper.Convert(session.Factory.SQLExceptionConverter, sqle, "could not get next sequence value"); } }