Ejemplo n.º 1
0
        internal void OpenTable(IDatabaseDesign dbDesign)
        {
            Table tableDesign = (Table)dbDesign.CreateTable(Name, this);

            _table = tableDesign;
            foreach (HashMap.Entry entry in _columns)
            {
                ColumnStructure colStructure = (ColumnStructure)entry.Value;
                Column          column       = colStructure.MakeColumn(tableDesign, colStructure.Name);
                tableDesign.AddColumn(column);
                if (colStructure.HasIndex)
                {
                    IDBIndex dbIndex =
                        new DBIndex(tableDesign, colStructure.Name, column.GetFixedFactory(), null, null, null);
                    tableDesign.AddIndex(colStructure.Name, dbIndex);
                }
            }
            tableDesign.CheckTableLength();
            foreach (HashMap.Entry entry in _compoundIndexes)
            {
                string   firstName    = (string)entry.Key;
                Column   firstColumn  = tableDesign.GetColumn(firstName);
                string   secondName   = (string)entry.Value;
                Column   secondColumn = tableDesign.GetColumn(secondName);
                string   compoundName = firstName + "#" + secondName;
                IDBIndex dbIndex      =
                    new DBIndex(tableDesign, compoundName,
                                new FixedLengthKey_Compound(firstColumn.GetFixedFactory(), secondColumn.GetFixedFactory()),
                                firstColumn.GetFixedFactory(), secondColumn.GetFixedFactory(), null);
                tableDesign.AddCompoundIndex(compoundName, dbIndex);
            }
            foreach (HashMap.Entry entry in _compoundIndexesWithValue)
            {
                string            firstName         = (string)entry.Key;
                Column            firstColumn       = tableDesign.GetColumn(firstName);
                CompoundWithValue compoundWithValue = (CompoundWithValue)entry.Value;
                string            secondName        = compoundWithValue.secondColumn;
                Column            secondColumn      = tableDesign.GetColumn(secondName);
                Column            valueColumn       = tableDesign.GetColumn(compoundWithValue.valueColumn);
                string            compoundName      = firstName + "#" + secondName;
                IDBIndex          dbIndex           =
                    new DBIndex(tableDesign, compoundName,
                                new FixedLengthKey_CompoundWithValue(firstColumn.GetFixedFactory(), secondColumn.GetFixedFactory(), valueColumn.GetFixedFactory()),
                                firstColumn.GetFixedFactory(), secondColumn.GetFixedFactory(), valueColumn.GetFixedFactory());
                tableDesign.AddCompoundIndexWithValue(compoundName, dbIndex, valueColumn.Name);
            }
            if (!tableDesign.Dirty)
            {
                try
                {
                    tableDesign.OpenIndexes();
                }
                catch (BadIndexesException)
                {
                    _dirty = true;
                }
            }
        }