Example #1
0
 /// <summary>Adds the object in the btree with the specific key</summary>
 /// <param name="key"></param>
 /// <param name="@object"></param>
 /// <returns></returns>
 public virtual bool AddWithKey(NeoDatis.Tool.Wrappers.OdbComparable key, object @object
                                )
 {
     tree.Insert(key, @object);
     size++;
     return(true);
 }
		public static NeoDatis.Tool.Wrappers.OdbComparable BuildIndexKey(string indexName
			, NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo oi, int[] fieldIds)
		{
			NeoDatis.Tool.Wrappers.OdbComparable[] keys = new NeoDatis.Tool.Wrappers.OdbComparable
				[fieldIds.Length];
			NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo aoi = null;
			System.IComparable o = null;
			for (int i = 0; i < fieldIds.Length; i++)
			{
				// Todo : can we assume that the object is a Comparable
				try
				{
					aoi = (NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo)oi.GetAttributeValueFromId
						(fieldIds[i]);
					o = (System.IComparable)aoi.GetObject();
					// JDK1.4 restriction: Boolean is not Comparable in jdk1.4
					if (aoi.GetOdbType().IsBoolean())
					{
						bool b = (bool)o;
						if (b)
						{
							o = (byte)1;
						}
						else
						{
							o = (byte)0;
						}
					}
					// If the index is on NonNativeObjectInfo, then the key is the oid 
					// of the object
					if (aoi.IsNonNativeObject())
					{
						NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo nnoi = (NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo
							)aoi;
						o = nnoi.GetOid();
					}
					keys[i] = new NeoDatis.Odb.Core.Query.SimpleCompareKey(o);
				}
				catch (System.Exception)
				{
					throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.IndexKeysMustImplementComparable
						.AddParameter(fieldIds[i]).AddParameter(oi.GetAttributeValueFromId(fieldIds[i]).
						GetType().FullName));
				}
			}
			if (keys.Length == 1)
			{
				return keys[0];
			}
			return new NeoDatis.Odb.Core.Query.ComposedCompareKey(keys);
		}
Example #3
0
 public static NeoDatis.Tool.Wrappers.OdbComparable BuildIndexKey(string indexName
                                                                  , NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo oi, int[] fieldIds)
 {
     NeoDatis.Tool.Wrappers.OdbComparable[] keys = new NeoDatis.Tool.Wrappers.OdbComparable
                                                   [fieldIds.Length];
     NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo aoi = null;
     System.IComparable o = null;
     for (int i = 0; i < fieldIds.Length; i++)
     {
         // Todo : can we assume that the object is a Comparable
         try
         {
             aoi = (NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo)oi.GetAttributeValueFromId
                       (fieldIds[i]);
             o = (System.IComparable)aoi.GetObject();
             // JDK1.4 restriction: Boolean is not Comparable in jdk1.4
             if (aoi.GetOdbType().IsBoolean())
             {
                 bool b = (bool)o;
                 if (b)
                 {
                     o = (byte)1;
                 }
                 else
                 {
                     o = (byte)0;
                 }
             }
             // If the index is on NonNativeObjectInfo, then the key is the oid
             // of the object
             if (aoi.IsNonNativeObject())
             {
                 NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo nnoi = (NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo
                                                                                  )aoi;
                 o = nnoi.GetOid();
             }
             keys[i] = new NeoDatis.Odb.Core.Query.SimpleCompareKey(o);
         }
         catch (System.Exception)
         {
             throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.IndexKeysMustImplementComparable
                                                        .AddParameter(fieldIds[i]).AddParameter(oi.GetAttributeValueFromId(fieldIds[i]).
                                                                                                GetType().FullName));
         }
     }
     if (keys.Length == 1)
     {
         return(keys[0]);
     }
     return(new NeoDatis.Odb.Core.Query.ComposedCompareKey(keys));
 }
Example #4
0
 private void Merge(NeoDatis.Tool.Wrappers.OdbComparable key, NeoDatis.Odb.Values
                    values)
 {
     while (values.HasNext())
     {
         if (queryHasOrderBy)
         {
             result.AddWithKey(key, values.NextValues());
         }
         else
         {
             result.Add(values.NextValues());
         }
     }
 }
Example #5
0
 // This method os not used in Values Query API
 public virtual void ObjectMatch(NeoDatis.Odb.OID oid, object @object, NeoDatis.Tool.Wrappers.OdbComparable
                                 orderByKey)
 {
     NeoDatis.Odb.Core.Layers.Layer2.Meta.AttributeValuesMap values = (NeoDatis.Odb.Core.Layers.Layer2.Meta.AttributeValuesMap
                                                                       )@object;
     NeoDatis.Tool.Wrappers.OdbComparable groupByKey = NeoDatis.Odb.Core.Query.Execution.IndexTool
                                                       .BuildIndexKey("GroupBy", values, groupByFieldList);
     NeoDatis.Odb.Impl.Core.Query.Values.ValuesQueryResultAction result = groupByResult
                                                                          [groupByKey];
     if (result == null)
     {
         result = new NeoDatis.Odb.Impl.Core.Query.Values.ValuesQueryResultAction(query, null
                                                                                  , instanceBuilder);
         result.Start();
         groupByResult.Add(groupByKey, result);
     }
     result.ObjectMatch(oid, @object, orderByKey);
 }
		public static NeoDatis.Tool.Wrappers.OdbComparable BuildIndexKey(string indexName
			, NeoDatis.Odb.Core.Layers.Layer2.Meta.AttributeValuesMap values, string[] fields
			)
		{
			if (fields.Length == 1)
			{
				return new NeoDatis.Odb.Core.Query.SimpleCompareKey(values.GetComparable(fields[0
					]));
			}
			NeoDatis.Tool.Wrappers.OdbComparable[] keys = new NeoDatis.Tool.Wrappers.OdbComparable
				[fields.Length];
			System.IComparable @object = null;
			for (int i = 0; i < fields.Length; i++)
			{
				// Todo : can we assume that the object is a Comparable
				try
				{
					@object = (System.IComparable)values[fields[i]];
					// JDK1.4 restriction: Boolean is not Comparable in jdk1.4
					if (@object is bool)
					{
						bool b = (bool)@object;
						if (b)
						{
							@object = (byte)1;
						}
						else
						{
							@object = (byte)0;
						}
					}
					keys[i] = new NeoDatis.Odb.Core.Query.SimpleCompareKey(@object);
				}
				catch (System.Exception)
				{
					throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.IndexKeysMustImplementComparable
						.AddParameter(indexName).AddParameter(fields[i]).AddParameter(values[fields[i]].
						GetType().FullName));
				}
			}
			NeoDatis.Odb.Core.Query.ComposedCompareKey key = new NeoDatis.Odb.Core.Query.ComposedCompareKey
				(keys);
			return key;
		}
Example #7
0
 public static NeoDatis.Tool.Wrappers.OdbComparable BuildIndexKey(string indexName
                                                                  , NeoDatis.Odb.Core.Layers.Layer2.Meta.AttributeValuesMap values, string[] fields
                                                                  )
 {
     if (fields.Length == 1)
     {
         return(new NeoDatis.Odb.Core.Query.SimpleCompareKey(values.GetComparable(fields[0
                                                                                  ])));
     }
     NeoDatis.Tool.Wrappers.OdbComparable[] keys = new NeoDatis.Tool.Wrappers.OdbComparable
                                                   [fields.Length];
     System.IComparable @object = null;
     for (int i = 0; i < fields.Length; i++)
     {
         // Todo : can we assume that the object is a Comparable
         try
         {
             @object = (System.IComparable)values[fields[i]];
             // JDK1.4 restriction: Boolean is not Comparable in jdk1.4
             if (@object is bool)
             {
                 bool b = (bool)@object;
                 if (b)
                 {
                     @object = (byte)1;
                 }
                 else
                 {
                     @object = (byte)0;
                 }
             }
             keys[i] = new NeoDatis.Odb.Core.Query.SimpleCompareKey(@object);
         }
         catch (System.Exception)
         {
             throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.IndexKeysMustImplementComparable
                                                        .AddParameter(indexName).AddParameter(fields[i]).AddParameter(values[fields[i]].
                                                                                                                      GetType().FullName));
         }
     }
     NeoDatis.Odb.Core.Query.ComposedCompareKey key = new NeoDatis.Odb.Core.Query.ComposedCompareKey
                                                          (keys);
     return(key);
 }
Example #8
0
 // This method os not used in Values Query API
 public virtual void ObjectMatch(NeoDatis.Odb.OID oid, object @object, NeoDatis.Tool.Wrappers.OdbComparable
                                 orderByKey)
 {
     if (query.IsMultiRow())
     {
         NeoDatis.Odb.ObjectValues values = ConvertObject((NeoDatis.Odb.Core.Layers.Layer2.Meta.AttributeValuesMap
                                                           )@object);
         if (queryHasOrderBy)
         {
             result.AddWithKey(orderByKey, values);
         }
         else
         {
             result.Add(values);
         }
     }
     else
     {
         Compute((NeoDatis.Odb.Core.Layers.Layer2.Meta.AttributeValuesMap)@object);
     }
 }
Example #9
0
 // Nothing to do
 public virtual void End()
 {
     if (query != null && query.HasOrderBy())
     {
         result = new NeoDatis.Odb.Impl.Core.Query.List.Values.InMemoryBTreeCollectionForValues
                      ((int)nbObjects, query.GetOrderByType());
     }
     else
     {
         result = new NeoDatis.Odb.Impl.Core.Query.List.Values.SimpleListForValues((int)nbObjects
                                                                                   );
     }
     System.Collections.IEnumerator iterator = groupByResult.Keys.GetEnumerator();
     NeoDatis.Odb.Impl.Core.Query.Values.ValuesQueryResultAction vqra = null;
     NeoDatis.Tool.Wrappers.OdbComparable key = null;
     while (iterator.MoveNext())
     {
         key  = (NeoDatis.Tool.Wrappers.OdbComparable)iterator.Current;
         vqra = (NeoDatis.Odb.Impl.Core.Query.Values.ValuesQueryResultAction)groupByResult
                [key];
         vqra.End();
         Merge(key, vqra.GetValues());
     }
 }
 public override bool AddWithKey(NeoDatis.Tool.Wrappers.OdbComparable key, NeoDatis.Odb.ObjectValues
                                 @object)
 {
     throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.OperationNotImplemented
                                                .AddParameter("addWithKey"));
 }
 public virtual bool AddWithKey(NeoDatis.Tool.Wrappers.OdbComparable key, T @object
                                )
 {
     throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.OperationNotImplemented
                                                );
 }
Example #12
0
 public virtual void ObjectMatch(NeoDatis.Odb.OID oid, NeoDatis.Tool.Wrappers.OdbComparable
                                 orderByKey)
 {
 }
 public virtual bool AddWithKey(NeoDatis.Tool.Wrappers.OdbComparable key, E o)
 {
     Add(o);
     return(true);
 }
Example #14
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>());
        }
Example #15
0
        /// <summary>
        /// Query execution full scan
        /// <pre>
        /// startIndex &amp; endIndex
        /// A B C D E F G H I J K L
        /// [1,3] : nb &gt;=1 &amp;&amp; nb&lt;3
        /// 1)
        /// analyze A
        /// nb = 0
        /// nb E [1,3] ? no
        /// r=[]
        /// 2)
        /// analyze B
        /// nb = 1
        /// nb E [1,3] ? yes
        /// r=[B]
        /// 3) analyze C
        /// nb = 2
        /// nb E [1,3] ? yes
        /// r=[B,C]
        /// 4) analyze C
        /// nb = 3
        /// nb E [1,3] ? no and 3&gt; upperBound([1,3]) =&gt; exit
        /// </pre>
        /// </summary>
        /// <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> ExecuteFullScan <T>(bool inMemory, int startIndex,
                                                             int endIndex, bool returnObjects, NeoDatis.Odb.Core.Query.Execution.IMatchingObjectAction
                                                             queryResultAction)
        {
            bool objectInRange = false;
            bool objectMatches = false;

            if (storageEngine.IsClosed())
            {
                throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.OdbIsClosed
                                                           .AddParameter(storageEngine.GetBaseIdentification().GetIdentification()));
            }
            long nbObjects = classInfo.GetNumberOfObjects();

            if (NeoDatis.Odb.OdbConfiguration.IsDebugEnabled(LogId))
            {
                NeoDatis.Tool.DLogger.Debug("loading " + nbObjects + " instance(s) of " + classInfo
                                            .GetFullClassName());
            }
            if (ExecuteStartAndEndOfQueryAction())
            {
                queryResultAction.Start();
            }
            NeoDatis.Odb.OID currentOID = null;
            NeoDatis.Odb.OID prevOID    = null;
            // TODO check if all instances are in the cache! and then load from the
            // cache
            nextOID = classInfo.GetCommitedZoneInfo().first;
            if (nbObjects > 0 && nextOID == null)
            {
                // This means that some changes have not been commited!
                // Take next position from uncommited zone
                nextOID = classInfo.GetUncommittedZoneInfo().first;
            }
            PrepareQuery();
            if (query != null)
            {
                queryHasOrderBy = query.HasOrderBy();
            }
            bool monitorMemory = NeoDatis.Odb.OdbConfiguration.IsMonitoringMemory();
            // used when startIndex and endIndex are not negative
            int nbObjectsInResult = 0;

            for (int i = 0; i < nbObjects; i++)
            {
                //Console.WriteLine(i);
                if (monitorMemory && i % 10000 == 0)
                {
                    NeoDatis.Odb.Impl.Tool.MemoryMonitor.DisplayCurrentMemory(string.Empty + (i + 1),
                                                                              true);
                }
                // Reset the order by key
                orderByKey    = null;
                objectMatches = false;
                prevOID       = currentOID;
                currentOID    = nextOID;
                // This is an error
                if (currentOID == null)
                {
                    if (NeoDatis.Odb.OdbConfiguration.ThrowExceptionWhenInconsistencyFound())
                    {
                        throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.NullNextObjectOid
                                                                   .AddParameter(classInfo.GetFullClassName()).AddParameter(i).AddParameter(nbObjects
                                                                                                                                            ).AddParameter(prevOID));
                    }
                    break;
                }
                // If there is an endIndex condition
                if (endIndex != -1 && nbObjectsInResult >= endIndex)
                {
                    break;
                }
                // If there is a startIndex condition
                if (startIndex != -1 && nbObjectsInResult < startIndex)
                {
                    objectInRange = false;
                }
                else
                {
                    objectInRange = true;
                }
                // There is no query
                if (!inMemory && query == null)
                {
                    nbObjectsInResult++;
                    // keep object position if we must
                    if (objectInRange)
                    {
                        orderByKey = BuildOrderByKey(currentNnoi);
                        // TODO Where is the key for order by
                        queryResultAction.ObjectMatch(nextOID, orderByKey);
                    }
                    nextOID = objectReader.GetNextObjectOID(currentOID);
                }
                else
                {
                    objectMatches = MatchObjectWithOid(currentOID, returnObjects, inMemory);
                    if (objectMatches)
                    {
                        nbObjectsInResult++;
                        if (objectInRange)
                        {
                            if (queryHasOrderBy)
                            {
                                orderByKey = BuildOrderByKey(GetCurrentObjectMetaRepresentation());
                            }
                            queryResultAction.ObjectMatch(currentOID, GetCurrentObjectMetaRepresentation(), orderByKey
                                                          );
                            if (callback != null)
                            {
                                callback.ReadingObject(i, -1);
                            }
                        }
                    }
                }
            }
            if (ExecuteStartAndEndOfQueryAction())
            {
                queryResultAction.End();
            }
            return(queryResultAction.GetObjects <T>());
        }