Example #1
0
        public override DataVar InternalExecute(ServerProcess AProcess, DataVar[] AArguments)
        {
            if (AProcess.ServerSession.Server.Catalog.Generators == null)             // if not set already
            {
                // check for existing table named Datphor.Generators
                Schema.TableVar LTableVar = (Schema.TableVar)Compiler.ResolveCatalogIdentifier(AProcess.Plan, "System.Generators", false);

                if (LTableVar == null)                 // if system.generators doesn't already exist
                {
                    // get device
                    Schema.Device LDevice =
                        AArguments.Length > 0
                                                        ? (Schema.Device)Compiler.ResolveCatalogIdentifier(AProcess.Plan, AArguments[0].Value.AsString, true)
                                                        : Language.D4.Compiler.GetDefaultDevice(AProcess.Plan, true);

                    // make sure the device is started so that DeviceScalarTypes is filled
                    AProcess.EnsureDeviceStarted(LDevice);

                    // create table type
                    Schema.TableType LTableType = new Schema.TableType();
                    // use System.String if available else System.IString
                    if (LDevice.DeviceScalarTypes.Contains(AProcess.Plan.Catalog.DataTypes.SystemIString))
                    {
                        LTableType.Columns.Add(new Schema.Column("ID", AProcess.Plan.Catalog.DataTypes.SystemIString));
                    }
                    else
                    {
                        LTableType.Columns.Add(new Schema.Column("ID", AProcess.Plan.Catalog.DataTypes.SystemString));
                    }
                    LTableType.Columns.Add(new Schema.Column("NextKey", AProcess.Plan.Catalog.DataTypes.SystemInteger));

                    // create table
                    LTableVar = new Schema.BaseTableVar("System.Generators", LTableType, LDevice);
                    MetaData LMetaData = new MetaData();
                    LMetaData.Tags.Add(new Tag("Storage.Length", "200", false, true));
                    LTableVar.Columns.Add(new Schema.TableVarColumn(LTableType.Columns["ID"], LMetaData));
                    LTableVar.Columns.Add(new Schema.TableVarColumn(LTableType.Columns["NextKey"]));
                    LTableVar.Keys.Add(new Schema.Key(new Schema.TableVarColumn[] { LTableVar.Columns["ID"] }));
                    LTableVar.Owner   = AProcess.Plan.User;
                    LTableVar.Library = AProcess.Plan.CurrentLibrary;
                    LTableVar.AddDependency(LDevice);
                    LTableVar.AddDependency((Schema.ScalarType)LTableVar.Columns[0].DataType);
                    LTableVar.AddDependency((Schema.ScalarType)LTableVar.Columns[1].DataType);

                    Compiler.Bind(AProcess.Plan, new CreateTableNode((Schema.BaseTableVar)LTableVar)).Execute(AProcess);

                    if (AProcess.Plan.User.ID == Server.Server.CAdminUserID)
                    {
                        Schema.Group LGroup = AProcess.Plan.Catalog.Groups[Server.Server.CUserGroupName];
                        LGroup.GrantRight(LTableVar.Rights.Select, true);
                        LGroup.GrantRight(LTableVar.Rights.Insert, true);
                        LGroup.GrantRight(LTableVar.Rights.Update, true);
                    }
                }

                // set generator table
                SystemSetGeneratorsNode.SetGenerator(AProcess, LTableVar);
            }
            return(null);
        }
Example #2
0
 private void EnsurePrepared(PlanNode planNode)
 {
     // The determine device visitor clears prepared device nodes to reduce memory footprint
     // (The resulting optimization is significant, on the order of 100MB for a large Dataphor application)
     // However, since there are cases where subnodes are executed independently (e.g. during a default),
     // we need to check that the node to be executed is prepared and prepare it if necessary.
     if (planNode.DeviceNode == null)
     {
         _serverProcess.EnsureDeviceStarted(planNode.Device);
         planNode.Device.Prepare(Plan, planNode);
     }
 }
Example #3
0
 public void EnsureDeviceStarted(Schema.Device device)
 {
     _serverProcess.EnsureDeviceStarted(device);
 }