예제 #1
0
        public void EndUpdate(ServerProcess process, Schema.TableVar tableVar)
        {
            SimpleDeviceHeader header = _headers[tableVar];

            if (header.UpdateCount > 0)
            {
                header.UpdateCount--;
                if (header.UpdateCount == 0)
                {
                    SaveTable(process, tableVar);
                }
            }
        }
예제 #2
0
        public void TruncateTable(ServerProcess process, Schema.TableVar tableVar)
        {
            string tableVarFileName = GetTableVarFileName(tableVar);

            if (File.Exists(tableVarFileName))
            {
                File.Delete(tableVarFileName);
            }
            Tables[tableVar].Truncate(process.ValueManager);
            SimpleDeviceHeader header = _headers[tableVar];

            header.TimeStamp    += 1;
            header.SaveTimeStamp = header.TimeStamp;
        }
예제 #3
0
        protected override object InternalExecute(Program program, PlanNode planNode)
        {
            if ((planNode is BaseTableVarNode) || (planNode is OrderNode))
            {
                Schema.TableVar tableVar = null;
                if (planNode is BaseTableVarNode)
                {
                    tableVar = ((BaseTableVarNode)planNode).TableVar;
                }
                else if (planNode is OrderNode)
                {
                    tableVar = ((BaseTableVarNode)planNode.Nodes[0]).TableVar;
                }
                if (tableVar != null)
                {
                    Device.LoadTable(ServerProcess, tableVar);
                }
            }
            object result = base.InternalExecute(program, planNode);

            if (planNode is CreateTableNode)
            {
                Schema.TableVar    tableVar = ((CreateTableNode)planNode).Table;
                SimpleDeviceHeader header   = new SimpleDeviceHeader(tableVar, 0);
                Device.Headers.Add(header);
                if (!ServerProcess.IsLoading() && ((Device.ReconcileMode & ReconcileMode.Command) != 0))
                {
                    string fileName = Device.GetTableVarFileName(tableVar);
                    if (File.Exists(fileName))
                    {
                        File.Delete(fileName);
                    }
                }
            }
            else if (planNode is DropTableNode)
            {
                Device.Headers.Remove(((DropTableNode)planNode).Table);
            }
            return(result);
        }
예제 #4
0
        public void BeginUpdate(ServerProcess process, Schema.TableVar tableVar)
        {
            SimpleDeviceHeader header = _headers[tableVar];

            header.UpdateCount++;
        }
예제 #5
0
        public void SaveTable(ServerProcess process, Schema.TableVar tableVar)
        {
            SimpleDeviceHeader header = _headers[tableVar];

            if ((header.UpdateCount == 0) && (header.TimeStamp > header.SaveTimeStamp))
            {
                Plan plan = new Plan(process);
                try
                {
                    plan.PushSecurityContext(new SecurityContext(tableVar.Owner));
                    try
                    {
                        plan.PushGlobalContext();
                        try
                        {
                            Program program = new Program(process);
                            program.Code = Compiler.Compile(plan, new IdentifierExpression(tableVar.Name), true).ExtractNode <BaseTableVarNode>();
                            program.Start(null);
                            try
                            {
                                ITable table = (ITable)program.Code.Execute(program);
                                try
                                {
                                    table.Open();
                                    Row row = new Row(program.ValueManager, tableVar.DataType.CreateRowType());
                                    try
                                    {
                                        string fileName = GetTableVarFileName(tableVar);
                                        FileUtility.EnsureWriteable(fileName);
                                        using (FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write))
                                        {
                                            while (table.Next())
                                            {
                                                table.Select(row);
                                                byte[] rowValue = row.AsPhysical;
                                                StreamUtility.WriteInteger(stream, rowValue.Length);
                                                stream.Write(rowValue, 0, rowValue.Length);
                                            }
                                        }
                                    }
                                    finally
                                    {
                                        row.Dispose();
                                    }
                                }
                                finally
                                {
                                    table.Dispose();
                                }
                            }
                            finally
                            {
                                program.Stop(null);
                            }
                        }
                        finally
                        {
                            plan.PopGlobalContext();
                        }
                    }
                    finally
                    {
                        plan.PopSecurityContext();
                    }
                }
                finally
                {
                    plan.Dispose();
                }
                header.SaveTimeStamp = header.TimeStamp;
            }
        }