Exemple #1
0
        public TableBufferIndex
        (
            ServerProcess AProcess,
            Schema.Order AKey,
            Schema.RowType AKeyRowType,
            Schema.RowType ADataRowType,
            bool AIsClustered,
            int AFanout,
            int ACapacity
        ) : base(AFanout, ACapacity, AKeyRowType.StaticByteSize, ADataRowType.StaticByteSize)
        {
            FKey = AKey;
                        #if DEBUG
            for (int LIndex = 0; LIndex < FKey.Columns.Count; LIndex++)
            {
                if (FKey.Columns[LIndex].Sort == null)
                {
                    throw new Exception("Sort is null");
                }
            }
                        #endif

            FKeyRowType  = AKeyRowType;
            FDataRowType = ADataRowType;
            FIsClustered = AIsClustered;
            Create(AProcess);
        }
Exemple #2
0
        public static bool IsOrderVisible(Schema.Order order, string pageType)
        {
            bool isVisible         = Convert.ToBoolean(GetTag(order.MetaData, "Visible", pageType, "True"));
            bool hasVisibleColumns = false;

            if (isVisible)
            {
                bool isColumnVisible;
                bool hasInvisibleColumns = false;
                foreach (Schema.OrderColumn column in order.Columns)
                {
                    isColumnVisible = IsColumnVisible(column.Column, pageType);
                    if (isColumnVisible)
                    {
                        hasVisibleColumns = true;
                    }
                    if (hasInvisibleColumns && isColumnVisible)
                    {
                        isVisible = false;
                        break;
                    }

                    if (!isColumnVisible)
                    {
                        hasInvisibleColumns = true;
                    }
                }
            }
            return(hasVisibleColumns && isVisible);
        }
Exemple #3
0
        protected virtual void ChangeOrderTo()
        {
            if (ParentGrid.DataLink.Active)
            {
                DAE.Client.TableDataSet dataSet = ParentGrid.DataLink.DataSet as DAE.Client.TableDataSet;
                if (dataSet != null)
                {
                    Schema.Order order = FindOrderForColumn();
                    if (order == null)
                    {
                        dataSet.OrderString = "order { " + ColumnName + " asc }";
                    }
                    else
                    {
                        Schema.Order currentOrder       = dataSet.Order;
                        int          currentColumnIndex = currentOrder == null ? -1 : currentOrder.Columns.IndexOf(ColumnName);

                        bool descending = (currentColumnIndex >= 0) && currentOrder.Columns[currentColumnIndex].Ascending;
                        if (!descending ^ order.Columns[ColumnName].Ascending)
                        {
                            order = new Schema.Order(order, true);
                        }

                        dataSet.Order = order;
                    }
                }
            }
        }
Exemple #4
0
        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();
        }
Exemple #5
0
        protected virtual void Prepare()
        {
            Expression expression = _elaboratedExpression.Expression;

            _tableVar = _elaboratedExpression.MainElaboratedTableVar.TableVar;
            Schema.Order order = GetDefaultOrder(_tableVar);
            if (order != null)
            {
                BaseOrderExpression browseExpression;
                if (Convert.ToBoolean(DerivationUtility.GetTag(_tableVar.MetaData, "UseBrowse", _elaboratedExpression.PageType, "True")))
                {
                    browseExpression = new BrowseExpression();
                }
                else
                {
                    browseExpression = new OrderExpression();
                }
                browseExpression.Expression = expression;
                foreach (Schema.OrderColumn column in order.Columns)
                {
                    OrderColumnDefinition definition = column.EmitStatement(EmitMode.ForCopy) as OrderColumnDefinition;
                    definition.ColumnName = Schema.Object.Qualify(column.Column.Name, _elaboratedExpression.MainElaboratedTableVar.ElaboratedName);
                    browseExpression.Columns.Add(definition);
                }
                expression = browseExpression;
            }

            _expression =
                new D4TextEmitter().Emit
                (
                    new CursorDefinition
                    (
                        expression,
                        CursorCapability.Navigable |
                        CursorCapability.BackwardsNavigable |
                        CursorCapability.Bookmarkable |
                        CursorCapability.Searchable |
                        CursorCapability.Updateable,
                        CursorIsolation.Browse,
                        CursorType.Dynamic
                    )
                );

            // Build the derivation info structure for use in structuring, layout and document production.
            _derivationInfo                      = new DerivationInfo();
            _derivationInfo.Program              = _program;
            _derivationInfo.Process              = _process;
            _derivationInfo.PageType             = _seed.PageType;
            _derivationInfo.Query                = _seed.Query;
            _derivationInfo.Elaborate            = _seed.Elaborate;
            _derivationInfo.MasterKeyNames       = _seed.MasterKeyNames;
            _derivationInfo.DetailKeyNames       = _seed.DetailKeyNames;
            _derivationInfo.KeyNames             = GetKeyNames(_tableVar);
            _derivationInfo.Expression           = _expression;
            _derivationInfo.ElaboratedExpression = _elaboratedExpression;
            _derivationInfo.TableVar             = _tableVar;
            _derivationInfo.MainSourceName       = DerivationUtility.MainSourceName;
            _derivationInfo.IsReadOnly           = DerivationUtility.IsReadOnlyPageType(_seed.PageType);
        }
 public Schema.Order OrderDefinitionToOrder(OrderDefinition order)
 {
     Schema.Order localOrder = new Schema.Order(order.MetaData);
     foreach (OrderColumnDefinition column in order.Columns)
     {
         localOrder.Columns.Add(new Schema.OrderColumn(TableVar.Columns[column.ColumnName], column.Ascending, column.IncludeNils));
     }
     return(localOrder);
 }
Exemple #7
0
 public int IndexOf(Schema.Order AKey)
 {
     for (int LIndex = 0; LIndex < Count; LIndex++)
     {
         if (AKey.Equivalent(this[LIndex].Key))
         {
             return(LIndex);
         }
     }
     return(-1);
 }
Exemple #8
0
        protected Schema.Order GetDefaultOrder(Schema.TableVar tableVar)
        {
            foreach (Schema.Order order in tableVar.Orders)
            {
                if (Convert.ToBoolean(DerivationUtility.GetTag(order.MetaData, "IsDefault", "False")))
                {
                    return(new Schema.Order(order));
                }
            }

            foreach (Schema.Key key in tableVar.Keys)
            {
                if (Convert.ToBoolean(DerivationUtility.GetTag(key.MetaData, "IsDefault", "False")))
                {
                    return(new Schema.Order(key));
                }
            }

            if (tableVar.Keys.Count > 0)
            {
                Schema.Order order = new Schema.Order(_program.FindClusteringKey(tableVar));
                if (IsOrderVisible(order))
                {
                    return(order);
                }

                foreach (Schema.Key key in tableVar.Keys)
                {
                    order = new Schema.Order(key);
                    if (IsOrderVisible(order))
                    {
                        return(order);
                    }
                }
            }

            if (tableVar.Orders.Count > 0)
            {
                foreach (Schema.Order order in tableVar.Orders)
                {
                    if (IsOrderVisible(order))
                    {
                        return(order);
                    }
                }
            }

            return(null);
        }
Exemple #9
0
        public override void InternalRenderHeader(HtmlTextWriter writer)
        {
            writer.AddAttribute(HtmlTextWriterAttribute.Class, "gridheaderdatacell");
            writer.AddAttribute(HtmlTextWriterAttribute.Onclick, Session.GetActionLink(Session.Get(this).Context, _headerID));
            writer.RenderBeginTag(HtmlTextWriterTag.Td);
            string title = GetTitle();

            if (title == String.Empty)
            {
                writer.Write("&nbsp;");
            }
            else
            {
                writer.Write(HttpUtility.HtmlEncode(Session.RemoveAccellerator(title)));
            }

            DAE.Client.DataLink link = ParentGrid.DataLink;
            if (link.Active)
            {
                DAE.Client.TableDataSet dataSet = ParentGrid.DataLink.DataSet as DAE.Client.TableDataSet;
                if (dataSet != null)
                {
                    Schema.Order order = dataSet.Order;
                    if ((order != null) && (order.Columns.IndexOf(ColumnName) > -1))
                    {
                        writer.Write("&nbsp;");
                        if (((Schema.OrderColumn)order.Columns[ColumnName]).Ascending)
                        {
                            writer.AddAttribute(HtmlTextWriterAttribute.Src, "images/downarrow.gif");
                        }
                        else
                        {
                            writer.AddAttribute(HtmlTextWriterAttribute.Src, "images/uparrow.gif");
                        }
                        writer.RenderBeginTag(HtmlTextWriterTag.Img);
                        writer.RenderEndTag();
                        writer.Write("&nbsp;");
                    }
                }
            }
            writer.RenderEndTag();
        }
Exemple #10
0
 private void DetermineOrder(Plan plan)
 {
     Order = null;
     if (SourceNode.Order != null)
     {
         Schema.Order       newOrder = new Schema.Order();
         Schema.OrderColumn orderColumn;
         Schema.OrderColumn newOrderColumn;
         newOrder.InheritMetaData(SourceNode.Order.MetaData);
         newOrder.IsInherited = true;
         for (int index = 0; index < SourceNode.Order.Columns.Count; index++)
         {
             orderColumn    = SourceNode.Order.Columns[index];
             newOrderColumn =
                 new Schema.OrderColumn
                 (
                     TableVar.Columns[SourceTableVar.Columns.IndexOfName(orderColumn.Column.Name)],
                     orderColumn.Ascending,
                     orderColumn.IncludeNils
                 );
             newOrderColumn.Sort          = orderColumn.Sort;
             newOrderColumn.IsDefaultSort = orderColumn.IsDefaultSort;
             Error.AssertWarn(newOrderColumn.Sort != null, "Sort is null");
             if (newOrderColumn.IsDefaultSort)
             {
                 plan.AttachDependency(newOrderColumn.Sort);
             }
             else
             {
                 if (newOrderColumn.Sort.HasDependencies())
                 {
                     plan.AttachDependencies(newOrderColumn.Sort.Dependencies);
                 }
             }
             newOrder.Columns.Add(newOrderColumn);
         }
         Order = newOrder;
     }
 }
Exemple #11
0
 public Schema.Order StringToOrder(string order)
 {
     if (order.IndexOf(Keywords.Key) >= 0)
     {
         KeyDefinition keyDefinition = _parser.ParseKeyDefinition(order);
         Schema.Order  localOrder    = new Schema.Order();
         foreach (KeyColumnDefinition column in keyDefinition.Columns)
         {
             localOrder.Columns.Add(new Schema.OrderColumn(TableVar.Columns[column.ColumnName], true));
         }
         return(localOrder);
     }
     else
     {
         OrderDefinition orderDefinition = _parser.ParseOrderDefinition(order);
         Schema.Order    localOrder      = new Schema.Order();
         foreach (OrderColumnDefinition column in orderDefinition.Columns)
         {
             localOrder.Columns.Add(new Schema.OrderColumn(TableVar.Columns[column.ColumnName], column.Ascending, column.IncludeNils));
         }
         return(localOrder);
     }
 }
Exemple #12
0
 public TableBufferIndex this[Schema.Order AKey] {
     get { return(this[IndexOf(AKey)]); }
 }
Exemple #13
0
 public bool Contains(Schema.Order AKey)
 {
     return(IndexOf(AKey) >= 0);
 }
Exemple #14
0
        protected void FormAccepted(IFormInterface form)
        {
            if
            (
                _sourceLinkRefresh &&
                (_sourceLink != null) &&
                (_sourceLink.Source != null) &&
                (_sourceLink.Source.DataView.State == DataSetState.Browse) &&
                (form.MainSource != null)                 //&&
                //!Object.ReferenceEquals(FSourceLink.Source.DataView, AForm.MainSource.DataView) // Do not refresh if this is a surrogate
            )
            {
                switch (Mode)
                {
                case FormMode.Delete:
                    form.MainSource.DataView.Close();                             // Close the data view first to prevent the following refresh from causing an unnecessary requery
                    _sourceLink.Source.DataView.Refresh();
                    break;

                case FormMode.Insert:
                case FormMode.Edit:
                    // Find the nearest row in current set
                    DataView sourceView = _sourceLink.Source.DataView;
                    DataView targetView = form.MainSource.DataView;

                    if (sourceView != targetView)
                    {
                        // Determine RefreshSourceKey
                        // Determine RefreshKey

                        // if SourceLinkRefreshKeyNames and RefreshKeyNames are specified, use them, otherwise
                        // if the current order of the source link data view is a subset of the columns in the detail view, use it, otherwise
                        // find the minimum key in the source link data view that is a subset of the columns in the detail view and use it

                        Schema.Order sourceKey = null;
                        Schema.Order targetKey = null;

                        if ((SourceLinkRefreshKeyNames != "") && (RefreshKeyNames != ""))
                        {
                            string[] sourceKeyNames = SourceLinkRefreshKeyNames.Split(new char[] { ';', ',' });
                            string[] targetKeyNames = RefreshKeyNames.Split(new char[] { ';', ',' });
                            if (sourceKeyNames.Length == targetKeyNames.Length)
                            {
                                sourceKey = new Schema.Order();
                                targetKey = new Schema.Order();
                                for (int index = 0; index < sourceKeyNames.Length; index++)
                                {
                                    sourceKey.Columns.Add(new Schema.OrderColumn(sourceView.TableVar.Columns[sourceKeyNames[index]], true));
                                    targetKey.Columns.Add(new Schema.OrderColumn(targetView.TableVar.Columns[targetKeyNames[index]], true));
                                }
                            }
                        }

                        if (sourceKey == null)
                        {
                            if ((sourceView.Order != null) && sourceView.Order.Columns.IsSubsetOf(targetView.TableVar.Columns))
                            {
                                sourceKey = sourceView.Order;
                                targetKey = sourceView.Order;
                            }
                            else
                            {
                                Schema.Key minimumKey = sourceView.TableVar.Keys.MinimumSubsetKey(targetView.TableVar.Columns);
                                if (minimumKey != null)
                                {
                                    sourceKey = new Schema.Order(minimumKey);
                                    targetKey = sourceKey;
                                }
                            }
                        }

                        if (sourceKey != null)
                        {
                            using (Row row = new Row(sourceView.Process.ValueManager, new Schema.RowType(sourceKey.Columns)))
                            {
                                for (int index = 0; index < sourceKey.Columns.Count; index++)
                                {
                                    DataField targetField = targetView[targetKey.Columns[index].Column.Name];
                                    if (targetField.HasValue())
                                    {
                                        row[index] = targetField.Value;
                                    }
                                    else
                                    {
                                        row.ClearValue(index);
                                    }
                                }

                                targetView.Close();                                         // to prevent unnecessary requery

                                string saveOrder = String.Empty;
                                if (!sourceView.Order.Equals(sourceKey))
                                {
                                    saveOrder = sourceView.OrderString;
                                    try
                                    {
                                        sourceView.Order = sourceKey;
                                    }
                                    catch (Exception exception)
                                    {
                                        if (sourceView.OrderString != saveOrder)
                                        {
                                            sourceView.OrderString = saveOrder;
                                        }
                                        else
                                        {
                                            sourceView.Refresh();
                                        }
                                        throw new ClientException(ClientException.Codes.UnableToFindModifiedRow, exception);
                                    }
                                }
                                try
                                {
                                    sourceView.Refresh(row);
                                }
                                finally
                                {
                                    if ((saveOrder != String.Empty) && (sourceView.OrderString != saveOrder))
                                    {
                                        sourceView.OrderString = saveOrder;
                                    }
                                }
                            }
                        }
                        else
                        {
                            targetView.Close();
                            sourceView.Refresh();
                        }
                    }
                    break;
                }
            }

            if ((Mode == FormMode.Insert) && _autoAcceptAfterInsertOnQuery)
            {
                IFormInterface localForm = (IFormInterface)FindParent(typeof(IFormInterface));
                if (localForm.Mode == FormMode.Query)
                {
                    localForm.Close(CloseBehavior.AcceptOrClose);
                }
            }

            if (_onFormAccepted != null)
            {
                _onFormAccepted.Execute(this, new EventParams("AForm", form));
            }

            if (OnFormAcceptedEvent != null)
            {
                OnFormAcceptedEvent(form);
            }
        }
Exemple #15
0
 private void ClearOrder()
 {
     _orderDefinition = _order != null ? (OrderDefinition)_order.EmitStatement(EmitMode.ForCopy) : null;
     _order           = null;
 }
Exemple #16
0
        public override void DetermineDataType(Plan plan)
        {
            DetermineModifiers(plan);
            _dataType       = new Schema.TableType();
            _tableVar       = new Schema.ResultTableVar(this);
            _tableVar.Owner = plan.User;
            _tableVar.InheritMetaData(SourceTableVar.MetaData);

            if (_expressions == null)
            {
                // This is a rename all expression, merge metadata and inherit columns
                _tableVar.MergeMetaData(_metaData);

                // Inherit columns
                Schema.TableVarColumn newColumn;
                foreach (Schema.TableVarColumn column in SourceTableVar.Columns)
                {
                    newColumn = column.Inherit(_tableAlias);
                    DataType.Columns.Add(newColumn.Column);
                    TableVar.Columns.Add(newColumn);
                }
            }
            else
            {
                bool columnAdded;
                Schema.TableVarColumn column;
                int renameColumnIndex;
                for (int index = 0; index < SourceTableVar.Columns.Count; index++)
                {
                    columnAdded = false;
                    foreach (RenameColumnExpression renameColumn in _expressions)
                    {
                        renameColumnIndex = SourceTableVar.Columns.IndexOf(renameColumn.ColumnName);
                        if (renameColumnIndex < 0)
                        {
                            throw new Schema.SchemaException(Schema.SchemaException.Codes.ObjectNotFound, renameColumn.ColumnName);
                        }
                        else if (renameColumnIndex == index)
                        {
                            if (columnAdded)
                            {
                                throw new CompilerException(CompilerException.Codes.DuplicateRenameColumn, renameColumn.ColumnName);
                            }

                            column = SourceTableVar.Columns[index].InheritAndRename(renameColumn.ColumnAlias);
                            column.MergeMetaData(renameColumn.MetaData);
                            DataType.Columns.Add(column.Column);
                            TableVar.Columns.Add(column);
                            columnAdded = true;
                        }
                    }
                    if (!columnAdded)
                    {
                        column = SourceTableVar.Columns[index].Inherit();
                        DataType.Columns.Add(column.Column);
                        TableVar.Columns.Add(column);
                    }
                }
            }

            DetermineRemotable(plan);

            // Inherit keys
            Schema.Key newKey;
            foreach (Schema.Key key in SourceTableVar.Keys)
            {
                newKey = new Schema.Key();
                newKey.InheritMetaData(key.MetaData);
                newKey.IsInherited = true;
                newKey.IsSparse    = key.IsSparse;
                foreach (Schema.TableVarColumn keyColumn in key.Columns)
                {
                    newKey.Columns.Add(TableVar.Columns[SourceTableVar.Columns.IndexOfName(keyColumn.Name)]);
                }
                TableVar.Keys.Add(newKey);
            }

            // Inherit orders
            Schema.Order       newOrder;
            Schema.OrderColumn orderColumn;
            Schema.OrderColumn newOrderColumn;
            foreach (Schema.Order order in SourceTableVar.Orders)
            {
                newOrder = new Schema.Order();
                newOrder.InheritMetaData(order.MetaData);
                newOrder.IsInherited = true;
                for (int index = 0; index < order.Columns.Count; index++)
                {
                    orderColumn    = order.Columns[index];
                    newOrderColumn =
                        new Schema.OrderColumn
                        (
                            TableVar.Columns[SourceTableVar.Columns.IndexOfName(orderColumn.Column.Name)],
                            orderColumn.Ascending,
                            orderColumn.IncludeNils
                        );
                    newOrderColumn.Sort          = orderColumn.Sort;
                    newOrderColumn.IsDefaultSort = orderColumn.IsDefaultSort;
                    Error.AssertWarn(newOrderColumn.Sort != null, "Sort is null");
                    if (newOrderColumn.IsDefaultSort)
                    {
                        plan.AttachDependency(newOrderColumn.Sort);
                    }
                    else
                    {
                        if (newOrderColumn.Sort.HasDependencies())
                        {
                            plan.AttachDependencies(newOrderColumn.Sort.Dependencies);
                        }
                    }
                    newOrder.Columns.Add(newOrderColumn);
                }
                TableVar.Orders.Add(newOrder);
            }

            DetermineOrder(plan);

                        #if UseReferenceDerivation
            // Copy references
                        #if UseElaborable
            if (plan.CursorContext.CursorCapabilities.HasFlag(CursorCapability.Elaborable))
                        #endif
            {
                if (SourceTableVar.HasReferences())
                {
                    foreach (Schema.ReferenceBase reference in SourceTableVar.References)
                    {
                        if (reference.SourceTable.Equals(SourceTableVar))
                        {
                            Schema.JoinKey sourceKey = new Schema.JoinKey();
                            foreach (Schema.TableVarColumn column in reference.SourceKey.Columns)
                            {
                                sourceKey.Columns.Add(TableVar.Columns[SourceTableVar.Columns.IndexOfName(column.Name)]);
                            }

                            int    newReferenceID   = Schema.Object.GetNextObjectID();
                            string newReferenceName = DeriveSourceReferenceName(reference, newReferenceID, sourceKey);

                            Schema.DerivedReference newReference = new Schema.DerivedReference(newReferenceID, newReferenceName, reference);
                            newReference.IsExcluded = reference.IsExcluded;
                            newReference.InheritMetaData(reference.MetaData);
                            newReference.SourceTable = _tableVar;
                            newReference.AddDependency(_tableVar);
                            newReference.TargetTable = reference.TargetTable;
                            newReference.AddDependency(reference.TargetTable);
                            newReference.SourceKey.IsUnique = reference.SourceKey.IsUnique;
                            foreach (Schema.TableVarColumn column in sourceKey.Columns)
                            {
                                newReference.SourceKey.Columns.Add(column);
                            }
                            newReference.TargetKey.IsUnique = reference.TargetKey.IsUnique;
                            foreach (Schema.TableVarColumn column in reference.TargetKey.Columns)
                            {
                                newReference.TargetKey.Columns.Add(column);
                            }
                            //newReference.UpdateReferenceAction = reference.UpdateReferenceAction;
                            //newReference.DeleteReferenceAction = reference.DeleteReferenceAction;
                            _tableVar.References.Add(newReference);
                        }
                        else if (reference.TargetTable.Equals(SourceTableVar))
                        {
                            Schema.JoinKey targetKey = new Schema.JoinKey();
                            foreach (Schema.TableVarColumn column in reference.TargetKey.Columns)
                            {
                                targetKey.Columns.Add(TableVar.Columns[SourceTableVar.Columns.IndexOfName(column.Name)]);
                            }

                            int    newReferenceID   = Schema.Object.GetNextObjectID();
                            string newReferenceName = DeriveTargetReferenceName(reference, newReferenceID, targetKey);

                            Schema.DerivedReference newReference = new Schema.DerivedReference(newReferenceID, newReferenceName, reference);
                            newReference.IsExcluded = reference.IsExcluded;
                            newReference.InheritMetaData(reference.MetaData);
                            newReference.SourceTable = reference.SourceTable;
                            newReference.AddDependency(reference.SourceTable);
                            newReference.TargetTable = _tableVar;
                            newReference.AddDependency(_tableVar);
                            newReference.SourceKey.IsUnique = reference.SourceKey.IsUnique;
                            foreach (Schema.TableVarColumn column in reference.SourceKey.Columns)
                            {
                                newReference.SourceKey.Columns.Add(column);
                            }
                            newReference.TargetKey.IsUnique = reference.TargetKey.IsUnique;
                            foreach (Schema.TableVarColumn column in targetKey.Columns)
                            {
                                newReference.TargetKey.Columns.Add(column);
                            }
                            //newReference.UpdateReferenceAction = reference.UpdateReferenceAction;
                            //newReference.DeleteReferenceAction = reference.DeleteReferenceAction;
                            _tableVar.References.Add(newReference);
                        }
                    }
                }
            }
                        #endif
        }
Exemple #17
0
 protected bool IsOrderVisible(Schema.Order order)
 {
     return(DerivationUtility.IsOrderVisible(order, _seed.PageType));
 }
Exemple #18
0
        // TODO: Compile row types for each index, saving column indexes to prevent the need for lookup during insert, update, and delete.
        private void InternalInitialize(ServerProcess AProcess)
        {
            Schema.RowType LKeyRowType;
            Schema.RowType LDataRowType;

            // Create the indexes required to store data as described by the given table type
            // Determine Fanout, Capacity, Clustering Key, KeyLength, DataLength
            FClusteringKey = TableVar.FindClusteringOrder(AProcess.Plan);
            //Schema.Key LClusteringKey = TableVar.FindClusteringKey();
            //FClusteringKey = new Schema.Order(LClusteringKey, AProcess.Plan);
            LKeyRowType  = new Schema.RowType(FClusteringKey.Columns);
            LDataRowType = new Schema.RowType();
            foreach (Schema.Column LColumn in TableVar.DataType.Columns)
            {
                if (!FClusteringKey.Columns.Contains(LColumn.Name))
                {
                    LDataRowType.Columns.Add(new Schema.Column(LColumn.Name, LColumn.DataType));
                }
            }

            // Add an internal identifier for uniqueness of keys in nonunique indexes
                        #if USEINTERNALID
            FInternalIDColumn = new Schema.TableVarColumn(new Schema.Column(CInternalIDColumnName, AProcess.Plan.Catalog.DataTypes.SystemGuid), Schema.TableVarColumnType.InternalID);
            LDataRowType.Columns.Add(FInternalIDColumn.Column);
                        #endif

            // Create the Clustered index
            FClusteredIndex =
                new TableBufferIndex
                (
                    AProcess,
                    FClusteringKey,
                    LKeyRowType,
                    LDataRowType,
                    true,
                    FFanout,
                    FCapacity
                );
            Indexes.Add(FClusteredIndex);

            // DataLength and DataColumns for all non clustered indexes is the key length and columns of the clustered key
            LDataRowType = LKeyRowType;

            // Create non clustered indexes for each key and order (unique sets)
            Schema.Order LKey;
            foreach (Schema.Key LNonClusteredKey in TableVar.Keys)
            {
                if (!FClusteringKey.Includes(LNonClusteredKey))
                {
                    LKey = new Schema.Order(LNonClusteredKey, AProcess.Plan);
                    if (!Indexes.Contains(LKey))
                    {
                        LKeyRowType = new Schema.RowType(LKey.Columns);

                        Indexes.Add
                        (
                            new TableBufferIndex
                            (
                                AProcess,
                                LKey,
                                LKeyRowType,
                                LDataRowType,
                                false,
                                FFanout,
                                FCapacity
                            )
                        );
                    }
                }
            }

            foreach (Schema.Order LOrder in TableVar.Orders)
            {
                // This is a potentially non-unique index, so add a GUID to ensure uniqueness of the key in the BTree
                LKey = new Schema.Order(LOrder);
                                #if USEINTERNALID
                if (!LKey.Includes(LClusteringKey))
                {
                    Schema.OrderColumn LUniqueColumn = new Schema.OrderColumn(FInternalIDColumn, true);
                    LUniqueColumn.Sort = ((Schema.ScalarType)LUniqueColumn.Column.DataType).GetUniqueSort(AProcess.Plan);
                    LKey.Columns.Add(LUniqueColumn);
                }
                                #endif

                if (!Indexes.Contains(LKey))
                {
                    LKeyRowType = new Schema.RowType(LKey.Columns);

                    Indexes.Add
                    (
                        new TableBufferIndex
                        (
                            AProcess,
                            LKey,
                            LKeyRowType,
                            LDataRowType,
                            false,
                            FFanout,
                            FCapacity
                        )
                    );
                }
            }
        }
Exemple #19
0
 private void SetOrder()
 {
     _order           = _cursor.Order;
     _orderDefinition = null;
 }