You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jh...@apache.org on 2015/12/07 19:57:10 UTC
calcite git commit: [CALCITE-1008] Replace Closeable with
AutoCloseable
Repository: calcite
Updated Branches:
refs/heads/master 8281668fb -> 9c86556ff
[CALCITE-1008] Replace Closeable with AutoCloseable
Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/9c86556f
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/9c86556f
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/9c86556f
Branch: refs/heads/master
Commit: 9c86556ff397f2548bffe90e7e338774d329211d
Parents: 8281668
Author: Julian Hyde <jh...@apache.org>
Authored: Sat Dec 5 23:29:58 2015 -0800
Committer: Julian Hyde <jh...@apache.org>
Committed: Sat Dec 5 23:29:58 2015 -0800
----------------------------------------------------------------------
.../org/apache/calcite/avatica/util/Cursor.java | 3 +-
.../calcite/avatica/util/IteratorCursor.java | 10 ++--
.../org/apache/calcite/sql/test/SqlTester.java | 3 +-
.../org/apache/calcite/linq4j/Enumerator.java | 4 +-
.../java/org/apache/calcite/linq4j/Linq4j.java | 52 ++++----------------
5 files changed, 18 insertions(+), 54 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/calcite/blob/9c86556f/avatica/src/main/java/org/apache/calcite/avatica/util/Cursor.java
----------------------------------------------------------------------
diff --git a/avatica/src/main/java/org/apache/calcite/avatica/util/Cursor.java b/avatica/src/main/java/org/apache/calcite/avatica/util/Cursor.java
index f700763..8eab72f 100644
--- a/avatica/src/main/java/org/apache/calcite/avatica/util/Cursor.java
+++ b/avatica/src/main/java/org/apache/calcite/avatica/util/Cursor.java
@@ -18,7 +18,6 @@ package org.apache.calcite.avatica.util;
import org.apache.calcite.avatica.ColumnMetaData;
-import java.io.Closeable;
import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
@@ -41,7 +40,7 @@ import java.util.Map;
* Interface to an iteration that is similar to, and can easily support,
* a JDBC {@link java.sql.ResultSet}, but is simpler to implement.
*/
-public interface Cursor extends Closeable {
+public interface Cursor extends AutoCloseable {
/**
* Creates a list of accessors, one per column.
*
http://git-wip-us.apache.org/repos/asf/calcite/blob/9c86556f/avatica/src/main/java/org/apache/calcite/avatica/util/IteratorCursor.java
----------------------------------------------------------------------
diff --git a/avatica/src/main/java/org/apache/calcite/avatica/util/IteratorCursor.java b/avatica/src/main/java/org/apache/calcite/avatica/util/IteratorCursor.java
index 781f6c6..c09373b 100644
--- a/avatica/src/main/java/org/apache/calcite/avatica/util/IteratorCursor.java
+++ b/avatica/src/main/java/org/apache/calcite/avatica/util/IteratorCursor.java
@@ -16,8 +16,6 @@
*/
package org.apache.calcite.avatica.util;
-import java.io.Closeable;
-import java.io.IOException;
import java.util.Iterator;
import java.util.NoSuchElementException;
@@ -57,10 +55,12 @@ public abstract class IteratorCursor<E> extends PositionedCursor<E> {
public void close() {
current = null;
position = Position.CLOSED;
- if (iterator instanceof Closeable) {
+ if (iterator instanceof AutoCloseable) {
try {
- ((Closeable) iterator).close();
- } catch (IOException e) {
+ ((AutoCloseable) iterator).close();
+ } catch (RuntimeException e) {
+ throw e;
+ } catch (Exception e) {
throw new RuntimeException(e);
}
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/9c86556f/core/src/test/java/org/apache/calcite/sql/test/SqlTester.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/sql/test/SqlTester.java b/core/src/test/java/org/apache/calcite/sql/test/SqlTester.java
index 5c14704..4144eb1 100644
--- a/core/src/test/java/org/apache/calcite/sql/test/SqlTester.java
+++ b/core/src/test/java/org/apache/calcite/sql/test/SqlTester.java
@@ -25,7 +25,6 @@ import org.apache.calcite.sql.validate.SqlConformance;
import org.apache.calcite.sql.validate.SqlMonotonicity;
import org.apache.calcite.test.SqlValidatorTestCase;
-import java.io.Closeable;
import java.sql.ResultSet;
/**
@@ -41,7 +40,7 @@ import java.sql.ResultSet;
* queries in different ways, for example, using a C++ versus Java calculator.
* An implementation might even ignore certain calls altogether.
*/
-public interface SqlTester extends Closeable, SqlValidatorTestCase.Tester {
+public interface SqlTester extends AutoCloseable, SqlValidatorTestCase.Tester {
//~ Enums ------------------------------------------------------------------
/**
http://git-wip-us.apache.org/repos/asf/calcite/blob/9c86556f/linq4j/src/main/java/org/apache/calcite/linq4j/Enumerator.java
----------------------------------------------------------------------
diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/Enumerator.java b/linq4j/src/main/java/org/apache/calcite/linq4j/Enumerator.java
index 143e644..0bc2e01 100644
--- a/linq4j/src/main/java/org/apache/calcite/linq4j/Enumerator.java
+++ b/linq4j/src/main/java/org/apache/calcite/linq4j/Enumerator.java
@@ -16,8 +16,6 @@
*/
package org.apache.calcite.linq4j;
-import java.io.Closeable;
-
/**
* Supports a simple iteration over a collection.
*
@@ -28,7 +26,7 @@ import java.io.Closeable;
*
* @param <T> Element type
*/
-public interface Enumerator<T> extends Closeable {
+public interface Enumerator<T> extends AutoCloseable {
/**
* Gets the current element in the collection.
*
http://git-wip-us.apache.org/repos/asf/calcite/blob/9c86556f/linq4j/src/main/java/org/apache/calcite/linq4j/Linq4j.java
----------------------------------------------------------------------
diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/Linq4j.java b/linq4j/src/main/java/org/apache/calcite/linq4j/Linq4j.java
index da46850..c0d8d75 100644
--- a/linq4j/src/main/java/org/apache/calcite/linq4j/Linq4j.java
+++ b/linq4j/src/main/java/org/apache/calcite/linq4j/Linq4j.java
@@ -20,11 +20,7 @@ import org.apache.calcite.linq4j.function.Function1;
import com.google.common.collect.Lists;
-import java.io.Closeable;
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -41,9 +37,6 @@ public abstract class Linq4j {
private static final Object DUMMY = new Object();
- private static final Method AUTO_CLOSEABLE_CLOSE_METHOD =
- getMethod("java.lang.AutoCloseable", "close");
-
public static Method getMethod(String className, String methodName,
Class... parameterTypes) {
try {
@@ -436,39 +429,13 @@ public abstract class Linq4j {
/** Closes an iterator, if it can be closed. */
private static <T> void closeIterator(Iterator<T> iterator) {
- if (AUTO_CLOSEABLE_CLOSE_METHOD != null) {
- // JDK 1.7 or later
- if (AUTO_CLOSEABLE_CLOSE_METHOD.getDeclaringClass()
- .isInstance(iterator)) {
- try {
- AUTO_CLOSEABLE_CLOSE_METHOD.invoke(iterator);
- } catch (IllegalAccessException e) {
- throw new RuntimeException(e);
- } catch (InvocationTargetException e) {
- throw new RuntimeException(e.getCause());
- }
- }
- } else {
- // JDK 1.5 or 1.6. No AutoCloseable. Cover the two most common cases
- // with a close().
- if (iterator instanceof Closeable) {
- try {
- ((Closeable) iterator).close();
- return;
- } catch (RuntimeException e) {
- throw e;
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- if (iterator instanceof ResultSet) {
- try {
- ((ResultSet) iterator).close();
- } catch (RuntimeException e) {
- throw e;
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
+ if (iterator instanceof AutoCloseable) {
+ try {
+ ((AutoCloseable) iterator).close();
+ } catch (RuntimeException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
}
}
}
@@ -687,7 +654,8 @@ public abstract class Linq4j {
}
/** Iterator that reads from an underlying {@link Enumerator}. */
- private static class EnumeratorIterator<T> implements Iterator<T>, Closeable {
+ private static class EnumeratorIterator<T>
+ implements Iterator<T>, AutoCloseable {
private final Enumerator<T> enumerator;
boolean hasNext;
@@ -710,7 +678,7 @@ public abstract class Linq4j {
throw new UnsupportedOperationException();
}
- public void close() throws IOException {
+ public void close() {
enumerator.close();
}
}