Beispiel #1
0
 internal void SaveStructure(BinaryWriter structWriter)
 {
     structWriter.Write(_name);
     structWriter.Write(_nextID);
     structWriter.Write(_totalCount);
     structWriter.Write(_dirty);
     structWriter.Write(_columns.Count);
     foreach (HashMap.Entry entry in _columns)
     {
         ColumnStructure column = (ColumnStructure)entry.Value;
         column.SaveStructure(structWriter);
     }
     structWriter.Write(_compoundIndexes.Count);
     foreach (HashMap.Entry entry in _compoundIndexes)
     {
         structWriter.Write((string)entry.Key);
         structWriter.Write((string)entry.Value);
     }
     structWriter.Write(_compoundIndexesWithValue.Count);
     foreach (HashMap.Entry entry in _compoundIndexesWithValue)
     {
         structWriter.Write((string)entry.Key);
         CompoundWithValue compoundWithValue = (CompoundWithValue)entry.Value;
         structWriter.Write(compoundWithValue.secondColumn);
         structWriter.Write(compoundWithValue.valueColumn);
     }
 }
Beispiel #2
0
        public void SetCompoundIndexWithValue(string columnName1, string columnName2, string valueColumnName)
        {
            _tracer.Trace("SetCompoundIndexWithValue : " + columnName1 + "#" + columnName2);
            CheckIfColumnExists(columnName1);
            CheckIfColumnExists(columnName2);
            CheckIfColumnExists(valueColumnName);
            CompoundWithValue compoundWithValue;

            if (_compoundIndexesWithValue.Contains(columnName1))
            {
                compoundWithValue = (CompoundWithValue)_compoundIndexesWithValue[columnName1];
                if (columnName2.Equals(compoundWithValue.secondColumn))
                {
                    throw new IndexAlreadyExistsException(columnName1 + "#" + columnName2);
                }
            }

            compoundWithValue              = new CompoundWithValue();
            compoundWithValue.firstColumn  = columnName1;
            compoundWithValue.secondColumn = columnName2;
            compoundWithValue.valueColumn  = valueColumnName;
            _compoundIndexesWithValue.Add(columnName1, compoundWithValue);
            if (_dbStructure.Mode != DatabaseMode.Create)
            {
                Dirty = true;
                Dirty = false;
            }
        }
Beispiel #3
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;
                }
            }
        }
Beispiel #4
0
        internal TableStructure(BinaryReader structReader, DBStructure dbStructure)
        {
            _dbStructure = dbStructure;
            _name        = structReader.ReadString();
            _tracer      = new Tracer("(DBUtils) Table structure - " + _name);
            if (_dbStructure.Version >= 3)
            {
                _nextID = structReader.ReadInt32();
            }
            if (_dbStructure.Version >= 18)
            {
                _totalCount = structReader.ReadInt32();
            }
            _dirty = structReader.ReadBoolean();
            int count = structReader.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                ColumnStructure column = new ColumnStructure(structReader);
                if (_columns.Contains(column.Name))
                {
                    throw new ColumnAlreadyExistsException("Table structure already contains such column", column.Name);
                }
                _columns.Add(column.Name, column);
            }
            int compoundCount = structReader.ReadInt32();

            for (int i = 0; i < compoundCount; i++)
            {
                string firstColumn  = structReader.ReadString();
                string secondColumn = structReader.ReadString();
                if (_compoundIndexes.Contains(firstColumn))
                {
                    throw new IndexAlreadyExistsException("Table structure already contains such compound index: " +
                                                          firstColumn + " : " + secondColumn);
                }
                _compoundIndexes.Add(firstColumn, secondColumn);
            }
            if (_dbStructure.Version >= 12)
            {
                compoundCount = structReader.ReadInt32();
                for (int i = 0; i < compoundCount; i++)
                {
                    CompoundWithValue compoundWithValue = new CompoundWithValue();
                    compoundWithValue.firstColumn  = structReader.ReadString();
                    compoundWithValue.secondColumn = structReader.ReadString();
                    compoundWithValue.valueColumn  = structReader.ReadString();
                    if (_compoundIndexesWithValue.Contains(compoundWithValue.firstColumn))
                    {
                        throw new IndexAlreadyExistsException("Table structure already contains such compound index with value" +
                                                              compoundWithValue.firstColumn + " : " + compoundWithValue.secondColumn +
                                                              " : " + compoundWithValue.valueColumn);
                    }
                    _compoundIndexesWithValue.Add(compoundWithValue.firstColumn, compoundWithValue);
                }
            }
        }
Beispiel #5
0
        public bool HasCompoundIndexWithValue(string columnName1, string columnName2)
        {
            if (!_compoundIndexesWithValue.Contains(columnName1))
            {
                return(false);
            }
            CompoundWithValue compoundWithValue = (CompoundWithValue)_compoundIndexesWithValue[columnName1];

            if (!compoundWithValue.secondColumn.Equals(columnName2))
            {
                return(false);
            }
            return(true);
        }