Return-Path: X-Original-To: apmail-calcite-commits-archive@www.apache.org Delivered-To: apmail-calcite-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9903B18A98 for ; Mon, 7 Dec 2015 18:57:11 +0000 (UTC) Received: (qmail 65491 invoked by uid 500); 7 Dec 2015 18:57:11 -0000 Delivered-To: apmail-calcite-commits-archive@calcite.apache.org Received: (qmail 65364 invoked by uid 500); 7 Dec 2015 18:57:11 -0000 Mailing-List: contact commits-help@calcite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@calcite.apache.org Delivered-To: mailing list commits@calcite.apache.org Received: (qmail 64996 invoked by uid 99); 7 Dec 2015 18:57:11 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 07 Dec 2015 18:57:11 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id DE34AE0537; Mon, 7 Dec 2015 18:57:10 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jhyde@apache.org To: commits@calcite.apache.org Message-Id: <286bfc97ad1a475994a736d717ca1ff0@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: calcite git commit: [CALCITE-1008] Replace Closeable with AutoCloseable Date: Mon, 7 Dec 2015 18:57:10 +0000 (UTC) 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 Authored: Sat Dec 5 23:29:58 2015 -0800 Committer: Julian Hyde 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 extends PositionedCursor { 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 Element type */ -public interface Enumerator extends Closeable { +public interface Enumerator 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 void closeIterator(Iterator 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 implements Iterator, Closeable { + private static class EnumeratorIterator + implements Iterator, AutoCloseable { private final Enumerator enumerator; boolean hasNext; @@ -710,7 +678,7 @@ public abstract class Linq4j { throw new UnsupportedOperationException(); } - public void close() throws IOException { + public void close() { enumerator.close(); } }