19 using System.Collections.Generic;
24 namespace Deveel.Data.Sql {
29 if (tableName == null)
30 throw new ArgumentNullException(
"tableName");
32 TableName = tableName;
33 this.indexes =
new List<IndexInfo>();
36 this.indexes.AddRange(indexes);
38 IsReadOnly = readOnly;
42 : this(tableName, null, false) {
47 public bool IsReadOnly {
get;
private set; }
49 public int IndexCount {
50 get {
return indexes.Count; }
55 throw new ArgumentException(
"The set is read-only.");
61 indexes.Add(indexInfo);
62 indexInfo.
Offset = indexes.Count;
66 return indexes.FirstOrDefault(x => x.Offset == offset);
72 indexes.RemoveAt(offset);
76 return FindNamedIndex(indexName,
true);
80 var compare = ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
81 return indexes.FirstOrDefault(x => x.IndexName.Equals(indexName, compare));
85 return FindIndexOffset(name,
true);
89 var compare = ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
90 for (
int i = 0; i < indexes.Count; i++) {
91 var indexInfo = indexes[i];
92 if (indexInfo.IndexName.Equals(name, compare))
101 for (
int i = 0; i < sz; ++i) {
102 string[] columns = indexes[i].ColumnNames;
103 if (columns.Length == columnNames.Length) {
105 for (
int n = 0; n < columns.Length && passed; ++n) {
106 if (!columns[n].Equals(columnNames[n])) {
120 return new IndexSetInfo(TableName, indexes.ToArray(),
true);
124 return indexes.GetEnumerator();
127 IEnumerator IEnumerable.GetEnumerator() {
128 return GetEnumerator();
132 var schemaName = TableName.Parent;
133 var catName = schemaName != null && schemaName.Parent != null ? schemaName.Parent.Name : String.Empty;
134 var schema = schemaName != null ? schemaName.Name : String.Empty;
136 var writer =
new BinaryWriter(stream, Encoding.Unicode);
138 writer.Write(catName);
139 writer.Write(schema);
140 writer.Write(TableName.Name);
142 int indexCount = indexes.Count;
144 writer.Write(indexCount);
146 for (
int i = 0; i < indexCount; i++) {
147 var index = indexes[i];
148 index.SerializeTo(stream);
153 var reader =
new BinaryReader(stream, Encoding.Unicode);
155 var version = reader.ReadInt32();
157 throw new FormatException(
"Invalid version number of the Index-Set Info");
159 var catName = reader.ReadString();
160 var schemaName = reader.ReadString();
161 var tableName = reader.ReadString();
164 if (String.IsNullOrEmpty(catName)) {
170 var objTableName =
new ObjectName(objSchemaName, tableName);
172 var indexCount = reader.ReadInt32();
174 var indices =
new List<IndexInfo>();
175 for (
int i = 0; i < indexCount; i++) {
177 indices.Add(indexInfo);
180 return new IndexSetInfo(objTableName, indices.ToArray(),
false);
int FindIndexOffset(string name, bool ignoreCase)
readonly List< IndexInfo > indexes
IndexInfo FindNamedIndex(string indexName, bool ignoreCase)
void RemoveIndexAt(int offset)
int FindIndexForColumns(string[] columnNames)
Describes the name of an object within a database.
IndexSetInfo(ObjectName tableName, IEnumerable< IndexInfo > indexes, bool readOnly)
int FindIndexOffset(string name)
IndexInfo GetIndex(int offset)
static IndexSetInfo DeserializeFrom(Stream stream)
IndexSetInfo AsReadOnly()
void AddIndex(IndexInfo indexInfo)
static IndexInfo DeserializeFrom(Stream stream)
IndexInfo FindNamedIndex(string indexName)
IEnumerator< IndexInfo > GetEnumerator()
IndexSetInfo(ObjectName tableName)
void SerialiazeTo(Stream stream)