public override IEnumerable<ObjectUUID> IndexSingleOperation(AAttributeIndex myIndex, ADBBaseObject myOperationValue, AttributeUUID myAttributeUUID, TypesOfBinaryExpression typeOfBinExpr, DBContext dbContext) { IndexKey lookup = new IndexKey(myAttributeUUID, myOperationValue, myIndex.IndexKeyDefinition); var currentType = dbContext.DBTypeManager.GetTypeByUUID(myIndex.IndexRelatedTypeUUID); var result = myIndex.Contains(lookup, currentType, dbContext); if (result.Value) { var interestingUUIDs = myIndex.GetValues(lookup, currentType, dbContext); foreach (var aIndexValue in myIndex.GetAllValues(currentType, dbContext)) { foreach (var aUUID in aIndexValue) { if (!interestingUUIDs.Contains(aUUID)) { yield return aUUID; } } } } else { foreach (var aIndexValue in myIndex.GetKeyValues(currentType, dbContext).Select(kv => kv.Value)) { foreach (var aUUID in aIndexValue) { yield return aUUID; } } } yield break; }
public override IEnumerable<ObjectUUID> IndexOperation(AAttributeIndex myIndex, TupleDefinition myTuple, TypesOfBinaryExpression typeOfBinExpr, DBContext dbContext) { if (myTuple.Count() != 2) { throw new GraphDBException(new Error_InvalidInRangeInterval(2, myTuple.Count())); } var currentType = dbContext.DBTypeManager.GetTypeByUUID(myIndex.IndexRelatedTypeUUID); #region As soon as the index supports ranges use them!! //limits var fromKey = new IndexKey(myIndex.IndexKeyDefinition.IndexKeyAttributeUUIDs[0], (myTuple.ElementAt(0).Value as ValueDefinition).Value, myIndex.IndexKeyDefinition); var toKey = new IndexKey(myIndex.IndexKeyDefinition.IndexKeyAttributeUUIDs[0], (myTuple.ElementAt(1).Value as ValueDefinition).Value, myIndex.IndexKeyDefinition); switch (myTuple.KindOfTuple) { case KindOfTuple.Inclusive: return myIndex.InRange(fromKey, toKey, true, true, currentType, dbContext); case KindOfTuple.LeftExclusive: return myIndex.InRange(fromKey, toKey, false, true, currentType, dbContext); case KindOfTuple.RightExclusive: return myIndex.InRange(fromKey, toKey, true, false, currentType, dbContext); case KindOfTuple.Exclusive: return myIndex.InRange(fromKey, toKey, false, false, currentType, dbContext); default: throw new GraphDBException(new Error_NotImplemented(new System.Diagnostics.StackTrace(true))); } #endregion }
public override IEnumerable<ObjectUUID> IndexSingleOperation(AAttributeIndex myIndex, ADBBaseObject myOperationValue, AttributeUUID myAttributeUUID, TypesOfBinaryExpression typeOfBinExpr, DBContext dbContext) { var myIndeyKey = new IndexKey(myAttributeUUID, myOperationValue, myIndex.IndexKeyDefinition); var currentType = dbContext.DBTypeManager.GetTypeByUUID(myIndex.IndexRelatedTypeUUID); if (myIndex.Contains(myIndeyKey, currentType, dbContext)) { foreach (var aUUID in myIndex.GetValues(myIndeyKey, currentType, dbContext)) { yield return aUUID; } } yield break; }
/// <summary> /// <seealso cref=" IAttributeIndex"/> /// </summary> public override IEnumerable<ObjectUUID> InRange(IndexKey fromIndexKey, IndexKey toIndexKey, bool myOrEqualFromKey, bool myOrEqualToKey, GraphDBType myTypeOfDBObject, DBContext myDBContext) { VerifyIndexDatastructure(myDBContext, myTypeOfDBObject); foreach (var aUUID in _indexDatastructure.InRange(fromIndexKey, toIndexKey, myOrEqualFromKey, myOrEqualToKey)) { yield return aUUID; } yield break; }
/// <summary> /// Get the shard id corresponding to an indexKey /// </summary> /// <param name="aIndexKey">An IndexKey</param> /// <returns>The shard id</returns> private int GetIndexShardID(IndexKey aIndexKey) { //stupid... might be solved by constant hashing or sth like that return Math.Abs(aIndexKey.GetHashCode()) % AttributeIdxShards; }
public abstract IEnumerable<ObjectUUID> InRange(IndexKey fromIndexKey, IndexKey toIndexKey, bool myOrEqualFromKey, bool myOrEqualToKey, GraphDBType myTypeOfDBObject, DBContext dbContext);
public override IEnumerable<ObjectUUID> GetValues(IndexKey myIndeyKey, GraphDBType myTypeOfDBObject, DBContext dbContext) { #region Get index reference var idxRef = GetIndexReference(dbContext.DBIndexManager); if (idxRef.Failed()) { throw new GraphDBException(new Error_CouldNotGetIndexReference(idxRef.IErrors, IndexName, IndexEdition)); } var idxRefVal = idxRef.Value; #endregion if (idxRefVal != null) { return idxRef.Value[myIndeyKey]; } else { throw new GraphDBException(new Error_InvalidIndexReference(IndexName, IndexEdition)); } }
internal Exceptional Remove(IndexKey indexKey, int shard, DBIndexManager myDBIndexManager) { //get the actual shard var currentIdxShard = GetIndexReference(myDBIndexManager, shard); if (!currentIdxShard.Success()) { return new Exceptional(currentIdxShard); } HashSet<ObjectUUID> removedItems = null; currentIdxShard.Value.TryGetValue(indexKey, out removedItems); if (removedItems != null) { currentIdxShard.Value.Remove(indexKey); DecreaseKeyCount(); DecreaseValueCount((UInt64)removedItems.Count); } return Exceptional.OK; }
public abstract bool Contains(IndexKey myIndeyKey, GraphDBType myTypeOfDBObject, DBContext dbContext);
/// <summary> /// <seealso cref=" IAtributeIndex"/> /// </summary> public override Exceptional<bool> Contains(IndexKey myIndexKey, GraphDBType myTypeOfDBObject, DBContext myDBContext) { #region get the shard //get the actual shard var currentIdxShard = GetIndexReference(myDBContext.DBIndexManager, myDBContext.DBIndexManager.GetIndexShardID(myIndexKey, this.AttributeIdxShards)); if (!currentIdxShard.Success()) { throw new GraphDBException(new Error_CouldNotGetIndexReference(currentIdxShard.IErrors, IndexName, IndexEdition, myDBContext.DBIndexManager.GetIndexShardID(myIndexKey, this.AttributeIdxShards))); } var currentIdxShardValue = currentIdxShard.Value; #endregion return new Exceptional<bool>(currentIdxShardValue.ContainsKey(myIndexKey)); }
/// <summary> /// <seealso cref=" IShardedHashTableIndex"/> /// </summary> public override IEnumerable<ObjectUUID> InRange(IndexKey fromIndexKey, IndexKey toIndexKey, bool myOrEqualFromKey, bool myOrEqualToKey, GraphDBType myTypeOfDBObject, DBContext myDBContext) { //TODO: PERFORMANCE BUG!!!!!!! foreach (var aIdxShardExceptional in GetAllIdxShards(myDBContext)) { #region get the shard if (!aIdxShardExceptional.Item2.Success()) { throw new GraphDBException(new Error_CouldNotGetIndexReference(aIdxShardExceptional.Item2.IErrors, IndexName, IndexEdition, aIdxShardExceptional.Item1)); } var idxRefVal = aIdxShardExceptional.Item2.Value; #endregion foreach (var aUUID in idxRefVal.InRange(fromIndexKey, toIndexKey, myOrEqualFromKey, myOrEqualToKey)) { yield return aUUID; } } yield break; }
public override IEnumerable<ObjectUUID> GetValues(IndexKey myIndeyKey, GraphDBType myTypeOfDBObject, DBContext dbContext) { if (Contains(myIndeyKey, myTypeOfDBObject, dbContext)) { //this has to work, because the same thing has been tested during contains yield return (ObjectUUID)myIndeyKey.IndexKeyValues[0].Value; } yield break; }
public override IEnumerable<ObjectUUID> InRange(IndexKey fromIndexKey, IndexKey toIndexKey, bool myOrEqualFromKey, bool myOrEqualToKey, GraphDBType myTypeOfDBObject, DBContext dbContext) { var fromUUID = (ObjectUUID)fromIndexKey.IndexKeyValues[0].Value; var toUUID = (ObjectUUID)toIndexKey.IndexKeyValues[0].Value; if (fromUUID <= toUUID) { #region <= if (myOrEqualFromKey && myOrEqualToKey) { foreach (var aUUID in GetAllUUIDs(myTypeOfDBObject, dbContext).Where(item => { return (item >= fromUUID) && (item <= toUUID); })) { yield return aUUID; } } else { if (!myOrEqualFromKey && myOrEqualToKey) { foreach (var aUUID in GetAllUUIDs(myTypeOfDBObject, dbContext).Where(item => { return (item > fromUUID) && (item <= toUUID); })) { yield return aUUID; } } else { if (myOrEqualFromKey && !myOrEqualToKey) { foreach (var aUUID in GetAllUUIDs(myTypeOfDBObject, dbContext).Where(item => { return (item >= fromUUID) && (item < toUUID); })) { yield return aUUID; } } else { foreach (var aUUID in GetAllUUIDs(myTypeOfDBObject, dbContext).Where(item => { return (item > fromUUID) && (item < toUUID); })) { yield return aUUID; } } } } #endregion } else { if (fromUUID == toUUID) { #region == if (Contains(fromIndexKey, myTypeOfDBObject, dbContext)) { yield return (ObjectUUID)fromIndexKey.IndexKeyValues[0].Value; } #endregion } else { #region > #region part 1 if (myOrEqualToKey) { foreach (var aUUID in GetAllUUIDs(myTypeOfDBObject, dbContext).Where(item => { return (item >= fromUUID); })) { yield return aUUID; } } else { foreach (var aUUID in GetAllUUIDs(myTypeOfDBObject, dbContext).Where(item => { return (item > fromUUID); })) { yield return aUUID; } } #endregion #region part 2 if (myOrEqualFromKey) { foreach (var aUUID in GetAllUUIDs(myTypeOfDBObject, dbContext).Where(item => { return (item <= toUUID); })) { yield return aUUID; } } else { foreach (var aUUID in GetAllUUIDs(myTypeOfDBObject, dbContext).Where(item => { return (item < toUUID); })) { yield return aUUID; } } #endregion #endregion } } yield break; }
public override Boolean Contains(IndexKey myIndeyKey, GraphDBType myTypeOfDBObject, DBContext dbContext) { if (myIndeyKey.IndexKeyValues.Count == 1) { var uuid = myIndeyKey.IndexKeyValues[0].Value as ObjectUUID; if(uuid == null) { throw new GraphDBException(new Error_InvalidIndexOperation(IndexName)); } else { return GetDirectoryObject(myTypeOfDBObject, uuid, dbContext).ObjectExists(uuid.ToString()); } } else { throw new GraphDBException(new Error_InvalidIndexOperation(IndexName)); } }
/// <summary> /// This method checks if the current attribute index contains a DBObject /// </summary> /// <param name="myIndexKey">The DBObject that should be checked</param> /// <param name="myTypeOfDBObject">The Type of the DBObject</param> /// <param name="myDBContext">The db context</param> /// <returns>boolean</returns> public abstract Exceptional<bool> Contains(IndexKey myIndexKey, GraphDBType myTypeOfDBObject, DBContext myDBContext);
private void SetIndexKeyAndValue(IndexKey myIndexKey, ObjectUUID objectUUID, IndexSetStrategy myIndexSetStrategy) { HashSet<ObjectUUID> value = null; var valueCount = 1UL; if (!_indexDatastructure.TryGetValue(myIndexKey, out value)) { //so there is one more key... IncreaseKeyCount(); IncreaseValueCount(valueCount); } else { if (!value.Contains(objectUUID)) { IncreaseValueCount(valueCount); } } _indexDatastructure.Set(myIndexKey, objectUUID, myIndexSetStrategy); this.Save(); }
private Exceptional Insert(IndexKey indexKey, HashSet<ObjectUUID> hashSet, int shard, DBIndexManager dBIndexManager, GraphDBType myTypeOfDBObject) { #region Check for uniqueness - TODO: remove me as soon as we have a unique indexObject implementation if (IsUniqueAttributeIndex) { if (_indexDatastructure.ContainsKey(indexKey)) { return new Exceptional(new Error_UniqueConstrainViolation(myTypeOfDBObject.Name, IndexName)); } } #endregion UInt64 previousKeyCount = _keyCount; HashSet<ObjectUUID> value = null; _indexDatastructure.TryGetValue(indexKey, out value); if (value == null) { _indexDatastructure.Set(indexKey, hashSet, IndexSetStrategy.MERGE); IncreaseKeyCount(); IncreaseValueCount((UInt64)hashSet.Count); } else { _indexDatastructure.Add(indexKey, hashSet); IncreaseValueCount((UInt64)_indexDatastructure[indexKey].Count); } return Exceptional.OK; }
internal Exceptional Remove(IndexKey indexKey) { HashSet<ObjectUUID> removedItems = null; _indexDatastructure.TryGetValue(indexKey, out removedItems); if (removedItems != null) { _indexDatastructure.Remove(indexKey); DecreaseKeyCount(); DecreaseValueCount((UInt64)removedItems.Count); } return Exceptional.OK; }
/// <summary> /// <seealso cref=" IShardedHashTableIndex"/> /// </summary> public override IEnumerable<ObjectUUID> GetValues(IndexKey myIndeyKey, GraphDBType myTypeOfDBObject, DBContext dbContext) { #region get the shard //get the actual shard var currentIdxShard = GetIndexReference(dbContext.DBIndexManager, dbContext.DBIndexManager.GetIndexShardID(myIndeyKey, this.AttributeIdxShards)); if (!currentIdxShard.Success()) { throw new GraphDBException(new Error_CouldNotGetIndexReference(currentIdxShard.IErrors, IndexName, IndexEdition, dbContext.DBIndexManager.GetIndexShardID(myIndeyKey, this.AttributeIdxShards))); } var currentIdxShardValue = currentIdxShard.Value; #endregion return currentIdxShardValue[myIndeyKey]; }
/// <summary> /// Get the shard id corresponding to an indexKey /// </summary> /// <param name="aIndexKey">An IndexKey</param> /// <returns>The shard id</returns> public int GetIndexShardID(IndexKey aIndexKey, UInt16 shardCount) { //stupid... might be solved by constant hashing or sth like that return Math.Abs(aIndexKey.GetHashCode()) % shardCount; }
internal Exceptional Insert(IndexKey indexKey, HashSet<ObjectUUID> hashSet, int shard, DBIndexManager dBIndexManager, GraphDBType myTypeOfDBObject) { //get the actual shard var currentIdxShard = GetIndexReference(dBIndexManager, shard); if (!currentIdxShard.Success()) { return new Exceptional(currentIdxShard); } #region Check for uniqueness - TODO: remove me as soon as we have a unique indexObject implementation if (IsUniqueAttributeIndex) { if (currentIdxShard.Value.ContainsKey(indexKey)) { return new Exceptional(new Error_UniqueConstrainViolation(myTypeOfDBObject.Name, IndexName)); } } #endregion UInt64 previousKeyCount = currentIdxShard.Value.KeyCount(); HashSet<ObjectUUID> value = null; currentIdxShard.Value.TryGetValue(indexKey, out value); if (value == null) { currentIdxShard.Value.Set(indexKey, hashSet, IndexSetStrategy.MERGE); IncreaseKeyCount(); IncreaseValueCount((UInt64)hashSet.Count); } else { currentIdxShard.Value.Add(indexKey, hashSet); IncreaseValueCount((UInt64)currentIdxShard.Value[indexKey].Count); } return Exceptional.OK; }
public Boolean Equals(IndexKey p) { // If parameter is null return false: if ((object)p == null) { return false; } if (this._indexKeyValues.Count != p.IndexKeyValues.Count) { return false; } for (int i = 0; i < _indexKeyValues.Count; i++) { if (!p.IndexKeyValues[i].Equals(this._indexKeyValues[i])) { return false; } } return true; }
private void SetIndexKeyAndValue(IVersionedIndexObject<IndexKey, ObjectUUID> currentIdxShardValue, IndexKey aIndexKex, ObjectUUID objectUUID, IndexSetStrategy myIndexSetStrategy) { UInt64 previousKeyCount = currentIdxShardValue.KeyCount(); currentIdxShardValue.Set(aIndexKex, objectUUID, myIndexSetStrategy); UInt64 afterKeyCount = currentIdxShardValue.KeyCount(); if (afterKeyCount > previousKeyCount) { //so there is one more key... IncreaseKeyCount(); } IncreaseValueCount(1UL); }
private object Deserialize(ref SerializationReader mySerializationReader, IndexKey myValue) { UInt32 count = mySerializationReader.ReadUInt32(); for (UInt32 i = 0; i < count; i++) { var a = (ADBBaseObject)mySerializationReader.ReadObject(); myValue._indexKeyValues.Add(a); CalcNewHashCode(a, ref myValue._hashCode); } return myValue; }
public abstract IEnumerable<ObjectUUID> GetValues(IndexKey myIndeyKey, GraphDBType myTypeOfDBObject, DBContext dbContext);
private void Serialize(ref SerializationWriter mySerializationWriter, IndexKey myValue) { mySerializationWriter.WriteUInt32((UInt32)myValue.IndexKeyValues.Count); foreach (var attr in myValue.IndexKeyValues) { //attr.Serialize(ref mySerializationWriter); mySerializationWriter.WriteObject(attr); } }
public override IEnumerable<ObjectUUID> IndexOperation(AAttributeIndex myIndex, TupleDefinition myTuple, TypesOfBinaryExpression typeOfBinExpr, DBContext dbContext) { HashSet<ObjectUUID> interestingUUIDs = new HashSet<ObjectUUID>(); IndexKey idxLookupKey = null; var currentType = dbContext.DBTypeManager.GetTypeByUUID(myIndex.IndexRelatedTypeUUID); var myOperationValues = myTuple; switch (typeOfBinExpr) { case TypesOfBinaryExpression.LeftComplex: if (!myIndex.IsListOfBaseObjectsIndex) { foreach (var aItem in myOperationValues) { idxLookupKey = new IndexKey(myIndex.IndexKeyDefinition.IndexKeyAttributeUUIDs[0], (aItem.Value as ValueDefinition).Value, myIndex.IndexKeyDefinition); interestingUUIDs.UnionWith(myIndex.GetValues(idxLookupKey, currentType, dbContext)); } } else { #region In case the index is from a set or list of baseobjects we use this way to get the values foreach (var aItem in myOperationValues) { idxLookupKey = new IndexKey(myIndex.IndexKeyDefinition.IndexKeyAttributeUUIDs[0], (aItem.Value as ValueDefinition).Value, myIndex.IndexKeyDefinition); interestingUUIDs.UnionWith(myIndex.GetValues(idxLookupKey, currentType, dbContext)); } /* What the hack is that??? - This is too slow for any usual usage of in operator! */ var indexRelatedType = dbContext.DBTypeManager.GetTypeByUUID(myIndex.IndexRelatedTypeUUID); foreach (var aKey in myIndex.GetKeys(currentType, dbContext).Where(item => !myOperationValues.Contains(new TupleElement(new ValueDefinition(item.IndexKeyValues[0]))))) { foreach (var aMatch in myIndex.GetValues(aKey, indexRelatedType, dbContext).Intersect(interestingUUIDs)) { interestingUUIDs.Remove(aMatch); } } #endregion } break; case TypesOfBinaryExpression.RightComplex: var myEnumerator = myOperationValues.GetEnumerator(); if (myEnumerator.MoveNext()) { idxLookupKey = new IndexKey(myIndex.IndexKeyDefinition.IndexKeyAttributeUUIDs[0], (myEnumerator.Current.Value as ValueDefinition).Value, myIndex.IndexKeyDefinition); interestingUUIDs.UnionWith(myIndex.GetValues(idxLookupKey, currentType, dbContext)); while (myEnumerator.MoveNext()) { idxLookupKey = new IndexKey(myIndex.IndexKeyDefinition.IndexKeyAttributeUUIDs[0], (myEnumerator.Current.Value as ValueDefinition).Value, myIndex.IndexKeyDefinition); interestingUUIDs.IntersectWith(myIndex.GetValues(idxLookupKey, currentType, dbContext)); } } break; case TypesOfBinaryExpression.Atom: case TypesOfBinaryExpression.Complex: case TypesOfBinaryExpression.Unknown: default: break; } foreach (var aValidUUID in interestingUUIDs) { yield return aValidUUID; } yield break; }
/// <summary> /// Instantiates a new IndexKey on the base of another one. Additionally a AADBBaseObject is added. /// </summary> /// <param name="myStartingIndexKey">The base of the new IndexKey</param> /// <param name="myAttributeUUID">AttributeUUID corresponding to the ADBBaseObject</param> /// <param name="myIndexKeyPayload">The ADBBaseObject that is going to be added</param> /// <param name="myIndexDefinition">The corresponding IndexKeyDefinition</param> public IndexKey(IndexKey myStartingIndexKey, AttributeUUID myAttributeUUID, ADBBaseObject myIndexKeyPayload, IndexKeyDefinition myIndexDefinition) { _hashCode = myStartingIndexKey.GetHashCode(); _indexKeyValues.AddRange(myStartingIndexKey.IndexKeyValues); if (!myIndexDefinition.IndexKeyAttributeUUIDs.Contains(myAttributeUUID)) { throw new GraphDBException(new Error_IndexKeyCreationError(myAttributeUUID, myIndexKeyPayload, myIndexDefinition)); } else { AddAAKey(myAttributeUUID, myIndexKeyPayload); } }
public override IEnumerable<ObjectUUID> InRange(IndexKey fromIndexKey, IndexKey toIndexKey, bool myOrEqualFromKey, bool myOrEqualToKey, GraphDBType myTypeOfDBObject, DBContext dbContext) { #region Get index reference var idxRef = GetIndexReference(dbContext.DBIndexManager); if (idxRef.Failed()) { throw new GraphDBException(new Error_CouldNotGetIndexReference(idxRef.IErrors, IndexName, IndexEdition)); } var idxRefVal = idxRef.Value; #endregion if (idxRefVal != null) { return idxRefVal.InRange(fromIndexKey, toIndexKey, myOrEqualFromKey, myOrEqualToKey); } else { throw new GraphDBException(new Error_InvalidIndexReference(IndexName, IndexEdition)); } }
public override Boolean Contains(IndexKey myIndeyKey, GraphDBType myTypeOfDBObject, DBContext dbContext) { #region get the shard //get the actual shard var currentIdxShard = GetIndexReference(dbContext.DBIndexManager, GetIndexShardID(myIndeyKey)); if (!currentIdxShard.Success()) { throw new GraphDBException(new Error_CouldNotGetIndexReference(currentIdxShard.IErrors, IndexName, IndexEdition, GetIndexShardID(myIndeyKey))); } var currentIdxShardValue = currentIdxShard.Value; #endregion return currentIdxShardValue.ContainsKey(myIndeyKey); }