コード例 #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);
        }
コード例 #2
0
ファイル: OrderTables.cs プロジェクト: laszlo-kiss/Dataphor
        protected override void InternalOpen()
        {
            // TODO: Rewrite this...
            Schema.TableType      tableType = new Schema.TableType();
            Schema.BaseTableVar   tableVar  = new Schema.BaseTableVar(tableType);
            Schema.TableVarColumn newColumn;
            foreach (Schema.TableVarColumn column in Node.TableVar.Columns)
            {
                newColumn = (Schema.TableVarColumn)column.Copy();
                tableType.Columns.Add(newColumn.Column);
                tableVar.Columns.Add(newColumn);
            }

            Schema.Order       order = new Schema.Order();
            Schema.OrderColumn newOrderColumn;
            Schema.OrderColumn orderColumn;
            for (int index = 0; index < Node.Order.Columns.Count; index++)
            {
                orderColumn                  = Node.Order.Columns[index];
                newOrderColumn               = new Schema.OrderColumn(tableVar.Columns[orderColumn.Column], orderColumn.Ascending, orderColumn.IncludeNils);
                newOrderColumn.Sort          = orderColumn.Sort;
                newOrderColumn.IsDefaultSort = orderColumn.IsDefaultSort;
                order.Columns.Add(newOrderColumn);
            }
            tableVar.Orders.Add(order);

            _table = new NativeTable(Manager, tableVar);
            PopulateTable();
            _scan = new Scan(Manager, _table, _table.ClusteredIndex, ScanDirection.Forward, null, null);
            _scan.Open();
        }
コード例 #3
0
ファイル: FHIRDevice.cs プロジェクト: laszlo-kiss/Dataphor
        public override Schema.Catalog GetDeviceCatalog(ServerProcess process, Schema.Catalog serverCatalog, Schema.TableVar tableVar)
        {
            Schema.Catalog catalog = base.GetDeviceCatalog(process, serverCatalog, tableVar);

            using (Plan plan = new Plan(process))
            {
                // Need to support reverse lookup to determine the scalar type for a given native type

                Type[] types = typeof(Base).Assembly.GetTypes();

                foreach (Type type in types)
                {
                    // create a table var for each DomainResource descendent
                    if (type.IsSubclassOf(typeof(DomainResource)))
                    {
                        if (!type.IsGenericTypeDefinition)
                        {
                            string tableName = Schema.Object.Qualify(ToFHIRTableName(type.Name), plan.CurrentLibrary.Name);
                            if (tableVar == null || Schema.Object.NamesEqual(tableName, tableVar.Name))
                            {
                                Schema.BaseTableVar localTableVar = new Schema.BaseTableVar(tableName, null);
                                localTableVar.Owner    = plan.User;
                                localTableVar.Library  = plan.CurrentLibrary;
                                localTableVar.Device   = this;
                                localTableVar.MetaData = new MetaData();

                                // with a FHIR.ResourceType tag
                                localTableVar.MetaData.Tags.Add(new Tag("FHIR.ResourceType", type.Name));
                                localTableVar.AddDependency(this);
                                localTableVar.DataType = new Schema.TableType();

                                var d4TypeName = Schema.Object.Qualify(GenerateTypesNode.GetD4TypeName(type.FullName), "FHIR.Core");
                                var d4Type     = Compiler.ResolveCatalogIdentifier(plan, d4TypeName, false) as Schema.ScalarType;
                                if (d4Type != null)
                                {
                                    AddColumnsForType(localTableVar, d4Type);

                                    localTableVar.Keys.Add(new Schema.Key(new Schema.TableVarColumn[] { localTableVar.Columns["Id"] }));

                                    catalog.Add(localTableVar);
                                }
                            }
                        }
                    }
                }

                return(catalog);
            }
        }
コード例 #4
0
ファイル: UnionTable.cs プロジェクト: laszlo-kiss/Dataphor
        protected override void InternalOpen()
        {
            _sourceRow = new Row(Manager, Node.DataType.RowType);
            _leftTable = (ITable)Node.Nodes[0].Execute(Program);
            try
            {
                _rightTable = (ITable)Node.Nodes[1].Execute(Program);
            }
            catch
            {
                _leftTable.Dispose();
                throw;
            }

            Schema.TableType      tableType = new Schema.TableType();
            Schema.BaseTableVar   tableVar  = new Schema.BaseTableVar(tableType, Program.TempDevice);
            Schema.TableVarColumn newColumn;
            foreach (Schema.TableVarColumn column in _leftTable.Node.TableVar.Columns)
            {
                newColumn = column.Inherit();
                tableType.Columns.Add(column.Column);
                tableVar.Columns.Add(column);
            }

            Schema.Key key = new Schema.Key();
            foreach (Schema.TableVarColumn column in Node.TableVar.Keys.MinimumKey(true).Columns)
            {
                key.Columns.Add(tableVar.Columns[column.Name]);
            }
            tableVar.Keys.Add(key);

            _buffer = new NativeTable(Manager, tableVar);
            PopulateBuffer();

            _scan = new Scan(Manager, _buffer, _buffer.ClusteredIndex, ScanDirection.Forward, null, null);
            _scan.Open();
        }
コード例 #5
0
        public override Schema.Catalog GetDeviceCatalog(ServerProcess process, Schema.Catalog serverCatalog, Schema.TableVar tableVar)
        {
            Schema.Catalog catalog = base.GetDeviceCatalog(process, serverCatalog, tableVar);

            using (Plan plan = new Plan(process))
            {
                // Need to support reverse lookup to determine the scalar type for a given native type

                Type[] types = typeof(Authority).Assembly.GetTypes();

                foreach (Type type in types)
                {
                    // create a table var for each class
                    if (type.IsClass && type.GetField("id") != null)
                    {
                        if (!type.IsGenericTypeDefinition)
                        {
                            string tableName = Schema.Object.Qualify(ToPHINVADSTableName(type.Name), plan.CurrentLibrary.Name);
                            if (tableVar == null || Schema.Object.NamesEqual(tableName, tableVar.Name))
                            {
                                Schema.BaseTableVar localTableVar = new Schema.BaseTableVar(tableName, null);
                                localTableVar.Owner    = plan.User;
                                localTableVar.Library  = plan.CurrentLibrary;
                                localTableVar.Device   = this;
                                localTableVar.MetaData = new MetaData();

                                // with a FHIR.ResourceType tag
                                localTableVar.MetaData.Tags.Add(new Tag("PHINVADS.ResourceType", type.Name));
                                localTableVar.AddDependency(this);
                                localTableVar.DataType = new Schema.TableType();

                                var d4TypeName = Schema.Object.Qualify(GenerateTypesNode.GetD4TypeName(type.FullName), "PHINVADS.Core");
                                var d4Type     = Compiler.ResolveCatalogIdentifier(plan, d4TypeName, false) as Schema.ScalarType;
                                if (d4Type != null)
                                {
                                    AddColumnsForType(localTableVar, d4Type);

                                    localTableVar.Keys.Add(new Schema.Key(new Schema.TableVarColumn[] { localTableVar.Columns["id"] }));

                                    switch (type.Name)
                                    {
                                    case "CodeSystem":
                                        localTableVar.Keys.Add(new Schema.Key(new Schema.TableVarColumn[] { localTableVar.Columns["oid"] }));
                                        localTableVar.Keys.Add(new Schema.Key(new Schema.TableVarColumn[] { localTableVar.Columns["codeSystemCode"] }));
                                        localTableVar.Keys.Add(new Schema.Key(new Schema.TableVarColumn[] { localTableVar.Columns["hl70396Identifier"] }));
                                        break;

                                    case "CodeSystemConcept": localTableVar.Keys.Add(new Schema.Key(new Schema.TableVarColumn[] { localTableVar.Columns["codeSystemOid"], localTableVar.Columns["conceptCode"] })); break;

                                    case "ValueSet":
                                        localTableVar.Keys.Add(new Schema.Key(new Schema.TableVarColumn[] { localTableVar.Columns["oid"] }));
                                        localTableVar.Keys.Add(new Schema.Key(new Schema.TableVarColumn[] { localTableVar.Columns["code"] }));
                                        break;

                                    case "ValueSetConcept":
                                        localTableVar.Keys.Add(new Schema.Key(new Schema.TableVarColumn[] { localTableVar.Columns["codeSystemOid"], localTableVar.Columns["conceptCode"] }));
                                        localTableVar.Keys.Add(new Schema.Key(new Schema.TableVarColumn[] { localTableVar.Columns["valueSetVersionId"], localTableVar.Columns["conceptCode"] }));
                                        break;

                                    case "ValueSetVersion":
                                        localTableVar.Keys.Add(new Schema.Key(new Schema.TableVarColumn[] { localTableVar.Columns["valueSetOid"], localTableVar.Columns["versionNumber"] }));
                                        break;
                                    }

                                    catalog.Add(localTableVar);
                                }
                            }
                        }
                    }
                }

                return(catalog);
            }
        }