This is an automated email from the ASF dual-hosted git repository.

vozerov pushed a commit to branch ignite-11310-nodml
in repository https://gitbox.apache.org/repos/asf/ignite.git

commit 093507152a1acf22cb9d438e4c3855dea1c1e924
Author: devozerov <voze...@gridgain.com>
AuthorDate: Thu Feb 14 14:19:17 2019 +0300

    Revert "DML."
    
    This reverts commit b4b5810aad5be3d69675427daa99a4045f65d298.
---
 .../processors/query/h2/ConnectionManager.java     |  4 +-
 .../processors/query/h2/H2CachedStatementKey.java  | 15 +++-
 .../processors/query/h2/H2StatementCache.java      |  2 +-
 .../processors/query/h2/IgniteH2Indexing.java      | 51 +++++++------
 .../processors/query/h2/dml/UpdatePlanBuilder.java | 22 ++++--
 .../query/h2/twostep/GridMapQueryExecutor.java     | 16 ++--
 .../query/h2/H2StatementCacheSelfTest.java         | 86 ++++++++++++++++++++++
 .../IgniteBinaryCacheQueryTestSuite.java           |  2 +
 8 files changed, 154 insertions(+), 44 deletions(-)

diff --git 
a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ConnectionManager.java
 
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ConnectionManager.java
index d0efc0a8..8c1e89c 100644
--- 
a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ConnectionManager.java
+++ 
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ConnectionManager.java
@@ -298,7 +298,7 @@ public class ConnectionManager {
     @Nullable public PreparedStatement cachedPreparedStatement(Connection c, 
String sql) throws SQLException {
         H2StatementCache cache = statementCacheForThread();
 
-        H2CachedStatementKey key = new H2CachedStatementKey(c.getSchema(), 
sql, null);
+        H2CachedStatementKey key = new H2CachedStatementKey(c.getSchema(), 
sql);
 
         PreparedStatement stmt = cache.get(key);
 
@@ -326,7 +326,7 @@ public class ConnectionManager {
         if (stmt == null) {
             H2StatementCache cache = statementCacheForThread();
 
-            H2CachedStatementKey key = new H2CachedStatementKey(c.getSchema(), 
sql, null);
+            H2CachedStatementKey key = new H2CachedStatementKey(c.getSchema(), 
sql);
 
             stmt = PreparedStatementExImpl.wrap(prepareStatementNoCache(c, 
sql));
 
diff --git 
a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2CachedStatementKey.java
 
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2CachedStatementKey.java
index ca94e24..300ed6c 100644
--- 
a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2CachedStatementKey.java
+++ 
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2CachedStatementKey.java
@@ -36,17 +36,28 @@ class H2CachedStatementKey {
     private final byte flags;
 
     /**
+     * Constructor.
+     *
+     * @param schemaName Schema name.
+     * @param sql SQL.
+     */
+    H2CachedStatementKey(String schemaName, String sql) {
+        this(schemaName, sql, null, false);
+    }
+
+    /**
      * Full-fledged constructor.
      *
      * @param schemaName Schema name.
      * @param sql SQL.
      * @param fieldsQry Query with flags.
+     * @param loc DML {@code SELECT} Locality flag.
      */
-    public H2CachedStatementKey(String schemaName, String sql, SqlFieldsQuery 
fieldsQry) {
+    public H2CachedStatementKey(String schemaName, String sql, SqlFieldsQuery 
fieldsQry, boolean loc) {
         this.schemaName = schemaName;
         this.sql = sql;
 
-        if (fieldsQry == null || 
!UpdatePlanBuilder.isSkipReducerOnUpdateQuery(fieldsQry))
+        if (fieldsQry == null || loc || 
!UpdatePlanBuilder.isSkipReducerOnUpdateQuery(fieldsQry))
             this.flags = 0; // flags only relevant for server side updates.
         else {
             this.flags = (byte)(1 +
diff --git 
a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2StatementCache.java
 
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2StatementCache.java
index 41e04c6..edde67a 100644
--- 
a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2StatementCache.java
+++ 
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2StatementCache.java
@@ -94,7 +94,7 @@ final class H2StatementCache {
      * @param sql SQL statement.
      */
     void remove(String schemaName, String sql) {
-        lruStmtCache.remove(new H2CachedStatementKey(schemaName, sql, null));
+        lruStmtCache.remove(new H2CachedStatementKey(schemaName, sql));
     }
 
     /**
diff --git 
a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
 
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
index 0d0c060..d43cfc5 100644
--- 
a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
+++ 
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
@@ -743,7 +743,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
 
         Prepared p = GridSqlQueryParser.prepared(stmt);
 
-        UpdatePlan plan = updatePlan(schemaName, conn, p, null);
+        UpdatePlan plan = updatePlan(schemaName, conn, p, null, true);
 
         IgniteDataStreamer<?, ?> streamer = 
cliCtx.streamerForCache(plan.cacheContext().name());
 
@@ -782,7 +782,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
 
             assert p != null;
 
-            final UpdatePlan plan = updatePlan(schemaName, null, p, null);
+            final UpdatePlan plan = updatePlan(schemaName, null, p, null, 
true);
 
             assert plan.isLocalSubquery();
 
@@ -1668,7 +1668,7 @@ public class IgniteH2Indexing implements 
GridQueryIndexing {
         fldsQry.setLocal(true);
         fldsQry.setDataPageScanEnabled(isDataPageScanEnabled(flags));
 
-        boolean locSplit = false;
+        boolean loc = true;
 
         final boolean replicated = U.isFlagSet(flags, 
GridH2QueryRequest.FLAG_REPLICATED);
 
@@ -1677,9 +1677,10 @@ public class IgniteH2Indexing implements 
GridQueryIndexing {
         if (!replicated
             && !F.isEmpty(ids)
             && (cctx0 = CU.firstPartitioned(cctx.shared(), ids)) != null
-            && cctx0.config().getQueryParallelism() > 1
-        ) {
-            locSplit = true;
+            && cctx0.config().getQueryParallelism() > 1) {
+            fldsQry.setDistributedJoins(true);
+
+            loc = false;
         }
 
         Connection conn = connMgr.connectionForThread().connection(schema);
@@ -1693,7 +1694,7 @@ public class IgniteH2Indexing implements 
GridQueryIndexing {
 
         Prepared prepared = GridSqlQueryParser.prepared(stmt);
 
-        UpdatePlan plan = updatePlan(schema, conn, prepared, fldsQry);
+        UpdatePlan plan = updatePlan(schema, conn, prepared, fldsQry, loc);
 
         GridCacheContext planCctx = plan.cacheContext();
 
@@ -1704,7 +1705,7 @@ public class IgniteH2Indexing implements 
GridQueryIndexing {
 
         // Do a two-step query only if locality flag is not set AND if plan's 
SELECT corresponds to an actual
         // sub-query and not some dummy stuff like "select 1, 2, 3;"
-        if (locSplit && !plan.isLocalSubquery()) {
+        if (!loc && !plan.isLocalSubquery()) {
             SqlFieldsQuery newFieldsQry = new 
SqlFieldsQuery(plan.selectQuery(), fldsQry.isCollocated())
                 .setArgs(fldsQry.getArgs())
                 .setDistributedJoins(fldsQry.isDistributedJoins())
@@ -1903,7 +1904,7 @@ public class IgniteH2Indexing implements 
GridQueryIndexing {
      * @param qry Query.
      * @param filter Filter.
      * @param cancel Cancel state.
-     * @param locSplit Locality flag.
+     * @param loc Locality flag.
      * @return Update result.
      * @throws IgniteCheckedException if failed.
      */
@@ -1912,7 +1913,7 @@ public class IgniteH2Indexing implements 
GridQueryIndexing {
         SqlFieldsQuery qry,
         IndexingQueryFilter filter,
         GridQueryCancel cancel,
-        boolean locSplit
+        boolean loc
     ) throws IgniteCheckedException {
         Connection conn = connMgr.connectionForThread().connection(schemaName);
 
@@ -1930,7 +1931,7 @@ public class IgniteH2Indexing implements 
GridQueryIndexing {
             throw new IgniteCheckedException(e);
         }
 
-        return executeUpdate(schemaName, c, GridSqlQueryParser.prepared(stmt), 
qry, locSplit, filter, cancel);
+        return executeUpdate(schemaName, c, GridSqlQueryParser.prepared(stmt), 
qry, loc, filter, cancel);
     }
 
     /**
@@ -2492,7 +2493,7 @@ public class IgniteH2Indexing implements 
GridQueryIndexing {
 
             List<Object[]> argss = fieldsQry0.batchedArguments();
 
-            UpdatePlan plan = updatePlan(schemaName, conn, prepared, 
fieldsQry0);
+            UpdatePlan plan = updatePlan(schemaName, conn, prepared, 
fieldsQry0, false);
 
             GridCacheContext<?, ?> cctx = plan.cacheContext();
 
@@ -2587,20 +2588,20 @@ public class IgniteH2Indexing implements 
GridQueryIndexing {
      * @param conn Connection.
      * @param prepared Prepared statement.
      * @param fieldsQry Original query.
-     * @param locSplit Whether local split is needed.
+     * @param loc Query locality flag.
      * @param filters Cache name and key filter.
      * @param cancel Cancel.
      * @return Update result (modified items count and failed keys).
      * @throws IgniteCheckedException if failed.
      */
     private UpdateResult executeUpdate(String schemaName, Connection conn, 
Prepared prepared,
-        SqlFieldsQuery fieldsQry, boolean locSplit, IndexingQueryFilter 
filters, GridQueryCancel cancel)
+        SqlFieldsQuery fieldsQry, boolean loc, IndexingQueryFilter filters, 
GridQueryCancel cancel)
         throws IgniteCheckedException {
         Object[] errKeys = null;
 
         long items = 0;
 
-        UpdatePlan plan = updatePlan(schemaName, conn, prepared, fieldsQry);
+        UpdatePlan plan = updatePlan(schemaName, conn, prepared, fieldsQry, 
loc);
 
         GridCacheContext<?, ?> cctx = plan.cacheContext();
 
@@ -2610,7 +2611,7 @@ public class IgniteH2Indexing implements 
GridQueryIndexing {
             UpdateResult r;
 
             try {
-                r = executeUpdate0(schemaName, plan, fieldsQry, locSplit, 
filters, cancel);
+                r = executeUpdate0(schemaName, plan, fieldsQry, loc, filters, 
cancel);
             }
             finally {
                 DmlUtils.restoreKeepBinaryContext(cctx, opCtx);
@@ -2639,7 +2640,7 @@ public class IgniteH2Indexing implements 
GridQueryIndexing {
      * @param schemaName Schema name.
      * @param plan Cache context.
      * @param fieldsQry Fields query.
-     * @param locSplit Whether local split is needed.
+     * @param loc Local query flag.
      * @param filters Cache name and key filter.
      * @param cancel Query cancel state holder.
      * @return Pair [number of successfully processed items; keys that have 
failed to be processed]
@@ -2650,7 +2651,7 @@ public class IgniteH2Indexing implements 
GridQueryIndexing {
         String schemaName,
         final UpdatePlan plan,
         SqlFieldsQuery fieldsQry,
-        boolean locSplit,
+        boolean loc,
         IndexingQueryFilter filters,
         GridQueryCancel cancel
     ) throws IgniteCheckedException {
@@ -2804,7 +2805,7 @@ public class IgniteH2Indexing implements 
GridQueryIndexing {
 
         // Do a two-step query only if locality flag is not set AND if plan's 
SELECT corresponds to an actual
         // sub-query and not some dummy stuff like "select 1, 2, 3;"
-        if (locSplit && !plan.isLocalSubquery()) {
+        if (!loc && !plan.isLocalSubquery()) {
             assert !F.isEmpty(plan.selectQuery());
 
             SqlFieldsQuery newFieldsQry = new 
SqlFieldsQuery(plan.selectQuery(), fieldsQry.isCollocated())
@@ -2847,7 +2848,9 @@ public class IgniteH2Indexing implements 
GridQueryIndexing {
             }, cancel);
         }
 
-        return DmlUtils.processSelectResult(plan, cur, 
fieldsQry.getPageSize());
+        int pageSize = loc ? 0 : fieldsQry.getPageSize();
+
+        return DmlUtils.processSelectResult(plan, cur, pageSize);
     }
 
     /**
@@ -2858,6 +2861,7 @@ public class IgniteH2Indexing implements 
GridQueryIndexing {
      * @param conn Connection.
      * @param p Prepared statement.
      * @param fieldsQry Original fields query.
+     * @param loc Local query flag.
      * @return Update plan.
      */
     @SuppressWarnings("IfMayBeConditional")
@@ -2865,20 +2869,21 @@ public class IgniteH2Indexing implements 
GridQueryIndexing {
         String schema,
         Connection conn,
         Prepared p,
-        SqlFieldsQuery fieldsQry
+        SqlFieldsQuery fieldsQry,
+        boolean loc
     ) throws IgniteCheckedException {
         if (F.eq(QueryUtils.SCHEMA_SYS, schema))
             throw new IgniteSQLException("DML statements are not supported on 
" + schema + " schema",
                 IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
 
-        H2CachedStatementKey planKey = new H2CachedStatementKey(schema, 
p.getSQL(), fieldsQry);
+        H2CachedStatementKey planKey = new H2CachedStatementKey(schema, 
p.getSQL(), fieldsQry, loc);
 
         UpdatePlan res = updatePlanCache.get(planKey);
 
         if (res != null)
             return res;
 
-        res = UpdatePlanBuilder.planForStatement(p, this, conn, fieldsQry, 
updateInTxAllowed);
+        res = UpdatePlanBuilder.planForStatement(p, loc, this, conn, 
fieldsQry, updateInTxAllowed);
 
         // Don't cache re-runs
         UpdatePlan oldRes = updatePlanCache.putIfAbsent(planKey, res);
diff --git 
a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/UpdatePlanBuilder.java
 
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/UpdatePlanBuilder.java
index 1cddabd..c3f55d5 100644
--- 
a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/UpdatePlanBuilder.java
+++ 
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/UpdatePlanBuilder.java
@@ -93,6 +93,7 @@ public final class UpdatePlanBuilder {
      * if available.
      *
      * @param prepared H2's {@link Prepared}.
+     * @param loc Local query flag.
      * @param idx Indexing.
      * @param conn Connection.
      * @param fieldsQry Original query.
@@ -101,6 +102,7 @@ public final class UpdatePlanBuilder {
     @SuppressWarnings("ConstantConditions")
     public static UpdatePlan planForStatement(
         Prepared prepared,
+        boolean loc,
         IgniteH2Indexing idx,
         @Nullable Connection conn,
         @Nullable SqlFieldsQuery fieldsQry,
@@ -141,9 +143,9 @@ public final class UpdatePlanBuilder {
         }
 
         if (stmt instanceof GridSqlMerge || stmt instanceof GridSqlInsert)
-            return planForInsert(stmt, idx, mvccEnabled, conn, fieldsQry);
+            return planForInsert(stmt, loc, idx, mvccEnabled, conn, fieldsQry);
         else if (stmt instanceof GridSqlUpdate || stmt instanceof 
GridSqlDelete)
-            return planForUpdate(stmt, idx, mvccEnabled, conn, fieldsQry);
+            return planForUpdate(stmt, loc, idx, mvccEnabled, conn, fieldsQry);
         else
             throw new IgniteSQLException("Unsupported operation: " + 
prepared.getSQL(),
                 IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
@@ -194,6 +196,7 @@ public final class UpdatePlanBuilder {
      * Prepare update plan for INSERT or MERGE.
      *
      * @param stmt INSERT or MERGE statement.
+     * @param loc Local query flag.
      * @param idx Indexing.
      * @param mvccEnabled Mvcc flag.
      * @param conn Connection.
@@ -202,7 +205,7 @@ public final class UpdatePlanBuilder {
      * @throws IgniteCheckedException if failed.
      */
     @SuppressWarnings("ConstantConditions")
-    private static UpdatePlan planForInsert(GridSqlStatement stmt, 
IgniteH2Indexing idx,
+    private static UpdatePlan planForInsert(GridSqlStatement stmt, boolean 
loc, IgniteH2Indexing idx,
         boolean mvccEnabled, @Nullable Connection conn, @Nullable 
SqlFieldsQuery fieldsQuery)
         throws IgniteCheckedException {
         GridSqlQuery sel = null;
@@ -327,7 +330,7 @@ public final class UpdatePlanBuilder {
         String selectSql = sel != null ? sel.getSQL() : null;
 
         DmlDistributedPlanInfo distributed = (rowsNum == 0 && 
!F.isEmpty(selectSql)) ?
-            checkPlanCanBeDistributed(idx, mvccEnabled, conn, fieldsQuery, 
selectSql,
+            checkPlanCanBeDistributed(idx, mvccEnabled, conn, fieldsQuery, 
loc, selectSql,
             tbl.dataTable().cacheName()) : null;
 
         UpdateMode mode = stmt instanceof GridSqlMerge ? UpdateMode.MERGE : 
UpdateMode.INSERT;
@@ -399,6 +402,7 @@ public final class UpdatePlanBuilder {
      * Prepare update plan for UPDATE or DELETE.
      *
      * @param stmt UPDATE or DELETE statement.
+     * @param loc Local query flag.
      * @param idx Indexing.
      * @param mvccEnabled Mvcc flag.
      * @param conn Connection.
@@ -408,6 +412,7 @@ public final class UpdatePlanBuilder {
      */
     private static UpdatePlan planForUpdate(
         GridSqlStatement stmt,
+        boolean loc,
         IgniteH2Indexing idx,
         boolean mvccEnabled,
         @Nullable Connection conn,
@@ -502,7 +507,7 @@ public final class UpdatePlanBuilder {
                 String selectSql = sel.getSQL();
 
                 DmlDistributedPlanInfo distributed = F.isEmpty(selectSql) ? 
null :
-                    checkPlanCanBeDistributed(idx, mvccEnabled, conn, 
fieldsQuery, selectSql,
+                    checkPlanCanBeDistributed(idx, mvccEnabled, conn, 
fieldsQuery, loc, selectSql,
                     tbl.dataTable().cacheName());
 
                 return new UpdatePlan(
@@ -528,7 +533,7 @@ public final class UpdatePlanBuilder {
                 String selectSql = sel.getSQL();
 
                 DmlDistributedPlanInfo distributed = F.isEmpty(selectSql) ? 
null :
-                    checkPlanCanBeDistributed(idx, mvccEnabled, conn, 
fieldsQuery, selectSql,
+                    checkPlanCanBeDistributed(idx, mvccEnabled, conn, 
fieldsQuery, loc, selectSql,
                     tbl.dataTable().cacheName());
 
                 return new UpdatePlan(
@@ -911,15 +916,16 @@ public final class UpdatePlanBuilder {
      * @param mvccEnabled Mvcc flag.
      * @param conn Connection.
      * @param fieldsQry Initial update query.
+     * @param loc Local query flag.
      * @param selectQry Derived select query.
      * @param cacheName Cache name.
      * @return distributed update plan info, or {@code null} if cannot be 
distributed.
      * @throws IgniteCheckedException if failed.
      */
     private static DmlDistributedPlanInfo 
checkPlanCanBeDistributed(IgniteH2Indexing idx, boolean mvccEnabled,
-        Connection conn, SqlFieldsQuery fieldsQry, String selectQry, String 
cacheName)
+        Connection conn, SqlFieldsQuery fieldsQry, boolean loc, String 
selectQry, String cacheName)
         throws IgniteCheckedException {
-        if ((!mvccEnabled && !isSkipReducerOnUpdateQuery(fieldsQry)) || 
DmlUtils.isBatched(fieldsQry))
+        if (loc || (!mvccEnabled && !isSkipReducerOnUpdateQuery(fieldsQry)) || 
DmlUtils.isBatched(fieldsQry))
             return null;
 
         assert conn != null;
diff --git 
a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMapQueryExecutor.java
 
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMapQueryExecutor.java
index ee0531b..e6bb564 100644
--- 
a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMapQueryExecutor.java
+++ 
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMapQueryExecutor.java
@@ -894,23 +894,23 @@ public class GridMapQueryExecutor {
             fldsQry.setLocal(true);
             fldsQry.setDataPageScanEnabled(req.isDataPageScanEnabled());
 
-            boolean locSplit = false;
+            boolean local = true;
 
             final boolean replicated = 
req.isFlagSet(GridH2QueryRequest.FLAG_REPLICATED);
 
-            if (!replicated &&
-                !F.isEmpty(cacheIds) &&
-                CU.firstPartitioned(ctx.cache().context(), 
cacheIds).config().getQueryParallelism() > 1
-            ) {
-                locSplit = true;
+            if (!replicated && !F.isEmpty(cacheIds) &&
+                CU.firstPartitioned(ctx.cache().context(), 
cacheIds).config().getQueryParallelism() > 1) {
+                fldsQry.setDistributedJoins(true);
+
+                local = false;
             }
 
-            UpdateResult updRes = h2.executeUpdateOnDataNode(req.schemaName(), 
fldsQry, filter, cancel, locSplit);
+            UpdateResult updRes = h2.executeUpdateOnDataNode(req.schemaName(), 
fldsQry, filter, cancel, local);
 
             GridCacheContext<?, ?> mainCctx =
                 !F.isEmpty(cacheIds) ? 
ctx.cache().context().cacheContext(cacheIds.get(0)) : null;
 
-            boolean evt = !locSplit && mainCctx != null && 
mainCctx.events().isRecordable(EVT_CACHE_QUERY_EXECUTED);
+            boolean evt = local && mainCctx != null && 
mainCctx.events().isRecordable(EVT_CACHE_QUERY_EXECUTED);
 
             if (evt) {
                 ctx.event().record(new CacheQueryExecutedEvent<>(
diff --git 
a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/H2StatementCacheSelfTest.java
 
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/H2StatementCacheSelfTest.java
new file mode 100644
index 0000000..de1fb09
--- /dev/null
+++ 
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/H2StatementCacheSelfTest.java
@@ -0,0 +1,86 @@
+/*
+ * 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;
+
+import java.sql.PreparedStatement;
+import 
org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class H2StatementCacheSelfTest extends AbstractIndexingCommonTest {
+    /**
+     * @throws Exception If failed.
+     */
+    @Test
+    public void testEviction() throws Exception {
+        H2StatementCache stmtCache = new H2StatementCache(1);
+        H2CachedStatementKey key1 = new H2CachedStatementKey("", "1");
+        PreparedStatement stmt1 = stmt();
+        stmtCache.put(key1, stmt1);
+
+        assertSame(stmt1, stmtCache.get(key1));
+
+        stmtCache.put(new H2CachedStatementKey("mydb", "2"), stmt());
+
+        assertNull(stmtCache.get(key1));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    @Test
+    public void testLruEvictionInStoreOrder() throws Exception {
+        H2StatementCache stmtCache = new H2StatementCache(2);
+
+        H2CachedStatementKey key1 = new H2CachedStatementKey("", "1");
+        H2CachedStatementKey key2 = new H2CachedStatementKey("", "2");
+        stmtCache.put(key1, stmt());
+        stmtCache.put(key2, stmt());
+
+        stmtCache.put(new H2CachedStatementKey("", "3"), stmt());
+
+        assertNull(stmtCache.get(key1));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    @Test
+    public void testLruEvictionInAccessOrder() throws Exception {
+        H2StatementCache stmtCache = new H2StatementCache(2);
+
+        H2CachedStatementKey key1 = new H2CachedStatementKey("", "1");
+        H2CachedStatementKey key2 = new H2CachedStatementKey("", "2");
+        stmtCache.put(key1, stmt());
+        stmtCache.put(key2, stmt());
+        stmtCache.get(key1);
+
+        stmtCache.put(new H2CachedStatementKey("", "3"), stmt());
+
+        assertNull(stmtCache.get(key2));
+    }
+
+    /**
+     *
+     */
+    private static PreparedStatement stmt() {
+        return new PreparedStatementExImpl(null);
+    }
+}
diff --git 
a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java
 
b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java
index 1dee71b..095518c 100644
--- 
a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java
+++ 
b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java
@@ -205,6 +205,7 @@ import 
org.apache.ignite.internal.processors.query.SqlSchemaSelfTest;
 import org.apache.ignite.internal.processors.query.SqlSystemViewsSelfTest;
 import org.apache.ignite.internal.processors.query.h2.GridIndexRebuildSelfTest;
 import 
org.apache.ignite.internal.processors.query.h2.H2ResultSetIteratorNullifyOnEndSelfTest;
+import org.apache.ignite.internal.processors.query.h2.H2StatementCacheSelfTest;
 import 
org.apache.ignite.internal.processors.query.h2.IgniteSqlBigIntegerKeyTest;
 import org.apache.ignite.internal.processors.query.h2.IgniteSqlQueryMinMaxTest;
 import 
org.apache.ignite.internal.processors.query.h2.PreparedStatementExSelfTest;
@@ -512,6 +513,7 @@ import org.junit.runners.Suite;
     EncryptedSqlTableTest.class,
 
     ThreadLocalObjectPoolSelfTest.class,
+    H2StatementCacheSelfTest.class,
     PreparedStatementExSelfTest.class,
 
     // Partition loss.

Reply via email to