protected override DatabaseItem createAsNew(DatabaseItem owner, bool save = true)
        {
            Table    newTable         = owner as Table;
            Database existingDatabase = owner as Database;

            if (newTable == null)
            {
                //look for corresponding table in existingDatabase
                newTable = (Table)existingDatabase.tables.FirstOrDefault(x => x.name == this.ownerTable.name);
            }
            if (newTable != null)
            {
                var newColumn = new Column(newTable, this.name);
                newColumn.isNew            = true;
                newColumn.isNotNullable    = isNotNullable;
                newColumn.type             = type;
                newColumn.logicalAttribute = logicalAttribute;
                newColumn.logicalElements  = logicalElements;
                newColumn.isOverridden     = isOverridden;
                newColumn.isRenamed        = isRenamed;
                newColumn.position         = position;
                newColumn.initialValue     = initialValue;
                newColumn.derivedFromItem  = this;
                if (save)
                {
                    newColumn.save();
                }
                return(newColumn);
            }
            return(null);
        }
Beispiel #2
0
        protected override DatabaseItem createAsNew(DatabaseItem owner, bool save = true)
        {
            Table    newTable         = owner as Table;
            Database existingDatabase = owner as Database;

            if (newTable == null)
            {
                //look for corresponding table in existingDatabase
                newTable = (Table)existingDatabase.tables.FirstOrDefault(x => x.name == this.ownerTable.name);
            }
            if (newTable != null && newTable.primaryKey == null)              //only create it if htere is not already one
            {
                var newPrimaryKey = new PrimaryKey(newTable, this._involvedColumns);
                newPrimaryKey.name  = name;
                newPrimaryKey.isNew = true;
                //newPrimaryKey.isOverridden = this.isOverridden;
                newPrimaryKey.derivedFromItem = this;
                if (save)
                {
                    newPrimaryKey.save();
                }
                return(newPrimaryKey);
            }
            return(null);
        }
        protected override DatabaseItem createAsNew(DatabaseItem owner, bool save = true)
        {
            Database existingDatabase = owner as Database;
            var      newTable         = new Table((Database)existingDatabase, this.name);

            newTable.isNew           = true;
            newTable.logicalElements = this.logicalElements;
            newTable.derivedFromItem = this;
            newTable.tableSpace      = this.tableSpace;
            if (save)
            {
                newTable.save();
            }
            return(newTable);
        }
        public override bool Equals(object obj)
        {
            DatabaseItem other = obj as DatabaseItem;

            if (other == null)
            {
                return(false);
            }
            bool nameEquals = this.name == other.name;

            if (!nameEquals)
            {
                return(false);
            }
            //check itemType
            bool itemTypeEquals = this.itemType == other.itemType;

            if (!itemTypeEquals)
            {
                return(false);
            }
            //check wrapped element
            bool wrappedElementEqual = false;

            wrappedElementEqual = this.wrappedElement != null && this.wrappedElement.Equals(other.wrappedElement) ||
                                  this.wrappedElement == null && other.wrappedElement == null;
            if (!wrappedElementEqual)
            {
                return(false);
            }
            //check owner
            bool ownerEqual = false;

            ownerEqual = this.owner != null && this.owner.Equals(other.owner) || this.owner == null && other.owner == null;
            if (!ownerEqual)
            {
                return(false);
            }
            //check logical elements
            bool logicalElementsEqual = false;

            logicalElementsEqual = this.logicalElements.All(x => other.logicalElements.Any(y => y.Equals(x))) ||
                                   this.logicalElements.Count == 0 && other.logicalElements.Count == 0;
            return(logicalElementsEqual);
        }
        protected override DatabaseItem createAsNew(DatabaseItem owner, bool save = true)
        {
            Table    newTable         = owner as Table;
            Database existingDatabase = owner as Database;

            if (newTable == null)
            {
                //look for corresponding table in existingDatabase
                newTable = (Table)existingDatabase.tables.FirstOrDefault(x => x.name == this.ownerTable.name);
            }

            if (newTable != null)
            {
                var index = new Index(newTable, this._involvedColumns);
                index.isNew = true;
                index.name  = name;
                if (save)
                {
                    index.save();
                }
                return(index);
            }
            return(null);
        }
        protected override DatabaseItem createAsNew(DatabaseItem owner, bool save = true)
        {
            Table    newTable         = owner as Table;
            Database existingDatabase = owner as Database;

            if (newTable != null)
            {
                existingDatabase = newTable.databaseOwner as Database;
            }
            if (newTable == null)
            {
                //look for corresponding table in existingDatabase
                newTable = (Table)existingDatabase.tables.FirstOrDefault(x => x.name == this.ownerTable.name);
            }
            var newForeignTable = existingDatabase.tables.FirstOrDefault(x => x.name == this.foreignTable.name);

            if (newTable != null && newForeignTable != null)
            {
                var newForeignKey = new ForeignKey(newTable, this._involvedColumns);
                newForeignKey.name                = name;
                newForeignKey.isNew               = true;
                newForeignKey._foreignTable       = (Table)newForeignTable;
                newForeignKey._logicalAssociation = _logicalAssociation;
                this.setLogicalName(save);
                newForeignKey.isOverridden    = isOverridden;
                newForeignKey.derivedFromItem = this;
                //set default value for onDelete
                newForeignKey.onDelete = "Restrict";
                if (save)
                {
                    newForeignKey.save();
                }
                return(newForeignKey);
            }
            return(null);
        }
Beispiel #7
0
        public override bool Equals(object obj)
        {
            DatabaseItem other = obj as DatabaseItem;

            if (other == null)
            {
                return(false);
            }
            bool ownerEqual = false;

            ownerEqual = this.owner != null && this.owner.Equals(other.owner) || this.owner == null && other.owner == null;
            bool wrappedElementEqual = false;

            wrappedElementEqual = this.wrappedElement != null && this.wrappedElement.Equals(other.wrappedElement) ||
                                  this.wrappedElement == null && other.wrappedElement == null;
            bool logicalElementsEqual = false;

            logicalElementsEqual = this.logicalElements.All(x => other.logicalElements.Any(y => y.Equals(x))) ||
                                   this.logicalElements.Count == 0 && other.logicalElements.Count == 0;
            bool itemTypeEquals = this.itemType == other.itemType;
            bool nameEquals     = this.name == other.name;

            return(ownerEqual && wrappedElementEqual && logicalElementsEqual && itemTypeEquals && nameEquals);
        }
 protected override DatabaseItem createAsNew(DatabaseItem owner, bool save = true)
 {
     throw new NotImplementedException();
 }
 protected abstract DatabaseItem createAsNew(DatabaseItem owner, bool save = true);
Beispiel #10
0
 protected override DatabaseItem createAsNew(DatabaseItem owner, bool save = true)
 {
     //TODO: figure out how to handle creation of new databases
     return(null);
 }