コード例 #1
0
        public WPOBaseObject(Session session)
        {
            this.Session = session;
            session.Register(this);

            Status      = ObjectStatus.New;
            ObjectGuid  = Guid.NewGuid();
            TableObject = new WPOTableObject(this);
        }
コード例 #2
0
        public WPOTableObject(WPOBaseObject obj)
        {
            WPOObject   = obj;
            TableName   = obj.GetTableName();
            Inheritance = obj.GetInheritanceType();
            PrimaryKey  = obj.GetPrimaryKey();

            if (Inheritance == InheritanceType.ClassTable)
            {
                WPOTableObject exsistObj = ExsistTableObjects.FirstOrDefault(e => e.GetType() == obj.GetType().BaseType);
                BaseTable = exsistObj ?? new WPOTableObject(obj.GetType().BaseType.CreateModelObj());
            }
        }
コード例 #3
0
        private List <ExecuteCommand> CreateUpdateTransactions()
        {
            List <ExecuteCommand> commands = new List <ExecuteCommand>();
            var objectsToUpdate            = objectsAll.Where(x => x.Status == ObjectStatus.Modified);

            if (objectsToUpdate.Any())
            {
                foreach (var obj in objectsToUpdate)
                {
                    ExecuteCommand command = new ExecuteCommand(ExecuteCommand.CommandType.Update);

                    command.TableName = obj.TableObject.TableName;
                    command.ObjectsIdentifiers.Add(obj.TableObject.PrimaryKey);
                    command.Objects = CreateDiffrentsDictionary(obj, true);

                    if (obj.TableObject.Inheritance == InheritanceType.ClassTable)
                    {
                        List <ExecuteCommand> tmpCommands = new List <ExecuteCommand>();
                        WPOTableObject        tableObj    = obj.TableObject;
                        while (tableObj.BaseTable != null)
                        {
                            ExecuteCommand baseTypeCommand = new ExecuteCommand(ExecuteCommand.CommandType.Update);
                            baseTypeCommand.TableName = tableObj.BaseTable.TableName;
                            baseTypeCommand.ObjectsIdentifiers.Add(tableObj.BaseTable.PrimaryKey);
                            baseTypeCommand.ObjectsIdentifiers.First().Value = obj.TableObject.PrimaryKey.Value;
                            baseTypeCommand.Objects = CreateDiffrentsDictionary(obj, true, tableObj.BaseTable.WPOObject.GetType().Name);
                            tmpCommands.Add(baseTypeCommand);

                            tableObj = tableObj.BaseTable;
                        }

                        tmpCommands.Reverse();
                        commands.AddRange(tmpCommands);
                    }

                    commands.Add(command);
                }
            }

            return(commands);
        }
コード例 #4
0
        private List <ExecuteCommand> CreateInsertTransactions()
        {
            List <ExecuteCommand> commands = new List <ExecuteCommand>();
            var objectsToInsert            = objectsAll.Where(x => x.Status == ObjectStatus.New);

            if (objectsToInsert.Any())
            {
                List <WPOBaseObject> readyObjects    = new List <WPOBaseObject>();
                List <WPOBaseObject> notReadyObjects = new List <WPOBaseObject>();

                Dictionary <string, int> sequences = new Dictionary <string, int>(); //using to storage sequnce name and the count of needed instances

                // Check for every object if it's using any sequence
                foreach (var obj in objectsToInsert)
                {
                    var primaryKeys = obj.GetPrimaryKey();
                    if (string.IsNullOrEmpty(primaryKeys.SequenceName))
                    {
                        readyObjects.Add(obj);
                    }
                    else
                    {
                        notReadyObjects.Add(obj);
                        if (sequences.ContainsKey(primaryKeys.SequenceName))
                        {
                            sequences[primaryKeys.SequenceName]++;
                        }
                        else
                        {
                            sequences.Add(primaryKeys.SequenceName, 1);
                        }
                    }
                }

                // Gets sequences values from database
                List <ExecuteResult <long> > sequencesFromDB = null;
                if (sequences.Any())
                {
                    sequencesFromDB = GetSequencesValuesFromDB(sequences);
                }

                // Puts sequences values into primary keys
                if (sequencesFromDB != null && sequencesFromDB.Any())
                {
                    foreach (var obj in notReadyObjects)
                    {
                        obj.SetSequences(sequencesFromDB);
                        readyObjects.Add(obj);
                    }
                }

                // Creates command for each object
                foreach (var obj in readyObjects)
                {
                    ExecuteCommand command = new ExecuteCommand(ExecuteCommand.CommandType.Insert);

                    obj.TableObject.PrimaryKey = obj.GetPrimaryKey();
                    command.TableName          = obj.TableObject.TableName;
                    command.ObjectsIdentifiers.Add(obj.TableObject.PrimaryKey);
                    command.Objects = CreateDiffrentsDictionary(obj, false);

                    if (obj.TableObject.Inheritance == InheritanceType.ClassTable)
                    {
                        List <ExecuteCommand> tmpCommands = new List <ExecuteCommand>();
                        WPOTableObject        tableObj    = obj.TableObject;
                        while (tableObj.BaseTable != null)
                        {
                            ExecuteCommand baseTypeCommand = new ExecuteCommand(ExecuteCommand.CommandType.Insert);
                            baseTypeCommand.TableName = tableObj.BaseTable.TableName;
                            baseTypeCommand.ObjectsIdentifiers.Add(tableObj.BaseTable.PrimaryKey);
                            baseTypeCommand.ObjectsIdentifiers.First().Value = obj.TableObject.PrimaryKey.Value;
                            baseTypeCommand.Objects = CreateDiffrentsDictionary(obj, false, tableObj.BaseTable.WPOObject.GetType().Name);
                            baseTypeCommand.Objects[tableObj.BaseTable.PrimaryKey.ColumnName] = Tuple.Create(obj.TableObject.PrimaryKey.Value, false);
                            tmpCommands.Add(baseTypeCommand);

                            tableObj = tableObj.BaseTable;
                        }

                        tmpCommands.Reverse();
                        commands.AddRange(tmpCommands);
                    }

                    commands.Add(command);
                }
            }

            return(commands);
        }
コード例 #5
0
        internal WPOType CreateOrGetObject <WPOType>(Dictionary <string, string> dataRow, WPOTableObject table, out bool alreadyExsist) where WPOType : WPOBaseObject
        {
            WPOType exsistObject = (WPOType)objectsAll.FirstOrDefault(o => o.DataRow != null &&
                                                                      o.TableObject.TableName == table.TableName &&
                                                                      o.DataRow[table.PrimaryKey.ColumnName] == dataRow[table.PrimaryKey.ColumnName]);

            alreadyExsist = exsistObject != null;
            return(exsistObject ?? (WPOType)Activator.CreateInstance(typeof(WPOType), new object[] { this }));
        }