예제 #1
0
        public TableStructure(Dialect.Dialect dialect, string tableName, string valueColumnName, int initialValue,
                              int incrementSize)
        {
            this.tableName       = tableName;
            this.valueColumnName = valueColumnName;
            this.initialValue    = initialValue;
            this.incrementSize   = incrementSize;

            SqlStringBuilder b = new SqlStringBuilder();

            b.Add("select ").Add(valueColumnName).Add(" id_val").Add(" from ").Add(dialect.AppendLockHint(LockMode.Upgrade,
                                                                                                          tableName)).Add(
                dialect.ForUpdateString);
            select = b.ToSqlString();

            b = new SqlStringBuilder();
            b.Add("update ").Add(tableName).Add(" set ").Add(valueColumnName).Add(" = ").Add(Parameter.Placeholder).Add(" where ")
            .Add(valueColumnName).Add(" = ").Add(Parameter.Placeholder);
            update = b.ToSqlString();
        }
예제 #2
0
        public TableStructure(Dialect.Dialect dialect, string tableName, string valueColumnName, int initialValue, int incrementSize)
        {
            _tableName       = tableName;
            _valueColumnName = valueColumnName;
            _initialValue    = initialValue;
            _incrementSize   = incrementSize;

            _selectQuery = new SqlString(
                "select ", valueColumnName, " as id_val from ",
                dialect.AppendLockHint(LockMode.Upgrade, tableName),
                dialect.ForUpdateString);

            _updateQuery = new SqlString(
                "update ", tableName,
                " set ", valueColumnName, " = ", Parameter.Placeholder,
                " where ", valueColumnName, " = ", Parameter.Placeholder);

            _updateParameterTypes = new[]
            {
                SqlTypeFactory.Int64,
                SqlTypeFactory.Int64,
            };
        }
예제 #3
0
        /// <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 = dialect.Qualify(catalogName, schemaName, tableName);
            }

            var selectBuilder = new SqlStringBuilder(100);

            selectBuilder.Add("select " + columnName)
            .Add(" from " + dialect.AppendLockHint(LockMode.Upgrade, tableName));
            if (string.IsNullOrEmpty(whereClause) == false)
            {
                selectBuilder.Add(" where ").Add(whereClause);
            }
            selectBuilder.Add(dialect.ForUpdateString);

            query = selectBuilder.ToString();

            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[] { columnSqlType, columnSqlType };

            var builder = new SqlStringBuilder(100);

            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();
        }
예제 #4
0
        public TableStructure(Dialect.Dialect dialect, string tableName, string valueColumnName, int initialValue, int incrementSize)
        {
            _tableName       = tableName;
            _valueColumnName = valueColumnName;
            _initialValue    = initialValue;
            _incrementSize   = incrementSize;

            var b = new SqlStringBuilder();

            b.Add("select ").Add(valueColumnName).Add(" as id_val").Add(" from ").Add(dialect.AppendLockHint(LockMode.Upgrade, tableName))
            .Add(dialect.ForUpdateString);

            _selectQuery = b.ToSqlString();

            b = new SqlStringBuilder();
            b.Add("update ").Add(tableName).Add(" set ").Add(valueColumnName).Add(" = ").Add(Parameter.Placeholder).Add(" where ")
            .Add(valueColumnName).Add(" = ").Add(Parameter.Placeholder);
            _updateQuery          = b.ToSqlString();
            _updateParameterTypes = new[]
            {
                SqlTypeFactory.Int64,
                SqlTypeFactory.Int64,
            };
        }