/// <summary> /// Generate an <see cref="Int16"/>, <see cref="Int32"/>, or <see cref="Int64"/> /// for the identifier by using a database sequence. /// </summary> /// <param name="session">The <see cref="ISessionImplementor"/> this id is being generated in.</param> /// <param name="obj">The entity for which the id is being generated.</param> /// <returns>The new identifier as a <see cref="Int16"/>, <see cref="Int32"/>, or <see cref="Int64"/>.</returns> public virtual object Generate(ISessionImplementor session, object obj) { try { var cmd = session.Batcher.PrepareCommand(CommandType.Text, sql, SqlTypeFactory.NoTypes); DbDataReader 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"); } }
public object Generate(ISessionImplementor session, object obj) { var sql = new SqlString(session.Factory.Dialect.SelectGUIDString); try { IDbCommand st = session.Batcher.PrepareCommand(CommandType.Text, sql, SqlTypeFactory.NoTypes); IDataReader reader = null; try { reader = session.Batcher.ExecuteReader(st); object result; try { reader.Read(); result = IdentifierGeneratorFactory.Get(reader, identifierType, session); } finally { reader.Close(); } log.Debug("GUID identifier generated: " + result); return(result); } finally { session.Batcher.CloseCommand(st, reader); } } catch (Exception sqle) { throw ADOExceptionHelper.Convert(session.Factory.SQLExceptionConverter, sqle, "could not retrieve GUID", sql); } }
public override object Generate(ISessionImplementor session, object obj) { if (maxLo < 1) { //keep the behavior consistent even for boundary usages long val = Convert.ToInt64(base.Generate(session, obj)); if (val == 0) { val = Convert.ToInt64(base.Generate(session, obj)); } return(IdentifierGeneratorFactory.CreateNumber(val, returnClass)); } if (lo > maxLo) { long hival = Convert.ToInt64(base.Generate(session, obj)); lo = 1; hi = hival * (maxLo + 1); if (log.IsDebugEnabled) { log.Debug("new hi value: " + hival); } } return(IdentifierGeneratorFactory.CreateNumber(hi + lo++, returnClass)); }
public override async Task <object> GenerateAsync(ISessionImplementor session, object obj, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); using (await _generate.LockAsync()) { if (maxLo < 1) { //keep the behavior consistent even for boundary usages long val = Convert.ToInt64(await(base.GenerateAsync(session, obj, cancellationToken)).ConfigureAwait(false)); if (val == 0) { val = Convert.ToInt64(await(base.GenerateAsync(session, obj, cancellationToken)).ConfigureAwait(false)); } return(IdentifierGeneratorFactory.CreateNumber(val, returnClass)); } if (lo > maxLo) { long hival = Convert.ToInt64(await(base.GenerateAsync(session, obj, cancellationToken)).ConfigureAwait(false)); lo = (hival == 0) ? 1 : 0; hi = hival * (maxLo + 1); if (log.IsDebugEnabled) { log.Debug("new hi value: " + hival); } } return(IdentifierGeneratorFactory.CreateNumber(hi + lo++, returnClass)); } }
/// <summary> /// Generate an <see cref="Int16"/>, <see cref="Int32"/>, or <see cref="Int64"/> /// for the identifier by using a database sequence. /// </summary> /// <param name="session">The <see cref="ISessionImplementor"/> this id is being generated in.</param> /// <param name="obj">The entity for which the id is being generated.</param> /// <returns>The new identifier as a <see cref="Int16"/>, <see cref="Int32"/>, or <see cref="Int64"/>.</returns> public virtual object Generate(ISessionImplementor session, object obj) { IDbCommand cmd = session.Batcher.PrepareCommand(new SqlString(sql)); IDataReader reader = null; try { reader = session.Batcher.ExecuteReader(cmd); object result = null; reader.Read(); result = IdentifierGeneratorFactory.Get(reader, returnClass); log.Debug("sequence ID generated: " + result); return(result); } // TODO: change to SQLException catch (Exception e) { // TODO: add code to log the sql exception log.Error("error generating sequence", e); throw; } finally { session.Batcher.CloseCommand(cmd, reader); } }
public async Task <object> GenerateAsync(ISessionImplementor session, object obj, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var sql = new SqlString(session.Factory.Dialect.SelectGUIDString); try { var st = await(session.Batcher.PrepareCommandAsync(CommandType.Text, sql, SqlTypeFactory.NoTypes, cancellationToken)).ConfigureAwait(false); DbDataReader reader = null; try { reader = await(session.Batcher.ExecuteReaderAsync(st, cancellationToken)).ConfigureAwait(false); object result; try { await(reader.ReadAsync(cancellationToken)).ConfigureAwait(false); result = await(IdentifierGeneratorFactory.GetAsync(reader, identifierType, session, cancellationToken)).ConfigureAwait(false); } finally { reader.Close(); } log.Debug("GUID identifier generated: " + result); return(result); } finally { session.Batcher.CloseCommand(st, reader); } } catch (Exception sqle) { throw ADOExceptionHelper.Convert(session.Factory.SQLExceptionConverter, sqle, "could not retrieve GUID", sql); } }
/// <summary> /// Generate a <see cref="Int64"/> for the identifier by selecting and updating a value in a table. /// </summary> /// <param name="session">The <see cref="ISessionImplementor"/> this id is being generated in.</param> /// <param name="obj">The entity for which the id is being generated.</param> /// <returns>The new identifier as a <see cref="Int64"/>.</returns> public override object Generate(ISessionImplementor session, object obj) { using (_asyncLock.Lock()) { if (maxLo < 1) { //keep the behavior consistent even for boundary usages long val = Convert.ToInt64(base.Generate(session, obj)); if (val == 0) { val = Convert.ToInt64(base.Generate(session, obj)); } return(IdentifierGeneratorFactory.CreateNumber(val, returnClass)); } if (lo > maxLo) { long hival = Convert.ToInt64(base.Generate(session, obj)); lo = (hival == 0) ? 1 : 0; hi = hival * (maxLo + 1); log.Debug("New high value: {0}", hival); } return(IdentifierGeneratorFactory.CreateNumber(hi + lo++, returnClass)); } }
public object Generate(ISessionImplementor session, object obj) { if (sql != null) { getNext(session); } return(IdentifierGeneratorFactory.CreateNumber(next++, returnClass)); }
protected internal override Task <object> GetResultAsync(ISessionImplementor session, DbDataReader rs, object obj, CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested) { return(Task.FromCanceled <object>(cancellationToken)); } return(IdentifierGeneratorFactory.GetGeneratedIdentityAsync(rs, persister.IdentifierType, session, cancellationToken)); }
public override object Generate(ISessionImplementor session, object obj) { if (lo > maxLo) { long hival = Convert.ToInt64(base.Generate(session, obj)); lo = 1; hi = hival * (maxLo + 1); log.Debug("new hi value: " + hival); } return(IdentifierGeneratorFactory.CreateNumber(hi + lo++, returnClass)); }
public async Task <object> GenerateAsync(ISessionImplementor session, object obj, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); using (await _generate.LockAsync()) { if (_sql != null) { await(GetNextAsync(session, cancellationToken)).ConfigureAwait(false); } return(IdentifierGeneratorFactory.CreateNumber(_next++, _returnClass)); } }
/// <summary> /// /// </summary> /// <param name="session"></param> /// <param name="obj"></param> /// <returns></returns> public object Generate(ISessionImplementor session, object obj) { using (_asyncLock.Lock()) { if (_sql != null) { GetNext(session); } return(IdentifierGeneratorFactory.CreateNumber(_next++, _returnClass)); } }
public override object ExecuteAndExtract(IDbCommand insert, ISessionImplementor session) { IDataReader rs = session.Batcher.ExecuteReader(insert); try { return IdentifierGeneratorFactory.GetGeneratedIdentity(rs, persister.IdentifierType, session); } finally { session.Batcher.CloseReader(rs); } }
public override async Task <object> ExecuteAndExtractAsync(DbCommand insert, ISessionImplementor session, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var rs = await(session.Batcher.ExecuteReaderAsync(insert, cancellationToken)).ConfigureAwait(false); try { return(await(IdentifierGeneratorFactory.GetGeneratedIdentityAsync(rs, persister.IdentifierType, session, cancellationToken)).ConfigureAwait(false)); } finally { session.Batcher.CloseReader(rs); } }
/// <summary> /// Generate an <see cref="Int16"/>, <see cref="Int32"/>, or <see cref="Int64"/> /// for the identifier by using a database sequence. /// </summary> /// <param name="session">The <see cref="ISessionImplementor"/> this id is being generated in.</param> /// <param name="obj">The entity for which the id is being generated.</param> /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param> /// <returns>The new identifier as a <see cref="Int16"/>, <see cref="Int32"/>, or <see cref="Int64"/>.</returns> public virtual async Task <object> GenerateAsync(ISessionImplementor session, object obj, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); try { var cmd = await(session.Batcher.PrepareCommandAsync(CommandType.Text, sql, SqlTypeFactory.NoTypes, cancellationToken)).ConfigureAwait(false); DbDataReader reader = null; try { reader = await(session.Batcher.ExecuteReaderAsync(cmd, cancellationToken)).ConfigureAwait(false); try { await(reader.ReadAsync(cancellationToken)).ConfigureAwait(false); object result = await(IdentifierGeneratorFactory.GetAsync(reader, identifierType, session, cancellationToken)).ConfigureAwait(false); 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"); } }
protected internal override object GetResult(ISessionImplementor session, DbDataReader rs, object obj) { return(IdentifierGeneratorFactory.GetGeneratedIdentity(rs, persister.IdentifierType, session)); }