Exemple #1
0
        protected override DevicePlanNode InternalPrepare(Schema.DevicePlan plan, PlanNode planNode)
        {
            // return a DevicePlanNode appropriate for execution of the given node
            TableNode tableNode = planNode as TableNode;

            if (tableNode != null)
            {
                var fhirTableNode = new FHIRDeviceTableNode(tableNode);
                fhirTableNode.Prepare(plan);
                if (plan.IsSupported)
                {
                    return(fhirTableNode);
                }

                return(null);
            }

            CreateTableNode createTableNode = planNode as CreateTableNode;

            if (createTableNode != null)
            {
                var fhirCreateTableNode = new FHIRCreateTableNode(createTableNode);
                return(fhirCreateTableNode);
            }

            DropTableNode dropTableNode = planNode as DropTableNode;

            if (dropTableNode != null)
            {
                var fhirDropTableNode = new FHIRDropTableNode(dropTableNode);
                return(fhirDropTableNode);
            }

            return(null);
        }
Exemple #2
0
        private void InternalPrepare(Schema.DevicePlan plan, TableNode planNode)
        {
            RestrictNode restrictNode = planNode as RestrictNode;

            if (restrictNode != null)
            {
                // Prepare the source
                InternalPrepare(plan, restrictNode.SourceNode);

                if (plan.IsSupported)
                {
                    if (restrictNode.IsSeekable)
                    {
                        // TODO: If this is a seek to the Id and there is more than one search parameter, this should not be supported
                        // TODO: Many FHIR servers don't support wide open queries, so if something isn't filtered, we would need to be able to indicate (warning maybe?) that the query will likely not return any data (maybe even an error, although some systems do support it).
                        // Verify that each condition corresponds to a known search parameter for this resource
                        foreach (ColumnConditions columnConditions in restrictNode.Conditions)
                        {
                            if (!IsSearchParamColumn(columnConditions.Column))
                            {
                                plan.TranslationMessages.Add(new Schema.TranslationMessage(String.Format("Service does not support restriction by {0}.", columnConditions.Column.Name)));
                                plan.IsSupported = false;
                                break;
                            }
                        }
                    }
                    else if (restrictNode.Nodes[1] is SatisfiesSearchParamNode)
                    {
                        plan.IsSupported = true;
                    }
                    else
                    {
                        plan.TranslationMessages.Add(new Schema.TranslationMessage("Service does not support arbitrary restriction."));
                        plan.IsSupported = false;
                    }
                }

                return;
            }

            BaseTableVarNode baseTableVarNode = planNode as BaseTableVarNode;

            if (baseTableVarNode != null)
            {
                ResourceType = MetaData.GetTag(baseTableVarNode.TableVar.MetaData, "FHIR.ResourceType", Schema.Object.Unqualify(baseTableVarNode.TableVar.Name));
                return;
            }

            plan.TranslationMessages.Add(new Schema.TranslationMessage("Service does not support arbitrary queries."));
            plan.IsSupported = false;
            return;
        }
Exemple #3
0
        //TODO: Add support as we can.
        protected override DevicePlanNode InternalPrepare(Schema.DevicePlan plan, PlanNode planNode)
        {
            if (planNode is BaseTableVarNode)
            {
                BaseTableVarNode node = (BaseTableVarNode)planNode;
                node.CursorType          = CursorType.Dynamic;
                node.RequestedCursorType = plan.Plan.CursorContext.CursorType;
                node.CursorCapabilities  =
                    CursorCapability.Navigable |
                    CursorCapability.BackwardsNavigable |
                    CursorCapability.Searchable |
                    CursorCapability.Updateable;

                node.CursorIsolation = plan.Plan.CursorContext.CursorIsolation;
                node.Order           = Compiler.OrderFromKey(plan.Plan, Compiler.FindClusteringKey(plan.Plan, node.TableVar));
                return(new DevicePlanNode(node));
            }
            else if ((planNode is OrderNode) && (planNode.Nodes[0] is BaseTableVarNode) && (plan.Plan.CursorContext.CursorType != CursorType.Static))
            {
                OrderNode        node         = (OrderNode)planNode;
                BaseTableVarNode tableVarNode = (BaseTableVarNode)planNode.Nodes[0];

                bool isSupported = false;

                foreach (Schema.Key key in tableVarNode.TableVar.Keys)
                {
                    var tableOrder = Compiler.OrderFromKey(plan.Plan, key);
                    if (node.RequestedOrder.Equivalent(tableOrder))
                    {
                        node.PhysicalOrder = tableOrder;
                        node.ScanDirection = ScanDirection.Forward;
                        isSupported        = true;
                        break;
                    }
                    else if (node.RequestedOrder.Equivalent(new Schema.Order(tableOrder, true)))
                    {
                        node.PhysicalOrder = tableOrder;
                        node.ScanDirection = ScanDirection.Backward;
                        isSupported        = true;
                        break;
                    }
                }

                if (!isSupported)
                {
                    foreach (Schema.Order order in tableVarNode.TableVar.Orders)
                    {
                        //We support one column (or one column plus a single-column key ordered in the same direction).
                        if (order.Columns.Count > 1)
                        {
                            break;
                        }

                        if (node.RequestedOrder.Equivalent(order))
                        {
                            node.PhysicalOrder = order;
                            node.ScanDirection = ScanDirection.Forward;
                            isSupported        = true;
                            break;
                        }
                        else if (node.RequestedOrder.Equivalent(new Schema.Order(order, true)))
                        {
                            node.PhysicalOrder = order;
                            node.ScanDirection = ScanDirection.Backward;
                            isSupported        = true;
                            break;
                        }

                        var rowIdKey   = tableVarNode.TableVar.Keys.MinimumSubsetKey(tableVarNode.TableVar.Columns);
                        var tableOrder = Compiler.OrderFromKey(plan.Plan, rowIdKey);
                        //If we have a rowId key... Add it to the ordering and see if we match
                        if (rowIdKey.Columns.Count == 1 && tableOrder.Columns.Count == 1)
                        {
                            Order newOrder = new Order(order);
                            newOrder.Columns.Add(tableOrder.Columns[0]);

                            if (node.RequestedOrder.Equivalent(newOrder))
                            {
                                node.PhysicalOrder = newOrder;
                                node.ScanDirection = ScanDirection.Forward;
                                isSupported        = true;
                                break;
                            }
                            else if (node.RequestedOrder.Equivalent(new Schema.Order(newOrder, true)))
                            {
                                node.PhysicalOrder = newOrder;
                                node.ScanDirection = ScanDirection.Backward;
                                isSupported        = true;
                                break;
                            }
                        }
                    }
                }

                if (!isSupported)
                {
                    //Support every ordering... Use nestedFilterCursor to emulate support...
                    node.PhysicalOrder = node.RequestedOrder;
                    node.ScanDirection = ScanDirection.Forward;
                    isSupported        = true;
                }

                if (isSupported)
                {
                    node.Order = new Schema.Order();
                    node.Order.MergeMetaData(node.RequestedOrder.MetaData);
                    node.Order.IsInherited = false;
                    Schema.OrderColumn orderColumn;
                    Schema.OrderColumn newOrderColumn;
                    for (int index = 0; index < node.PhysicalOrder.Columns.Count; index++)
                    {
                        orderColumn    = node.PhysicalOrder.Columns[index];
                        newOrderColumn =
                            new Schema.OrderColumn
                            (
                                node.TableVar.Columns[orderColumn.Column],
                                node.ScanDirection == ScanDirection.Forward ?
                                orderColumn.Ascending :
                                !orderColumn.Ascending
                            );
                        newOrderColumn.Sort          = orderColumn.Sort;
                        newOrderColumn.IsDefaultSort = orderColumn.IsDefaultSort;
                        Error.AssertWarn(newOrderColumn.Sort != null, "Sort is null");
                        node.Order.Columns.Add(newOrderColumn);
                    }
                    if (!node.TableVar.Orders.Contains(node.Order))
                    {
                        node.TableVar.Orders.Add(node.Order);
                    }

                    node.CursorType          = CursorType.Dynamic;
                    node.RequestedCursorType = plan.Plan.CursorContext.CursorType;
                    node.CursorCapabilities  =
                        CursorCapability.Navigable |
                        CursorCapability.BackwardsNavigable |
                        CursorCapability.Searchable |
                        (plan.Plan.CursorContext.CursorCapabilities & CursorCapability.Updateable);
                    node.CursorIsolation = plan.Plan.CursorContext.CursorIsolation;

                    return(new DevicePlanNode(node));
                }
            }
            else if (planNode is CreateTableVarBaseNode)
            {
                plan.Plan.CheckRight(GetRight(Schema.RightNames.CreateStore));
                return(new DevicePlanNode(planNode));
            }
            else if (planNode is AlterTableNode)
            {
                //Don't support altering tables in V1

                //plan.Plan.CheckRight(GetRight(Schema.RightNames.AlterStore));
                //AlterTableNode alterTableNode = (AlterTableNode)planNode;
                //if (alterTableNode.AlterTableStatement.CreateColumns.Count > 0)
                //    throw new RuntimeException(RuntimeException.Codes.UnimplementedCreateCommand, "Columns in a memory device");
                //if (alterTableNode.AlterTableStatement.DropColumns.Count > 0)
                //    throw new RuntimeException(RuntimeException.Codes.UnimplementedDropCommand, "Columns in a memory device");
                //return new DevicePlanNode(planNode);
            }
            else if (planNode is DropTableNode)
            {
                plan.Plan.CheckRight(GetRight(Schema.RightNames.DropStore));
                return(new DevicePlanNode(planNode));
            }
            plan.IsSupported = false;
            return(null);
        }
Exemple #4
0
 public void Prepare(Schema.DevicePlan plan)
 {
     InternalPrepare(plan, Node);
 }
Exemple #5
0
        private void InternalPrepare(Schema.DevicePlan plan, TableNode planNode)
        {
            RestrictNode restrictNode = planNode as RestrictNode;

            if (restrictNode != null)
            {
                // Prepare the source
                InternalPrepare(plan, restrictNode.SourceNode);

                if (plan.IsSupported)
                {
                    SetSearchParamContainer(plan);
                    if (restrictNode.IsSeekable)
                    {
                        foreach (ColumnConditions columnConditions in restrictNode.Conditions)
                        {
                            if (!IsSearchParamColumn(columnConditions.Column))
                            {
                                plan.TranslationMessages.Add(new Schema.TranslationMessage(String.Format("Service does not support restriction by {0}.", columnConditions.Column.Name)));
                                plan.IsSupported = false;
                                break;
                            }
                        }
                    }
                    else if (restrictNode.IsScanable)
                    {
                        foreach (ColumnConditions columnConditions in restrictNode.Conditions)
                        {
                            if (!IsSearchParamColumn(columnConditions.Column))
                            {
                                plan.TranslationMessages.Add(new Schema.TranslationMessage(String.Format("Service does not support restriction by {0}.", columnConditions.Column.Name)));
                                plan.IsSupported = false;
                                break;
                            }

                            foreach (ColumnCondition condition in columnConditions)
                            {
                                if (condition.Instruction != Instructions.Equal)
                                {
                                    plan.IsSupported = false;
                                    break;
                                }
                            }

                            if (!plan.IsSupported)
                            {
                                break;
                            }
                        }
                    }
                    else if (restrictNode.Nodes[1] is SatisfiesSearchParamNode)
                    {
                        plan.IsSupported = true;
                    }
                    else
                    {
                        plan.TranslationMessages.Add(new Schema.TranslationMessage("Service does not support arbitrary restriction."));
                        plan.IsSupported = false;
                    }
                }

                return;
            }

            BaseTableVarNode baseTableVarNode = planNode as BaseTableVarNode;

            if (baseTableVarNode != null)
            {
                ResourceType = MetaData.GetTag(baseTableVarNode.TableVar.MetaData, "PHINVADS.ResourceType", Schema.Object.Unqualify(baseTableVarNode.TableVar.Name));
                return;
            }

            plan.TranslationMessages.Add(new Schema.TranslationMessage("Service does not support arbitrary queries."));
            plan.IsSupported = false;
            return;
        }
Exemple #6
0
 public void SetSearchParamContainer(Schema.DevicePlan plan)
 {
     _searchParams = PHINVADSDevice.GetSearchParamInstanceForResource(plan.Plan, _resourceType);
     _directParams = new Dictionary <string, object>();
 }