Esempio n. 1
0
		public PrimaryKey(string name, ColumnDefinition[] columns)
		{
			if(columns == null)
				throw new ArgumentNullException("columns");

			_name = name;
			_columns.AddRange(columns);
		}
Esempio n. 2
0
 public override string NativeColumnString(ColumnDefinition column)
 {
     return String.Format("IDENTITY({0},{1})", column.Seed, column.Increment);
 }
Esempio n. 3
0
        private void AddColumnTo(CreateTableSQLCommand table, string columnName, DbType type, int size, byte precision, byte scale, bool isNotNull, object defaultValue)
        {
            SqlObjectModel.LDD.ColumnConstraint constraint = null;
            if (defaultValue != null)
                constraint = new SqlObjectModel.LDD.DefaultConstraint(new Constant(defaultValue, type), !isNotNull);
            else
                constraint = new SqlObjectModel.LDD.ColumnConstraint(!isNotNull);

            if (!table.ColumnDefinitions.Contains(columnName))
            {

                ColumnDefinition column = new ColumnDefinition(columnName, type, size, precision, scale, constraint);
                table.ColumnDefinitions.Add(columnName, column);
            }
            else
            {
                ColumnDefinition column = table.ColumnDefinitions[columnName] as ColumnDefinition;
                column.ColumnConstraint = constraint;
            }
        }
Esempio n. 4
0
        private void AddForeignKeysTo(CreateTableSQLCommand table, string columnName, string ref_column_name, string ref_table_name, GeneratorMapping map_generator, object defaultValue)
        {
            if (!table.ColumnDefinitions.Contains(columnName))
            {
                DbType type = _Dialect.GetDbTypeToPrimaryKey(map_generator);

                SqlObjectModel.LDD.ColumnConstraint constraint = null;
                if (defaultValue != null)
                    constraint = new SqlObjectModel.LDD.DefaultConstraint(new Constant(defaultValue, type), false);
                else
                    constraint = new SqlObjectModel.LDD.ColumnConstraint(true);

                int size = _Dialect.GetSizeToPrimaryKey(map_generator);
                ColumnDefinition column = new ColumnDefinition(columnName, type, size, constraint);
                table.ColumnDefinitions.Add(columnName, column);

                // Add foreign keys here

            }
        }
Esempio n. 5
0
        private void AddPrimaryKeysTo(CreateTableSQLCommand table, string columnName, GeneratorMapping map_generator)
        {
            if (!table.ColumnDefinitions.Contains(columnName))
            {
                DbType type;
                try
                {
                    type = _Dialect.GetDbTypeToPrimaryKey(map_generator);
                }
                catch (NullReferenceException ex)
                {
                    throw new MappingNotFoundException(string.Format("The type is not defined for the field {0} in the table {1}", columnName, table.TableName));
                }
                int size = _Dialect.GetSizeToPrimaryKey(map_generator);
                ColumnDefinition column = new ColumnDefinition(columnName, type, size);
                if (map_generator.Name == GeneratorMapping.GeneratorType.native)
                {
                    int seed = map_generator.GetParam("seed") != null ? Convert.ToInt32(map_generator.GetParam("seed").Value) : 1;
                    int increment = map_generator.GetParam("increment") != null ? Convert.ToInt32(map_generator.GetParam("increment").Value) : 1;
                    column.EnableAutoIncrement(increment, seed);
                }
                table.ColumnDefinitions.Add(columnName, column);

                if (table.PrimaryKey == null)
                    table.PrimaryKey = new PrimaryKey(String.Concat("PK_", table.TableName), new ColumnDefinition[] { column });
                else
                    table.PrimaryKey.Columns.Add(column);
            }
            else
            {
                if (map_generator.Name == GeneratorMapping.GeneratorType.business)
                {
                    ColumnDefinition column = table.ColumnDefinitions[columnName] as ColumnDefinition;
                    if (table.PrimaryKey == null)
                        table.PrimaryKey = new PrimaryKey(String.Concat("PK_", table.TableName), new ColumnDefinition[] { column });
                    else
                    {
                        if (!table.PrimaryKey.Columns.Contains(column))
                            table.PrimaryKey.Columns.Add(column);
                    }
                }
            }
        }
Esempio n. 6
0
        public override string NativeColumnString(ColumnDefinition column)
		{
			return String.Format("AUTO_INCREMENT");
		}
Esempio n. 7
0
		public PrimaryKey(ColumnDefinition[] columns) : this(null, columns)
		{
		}
Esempio n. 8
0
		public abstract void Visit(ColumnDefinition column);
Esempio n. 9
0
 public override string NativeColumnString(ColumnDefinition column)
 {
     return String.Format(String.Empty);
 }
Esempio n. 10
0
		public virtual void Visit(ColumnDefinition column)
		{
            _Query.Append(FormatAttribute(column.ColumnName)).Append(SPACE).Append(ConvertDbTypeToString(column.Type, column.Size, column.Precision, column.Scale)).Append(SPACE);
			if (column.IsAutoIncrement)
                _Query.Append(this.NativeColumnString(column)).Append(SPACE);

            if(column.ColumnConstraint != null)
				column.ColumnConstraint.Accept(this	);
		}
Esempio n. 11
0
		public abstract string NativeColumnString(ColumnDefinition column);