예제 #1
0
 protected virtual void Init()
 {
     start = 0;
     end   = 0;
     // for instance, only manage index for one field query using 'equal'
     if (classInfo.HasIndex() && query.HasCriteria() && CanUseIndex(query.GetCriteria(
                                                                        )))
     {
         NeoDatis.Tool.Wrappers.List.IOdbList <string> fields = query.GetAllInvolvedFields(
             );
         if (fields.IsEmpty())
         {
             useIndex = false;
         }
         else
         {
             int[] fieldIds = GetAllInvolvedFieldIds(fields);
             classInfoIndex = classInfo.GetIndexForAttributeIds(fieldIds);
             if (classInfoIndex != null)
             {
                 useIndex = true;
             }
         }
     }
     // Keep the detail
     details = GetDetails();
 }
		protected virtual void Init()
		{
			start = 0;
			end = 0;
			// for instance, only manage index for one field query using 'equal'
			if (classInfo.HasIndex() && query.HasCriteria() && CanUseIndex(query.GetCriteria(
				)))
			{
				NeoDatis.Tool.Wrappers.List.IOdbList<string> fields = query.GetAllInvolvedFields(
					);
				if (fields.IsEmpty())
				{
					useIndex = false;
				}
				else
				{
					int[] fieldIds = GetAllInvolvedFieldIds(fields);
					classInfoIndex = classInfo.GetIndexForAttributeIds(fieldIds);
					if (classInfoIndex != null)
					{
						useIndex = true;
					}
				}
			}
			// Keep the detail
			details = GetDetails();
		}
예제 #3
0
 /// <summary>Take the fields of the index and take value from the query</summary>
 /// <param name="ci">The class info involved</param>
 /// <param name="index">The index</param>
 /// <param name="query"></param>
 /// <returns>The key of the index</returns>
 public static NeoDatis.Tool.Wrappers.OdbComparable ComputeKey(NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo
                                                               ci, NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfoIndex index, NeoDatis.Odb.Impl.Core.Query.Criteria.CriteriaQuery
                                                               query)
 {
     string[] attributesNames = ci.GetAttributeNames(index.GetAttributeIds());
     NeoDatis.Odb.Core.Layers.Layer2.Meta.AttributeValuesMap values = query.GetCriteria
                                                                          ().GetValues();
     return(BuildIndexKey(index.GetName(), values, attributesNames));
 }
 /// <summary>Used to rebuild an index</summary>
 public virtual void RebuildIndex(string className, string indexName, bool verbose
                                  )
 {
     if (verbose)
     {
         NeoDatis.Tool.DLogger.Info("Rebuilding index " + indexName + " on class " + className
                                    );
     }
     NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo classInfo = GetMetaModel().GetClassInfo
                                                                    (className, true);
     if (!classInfo.HasIndex(indexName))
     {
         throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.IndexDoesNotExist
                                                    .AddParameter(indexName).AddParameter(className));
     }
     NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfoIndex cii = classInfo.GetIndexWithName
                                                                   (indexName);
     DeleteIndex(className, indexName, verbose);
     AddIndexOn(className, indexName, classInfo.GetAttributeNames(cii.GetAttributeIds(
                                                                      )), verbose, !cii.IsUnique());
 }
 public virtual void DeleteIndex(string className, string indexName, bool verbose)
 {
     NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo classInfo = GetMetaModel().GetClassInfo
                                                                    (className, true);
     if (!classInfo.HasIndex(indexName))
     {
         throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.IndexDoesNotExist
                                                    .AddParameter(indexName).AddParameter(className));
     }
     NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfoIndex cii = classInfo.GetIndexWithName
                                                                   (indexName);
     if (verbose)
     {
         NeoDatis.Tool.DLogger.Info("Deleting index " + indexName + " on class " + className
                                    );
     }
     Delete(cii);
     classInfo.RemoveIndex(cii);
     if (verbose)
     {
         NeoDatis.Tool.DLogger.Info("Index " + indexName + " deleted");
     }
 }
예제 #6
0
 public override System.IComparable ComputeIndexKey(NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo
                                                    ci, NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfoIndex index)
 {
     return(null);
 }
예제 #7
0
 public override System.IComparable ComputeIndexKey(NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo
                                                    ci, NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfoIndex index)
 {
     return(NeoDatis.Odb.Core.Query.Execution.IndexTool.ComputeKey(classInfo, index, (
                                                                       NeoDatis.Odb.Impl.Core.Query.Criteria.CriteriaQuery)query));
 }
예제 #8
0
 public abstract System.IComparable ComputeIndexKey(NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo
                                                    ci, NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfoIndex index);
예제 #9
0
        /// <summary>Execute query using index</summary>
        /// <param name="index"></param>
        /// <param name="inMemory"></param>
        /// <param name="startIndex"></param>
        /// <param name="endIndex"></param>
        /// <param name="returnObjects"></param>
        /// <returns></returns>
        /// <exception cref="System.Exception">System.Exception</exception>
        private NeoDatis.Odb.Objects <T> ExecuteUsingIndex <T>(NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfoIndex
                                                               index, bool inMemory, int startIndex, int endIndex, bool returnObjects, NeoDatis.Odb.Core.Query.Execution.IMatchingObjectAction
                                                               queryResultAction)
        {
            // Index that have not been used yet do not have persister!
            if (index.GetBTree().GetPersister() == null)
            {
                index.GetBTree().SetPersister(new NeoDatis.Odb.Impl.Core.Btree.LazyODBBTreePersister
                                                  (storageEngine));
            }
            bool objectMatches = false;
            long nbObjects     = classInfo.GetNumberOfObjects();
            long btreeSize     = index.GetBTree().GetSize();

            // the two values should be equal
            if (nbObjects != btreeSize)
            {
                NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo ci = storageEngine.GetSession(true
                                                                                             ).GetMetaModel().GetClassInfoFromId(index.GetClassInfoId());
                throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.IndexIsCorrupted
                                                           .AddParameter(index.GetName()).AddParameter(ci.GetFullClassName()).AddParameter(
                                                               nbObjects).AddParameter(btreeSize));
            }
            if (NeoDatis.Odb.OdbConfiguration.IsDebugEnabled(LogId))
            {
                NeoDatis.Tool.DLogger.Debug("loading " + nbObjects + " instance(s) of " + classInfo
                                            .GetFullClassName());
            }
            if (ExecuteStartAndEndOfQueryAction())
            {
                queryResultAction.Start();
            }
            PrepareQuery();
            if (query != null)
            {
                queryHasOrderBy = query.HasOrderBy();
            }
            NeoDatis.Btree.IBTree tree = index.GetBTree();
            bool isUnique = index.IsUnique();

            // Iterator iterator = new BTreeIterator(tree,
            // OrderByConstants.ORDER_BY_ASC);
            System.IComparable       key  = ComputeIndexKey(classInfo, index);
            System.Collections.IList list = null;
            // If index is unique, get the object
            if (isUnique)
            {
                NeoDatis.Btree.IBTreeSingleValuePerKey treeSingle = (NeoDatis.Btree.IBTreeSingleValuePerKey
                                                                     )tree;
                object o = treeSingle.Search(key);
                if (o != null)
                {
                    list = new System.Collections.ArrayList();
                    list.Add(o);
                }
            }
            else
            {
                NeoDatis.Btree.IBTreeMultipleValuesPerKey treeMultiple = (NeoDatis.Btree.IBTreeMultipleValuesPerKey
                                                                          )tree;
                list = treeMultiple.Search(key);
            }
            if (list != null)
            {
                System.Collections.IEnumerator iterator = list.GetEnumerator();
                while (iterator.MoveNext())
                {
                    NeoDatis.Odb.OID oid = (NeoDatis.Odb.OID)iterator.Current;
                    // FIXME Why calling this method
                    long position = objectReader.GetObjectPositionFromItsOid(oid, true, true);
                    orderByKey    = null;
                    objectMatches = MatchObjectWithOid(oid, returnObjects, inMemory);
                    if (objectMatches)
                    {
                        queryResultAction.ObjectMatch(oid, GetCurrentObjectMetaRepresentation(), orderByKey
                                                      );
                    }
                }
                queryResultAction.End();
                return(queryResultAction.GetObjects <T>());
            }
            if (ExecuteStartAndEndOfQueryAction())
            {
                queryResultAction.End();
            }
            return(queryResultAction.GetObjects <T>());
        }
        public virtual void AddIndexOn(string className, string indexName, string[] indexFields
                                       , bool verbose, bool acceptMultipleValuesForSameKey)
        {
            NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo classInfo = GetMetaModel().GetClassInfo
                                                                           (className, true);
            if (classInfo.HasIndex(indexName))
            {
                throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.IndexAlreadyExist
                                                           .AddParameter(indexName).AddParameter(className));
            }
            NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfoIndex cii = classInfo.AddIndexOn(indexName
                                                                                           , indexFields, acceptMultipleValuesForSameKey);
            NeoDatis.Btree.IBTree btree = null;
            if (acceptMultipleValuesForSameKey)
            {
                btree = new NeoDatis.Odb.Impl.Core.Btree.ODBBTreeMultiple(className, NeoDatis.Odb.OdbConfiguration
                                                                          .GetDefaultIndexBTreeDegree(), new NeoDatis.Odb.Impl.Core.Btree.LazyODBBTreePersister
                                                                              (this));
            }
            else
            {
                btree = new NeoDatis.Odb.Impl.Core.Btree.ODBBTreeSingle(className, NeoDatis.Odb.OdbConfiguration
                                                                        .GetDefaultIndexBTreeDegree(), new NeoDatis.Odb.Impl.Core.Btree.LazyODBBTreePersister
                                                                            (this));
            }
            cii.SetBTree(btree);
            Store(cii);
            // Now The index must be updated with all existing objects.
            if (classInfo.GetNumberOfObjects() == 0)
            {
                // There are no objects. Nothing to do
                return;
            }
            if (verbose)
            {
                NeoDatis.Tool.DLogger.Info("Creating index " + indexName + " on class " + className
                                           + " - Class has already " + classInfo.GetNumberOfObjects() + " Objects. Updating index"
                                           );
            }
            if (verbose)
            {
                NeoDatis.Tool.DLogger.Info(indexName + " : loading " + classInfo.GetNumberOfObjects
                                               () + " objects from database");
            }
            // We must load all objects and insert them in the index!
            NeoDatis.Odb.Objects <object> objects = GetObjectInfos <object>(new NeoDatis.Odb.Impl.Core.Query.Criteria.CriteriaQuery
                                                                                (className), false, -1, -1, false);
            if (verbose)
            {
                NeoDatis.Tool.DLogger.Info(indexName + " : " + classInfo.GetNumberOfObjects() + " objects loaded"
                                           );
            }
            NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo nnoi = null;
            int  i             = 0;
            bool monitorMemory = NeoDatis.Odb.OdbConfiguration.IsMonitoringMemory();

            while (objects.HasNext())
            {
                nnoi = (NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo)objects.Next();
                btree.Insert(cii.ComputeKey(nnoi), nnoi.GetOid());
                if (verbose && i % 1000 == 0)
                {
                    if (monitorMemory)
                    {
                        NeoDatis.Odb.Impl.Tool.MemoryMonitor.DisplayCurrentMemory("Index " + indexName +
                                                                                  " " + i + " objects inserted", true);
                    }
                }
                i++;
            }
            if (verbose)
            {
                NeoDatis.Tool.DLogger.Info(indexName + " created!");
            }
        }