lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject [Lucene.Net] svn commit: r1085312 - in /incubator/lucene.net/trunk/C#/src: Lucene.Net/Index/ Lucene.Net/Search/ Lucene.Net/Store/ Test/ Test/Index/ Test/Search/ Test/Store/
Date Fri, 25 Mar 2011 10:45:24 GMT
Author: digy
Date: Fri Mar 25 10:45:23 2011
New Revision: 1085312

URL: http://svn.apache.org/viewvc?rev=1085312&view=rev
Log:
[LUCENENET-399] [LUCENENET-378] Added IDisposable for IndexWriter,IndexReader,Searcher,Directory
and other subclasses of them.

Modified:
    incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/CompoundFileReader.cs
    incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/IndexReader.cs
    incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/IndexWriter.cs
    incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/IndexSearcher.cs
    incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/MultiSearcher.cs
    incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Searcher.cs
    incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/Directory.cs
    incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/FSDirectory.cs
    incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/FileSwitchDirectory.cs
    incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/RAMDirectory.cs
    incubator/lucene.net/trunk/C#/src/Test/Index/TestFieldsReader.cs
    incubator/lucene.net/trunk/C#/src/Test/Search/JustCompileSearch.cs
    incubator/lucene.net/trunk/C#/src/Test/Store/TestBufferedIndexInput.cs
    incubator/lucene.net/trunk/C#/src/Test/TestSupportClass.cs

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/CompoundFileReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Index/CompoundFileReader.cs?rev=1085312&r1=1085311&r2=1085312&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/CompoundFileReader.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/CompoundFileReader.cs Fri Mar 25 10:45:23
2011
@@ -135,6 +135,14 @@ namespace Lucene.Net.Index
 				stream = null;
 			}
 		}
+
+        /// <summary>
+        /// .NET
+        /// </summary>
+        public override void Dispose()
+        {
+            Close();
+        }
 		
 		public override IndexInput OpenInput(System.String id)
 		{

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/IndexReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Index/IndexReader.cs?rev=1085312&r1=1085311&r2=1085312&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/IndexReader.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/IndexReader.cs Fri Mar 25 10:45:23
2011
@@ -66,7 +66,7 @@ namespace Lucene.Net.Index
 	/// </summary>
 	/// <version>  $Id: IndexReader.java 826049 2009-10-16 19:28:55Z mikemccand $
 	/// </version>
-	public abstract class IndexReader : System.ICloneable
+	public abstract class IndexReader : System.ICloneable, System.IDisposable
 	{
 		private class AnonymousClassFindSegmentsFile:SegmentInfos.FindSegmentsFile
 		{
@@ -1548,6 +1548,14 @@ namespace Lucene.Net.Index
 				}
 			}
 		}
+
+        /// <summary>
+        /// .NET
+        /// </summary>
+        public void Dispose()
+        {
+            Close();
+        }
 		
 		/// <summary>Implements close. </summary>
 		protected internal abstract void  DoClose();

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/IndexWriter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Index/IndexWriter.cs?rev=1085312&r1=1085311&r2=1085312&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/IndexWriter.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/IndexWriter.cs Fri Mar 25 10:45:23
2011
@@ -200,7 +200,7 @@ namespace Lucene.Net.Index
 	* referenced by the "front" of the index). For this, IndexFileDeleter 
 	* keeps track of the last non commit checkpoint.
 	*/
-	public class IndexWriter
+	public class IndexWriter : System.IDisposable
 	{
 		private void  InitBlock()
 		{
@@ -2471,6 +2471,14 @@ namespace Lucene.Net.Index
 		{
 			Close(true);
 		}
+
+        /// <summary>
+        /// .NET
+        /// </summary>
+        public virtual void Dispose()
+        {
+            Close();
+        }
 		
 		/// <summary> Closes the index with or without waiting for currently
 		/// running merges to finish.  This is only meaningful when

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/IndexSearcher.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/IndexSearcher.cs?rev=1085312&r1=1085311&r2=1085312&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/IndexSearcher.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/IndexSearcher.cs Fri Mar 25 10:45:23
2011
@@ -152,6 +152,14 @@ namespace Lucene.Net.Search
 			if (closeReader)
 				reader.Close();
 		}
+
+        /// <summary>
+        /// .NET
+        /// </summary>
+        public override void Dispose()
+        {
+            Close();
+        }
 		
 		// inherit javadoc
 		public override int DocFreq(Term term)

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/MultiSearcher.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/MultiSearcher.cs?rev=1085312&r1=1085311&r2=1085312&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/MultiSearcher.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/MultiSearcher.cs Fri Mar 25 10:45:23
2011
@@ -133,6 +133,14 @@ namespace Lucene.Net.Search
 			{
 				throw new System.NotSupportedException();
 			}
+
+            /// <summary>
+            /// .NET
+            /// </summary>
+            public override void Dispose()
+            {
+                Close();
+            }
 			
 			public override Document Doc(int i)
 			{
@@ -200,7 +208,15 @@ namespace Lucene.Net.Search
 			for (int i = 0; i < searchables.Length; i++)
 				searchables[i].Close();
 		}
-		
+
+        /// <summary>
+        /// .NET
+        /// </summary>
+        public override void Dispose()
+        {
+            Close();
+        }
+
 		public override int DocFreq(Term term)
 		{
 			int docFreq = 0;

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Searcher.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Searcher.cs?rev=1085312&r1=1085311&r2=1085312&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Searcher.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Searcher.cs Fri Mar 25 10:45:23 2011
@@ -31,7 +31,7 @@ namespace Lucene.Net.Search
 	/// Note that you can only access hits from a Searcher as long as it is not yet
 	/// closed, otherwise an IOException will be thrown.
 	/// </summary>
-	public abstract class Searcher : System.MarshalByRefObject, Searchable
+	public abstract class Searcher : System.MarshalByRefObject, Searchable, System.IDisposable
 	{
 		public Searcher()
 		{
@@ -283,6 +283,7 @@ namespace Lucene.Net.Search
 		}
 		abstract public void  Search(Weight weight, Filter filter, Collector results);
 		abstract public void  Close();
+        abstract public void Dispose();
 		abstract public int DocFreq(Term term);
 		abstract public int MaxDoc();
 		abstract public TopDocs Search(Weight weight, Filter filter, int n);

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/Directory.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Store/Directory.cs?rev=1085312&r1=1085311&r2=1085312&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/Directory.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/Directory.cs Fri Mar 25 10:45:23 2011
@@ -39,7 +39,7 @@ namespace Lucene.Net.Store
 	/// 
 	/// </summary>
 	[Serializable]
-	public abstract class Directory
+	public abstract class Directory : System.IDisposable
 	{
 		protected internal volatile bool isOpen = true;
 		
@@ -150,6 +150,8 @@ namespace Lucene.Net.Store
 		
 		/// <summary>Closes the store. </summary>
 		public abstract void  Close();
+
+        public abstract void Dispose();
 		
 		/// <summary> Set the LockFactory that this Directory instance should
 		/// use for its locking implementation.  Each * instance of

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/FSDirectory.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Store/FSDirectory.cs?rev=1085312&r1=1085311&r2=1085312&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/FSDirectory.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/FSDirectory.cs Fri Mar 25 10:45:23
2011
@@ -936,6 +936,14 @@ namespace Lucene.Net.Store
 			}
 		}
 
+        /// <summary>
+        /// .NET
+        /// </summary>
+        public override void Dispose()
+        {
+            Close();
+        }
+
         [System.Obsolete("A DirectoryInfo is more appropriate, however this is here for backwards
compatibility. This will be removed in the 3.0 release")]
 		public virtual System.IO.FileInfo GetFile()
 		{

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/FileSwitchDirectory.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Store/FileSwitchDirectory.cs?rev=1085312&r1=1085311&r2=1085312&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/FileSwitchDirectory.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/FileSwitchDirectory.cs Fri Mar 25 10:45:23
2011
@@ -75,6 +75,14 @@ namespace Lucene.Net.Store
 				doClose = false;
 			}
 		}
+
+        /// <summary>
+        /// .NET
+        /// </summary>
+        public override void Dispose()
+        {
+            Close();
+        }
 		
 		public override System.String[] ListAll()
 		{

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/RAMDirectory.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Store/RAMDirectory.cs?rev=1085312&r1=1085311&r2=1085312&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/RAMDirectory.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/RAMDirectory.cs Fri Mar 25 10:45:23
2011
@@ -309,6 +309,14 @@ namespace Lucene.Net.Store
 			fileMap = null;
 		}
 
+        /// <summary>
+        /// .NET
+        /// </summary>
+        public override void Dispose()
+        {
+            Close();
+        }
+
         public System.Collections.Hashtable fileMap_ForNUnit
         {
             get { return fileMap; }

Modified: incubator/lucene.net/trunk/C#/src/Test/Index/TestFieldsReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Index/TestFieldsReader.cs?rev=1085312&r1=1085311&r2=1085312&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Index/TestFieldsReader.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Index/TestFieldsReader.cs Fri Mar 25 10:45:23 2011
@@ -415,6 +415,11 @@ namespace Lucene.Net.Index
 			{
 				fsDir.Close();
 			}
+
+            public override void Dispose()
+            {
+                this.Close();
+            }
 		}
 		
 		private class FaultyIndexInput:BufferedIndexInput, System.ICloneable

Modified: incubator/lucene.net/trunk/C#/src/Test/Search/JustCompileSearch.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/JustCompileSearch.cs?rev=1085312&r1=1085311&r2=1085312&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/JustCompileSearch.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/JustCompileSearch.cs Fri Mar 25 10:45:23
2011
@@ -53,6 +53,14 @@ namespace Lucene.Net.Search
 			{
 				throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
 			}
+
+            /// <summary>
+            /// .NET
+            /// </summary>
+            public override void Dispose()
+            {
+                Close();
+            }
 			
 			public override Document Doc(int i)
 			{

Modified: incubator/lucene.net/trunk/C#/src/Test/Store/TestBufferedIndexInput.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Store/TestBufferedIndexInput.cs?rev=1085312&r1=1085311&r2=1085312&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Store/TestBufferedIndexInput.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Store/TestBufferedIndexInput.cs Fri Mar 25 10:45:23
2011
@@ -386,6 +386,14 @@ namespace Lucene.Net.Store
 			{
 				dir.Close();
 			}
+
+            /// <summary>
+            /// .NET
+            /// </summary>
+            public override void Dispose()
+            {
+                Close();
+            }
 			
 			public override void  DeleteFile(System.String name)
 			{

Modified: incubator/lucene.net/trunk/C#/src/Test/TestSupportClass.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/TestSupportClass.cs?rev=1085312&r1=1085311&r2=1085312&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/TestSupportClass.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/TestSupportClass.cs Fri Mar 25 10:45:23 2011
@@ -727,6 +727,57 @@ namespace Lucene.Net._SupportClass
         }
     }
 
+    [TestFixture]
+    public class TestIDisposable
+    {
+        [Test]
+        public void TestReadersWriters()
+        {
+            Directory dir;
+            
+            using(dir = new RAMDirectory())
+            {
+                Document doc;
+                IndexWriter writer;
+                IndexReader reader;
+
+                using (writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true))
+                {
+                    Field field = new Field("name", "value", Field.Store.YES,Field.Index.ANALYZED);
+                    doc = new Document();
+                    doc.Add(field);
+                    writer.AddDocument(doc);
+                    writer.Commit();
+
+                    using (reader = writer.GetReader())
+                    {
+                        IndexReader r1 =  reader.Reopen();
+                    }
+
+                    try
+                    {
+                        IndexReader r2 = reader.Reopen();
+                        Assert.Fail("IndexReader shouldn't be open here");
+                    }
+                    catch (AlreadyClosedException)
+                    {
+                    }
+                }
+                try
+                {
+                    writer.AddDocument(doc);
+                    Assert.Fail("IndexWriter shouldn't be open here");
+                }
+                catch (AlreadyClosedException)
+                {
+                }
+
+                Assert.IsTrue(dir.isOpen_ForNUnit, "RAMDirectory");
+            }
+            Assert.IsFalse(dir.isOpen_ForNUnit, "RAMDirectory");
+        }
+    }
+
     internal class BigObject
     {
         public int i = 0;



Mime
View raw message