Permalink
Browse files

[GRAPHDB-544] implemented closeable enumerable and use it in all inde…

…x plugins
  • Loading branch information...
1 parent b7cb6b5 commit 716b8c3a7f11f04b92401d366ef23006b90058dd @sunlounger sunlounger committed Dec 9, 2011
@@ -85,7 +85,7 @@ public override ISonesIndex GetBestMatchingIdx(IEnumerable<ISonesIndex> myIndexC
protected override IEnumerable<long> GetValues(ISonesIndex myIndex, IComparable myIComparable)
{
- IEnumerable<long> values;
+ ICloseableEnumerable<long> values;
myIndex.TryGetValues(myIComparable, out values);
@@ -617,7 +617,7 @@ public ISonesIndex GetIndex(BaseUniqueIndex myIndex)
public ISonesIndex GetIndex(string myIndexName, SecurityToken mySecurity, Int64 myTransaction)
{
- IEnumerable<long> values;
+ ICloseableEnumerable<long> values;
_ownIndex.TryGetValues(myIndexName, out values);
@@ -28,16 +28,16 @@ public abstract class ASonesIndex : ISonesIndex
public abstract long ValueCount();
- public abstract IEnumerable<IComparable> Keys();
+ public abstract ICloseableEnumerable<IComparable> Keys();
public abstract Type GetKeyType();
public abstract void Add(IComparable myKey, long? myVertexID,
IndexAddStrategy myIndexAddStrategy = IndexAddStrategy.MERGE);
- public abstract bool TryGetValues(IComparable myKey, out IEnumerable<long> myVertexIDs);
+ public abstract bool TryGetValues(IComparable myKey, out ICloseableEnumerable<long> myVertexIDs);
- public abstract IEnumerable<long> this[IComparable myKey] { get; }
+ public abstract ICloseableEnumerable<long> this[IComparable myKey] { get; }
public abstract bool ContainsKey(IComparable myKey);
@@ -0,0 +1,42 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace sones.Plugins.Index.Helper
+{
+ public class CloseableEnumerable<T> : ICloseableEnumerable<T>
+ {
+ IEnumerable<T> _Enumerable;
+ Action _Close = null;
+
+ public CloseableEnumerable(IEnumerable<T> myEnumerable, Action myClose = null)
+ {
+ _Enumerable = myEnumerable;
+ _Close = myClose;
+ }
+
+ public virtual void Close()
+ {
+ if (_Close != null)
+ {
+ _Close();
+ }
+ }
+
+ public IEnumerator<T> GetEnumerator()
+ {
+ return _Enumerable.GetEnumerator();
+ }
+
+ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
+ {
+ return _Enumerable.GetEnumerator();
+ }
+
+ public virtual void Dispose()
+ {
+ Close();
+ }
+ }
+}
@@ -48,13 +48,15 @@
<Compile Include="ErrorHandling\IndexRemoveFailedException.cs" />
<Compile Include="ErrorHandling\NullKeysNotSupportedException.cs" />
<Compile Include="ErrorHandling\UnknownIndexException.cs" />
+ <Compile Include="Helper\CloseableEnumerable.cs" />
<Compile Include="Helper\IndexAddStrategy.cs" />
<Compile Include="Helper\IndexConstants.cs" />
<Compile Include="Interfaces\Compound\ICompoundIndexKey.cs" />
<Compile Include="Interfaces\Compound\ISonesCompoundIndex.cs" />
<Compile Include="Interfaces\Fulltext\ISonesFulltextIndex.cs" />
<Compile Include="Interfaces\Fulltext\ISonesFulltextResult.cs" />
<Compile Include="Interfaces\Fulltext\ISonesFulltextResultEntry.cs" />
+ <Compile Include="Interfaces\ICloseableEnumerable.cs" />
<Compile Include="Interfaces\ISonesIndex.cs" />
<Compile Include="Interfaces\Persistent\ISonesPersistentIndex.cs" />
<Compile Include="Interfaces\Range\ISonesRangeIndex.cs" />
@@ -37,7 +37,7 @@ public interface ISonesCompoundIndex : ISonesIndex
/// </summary>
/// <param name="myPropertyID">The propertyID of the keys to be returned</param>
/// <returns>All keys associated with the given propertyID.</returns>
- IEnumerable<IComparable> Keys(Int64 myPropertyID);
+ ICloseableEnumerable<IComparable> Keys(Int64 myPropertyID);
#endregion
@@ -88,7 +88,7 @@ public interface ISonesCompoundIndex : ISonesIndex
/// <param name="myVertexIDs">
/// Stores the vertexIDs if a matching for all keys was found.
/// </param>
- bool TryGetValues(IEnumerable<ICompoundIndexKey> myKeys, out IEnumerable<Int64> myVertexIDs);
+ bool TryGetValues(IEnumerable<ICompoundIndexKey> myKeys, out ICloseableEnumerable<Int64> myVertexIDs);
#endregion
@@ -106,7 +106,7 @@ public interface ISonesCompoundIndex : ISonesIndex
/// <param name="myVertexIDs">
/// Stores the vertexIDs if a matching for 1-n keys was found.
/// </param>
- bool TryGetValuesPartial(IEnumerable<ICompoundIndexKey> myKeys, out IEnumerable<Int64> myVertexIDs);
+ bool TryGetValuesPartial(IEnumerable<ICompoundIndexKey> myKeys, out ICloseableEnumerable<Int64> myVertexIDs);
#endregion
@@ -118,7 +118,7 @@ public interface ISonesCompoundIndex : ISonesIndex
/// </summary>
/// <param name="myKeys">A collection of search keys</param>
/// <returns>Associated values</returns>
- IEnumerable<Int64> this[IEnumerable<ICompoundIndexKey> myKeys] { get; }
+ ICloseableEnumerable<Int64> this[IEnumerable<ICompoundIndexKey> myKeys] { get; }
#endregion
}
@@ -24,7 +24,7 @@ public interface ISonesFulltextResult
/// <value>
/// The entries.
/// </value>
- IEnumerable<ISonesFulltextResultEntry> Entries { get; }
+ ICloseableEnumerable<ISonesFulltextResultEntry> Entries { get; }
/*
* TODO: place for additional functionality
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace sones.Plugins.Index
+{
+ public interface ICloseableEnumerable<T> : IEnumerable<T>, IDisposable
+ {
+ void Close();
+ }
+}
@@ -100,7 +100,7 @@ public interface ISonesIndex
/// Returns all stored keys.
/// </summary>
/// <returns>All stored keys</returns>
- IEnumerable<IComparable> Keys();
+ ICloseableEnumerable<IComparable> Keys();
#endregion
@@ -198,7 +198,7 @@ public interface ISonesIndex
/// <param name="myVertexIDs">
/// Stores the vertexIDs if the key has been found.
/// </param>
- bool TryGetValues(IComparable myKey, out IEnumerable<Int64> myVertexIDs);
+ bool TryGetValues(IComparable myKey, out ICloseableEnumerable<Int64> myVertexIDs);
#endregion
@@ -213,7 +213,7 @@ public interface ISonesIndex
/// </summary>
/// <param name="myKey">The search key</param>
/// <returns>Associated values</returns>
- IEnumerable<Int64> this[IComparable myKey] { get; }
+ ICloseableEnumerable<Int64> this[IComparable myKey] { get; }
#endregion
@@ -30,7 +30,7 @@ public interface ISonesRangeIndex : ISonesIndex
/// <param name="myIncludeKey">
/// True if the values associated with the upper bound shall be returned, too.
/// </param>
- IEnumerable<Int64> LowerThan(IComparable myKey, bool myIncludeKey = true);
+ ICloseableEnumerable<Int64> LowerThan(IComparable myKey, bool myIncludeKey = true);
/// <summary>
/// Returns all vertexIDs that are greater than (or equal to) to the given key.
@@ -44,7 +44,7 @@ public interface ISonesRangeIndex : ISonesIndex
/// <param name="myIncludeKey">
/// True if the values associated with the lower bound shall be returned, too.
/// </param>
- IEnumerable<Int64> GreaterThan(IComparable myKey, bool myIncludeKey = true);
+ ICloseableEnumerable<Int64> GreaterThan(IComparable myKey, bool myIncludeKey = true);
/// <summary>
/// Returns all vertexID ids that are in a given key range.
@@ -61,7 +61,7 @@ public interface ISonesRangeIndex : ISonesIndex
/// <param name='myIncludeToKey'>
/// True, if the upper bound shall be included in the range.
/// </param>
- IEnumerable<Int64> Between(IComparable myFromKey,
+ ICloseableEnumerable<Int64> Between(IComparable myFromKey,
IComparable myToKey,
bool myIncludeFromKey = true,
bool myIncludeToKey = true);
@@ -27,7 +27,7 @@ public interface ISonesSpatialIndex : ISonesIndex
/// <param name="myGeometry">Search space</param>
/// <param name="myVertexIDs">Stores found vertexIDs</param>
/// <returns>True, if at least one object has been found at the given point or in the space.</returns>
- bool TryGetValues(IGeometry myGeometry, out IEnumerable<Int64> myVertexIDs);
+ bool TryGetValues(IGeometry myGeometry, out ICloseableEnumerable<Int64> myVertexIDs);
#endregion
@@ -41,7 +41,7 @@ public interface ISonesSpatialIndex : ISonesIndex
/// <param name="myVertexIDs">Stores found vertexIDs</param>
/// <param name="myMaximumDistance">Defines an optional search boundary</param>
/// <returns>True, if at least one neighbour has been found.</returns>
- bool TryGetValuesNear(IPoint myCentralPoint, Int32 myK, out IEnumerable<Int64> myVertexIDs, double? myMaximumDistance);
+ bool TryGetValuesNear(IPoint myCentralPoint, Int32 myK, out ICloseableEnumerable<Int64> myVertexIDs, double? myMaximumDistance);
#endregion
@@ -37,7 +37,7 @@ public interface ISonesVersionedIndex : ISonesIndex
/// Returns all stored keys at a given version
/// </summary>
/// <returns>Search keys associated with a given version.</returns>
- IEnumerable<IComparable> Keys(Int64 myVersion);
+ ICloseableEnumerable<IComparable> Keys(Int64 myVersion);
#endregion
@@ -59,7 +59,7 @@ public interface ISonesVersionedIndex : ISonesIndex
/// </param>
/// <param name="myVersion">The version</param>
bool TryGetValues(IComparable myKey,
- out IEnumerable<Int64> myVertexIDs,
+ out ICloseableEnumerable<Int64> myVertexIDs,
Int64 myVersion);
#endregion
@@ -76,7 +76,7 @@ public interface ISonesVersionedIndex : ISonesIndex
/// <param name="myKey">The search key</param>
/// <param name="myVersion">The version</param>
/// <returns>Values associated with the key at a given version</returns>
- IEnumerable<Int64> this[IComparable myKey, Int64 myVersion] { get; }
+ ICloseableEnumerable<Int64> this[IComparable myKey, Int64 myVersion] { get; }
#endregion
@@ -125,9 +125,9 @@ public override long ValueCount()
/// Returns all keys currently stored in the index
/// </summary>
/// <returns>All stored keys</returns>
- public override IEnumerable<IComparable> Keys()
+ public override ICloseableEnumerable<IComparable> Keys()
{
- return _Index.Keys;
+ return new CloseableEnumerable<IComparable>(_Index.Keys);
}
/// <summary>
@@ -210,7 +210,7 @@ public override Type GetKeyType()
/// <param name="myKey">Search key</param>
/// <param name="myVertexIDs">Associated values</param>
/// <returns>True, if the key exists</returns>
- public override bool TryGetValues(IComparable myKey, out IEnumerable<long> myVertexIDs)
+ public override bool TryGetValues(IComparable myKey, out ICloseableEnumerable<long> myVertexIDs)
{
if (!KeyNullSupportCheck(myKey))
{
@@ -219,7 +219,7 @@ public override bool TryGetValues(IComparable myKey, out IEnumerable<long> myVer
var values = new HashSet<long>();
var done = _Index.TryGetValue(myKey, out values);
- myVertexIDs = values;
+ myVertexIDs = new CloseableEnumerable<long>(values);
return done;
}
@@ -231,7 +231,7 @@ public override bool TryGetValues(IComparable myKey, out IEnumerable<long> myVer
/// </summary>
/// <param name="myKey">Search key</param>
/// <returns>All values associated to the key.</returns>
- public override IEnumerable<long> this[IComparable myKey]
+ public override ICloseableEnumerable<long> this[IComparable myKey]
{
get
{
@@ -243,7 +243,7 @@ public override bool TryGetValues(IComparable myKey, out IEnumerable<long> myVer
HashSet<Int64> values;
if (_Index.TryGetValue(myKey, out values))
{
- return values;
+ return new CloseableEnumerable<Int64>(values);
}
else
{
Oops, something went wrong.

0 comments on commit 716b8c3

Please sign in to comment.