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="dialect"></param> /// <returns></returns> public IIdentifierGenerator CreateIdentifierGenerator(Dialect.Dialect dialect) { if (uniqueIdentifierGenerator == null) { uniqueIdentifierGenerator = IdentifierGeneratorFactory.Create(identifierGeneratorStrategy, type, identifierGeneratorProperties, dialect); } return(uniqueIdentifierGenerator); }
public object Generate(ISessionImplementor session, object obj) { if (max_lo < 1) { long val = Convert.ToInt64(DoWorkInNewTransaction(session)); if (val == 0) { val = Convert.ToInt64(DoWorkInNewTransaction(session)); } return(IdentifierGeneratorFactory.CreateNumber(val, returnClass)); } if (lo > max_lo) { long hival = Convert.ToInt64(DoWorkInNewTransaction(session)); lo = (hival == 0) ? 1 : 0; hi = hival * (max_lo + 1); log.Debug("New high value: " + hival); } return(IdentifierGeneratorFactory.CreateNumber(hi + lo++, returnClass)); }
/// <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"); } }
protected virtual object Make(long value) { return(IdentifierGeneratorFactory.CreateNumber(value, ReturnClass)); }
public void NonCreatableStrategy() { Assert.Throws <IdentifierGenerationException>(() => IdentifierGeneratorFactory.Create("Guid", NHibernateUtil.Guid, null, new MsSql2000Dialect()), "Could not interpret id generator strategy: Guid"); }
public bool IsIdentityColumn(Dialect.Dialect dialect) { return (IdentifierGeneratorFactory.GetIdentifierGeneratorClass(identifierGeneratorStrategy, dialect).Equals( typeof(IdentityGenerator))); }
public IIdentifierGenerator CreateIdentifierGenerator(Dialect.Dialect dialect, string defaultCatalog, string defaultSchema, RootClass rootClass) { Dictionary <string, string> @params = new Dictionary <string, string>(); //if the hibernate-mapping did not specify a schema/catalog, use the defaults //specified by properties - but note that if the schema/catalog were specified //in hibernate-mapping, or as params, they will already be initialized and //will override the values set here (they are in identifierGeneratorProperties) if (!string.IsNullOrEmpty(defaultSchema)) { @params[PersistentIdGeneratorParmsNames.Schema] = defaultSchema; } if (!string.IsNullOrEmpty(defaultCatalog)) { @params[PersistentIdGeneratorParmsNames.Catalog] = defaultCatalog; } //pass the entity-name, if not a collection-id if (rootClass != null) { @params[IdGeneratorParmsNames.EntityName] = rootClass.EntityName; } //init the table here instead of earlier, so that we can get a quoted table name //TODO: would it be better to simply pass the qualified table name, instead of // splitting it up into schema/catalog/table names string tableName = Table.GetQuotedName(dialect); @params[PersistentIdGeneratorParmsNames.Table] = tableName; //pass the column name (a generated id almost always has a single column and is not a formula) IEnumerator enu = ColumnIterator.GetEnumerator(); enu.MoveNext(); string columnName = ((Column)enu.Current).GetQuotedName(dialect); @params[PersistentIdGeneratorParmsNames.PK] = columnName; if (rootClass != null) { StringBuilder tables = new StringBuilder(); bool commaNeeded = false; foreach (Table identityTable in rootClass.IdentityTables) { if (commaNeeded) { tables.Append(StringHelper.CommaSpace); } commaNeeded = true; tables.Append(identityTable.GetQuotedName(dialect)); } @params[PersistentIdGeneratorParmsNames.Tables] = tables.ToString(); } else { @params[PersistentIdGeneratorParmsNames.Tables] = tableName; } if (identifierGeneratorProperties != null) { ArrayHelper.AddAll(@params, identifierGeneratorProperties); } return(IdentifierGeneratorFactory.Create(identifierGeneratorStrategy, Type, @params, dialect)); }
public override object GetDefaultValue(object currentValue) { return(IdentifierGeneratorFactory.CreateNumber(-1L, currentValue.GetType())); }