protected Table GetParentTable(Attribute attribute)
 {
     return
         (_tableRepository
          .All()
          .Single(t => t.Id == attribute.TableId));
 }
Пример #2
0
        public bool IsDeployable(Attribute attribute)
        {
            if (attribute is null)
            {
                throw new ArgumentNullException(nameof(attribute));
            }

            return(true);
        }
Пример #3
0
        public void RemoveAttribute(Attribute attribute)
        {
            Table table = _tableService.GetTableById(tableId: attribute.TableId);

            Database database = _databaseService.GetById(id: table.DatabaseId);

            if (_deployService.IsDeployed(database: database))
            {
                _deployService.DropDeployedAttribute(attribute: attribute);
            }

            _attributeService.Remove(attribute: attribute);
        }
Пример #4
0
        public void Rename(Attribute attribute, string name)
        {
            if (attribute is null)
            {
                throw new ArgumentNullException(nameof(attribute));
            }
            if (name is null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            attribute.Rename(name: name);

            _attributeRepository.Update(entity: attribute);
        }
Пример #5
0
        public void Remove(Attribute attribute)
        {
            switch (attribute)
            {
            case null:
                throw new ArgumentNullException(nameof(attribute));

            case PrimaryKey _:
                throw new ArgumentException("Cannot remove primary key attribute.");

            case ForeignKey _:
                throw new ArgumentException("cannot remove foreign key attribute.");
            }

            _attributeRepository
            .Remove(entity: attribute);
        }
Пример #6
0
        public void RenameAttribute(Attribute attribute, string name)
        {
            if (attribute is null)
            {
                throw new ArgumentNullException(nameof(attribute));
            }
            if (name is null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (attribute.Name == name)
            {
                return;
            }

            if (!_attributeValidator.IsValidName(name: name))
            {
                throw new ArgumentException($"Invalid primary key name {name}.");
            }

            Table table = _tableService.GetTableById(tableId: attribute.TableId);

            if (!_attributeValidator.IsUniqueName(table: table, attributeName: name))
            {
                throw new InvalidOperationException($"The attribute {name} is already exists.");
            }

            Database database = _databaseService.GetById(id: table.DatabaseId);

            if (_deployService.IsDeployed(database: database))
            {
                _deployService.RenameDeployedAttribute(attribute: attribute, validAttributeName: name);
            }

            _attributeService.Rename(attribute: attribute, name: name);
        }
        protected string GetTypeString(Attribute attribute)
        {
            string defaultTypeString = Enum.GetName(typeof(TSQLType), value: attribute.SqlType);

            switch (attribute)
            {
            case PrimaryKey _:
                return(defaultTypeString);

            case ForeignKey _:
                return(defaultTypeString);

            case IntegerNumber _:
                return(defaultTypeString);

            case String a when a.Length != null:
                return(defaultTypeString + $"({a.Length})");

            case String _:
                return(defaultTypeString + "(MAX)");

            case RealNumber a when a.BitCapacity != null:
                return(defaultTypeString + $"({a.BitCapacity})");

            case DecimalNumber a when a.Precision != null && a.Scale is null:
                return(defaultTypeString + $"({a.Precision})");

            case DecimalNumber a when a.Precision != null && a.Scale != null:
                return(defaultTypeString + $"({a.Precision},{a.Scale})");

            case DecimalNumber _:
                return(defaultTypeString);

            default:
                throw new ArgumentException("Unexpected attribute type: " + attribute.GetType());
            }
        }
Пример #8
0
 public Table GetAttributeTable(Attribute attribute)
 {
     return(_tableService.GetTableById(tableId: attribute.TableId));
 }
 protected string GetIsNullableString(Attribute attribute)
 {
     return(attribute.IsNullable ? "NULL" : "NOT NULL");
 }
 public string FullDefinition(Attribute attribute)
 {
     return
         ($"{attribute.Name} {GetTypeString(attribute: attribute)} {GetIsNullableString(attribute: attribute)} {GetIsPrimaryKeyString(attribute: attribute)}");
 }
 public string Delele(Attribute attribute)
 {
     return
         ($"ALTER TABLE {GetParentTable(attribute: attribute).Name} \n" +
          $"\tDROP COLUMN {attribute.Name}");
 }
 public string Update(Attribute attribute)
 {
     return(";");
 }
 public string Rename(Attribute attribute, string newValidName)
 {
     return
         ("EXEC sp_rename \n" +
          $"\'{GetParentTable(attribute: attribute).Name}.{attribute.Name}\', \'{newValidName}\', \'COLUMN\'");
 }
 public string Create(Attribute attribute)
 {
     return
         ($"ALTER TABLE {GetParentTable(attribute: attribute).Name} \n" +
          $"\tADD {FullDefinition(attribute: attribute)}");
 }
 protected string GetIsPrimaryKeyString(Attribute attribute)
 {
     return(attribute.IsPrimaryKey ? "PRIMARY KEY IDENTITY" : string.Empty);
 }
Пример #16
0
        public void OffModified(Attribute attribute)
        {
            attribute.OffModified();

            _attributeRepository.Update(entity: attribute);
        }