/// <summary> /// Configures the TableGenerator by reading the value of <c>table</c>, /// <c>column</c>, and <c>schema</c> from the <c>parms</c> parameter. /// </summary> /// <param name="type">The <see cref="IType"/> the identifier should be.</param> /// <param name="parms">An <see cref="IDictionary"/> of Param values that are keyed by parameter name.</param> /// <param name="dialect">The <see cref="Dialect"/> to help with Configuration.</param> public virtual void Configure(IType type, IDictionary parms, Dialect.Dialect dialect) { tableName = PropertiesHelper.GetString(Table, parms, "hibernate_unique_key"); columnName = PropertiesHelper.GetString(Column, parms, "next_hi"); string schemaName = (string) parms[Schema]; if (schemaName != null && tableName.IndexOf(StringHelper.Dot) < 0) { tableName = schemaName + "." + tableName; } query = "select " + columnName + " from " + dialect.AppendLockHint(LockMode.Upgrade, tableName) + dialect.ForUpdateString; columnType = type as ValueTypeType; if (columnType == null) { log.Error("Column type for TableGenerator is not a value type"); throw new ArgumentException("type is not a ValueTypeType", "type"); } // build the sql string for the Update since it uses parameters if (type is Int16Type) { columnSqlType = SqlTypeFactory.Int16; } else if (type is Int64Type) { columnSqlType = SqlTypeFactory.Int64; } else { columnSqlType = SqlTypeFactory.Int32; } parameterTypes = new SqlType[2] {columnSqlType, columnSqlType}; SqlStringBuilder builder = new SqlStringBuilder(); builder.Add("update " + tableName + " set ") .Add(columnName) .Add(" = ") .Add(Parameter.Placeholder) .Add(" where ") .Add(columnName) .Add(" = ") .Add(Parameter.Placeholder); updateSql = builder.ToSqlString(); }
/// <summary> /// Configures the TableGenerator by reading the value of <c>table</c>, /// <c>column</c>, and <c>schema</c> from the <c>parms</c> parameter. /// </summary> /// <param name="type">The <see cref="IType"/> the identifier should be.</param> /// <param name="parms">An <see cref="IDictionary"/> of Param values that are keyed by parameter name.</param> /// <param name="dialect">The <see cref="Dialect"/> to help with Configuration.</param> public virtual void Configure(IType type, IDictionary<string, string> parms, Dialect.Dialect dialect) { tableName = PropertiesHelper.GetString(TableParamName, parms, DefaultTableName); columnName = PropertiesHelper.GetString(ColumnParamName, parms, DefaultColumnName); whereClause = PropertiesHelper.GetString(Where, parms, ""); string schemaName = PropertiesHelper.GetString(PersistentIdGeneratorParmsNames.Schema, parms, null); string catalogName = PropertiesHelper.GetString(PersistentIdGeneratorParmsNames.Catalog, parms, null); if (tableName.IndexOf('.') < 0) { tableName = Table.Qualify(catalogName, schemaName, tableName); } query = "select " + columnName + " from " + dialect.AppendLockHint(LockMode.Upgrade, tableName) + dialect.ForUpdateString; columnType = type as PrimitiveType; if (columnType == null) { log.Error("Column type for TableGenerator is not a value type"); throw new ArgumentException("type is not a ValueTypeType", "type"); } // build the sql string for the Update since it uses parameters if (type is Int16Type) { columnSqlType = SqlTypeFactory.Int16; } else if (type is Int64Type) { columnSqlType = SqlTypeFactory.Int64; } else { columnSqlType = SqlTypeFactory.Int32; } parameterTypes = new SqlType[2] {columnSqlType, columnSqlType}; SqlStringBuilder builder = new SqlStringBuilder(); builder.Add("update " + tableName + " set ") .Add(columnName) .Add(" = ") .Add(Parameter.Placeholder) .Add(" where ") .Add(columnName) .Add(" = ") .Add(Parameter.Placeholder); if (string.IsNullOrEmpty(whereClause) == false) { builder.Add(" and ") .Add(whereClause); } updateSql = builder.ToSqlString(); }