Example #1
0
 internal void FillDeleteScriptCollection(SQLScriptCollection collection)
 {
     if (collection == null)
     {
         throw new ArgumentNullException("collection");
     }
     collection.Clear();
     FillDeleteScript(collection);
 }
Example #2
0
 internal void FillFreshScriptCollection(SQLScriptCollection collection)
 {
     if (collection == null)
     {
         throw new ArgumentNullException("collection");
     }
     collection.Clear();
     FillSelectScript(null, 0, collection);
 }
Example #3
0
        public void Delete(IDatabaseAccessor accessor)
        {
            if (accessor == null)
            {
                throw new ArgumentNullException("accessor");
            }
            var collection = new SQLScriptCollection(accessor);

            this.Schema.FillDeleteScriptCollection(collection);
            accessor.ExecuteSQLCommand(collection.ExportCommands());
        }
Example #4
0
        public void Delete(IDatabaseAccessor accessor)
        {
            ThrowNotReadyException();

            if (accessor == null)
            {
                throw new ArgumentNullException("accessor");
            }
            var collection = new SQLScriptCollection(accessor);

            Delete(collection);
            accessor.ExecuteSQLCommand(collection.ExportCommands());
        }
Example #5
0
        internal void Delete(SQLScriptCollection collection)
        {
            if (collection == null)
            {
                throw new ArgumentNullException("collection");
            }
            var value = Value;

            if (value != null)
            {
                value.Delete(collection);
            }
        }
Example #6
0
 internal override void Delete(SQLScriptCollection collection)
 {
     if (collection == null)
     {
         throw new ArgumentNullException("collection");
     }
     _list0.ForEach(item => {
         item.Schema.FillDeleteScript(collection);
     });
     if (Entity != null)
     {
         Entity.Schema.FillDeleteScript(collection);
     }
 }
Example #7
0
        public void Save(IDatabaseAccessor accessor, bool fresh = false)
        {
            if (accessor == null)
            {
                throw new ArgumentNullException("accessor");
            }
            var collection = new SQLScriptCollection(accessor);

            this.Schema.FillSaveScriptCollection(collection);
            accessor.ExecuteSQLCommand(collection.ExportCommands());
            if (fresh)
            {
                this.Fresh(accessor);
            }
        }
Example #8
0
        internal override void Delete(SQLScriptCollection collection)
        {
            ThrowNotReadyException();

            if (collection == null)
            {
                throw new ArgumentNullException("collection");
            }
            _list0.ForEach(item => {
                item.Schema.FillDeleteScript(collection);
            });
            _list.ForEach(ent =>
            {
                ent.Schema.FillDeleteScript(collection);
            });
        }
Example #9
0
        private DataSet RetrieveDataSet(IDatabaseAccessor accessor)
        {
            var collection = new SQLScriptCollection(accessor);

            Schema.FillFreshScriptCollection(collection);
            var dbset = accessor.RetrieveDataSet(collection.ExportCommand());

            if (dbset.Tables.Count > 0)
            {
                for (var i = 0; i < dbset.Tables.Count; i++)
                {
                    if (string.IsNullOrWhiteSpace(collection.Scripts[i].ID))
                    {
                        continue;
                    }
                    dbset.Tables[i].TableName = collection.Scripts[i].ID.ToString();
                }
            }
            return(dbset);
        }
Example #10
0
        internal void FillSaveScript(SQLScriptCollection collection)
        {
            switch (this.ColumnsStatus)
            {
            case STATUS.ASSIGNED:
            case STATUS.RAW:
                var script1 = collection.NewSQLScript(null, SQLTYPE.INSERT);
                var insert  = new InsertItem <TableEntity>(collection.accessor, Entity);
                Columns.ToList().ForEach(col =>
                {
                    var param = collection.NewParameter(col.Name, col.Value);
                    insert.Append(new Clause(script1.accessor, param.CoveredName, new KeyValuePair <string, object>[] { param.ToKeyValuePair() }));
                });
                script1.AddItem(insert);
                break;

            case STATUS.CHANGED:
                var script2 = collection.NewSQLScript(null, SQLTYPE.UPDATE);
                var update  = new UpdateItem <TableEntity>(collection.accessor, Entity);
                Columns.Where(c => c.Status == STATUS.CHANGED).ToList().ForEach(col =>
                {
                    var param = collection.NewParameter(col.Name, col.Value);
                    update.Append(new Clause(script2.accessor, string.Format("{0} = {1}", col.Name, param.CoveredName), new KeyValuePair <string, object>[] { param.ToKeyValuePair() }));
                });
                script2.AddItem(update);
                var where = new WhereItem(script2.accessor, update);
                Columns.Where(c => c.IsPK).ToList().ForEach(col =>
                {
                    var param = collection.NewParameter(col.Name, col.Value);
                    where.And(where.ColumnEquals(col.Name, param));
                });
                script2.AddItem(where);
                break;
            }

            foreach (var foreign in this.Foreigns)
            {
                foreign.Save(collection);
            }
        }
Example #11
0
        internal void FillDeleteScript(SQLScriptCollection collection)
        {
            var script = collection.NewSQLScript(null, SQLTYPE.DELETE);
            var delete = new DeleteItem <TableEntity>(collection.accessor, Entity);

            script.AddItem(delete);
            var where = new WhereItem(script.accessor, delete);
            Columns.Where(c => c.IsPK).ToList().ForEach(col =>
            {
                var param = collection.NewParameter(col.Name, col.Value);
                where.And(where.ColumnEquals(col.Name, param));
            });
            script.AddItem(where);

            if (this.HasForeigns)
            {
                foreach (var foreign in this.Foreigns)
                {
                    foreign.Delete(collection);
                }
            }
        }
Example #12
0
 internal abstract void Delete(SQLScriptCollection collection);
Example #13
0
 internal abstract void Save(SQLScriptCollection collection);
Example #14
0
        private void FillSelectScript(string name, int level, SQLScriptCollection collection, WhereItem where = null, Stack <JoinItem <TableEntity> > stack = null)
        {
            if (collection == null)
            {
                throw new ArgumentNullException("collection");
            }

            var script = collection.NewSQLScript(level == 0 ? 0.ToString() : string.Format("{0}-{1}", name.Trim(), level), SQLTYPE.SELECT);
            var alias  = collection.NewTableAlias();
            var from   = new FromItem <TableEntity>(collection.accessor, Entity, alias);
            var select = new SelectItem(collection.accessor, from);

            script.AddItems(select, from);

            //Build Jions
            JoinItem <TableEntity>[] join_items = null;
            if (stack != null)
            {
                if (HasForeigns)
                {
                    join_items = new JoinItem <TableEntity> [stack.Count];
                    stack.CopyTo(join_items, 0);
                }

                TableItem table1 = from;
                JoinItem <TableEntity> table2 = null;
                while (stack.Count > 0)
                {
                    table2 = stack.Pop().Clone() as JoinItem <TableEntity>;
                    table2.ON(table1, table2.Keys.ToArray());
                    table2.Entity.AddJoinFilter(table2, collection.SQLParamCreater);
                    script.AddItems(table2);
                    table1 = table2;
                }
            }

            //Build Where
            if (level == 0)
            {
                var where1 = new WhereItem(collection.accessor, from);
                Columns.Where(c => c.IsPK).ToList().ForEach(col =>
                {
                    var param = collection.NewParameter(col.Value);
                    where1.And(where1.ColumnEquals(col.Name, param));
                });
                where = where == null ? where1 : where + where1;
            }
            if (where != null)
            {
                script.AddItem(where.Clone() as WhereItem);
            }
            var where0 = new WhereItem(collection.accessor, from);

            Entity.AddWhereFilter(where0, collection.SQLParamCreater);
            script.AddItem(where0);

            foreach (var foreign in this.Foreigns)
            {
                var nstack = join_items != null ? new Stack <JoinItem <TableEntity> >(join_items) : new Stack <JoinItem <TableEntity> >();
                nstack.Push(new JoinItem <TableEntity>(collection.accessor, Entity, alias, foreign.Keys.Select(key => key.ToKeyValuePair()).ToArray()));
                foreign.EntityInst.Schema.FillSelectScript(foreign.Name, level + 1, collection, where.Clone() as WhereItem, nstack);
            }
        }