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 2014/08/11 21:46:03 UTC
[6/8] git commit: Add class Holder,
a mutable slot that can contain one object.
Add class Holder, a mutable slot that can contain one object.
Project: http://git-wip-us.apache.org/repos/asf/incubator-optiq/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-optiq/commit/5a42f3f3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-optiq/tree/5a42f3f3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-optiq/diff/5a42f3f3
Branch: refs/heads/master
Commit: 5a42f3f30cb1103ac9750fa40f9ca43e97837aa8
Parents: d8bf473
Author: Julian Hyde <jh...@apache.org>
Authored: Fri Aug 8 16:41:59 2014 -0700
Committer: Julian Hyde <jh...@apache.org>
Committed: Fri Aug 8 16:41:59 2014 -0700
----------------------------------------------------------------------
.../optiq/jdbc/OptiqConnectionImpl.java | 7 +--
.../net/hydromatic/optiq/prepare/Prepare.java | 10 ++--
.../main/java/org/eigenbase/util/Holder.java | 55 ++++++++++++++++++++
.../eigenbase/sql/test/SqlOperatorBaseTest.java | 6 +--
4 files changed, 67 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-optiq/blob/5a42f3f3/core/src/main/java/net/hydromatic/optiq/jdbc/OptiqConnectionImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/net/hydromatic/optiq/jdbc/OptiqConnectionImpl.java b/core/src/main/java/net/hydromatic/optiq/jdbc/OptiqConnectionImpl.java
index e030140..6311029 100644
--- a/core/src/main/java/net/hydromatic/optiq/jdbc/OptiqConnectionImpl.java
+++ b/core/src/main/java/net/hydromatic/optiq/jdbc/OptiqConnectionImpl.java
@@ -39,6 +39,7 @@ import org.eigenbase.sql.advise.SqlAdvisorValidator;
import org.eigenbase.sql.fun.SqlStdOperatorTable;
import org.eigenbase.sql.validate.SqlConformance;
import org.eigenbase.sql.validate.SqlValidatorWithHints;
+import org.eigenbase.util.Holder;
import com.google.common.collect.*;
@@ -273,11 +274,11 @@ abstract class OptiqConnectionImpl
// Store the time at which the query started executing. The SQL
// standard says that functions such as CURRENT_TIMESTAMP return the
// same value throughout the query.
- final long[] times = {System.currentTimeMillis()};
+ final Holder<Long> timeHolder = Holder.of(System.currentTimeMillis());
// Give a hook chance to alter the clock.
- Hook.CURRENT_TIME.run(times);
- final long time = times[0];
+ Hook.CURRENT_TIME.run(timeHolder);
+ final long time = timeHolder.get();
final TimeZone timeZone = connection.getTimeZone();
final long localOffset = timeZone.getOffset(time);
final long currentOffset = localOffset;
http://git-wip-us.apache.org/repos/asf/incubator-optiq/blob/5a42f3f3/core/src/main/java/net/hydromatic/optiq/prepare/Prepare.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/net/hydromatic/optiq/prepare/Prepare.java b/core/src/main/java/net/hydromatic/optiq/prepare/Prepare.java
index 705389a..bae33cf 100644
--- a/core/src/main/java/net/hydromatic/optiq/prepare/Prepare.java
+++ b/core/src/main/java/net/hydromatic/optiq/prepare/Prepare.java
@@ -36,6 +36,7 @@ import org.eigenbase.sql.validate.*;
import org.eigenbase.sql2rel.SqlToRelConverter;
import org.eigenbase.trace.EigenbaseTimingTracer;
import org.eigenbase.trace.EigenbaseTrace;
+import org.eigenbase.util.Holder;
import org.eigenbase.util.Pair;
import com.google.common.collect.ImmutableList;
@@ -128,11 +129,10 @@ public abstract class Prepare {
private Program getProgram() {
// Allow a test to override the planner.
final List<Materialization> materializations = ImmutableList.of();
- final Pair<List<Materialization>, Program[]> pair =
- Pair.of(materializations, new Program[1]);
- Hook.PROGRAM.run(pair);
- if (pair.right[0] != null) {
- return pair.right[0];
+ final Holder<Program> holder = Holder.of(null);
+ Hook.PROGRAM.run(Pair.of(materializations, holder));
+ if (holder.get() != null) {
+ return holder.get();
}
return Programs.standard();
http://git-wip-us.apache.org/repos/asf/incubator-optiq/blob/5a42f3f3/core/src/main/java/org/eigenbase/util/Holder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eigenbase/util/Holder.java b/core/src/main/java/org/eigenbase/util/Holder.java
new file mode 100644
index 0000000..d4e8787
--- /dev/null
+++ b/core/src/main/java/org/eigenbase/util/Holder.java
@@ -0,0 +1,55 @@
+/*
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to you under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+*/
+package org.eigenbase.util;
+
+/**
+ * A mutable slot that can contain one object.
+ *
+ * <p>A holder is useful for implementing OUT or IN-OUT parameters.</p>
+ *
+ * <p>It is possible to sub-class to receive events on get or set.</p>
+ *
+ * @param <E> Element type
+ */
+public class Holder<E> {
+ private E e;
+
+ /** Creates a Holder containing a given value.
+ *
+ * <p>Call this method from a derived constructor or via the {@link #of}
+ * method. */
+ protected Holder(E e) {
+ this.e = e;
+ }
+
+ /** Sets the value. */
+ public void set(E e) {
+ this.e = e;
+ }
+
+ /** Gets the value. */
+ public E get() {
+ return e;
+ }
+
+ /** Creates a holder containing a given value. */
+ public static <E> Holder<E> of(E e) {
+ return new Holder<E>(e);
+ }
+}
+
+// End Holder.java
http://git-wip-us.apache.org/repos/asf/incubator-optiq/blob/5a42f3f3/core/src/test/java/org/eigenbase/sql/test/SqlOperatorBaseTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eigenbase/sql/test/SqlOperatorBaseTest.java b/core/src/test/java/org/eigenbase/sql/test/SqlOperatorBaseTest.java
index 232a43a..bba43ce 100644
--- a/core/src/test/java/org/eigenbase/sql/test/SqlOperatorBaseTest.java
+++ b/core/src/test/java/org/eigenbase/sql/test/SqlOperatorBaseTest.java
@@ -3869,9 +3869,9 @@ public abstract class SqlOperatorBaseTest {
calendar.set(Calendar.MILLISECOND, 15);
final long timeInMillis = calendar.getTimeInMillis();
closeable = Hook.CURRENT_TIME.addThread(
- new Function<long[], Void>() {
- public Void apply(long[] o) {
- o[0] = timeInMillis;
+ new Function<Holder<Long>, Void>() {
+ public Void apply(Holder<Long> o) {
+ o.set(timeInMillis);
return null;
}
});