ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [18/31] ignite git commit: Old code to new approach.
Date Tue, 19 Dec 2017 12:18:15 GMT
Old code to new approach.


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

Branch: refs/heads/ignite-6022-proto
Commit: 94aabdab98888a3783196486a1c08fb1ab1898ad
Parents: 58ffec9
Author: devozerov <vozerov@gridgain.com>
Authored: Mon Dec 18 11:24:44 2017 +0300
Committer: devozerov <vozerov@gridgain.com>
Committed: Mon Dec 18 11:24:44 2017 +0300

----------------------------------------------------------------------
 .../processors/query/h2/dml/DmlArgument.java    |  31 ++++++
 .../processors/query/h2/dml/DmlArguments.java   | 105 +++++++++++++++++++
 .../processors/query/h2/dml/FastUpdate.java     |  91 ++--------------
 .../query/h2/dml/FastUpdateArguments.java       |  10 +-
 4 files changed, 147 insertions(+), 90 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/94aabdab/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/DmlArgument.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/DmlArgument.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/DmlArgument.java
new file mode 100644
index 0000000..b3c3dce
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/DmlArgument.java
@@ -0,0 +1,31 @@
+/*
+ * 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.apache.ignite.internal.processors.query.h2.dml;
+
+/**
+ * DML argument
+ */
+public interface DmlArgument {
+    /**
+     * Get argument from parameter list.
+     *
+     * @param params Query input parameters.
+     * @return value.
+     */
+    Object get(Object[] params);
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/94aabdab/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/DmlArguments.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/DmlArguments.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/DmlArguments.java
new file mode 100644
index 0000000..87fc588
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/DmlArguments.java
@@ -0,0 +1,105 @@
+/*
+ * 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.apache.ignite.internal.processors.query.h2.dml;
+
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.processors.query.h2.sql.GridSqlConst;
+import org.apache.ignite.internal.processors.query.h2.sql.GridSqlElement;
+import org.apache.ignite.internal.processors.query.h2.sql.GridSqlParameter;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * DML arguments factory.
+ */
+public class DmlArguments {
+    /** Operand that always evaluates as {@code null}. */
+    private final static DmlArgument NULL_ARG = new ConstantArgument(null);
+
+    /**
+     * Create argument from AST element.
+     *
+     * @param el Element.
+     * @return DML argument.
+     */
+    public static DmlArgument create(@Nullable GridSqlElement el) {
+        assert el == null ^ (el instanceof GridSqlConst || el instanceof GridSqlParameter);
+
+        if (el == null)
+            return NULL_ARG;
+
+        if (el instanceof GridSqlConst)
+            return new ConstantArgument(((GridSqlConst)el).value().getObject());
+        else
+            return new ParamArgument(((GridSqlParameter)el).index());
+    }
+
+    /**
+     * Private constructor.
+     */
+    private DmlArguments() {
+        // No-op.
+    }
+
+    /**
+     * Value argument.
+     */
+    private static class ConstantArgument implements DmlArgument {
+        /** Value to return. */
+        private final Object val;
+
+        /**
+         * Constructor.
+         *
+         * @param val Value.
+         */
+        private ConstantArgument(Object val) {
+            this.val = val;
+        }
+
+        /** {@inheritDoc} */
+        public Object get(Object[] params) {
+            return val;
+        }
+    }
+
+    /**
+     * Parameter argument.
+     */
+    private static class ParamArgument implements DmlArgument {
+        /** Value to return. */
+        private final int paramIdx;
+
+        /**
+         * Constructor.
+         *
+         * @param paramIdx Parameter index.
+         */
+        private ParamArgument(int paramIdx) {
+            assert paramIdx >= 0;
+
+            this.paramIdx = paramIdx;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Object get(Object[] params) {
+            assert params.length > paramIdx;
+
+            return params[paramIdx];
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/94aabdab/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/FastUpdate.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/FastUpdate.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/FastUpdate.java
index e662245..dcceff3 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/FastUpdate.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/FastUpdate.java
@@ -20,26 +20,21 @@ package org.apache.ignite.internal.processors.query.h2.dml;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.internal.processors.cache.GridCacheAdapter;
 import org.apache.ignite.internal.processors.query.h2.UpdateResult;
-import org.apache.ignite.internal.processors.query.h2.sql.GridSqlConst;
 import org.apache.ignite.internal.processors.query.h2.sql.GridSqlElement;
-import org.apache.ignite.internal.processors.query.h2.sql.GridSqlParameter;
 import org.jetbrains.annotations.Nullable;
 
 /**
  * Arguments for fast, query-less UPDATE or DELETE - key and, optionally, value and new value.
  */
 public final class FastUpdate {
-    /** Operand that always evaluates as {@code null}. */
-    private final static FastUpdateArgument NULL_ARG = new ConstantArgument(null);
-
     /** Operand to compute key. */
-    private final FastUpdateArgument keyArg;
+    private final DmlArgument keyArg;
 
     /** Operand to compute value. */
-    private final FastUpdateArgument valArg;
+    private final DmlArgument valArg;
 
     /** Operand to compute new value. */
-    private final FastUpdateArgument newValArg;
+    private final DmlArgument newValArg;
 
     /**
      * Create fast update instance.
@@ -50,9 +45,9 @@ public final class FastUpdate {
      * @return Fast update.
      */
     public static FastUpdate create(GridSqlElement key, GridSqlElement val, @Nullable GridSqlElement
newVal) {
-        FastUpdateArgument keyArg = argument(key);
-        FastUpdateArgument valArg = argument(val);
-        FastUpdateArgument newValArg = argument(newVal);
+        DmlArgument keyArg = DmlArguments.create(key);
+        DmlArgument valArg = DmlArguments.create(val);
+        DmlArgument newValArg = DmlArguments.create(newVal);
 
         return new FastUpdate(keyArg, valArg, newValArg);
     }
@@ -64,7 +59,7 @@ public final class FastUpdate {
      * @param valArg Value argument.
      * @param newValArg New value argument.
      */
-    private FastUpdate(FastUpdateArgument keyArg, FastUpdateArgument valArg, FastUpdateArgument
newValArg) {
+    private FastUpdate(DmlArgument keyArg, DmlArgument valArg, DmlArgument newValArg) {
         this.keyArg = keyArg;
         this.valArg = valArg;
         this.newValArg = newValArg;
@@ -80,12 +75,12 @@ public final class FastUpdate {
      */
     @SuppressWarnings({"unchecked", "ConstantConditions"})
     public UpdateResult execute(GridCacheAdapter cache, Object[] args) throws IgniteCheckedException
{
-        Object key = keyArg.apply(args);
+        Object key = keyArg.get(args);
 
         assert key != null;
 
-        Object val = valArg.apply(args);
-        Object newVal = newValArg.apply(args);
+        Object val = valArg.get(args);
+        Object newVal = newValArg.get(args);
 
         boolean res;
 
@@ -106,70 +101,4 @@ public final class FastUpdate {
 
         return res ? UpdateResult.ONE : UpdateResult.ZERO;
     }
-
-    /**
-     * Create argument for AST element.
-     *
-     * @param el Element.
-     * @return Argument.
-     */
-    private static FastUpdateArgument argument(@Nullable GridSqlElement el) {
-        assert el == null ^ (el instanceof GridSqlConst || el instanceof GridSqlParameter);
-
-        if (el == null)
-            return NULL_ARG;
-
-        if (el instanceof GridSqlConst)
-            return new ConstantArgument(((GridSqlConst)el).value().getObject());
-        else
-            return new ParamArgument(((GridSqlParameter)el).index());
-    }
-
-    /**
-     * Value argument.
-     */
-    private static class ConstantArgument implements FastUpdateArgument {
-        /** Value to return. */
-        private final Object val;
-
-        /**
-         * Constructor.
-         *
-         * @param val Value.
-         */
-        private ConstantArgument(Object val) {
-            this.val = val;
-        }
-
-        /** {@inheritDoc} */
-        @Override public Object apply(Object[] arg) throws IgniteCheckedException {
-            return val;
-        }
-    }
-
-    /**
-     * Parameter argument.
-     */
-    private static class ParamArgument implements FastUpdateArgument {
-        /** Value to return. */
-        private final int paramIdx;
-
-        /**
-         * Constructor.
-         *
-         * @param paramIdx Parameter index.
-         */
-        private ParamArgument(int paramIdx) {
-            assert paramIdx >= 0;
-
-            this.paramIdx = paramIdx;
-        }
-
-        /** {@inheritDoc} */
-        @Override public Object apply(Object[] arg) throws IgniteCheckedException {
-            assert arg.length > paramIdx;
-
-            return arg[paramIdx];
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/94aabdab/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/FastUpdateArguments.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/FastUpdateArguments.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/FastUpdateArguments.java
index 9ba66f1..c7a45a3 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/FastUpdateArguments.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/FastUpdateArguments.java
@@ -34,7 +34,7 @@ public final class FastUpdateArguments {
 
     /** */
     public FastUpdateArguments(FastUpdateArgument key, FastUpdateArgument val, FastUpdateArgument
newVal) {
-        assert key != null && key != NULL_ARGUMENT;
+        assert key != null;
         assert val != null;
         assert newVal != null;
 
@@ -43,14 +43,6 @@ public final class FastUpdateArguments {
         this.newVal = newVal;
     }
 
-    /** Operand that always evaluates as {@code null}. */
-    public final static FastUpdateArgument NULL_ARGUMENT = new FastUpdateArgument() {
-        /** {@inheritDoc} */
-        @Override public Object apply(Object[] arg) throws IgniteCheckedException {
-            return null;
-        }
-    };
-
     /**
      * Simple constant value based operand.
      */


Mime
View raw message