public SystemIndexSetDataSource CreateIndex(TableName onTable, string indexName, string indexType, IndexCollation collation)
        {
            CheckNotDisposed();
            // Check the table name given is qualified
            CheckTableNameQualified(onTable);

            // We can't create an index that already exists
            if (IndexExists(onTable, indexName)) {
                throw new ApplicationException("Index '" + indexName + "' already exists");
            }

            string[] columnNames = new string[collation.Columns.Length];
            bool[] columnOrders = new bool[columnNames.Length];
            for (int i = 0; i < columnNames.Length; i++) {
                columnNames[i] = collation.Columns[i].ColumnName;
                columnOrders[i] = collation.Columns[i].Ascending;
            }

            ITableIndex index = state.CreateIndex(new IndexName(onTable, indexName), indexType, columnNames, columnOrders);
            if (index == null)
                throw new ApplicationException("Unable to create index.");

            long indexId = state.CreateUniqueId(SystemTableNames.Index);

            // Create the index object
            SystemIndexSetDataSource indexSet = new SystemIndexSetDataSource(this, index);

            // Add this index item
            AddIndex(indexId, onTable, indexName, indexType, collation);

            // Log the change in the journal
            journal.AddEntry(JournalCommandCode.IndexAdd, indexId);
            OnChanged();

            // Put it in the local cache
            indexMap[indexId] = indexSet;

            // Return the index
            return indexSet;
        }
        public SystemIndexSetDataSource[] GetTableIndexes(TableName tableName)
        {
            SystemTable table = InternalGetTable(SystemTableNames.Index);
            if (table == null)
                return new SystemIndexSetDataSource[0];

            IRowCursor cursor = GetNames(table, tableName);

            if (cursor.Count == 0)
                return new SystemIndexSetDataSource[0];

            SystemIndexSetDataSource[] indexes = new SystemIndexSetDataSource[cursor.Count];
            int i = -1;
            while (cursor.MoveNext()) {
                SqlObject indexId = table.GetValue(0, cursor.Current);
                indexes[i++] = GetIndex(indexId);
            }

            return indexes;
        }