private IndexInfo2 BuildIndex(FieldSqoInfo finfo, SqoTypeInfo tinfo, IBTree index) { this.FillIndex(finfo, tinfo, index); IndexInfo2 ii = new IndexInfo2(); ii.IndexName = finfo.Name + tinfo.TypeName; ii.RootOID = index.GetRootOid(); siaqodb.StoreObject(ii); storedIndexes.Add(ii); return(ii); }
private async Task <IndexInfo2> BuildIndexAsync(FieldSqoInfo finfo, SqoTypeInfo tinfo, IBTree index) { await this.FillIndexAsync(finfo, tinfo, index).ConfigureAwait(false); IndexInfo2 ii = new IndexInfo2(); ii.IndexName = finfo.Name + tinfo.TypeName; ii.RootOID = index.GetRootOid(); await siaqodb.StoreObjectAsync(ii).ConfigureAwait(false); storedIndexes.Add(ii); return(ii); }
private async Task <IBTree> RenewIndexAsync(SqoTypeInfo ti, string fieldName) { FieldSqoInfo finfo = MetaHelper.FindField(ti.Fields, fieldName); IndexInfo2 indexInfo = null; if (finfo != null) { string indexName = finfo.Name + ti.TypeName; IList <IndexInfo2> stIndexes = await this.GetStoredIndexesAsync().ConfigureAwait(false); foreach (IndexInfo2 ii in stIndexes) { if (indexName.StartsWith(ii.IndexName) || ii.IndexName.StartsWith(indexName)) { indexInfo = ii; break; } } if (indexInfo != null) { if (storedIndexes != null && storedIndexes.Contains(indexInfo)) { storedIndexes.Remove(indexInfo); } await siaqodb.DeleteAsync(indexInfo); } Type t = typeof(BTree <>).MakeGenericType(finfo.AttributeType); ConstructorInfo ctor = t.GetConstructor(new Type[] { typeof(Siaqodb) }); IBTree index = (IBTree)ctor.Invoke(new object[] { this.siaqodb }); indexInfo = await this.BuildIndexAsync(finfo, ti, index); index.SetIndexInfo(indexInfo); await index.PersistAsync(); cacheIndexes.Set(ti, finfo, index); return(index); } return(null); }
public async Task <IBTree> GetIndexAsync(FieldSqoInfo finfo, SqoTypeInfo tinfo) { Type t = typeof(BTree <>).MakeGenericType(finfo.AttributeType); ConstructorInfo ctor = t.GetConstructor(new Type[] { typeof(Siaqodb) }); IBTree index = (IBTree)ctor.Invoke(new object[] { this.siaqodb }); IndexInfo2 indexInfo = null; string indexName = finfo.Name + tinfo.TypeName; try { IList <IndexInfo2> stIndexes = await this.GetStoredIndexesAsync().ConfigureAwait(false); foreach (IndexInfo2 ii in stIndexes) { if (ii.IndexName == indexName) { indexInfo = ii; break; } } } catch (Exception ex) { SiaqodbConfigurator.LogMessage("IndexInfo cannot be loaded, index will be rebuild", VerboseLevel.Info); } bool indexExists = false; if (indexInfo == null) { indexInfo = await this.BuildIndexAsync(finfo, tinfo, index).ConfigureAwait(false); } else { indexExists = true; } index.SetIndexInfo(indexInfo); Type nodeType = typeof(BTreeNode <>).MakeGenericType(finfo.AttributeType); if (indexInfo.RootOID > 0 && indexExists) { object rootP = null; bool error = false; try { rootP = await siaqodb.LoadObjectByOIDAsync(nodeType, indexInfo.RootOID).ConfigureAwait(false); } catch (IndexCorruptedException ex) { error = true; } if (error) { if (storedIndexes != null && storedIndexes.Contains(indexInfo)) { storedIndexes.Remove(indexInfo); } await siaqodb.DeleteAsync(indexInfo); indexInfo = await this.BuildIndexAsync(finfo, tinfo, index); index.SetIndexInfo(indexInfo); index.Persist(); } if (rootP != null) { index.SetRoot(rootP); } } return(index); }
public IBTree GetIndex(FieldSqoInfo finfo, SqoTypeInfo tinfo) { Type t = typeof(BTree <>).MakeGenericType(finfo.AttributeType); ConstructorInfo ctor = t.GetConstructor(new Type[] { typeof(Siaqodb) }); IBTree index = (IBTree)ctor.Invoke(new object[] { this.siaqodb }); IndexInfo2 indexInfo = null; string indexName = finfo.Name + tinfo.TypeName; try { foreach (IndexInfo2 ii in StoredIndexes) { if (indexName.StartsWith(ii.IndexName) || ii.IndexName.StartsWith(indexName)) { indexInfo = ii; break; } } } catch (Exception ex) { SiaqodbConfigurator.LogMessage("IndexInfo cannot be loaded, index will be rebuild", VerboseLevel.Info); } bool indexExists = false; if (indexInfo == null) { indexInfo = this.BuildIndex(finfo, tinfo, index); } else { indexExists = true; } index.SetIndexInfo(indexInfo); if (!indexExists) { index.Persist(); } Type nodeType = typeof(BTreeNode <>).MakeGenericType(finfo.AttributeType); if (indexInfo.RootOID > 0 && indexExists) { object rootP = null; try { rootP = siaqodb.LoadObjectByOID(nodeType, indexInfo.RootOID); } catch (IndexCorruptedException ex) { if (storedIndexes != null && storedIndexes.Contains(indexInfo)) { storedIndexes.Remove(indexInfo); } siaqodb.Delete(indexInfo); indexInfo = this.BuildIndex(finfo, tinfo, index); index.SetIndexInfo(indexInfo); index.Persist(); } if (rootP != null) { index.SetRoot(rootP); } } return(index); }
public void SetIndexInfo(IndexInfo2 indexInfo) { this.indexInfo = indexInfo; }