コード例 #1
0
        /// <summary>
        /// Visits primary index.
        /// </summary>
        /// <param name="index">The index.</param>
        /// <returns>Visit result.</returns>
        private IPathNode VisitPrimaryIndexInfo(IndexInfo index)
        {
            foreach (var column in index.Columns)
            {
                Visit(column);
            }

            // Support for mysql as primary indexes there always have name 'PRIMARY'
            string name = providerInfo.ConstantPrimaryIndexName;

            if (string.IsNullOrEmpty(name))
            {
                name = index.MappingName;
            }

            var primaryIndex = new PrimaryIndexInfo(currentTable, name);

            foreach (KeyValuePair <ColumnInfo, Direction> pair in index.KeyColumns)
            {
                string columName = GetPrimaryIndexColumnName(index, pair.Key, index);
                var    column    = currentTable.Columns[columName];
                new KeyColumnRef(primaryIndex, column,
                                 providerInfo.Supports(ProviderFeatures.KeyColumnSortOrder)
            ? pair.Value
            : Direction.Positive);
            }
            primaryIndex.PopulateValueColumns();
            primaryIndex.IsClustered = index.IsClustered && providerInfo.Supports(ProviderFeatures.ClusteredIndexes);

            foreach (var secondaryIndex in index.ReflectedType.Indexes.Where(i => i.IsSecondary && !i.IsVirtual))
            {
                VisitIndexInfo(index, secondaryIndex);
            }
            return(primaryIndex);
        }
コード例 #2
0
 public void CreateModel()
 {
     storage       = new StorageModel("storage1");
     table         = new TableInfo(storage, "table");
     primary       = new PrimaryIndexInfo(table, "primary1");
     secondary     = new SecondaryIndexInfo(table, "secondary1");
     primaryKey    = new StorageColumnInfo(table, "key", new StorageTypeInfo(typeof(int), null));
     primaryValue1 = new StorageColumnInfo(table, "value1", new StorageTypeInfo(typeof(int), null));
     primaryValue2 = new StorageColumnInfo(table, "value2", new StorageTypeInfo(typeof(int), null));
     new KeyColumnRef(primary, primaryKey, Direction.Positive);
     new ValueColumnRef(primary, primaryValue1);
     new ValueColumnRef(primary, primaryValue2);
 }
コード例 #3
0
        /// <inheritdoc/>
        protected override IPathNode VisitPrimaryKey(PrimaryKey key)
        {
            var tableInfo        = currentTable;
            var primaryIndexInfo = new PrimaryIndexInfo(tableInfo, key.Name)
            {
                IsClustered = key.IsClustered
            };

            foreach (var keyColumn in key.Columns)
            {
                new KeyColumnRef(primaryIndexInfo, tableInfo.Columns[keyColumn.Name],
                                 Direction.Positive);
            }
            // TODO: Get direction for key columns
            primaryIndexInfo.PopulateValueColumns();

            return(primaryIndexInfo);
        }
コード例 #4
0
        public void CreateModel()
        {
            storage = new StorageModel("STORAGE")
            {
                Actions = new ActionSequence()
            };
            table         = new TableInfo(storage, "TABLE");
            primary       = new PrimaryIndexInfo(table, "PK");
            secondary     = new SecondaryIndexInfo(table, "IX");
            primaryKey    = new StorageColumnInfo(table, "ID", new StorageTypeInfo(typeof(int), null));
            primaryValue1 = new StorageColumnInfo(table, "AGE", new StorageTypeInfo(typeof(int), null));
            primaryValue2 = new StorageColumnInfo(table, "NAME", new StorageTypeInfo(typeof(int), null));
            new KeyColumnRef(primary, primaryKey, Direction.Positive);
            new ValueColumnRef(primary, primaryValue1);
            new ValueColumnRef(primary, primaryValue2);
            new KeyColumnRef(secondary, primaryValue1, Direction.Positive);

            storage.Dump();
        }
コード例 #5
0
        public void BuildStorageModel()
        {
            storage          = new StorageModel("storage");
            referencingTable = new TableInfo(storage, "referencingTable");
            var pkColumn   = new StorageColumnInfo(referencingTable, "Id", new StorageTypeInfo(typeof(int), null));
            var fkColumn   = new StorageColumnInfo(referencingTable, "foreignId", new StorageTypeInfo(typeof(int?), null));
            var fkColumn2  = new StorageColumnInfo(referencingTable, "invalideForeignId", new StorageTypeInfo(typeof(string), null));
            var primaryKey = new PrimaryIndexInfo(referencingTable, "PK1");

            new KeyColumnRef(primaryKey, pkColumn);
            referencingIndex = new SecondaryIndexInfo(referencingTable, "FK");
            new KeyColumnRef(referencingIndex, fkColumn);
            referencingIndex.PopulatePrimaryKeyColumns();
            invalideReferencingIndex = new SecondaryIndexInfo(referencingTable, "FK2");
            invalideReferencingIndex.PopulatePrimaryKeyColumns();
            new KeyColumnRef(invalideReferencingIndex, fkColumn2);
            primaryKey.PopulateValueColumns();

            referencedTable = new TableInfo(storage, "referencedTable");
            pkColumn        = new StorageColumnInfo(referencedTable, "Id", new StorageTypeInfo(typeof(int), null));
            foreignPrimary  = new PrimaryIndexInfo(referencedTable, "Id");
            new KeyColumnRef(foreignPrimary, pkColumn);
        }
コード例 #6
0
        public void CreateModel()
        {
            storage = new StorageModel("storage")
            {
                Actions = new ActionSequence()
            };
            // Table 1
            table1  = new TableInfo(storage, "table1");
            pi1     = new PrimaryIndexInfo(table1, "pk1");
            column1 = new StorageColumnInfo(table1, "col1", new StorageTypeInfo(typeof(string), null, false));
            column2 = new StorageColumnInfo(table1, "col2", new StorageTypeInfo(typeof(string), null));
            column3 = new StorageColumnInfo(table1, "col3", new StorageTypeInfo(typeof(string), null));
            new KeyColumnRef(pi1, column1, Direction.Positive);
            pi1.PopulateValueColumns();
            si1 = new SecondaryIndexInfo(table1, "ix1");
            new KeyColumnRef(si1, column2, Direction.Positive);
            si1.PopulatePrimaryKeyColumns();

            // Table 2
            table2  = new TableInfo(storage, "table2");
            pi2     = new PrimaryIndexInfo(table2, "pk2");
            column4 = new StorageColumnInfo(table2, "col4", new StorageTypeInfo(typeof(int), null));
            column5 = new StorageColumnInfo(table2, "col5", new StorageTypeInfo(typeof(string), null));
            new KeyColumnRef(pi2, column4, Direction.Negative);
            pi2.PopulateValueColumns();
            si2 = new SecondaryIndexInfo(table2, "ix2");
            new KeyColumnRef(si2, column5, Direction.Positive);
            si2.PopulatePrimaryKeyColumns();

            // Foreign keys
            fk1 = new ForeignKeyInfo(table2, "fk1")
            {
                PrimaryKey = pi1
            };
            fk1.ForeignKeyColumns.Set(si2);
        }
コード例 #7
0
        private static StorageInfo CreateSimpleStorageModel()
        {
            var storage = new StorageInfo("Storage");

            // Model:
            // class A:Entity {int Id, int Data}
            // class B:A {int Id}
            // class C:B {int Id; A RefA; B RefB; C RefC}

            var tA = new TableInfo(storage, "A");
            var tB = new TableInfo(storage, "B");
            var tC = new TableInfo(storage, "C");

            var idA = new ColumnInfo(tA, "Id", new TypeInfo(typeof(int)));
            var idB = new ColumnInfo(tB, "Id", new TypeInfo(typeof(int)));
            var idC = new ColumnInfo(tC, "Id", new TypeInfo(typeof(int)));

            var refCA = new ColumnInfo(tC, "RefA", new TypeInfo(typeof(int)));
            var refCB = new ColumnInfo(tC, "RefB", new TypeInfo(typeof(int)));
            var refCC = new ColumnInfo(tC, "RefC", new TypeInfo(typeof(int)));

            var dataA = new ColumnInfo(tA, "Data", new TypeInfo(typeof(int)));

            var pkA = new PrimaryIndexInfo(tA, "PK_A");
            var pkB = new PrimaryIndexInfo(tB, "PK_B");
            var pkC = new PrimaryIndexInfo(tC, "PK_C");

            new KeyColumnRef(pkA, idA);
            new KeyColumnRef(pkB, idB);
            new KeyColumnRef(pkC, idC);
            pkC.PopulateValueColumns();
            pkA.PopulateValueColumns();

            var ixRefCA = new SecondaryIndexInfo(tC, "FK_CRefA");

            new KeyColumnRef(ixRefCA, refCA);
            ixRefCA.PopulatePrimaryKeyColumns();
            var ixRefCB = new SecondaryIndexInfo(tC, "FK_CRefB");

            new KeyColumnRef(ixRefCB, refCB);
            ixRefCB.PopulatePrimaryKeyColumns();
            var ixRefCC = new SecondaryIndexInfo(tC, "FK_CRefC");

            new KeyColumnRef(ixRefCC, refCC);
            ixRefCC.PopulatePrimaryKeyColumns();

            var fkCRefA = new ForeignKeyInfo(tC, "FK_CRefA");

            fkCRefA.PrimaryKey = pkA;
            fkCRefA.ForeignKeyColumns.Set(ixRefCA);

            var fkCRefB = new ForeignKeyInfo(tC, "FK_CRefB");

            fkCRefB.PrimaryKey = pkB;
            fkCRefB.ForeignKeyColumns.Set(ixRefCB);

            var fkCRefC = new ForeignKeyInfo(tC, "FK_CRefC");

            fkCRefC.PrimaryKey = pkC;
            fkCRefC.ForeignKeyColumns.Set(ixRefCC);

            var fkCA = new ForeignKeyInfo(tC, "FK_CA");

            fkCA.PrimaryKey = pkA;
            fkCA.ForeignKeyColumns.Set(pkC);

            var fkBA = new ForeignKeyInfo(tB, "FK_BA");

            fkBA.PrimaryKey = pkA;
            fkBA.ForeignKeyColumns.Set(pkB);

            storage.Validate();

            return(storage);
        }
コード例 #8
0
        private static StorageInfo CreateSimpleStorageModel()
        {
            var storage = new StorageInfo("Storage");

            // Types table
            var t   = new TableInfo(storage, "Types");
            var tId = new ColumnInfo(t, "Id")
            {
                Type = new TypeInfo(typeof(int), false)
            };
            var tValue = new ColumnInfo(t, "Value")
            {
                Type = new TypeInfo(typeof(string), 1024)
            };
            var tData = new ColumnInfo(t, "Data")
            {
                Type = new TypeInfo(typeof(byte[]), 1024 * 1024)
            };

            var tiPk = new PrimaryIndexInfo(t, "PK_Types");

            new KeyColumnRef(tiPk, tId);
            tiPk.PopulateValueColumns();

            var tiValue = new SecondaryIndexInfo(t, "IX_Value");

            new KeyColumnRef(tiValue, tValue);
            tiValue.PopulatePrimaryKeyColumns();

            var tiFt = new FullTextIndexInfo(t, "FT_Index");

            new FullTextColumnRef(tiFt, tValue);

            // Objects table
            var o   = new TableInfo(storage, "Objects");
            var oId = new ColumnInfo(o, "Id")
            {
                Type = new TypeInfo(typeof(long), false)
            };
            var oTypeId = new ColumnInfo(o, "TypeId")
            {
                Type = new TypeInfo(typeof(int), false)
            };
            var oValue = new ColumnInfo(o, "Value")
            {
                Type = new TypeInfo(typeof(string), 1024)
            };

            var oiPk = new PrimaryIndexInfo(o, "PK_Objects");

            new KeyColumnRef(oiPk, oId);
            oiPk.PopulateValueColumns();

            var oiTypeId = new SecondaryIndexInfo(o, "IX_TypeId");

            new KeyColumnRef(oiTypeId, oTypeId);
            oiTypeId.PopulatePrimaryKeyColumns();

            var oiValue = new SecondaryIndexInfo(o, "IX_Value");

            new KeyColumnRef(oiValue, oValue);
            new IncludedColumnRef(oiValue, oTypeId);
            oiValue.PopulatePrimaryKeyColumns();

            var ofkTypeId = new ForeignKeyInfo(o, "FK_TypeId")
            {
                PrimaryKey = tiPk,
            };

            ofkTypeId.ForeignKeyColumns.Set(oiTypeId);

            storage.Validate();
            return(storage);
        }
コード例 #9
0
 public void CreateStorage()
 {
     storage = new StorageModel("s1");
     table   = new TableInfo(storage, "table");
     index   = new PrimaryIndexInfo(table, "i");
 }