jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [04/15] jena git commit: Use try-resource ; remove warnings (Java 7)
Date Tue, 23 Dec 2014 17:59:00 GMT
Use try-resource ; remove warnings (Java 7)


Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/e0cfdb23
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/e0cfdb23
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/e0cfdb23

Branch: refs/heads/master
Commit: e0cfdb234f2ccc16d961847bff98f8ae6f9d5841
Parents: 6d0803d
Author: Andy Seaborne <andy@apache.org>
Authored: Tue Dec 23 13:19:14 2014 +0000
Committer: Andy Seaborne <andy@apache.org>
Committed: Tue Dec 23 13:19:14 2014 +0000

----------------------------------------------------------------------
 .../jena/query/spatial/SpatialIndexLucene.java  | 26 +++++++++-----------
 .../assembler/SpatialIndexLuceneAssembler.java  |  1 +
 .../AbstractTestDatasetWithSpatialIndex.java    |  9 +++----
 .../jena/query/spatial/SpatialSearchUtil.java   |  1 +
 4 files changed, 16 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/e0cfdb23/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialIndexLucene.java
----------------------------------------------------------------------
diff --git a/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialIndexLucene.java
b/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialIndexLucene.java
index f515d6e..3e3e3be 100644
--- a/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialIndexLucene.java
+++ b/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialIndexLucene.java
@@ -176,21 +176,17 @@ public class SpatialIndexLucene implements SpatialIndex {
 		return doc;
 	}
 	
-	@Override
-	public List<Node> query(Shape shape, int limit, SpatialOperation operation) {
-		try {
-			// Upgrade at Java7 ...
-			IndexReader indexReader = DirectoryReader.open(directory);
-			try {
-				return query$(indexReader, shape, limit, operation);
-			} finally {
-				indexReader.close();
-			}
-		} catch (Exception ex) {
-			exception(ex);
-			return null;
-		}
-	}
+    @Override
+    public List<Node> query(Shape shape, int limit, SpatialOperation operation) {
+        // Upgrade at Java7 ...
+        try (IndexReader indexReader = DirectoryReader.open(directory)) {
+            return query$(indexReader, shape, limit, operation) ;
+        }
+        catch (Exception ex) {
+            exception(ex) ;
+            return null ;
+        }
+    }
 	
 	private List<Node> query$(IndexReader indexReader, Shape shape, int limit, SpatialOperation
operation) throws IOException {
 		if (limit <= 0)

http://git-wip-us.apache.org/repos/asf/jena/blob/e0cfdb23/jena-spatial/src/main/java/org/apache/jena/query/spatial/assembler/SpatialIndexLuceneAssembler.java
----------------------------------------------------------------------
diff --git a/jena-spatial/src/main/java/org/apache/jena/query/spatial/assembler/SpatialIndexLuceneAssembler.java
b/jena-spatial/src/main/java/org/apache/jena/query/spatial/assembler/SpatialIndexLuceneAssembler.java
index 3aba4e2..5b48b5e 100644
--- a/jena-spatial/src/main/java/org/apache/jena/query/spatial/assembler/SpatialIndexLuceneAssembler.java
+++ b/jena-spatial/src/main/java/org/apache/jena/query/spatial/assembler/SpatialIndexLuceneAssembler.java
@@ -51,6 +51,7 @@ public class SpatialIndexLuceneAssembler extends AssemblerBase
         .
     */
 
+    @SuppressWarnings("resource")
     @Override
     public SpatialIndex open(Assembler a, Resource root, Mode mode)
     {

http://git-wip-us.apache.org/repos/asf/jena/blob/e0cfdb23/jena-spatial/src/test/java/org/apache/jena/query/spatial/AbstractTestDatasetWithSpatialIndex.java
----------------------------------------------------------------------
diff --git a/jena-spatial/src/test/java/org/apache/jena/query/spatial/AbstractTestDatasetWithSpatialIndex.java
b/jena-spatial/src/test/java/org/apache/jena/query/spatial/AbstractTestDatasetWithSpatialIndex.java
index 7bc6165..2768720 100644
--- a/jena-spatial/src/test/java/org/apache/jena/query/spatial/AbstractTestDatasetWithSpatialIndex.java
+++ b/jena-spatial/src/test/java/org/apache/jena/query/spatial/AbstractTestDatasetWithSpatialIndex.java
@@ -90,9 +90,8 @@ public abstract class AbstractTestDatasetWithSpatialIndex {
 	public static void doTestQuery(Dataset dataset, String queryString, Set<String> expectedEntityURIs,
int expectedNumResults, boolean throwException) {
 		Query query = QueryFactory.create(queryString) ;
 		
-		QueryExecution qexec = QueryExecutionFactory.create(query, dataset) ;
-		try {
-			dataset.begin(ReadWrite.READ);
+		dataset.begin(ReadWrite.READ);
+		try ( QueryExecution qexec = QueryExecutionFactory.create(query, dataset) ) {
 		    ResultSet results = qexec.execSelect() ;
 
 		    boolean b = ( (expectedNumResults > 0) == results.hasNext() ) ;
@@ -115,9 +114,7 @@ public abstract class AbstractTestDatasetWithSpatialIndex {
 			if (!throwException){
 				fail("The exception is not supposed to be thrown: "+ e.getMessage());
 			}	
-		} finally { qexec.close() ; dataset.end() ; }			
-		
-	
+		} finally { dataset.end() ; }			
 	}
 	
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/e0cfdb23/jena-spatial/src/test/java/org/apache/jena/query/spatial/SpatialSearchUtil.java
----------------------------------------------------------------------
diff --git a/jena-spatial/src/test/java/org/apache/jena/query/spatial/SpatialSearchUtil.java
b/jena-spatial/src/test/java/org/apache/jena/query/spatial/SpatialSearchUtil.java
index 38f2a69..891f6c2 100644
--- a/jena-spatial/src/test/java/org/apache/jena/query/spatial/SpatialSearchUtil.java
+++ b/jena-spatial/src/test/java/org/apache/jena/query/spatial/SpatialSearchUtil.java
@@ -66,6 +66,7 @@ public class SpatialSearchUtil {
         try {
             Directory directory = FSDirectory.open(indexDir) ;
             IndexWriterConfig wConfig = new IndexWriterConfig(VER, analyzer) ;
+            @SuppressWarnings("resource")
             IndexWriter indexWriter = new IndexWriter(directory, wConfig) ;
             indexWriter.close() ; // force creation of the index files
         } catch (IOException ex) {


Mime
View raw message