ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject ignite git commit: ignite-2382 JDBC drivers improvements
Date Mon, 16 May 2016 11:56:34 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-1.6 0c3f5d9b7 -> 6bd045338


ignite-2382 JDBC drivers improvements


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

Branch: refs/heads/ignite-1.6
Commit: 6bd0453382293b30df718ec03efa8ecdf347cc0e
Parents: 0c3f5d9
Author: agura <agura@gridgain.com>
Authored: Mon May 16 00:19:46 2016 +0300
Committer: agura <agura@gridgain.com>
Committed: Mon May 16 14:56:16 2016 +0300

----------------------------------------------------------------------
 modules/clients/src/test/config/jdbc-config.xml |   3 +-
 .../internal/jdbc2/JdbcConnectionSelfTest.java  |   2 +
 .../internal/jdbc2/JdbcNoDefaultCacheTest.java  | 161 +++++++++++++++++++
 .../ignite/jdbc/JdbcNoDefaultCacheTest.java     | 161 +++++++++++++++++++
 .../jdbc/suite/IgniteJdbcDriverTestSuite.java   |   3 +
 .../org/apache/ignite/IgniteJdbcDriver.java     |   2 +-
 .../ignite/internal/jdbc2/JdbcConnection.java   |  21 ++-
 .../ignite/internal/jdbc2/JdbcQueryTask.java    |  15 ++
 .../processors/cache/GridCacheProcessor.java    |  45 +++++-
 .../query/jdbc/GridCacheQueryJdbcTask.java      |  59 ++++++-
 .../jdbc/GridCacheQueryJdbcValidationTask.java  |   7 +-
 11 files changed, 462 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/6bd04533/modules/clients/src/test/config/jdbc-config.xml
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/config/jdbc-config.xml b/modules/clients/src/test/config/jdbc-config.xml
index 980eaf1..5e6e12c 100644
--- a/modules/clients/src/test/config/jdbc-config.xml
+++ b/modules/clients/src/test/config/jdbc-config.xml
@@ -26,7 +26,8 @@
         http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans.xsd">
     <bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
-        <property name="clientMode" value="true"/>
+        <!-- JDBC driver should force true value -->
+        <property name="clientMode" value="false"/>
 
         <property name="localHost" value="127.0.0.1"/>
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/6bd04533/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcConnectionSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcConnectionSelfTest.java
b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcConnectionSelfTest.java
index 951890e..8c05df3 100644
--- a/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcConnectionSelfTest.java
+++ b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcConnectionSelfTest.java
@@ -108,10 +108,12 @@ public class JdbcConnectionSelfTest extends GridCommonAbstractTest {
 
         try (Connection conn = DriverManager.getConnection(url)) {
             assertNotNull(conn);
+            assertTrue(((JdbcConnection)conn).ignite().configuration().isClientMode());
         }
 
         try (Connection conn = DriverManager.getConnection(url + '/')) {
             assertNotNull(conn);
+            assertTrue(((JdbcConnection)conn).ignite().configuration().isClientMode());
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/6bd04533/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcNoDefaultCacheTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcNoDefaultCacheTest.java
b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcNoDefaultCacheTest.java
new file mode 100644
index 0000000..0acaa05
--- /dev/null
+++ b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcNoDefaultCacheTest.java
@@ -0,0 +1,161 @@
+/*
+ * 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.jdbc2;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jetbrains.annotations.Nullable;
+
+import static org.apache.ignite.IgniteJdbcDriver.CFG_URL_PREFIX;
+
+/**
+ *
+ */
+public class JdbcNoDefaultCacheTest extends GridCommonAbstractTest {
+    /** IP finder. */
+    private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+    /** First cache name. */
+    private static final String CACHE1_NAME = "cache1";
+
+    /** Second cache name. */
+    private static final String CACHE2_NAME = "cache2";
+
+    /** Ignite configuration URL. */
+    private static final String CFG_URL = "modules/clients/src/test/config/jdbc-config.xml";
+
+    /** Grid count. */
+    private static final int GRID_CNT = 2;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception
{
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.setCacheConfiguration(cacheConfiguration(CACHE1_NAME), cacheConfiguration(CACHE2_NAME));
+
+        TcpDiscoverySpi disco = new TcpDiscoverySpi();
+
+        disco.setIpFinder(IP_FINDER);
+
+        cfg.setDiscoverySpi(disco);
+
+        return cfg;
+    }
+
+    /**
+     * @param name Cache name.
+     * @return Cache configuration.
+     * @throws Exception In case of error.
+     */
+    private CacheConfiguration cacheConfiguration(@Nullable String name) throws Exception
{
+        CacheConfiguration cfg = defaultCacheConfiguration();
+
+        cfg.setIndexedTypes(Integer.class, Integer.class);
+
+        cfg.setName(name);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGridsMultiThreaded(GRID_CNT);
+
+        Class.forName("org.apache.ignite.IgniteJdbcDriver");
+
+        Ignite ignite = ignite(0);
+
+        IgniteCache<Integer, Integer> cache1 = ignite.cache(CACHE1_NAME);
+        IgniteCache<Integer, Integer> cache2 = ignite.cache(CACHE2_NAME);
+
+        for (int i = 0; i < 10; i++) {
+            cache1.put(i, i * 2);
+            cache2.put(i, i * 3);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDefaults() throws Exception {
+        String url = CFG_URL_PREFIX + CFG_URL;
+
+        try (Connection conn = DriverManager.getConnection(url)) {
+            assertNotNull(conn);
+            assertTrue(((JdbcConnection)conn).ignite().configuration().isClientMode());
+        }
+
+        try (Connection conn = DriverManager.getConnection(url + '/')) {
+            assertNotNull(conn);
+            assertTrue(((JdbcConnection)conn).ignite().configuration().isClientMode());
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNoCacheNameQuery() throws Exception {
+        Statement stmt;
+
+        stmt = DriverManager.getConnection(CFG_URL_PREFIX + CFG_URL).createStatement();
+
+        assertNotNull(stmt);
+        assertFalse(stmt.isClosed());
+
+        stmt.execute("select t._key, t._val from \"cache1\".Integer t");
+
+        ResultSet rs = stmt.getResultSet();
+
+        while(rs.next())
+            assertEquals(rs.getInt(2), rs.getInt(1) * 2);
+
+        stmt.execute("select t._key, t._val from \"cache2\".Integer t");
+
+        rs = stmt.getResultSet();
+
+        while(rs.next())
+            assertEquals(rs.getInt(2), rs.getInt(1) * 3);
+
+        stmt.execute("select t._key, t._val, v._val " +
+            "from \"cache1\".Integer t join \"cache2\".Integer v on t._key = v._key");
+
+        rs = stmt.getResultSet();
+
+        while(rs.next()) {
+            assertEquals(rs.getInt(2), rs.getInt(1) * 2);
+            assertEquals(rs.getInt(3), rs.getInt(1) * 3);
+        }
+
+        stmt.close();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/6bd04533/modules/clients/src/test/java/org/apache/ignite/jdbc/JdbcNoDefaultCacheTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/JdbcNoDefaultCacheTest.java
b/modules/clients/src/test/java/org/apache/ignite/jdbc/JdbcNoDefaultCacheTest.java
new file mode 100644
index 0000000..48748ba
--- /dev/null
+++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/JdbcNoDefaultCacheTest.java
@@ -0,0 +1,161 @@
+/*
+ * 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.jdbc;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.ConnectorConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ *
+ */
+public class JdbcNoDefaultCacheTest extends GridCommonAbstractTest {
+    /** IP finder. */
+    private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+    /** First cache name. */
+    private static final String CACHE1_NAME = "cache1";
+
+    /** Second cache name. */
+    private static final String CACHE2_NAME = "cache2";
+
+    /** URL. */
+    private static final String URL = "jdbc:ignite://127.0.0.1/";
+
+    /** Grid count. */
+    private static final int GRID_CNT = 2;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception
{
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.setCacheConfiguration(cacheConfiguration(CACHE1_NAME), cacheConfiguration(CACHE2_NAME));
+
+        TcpDiscoverySpi disco = new TcpDiscoverySpi();
+
+        disco.setIpFinder(IP_FINDER);
+
+        cfg.setDiscoverySpi(disco);
+
+        cfg.setConnectorConfiguration(new ConnectorConfiguration());
+
+        return cfg;
+    }
+
+    /**
+     * @param name Cache name.
+     * @return Cache configuration.
+     * @throws Exception In case of error.
+     */
+    @SuppressWarnings("unchecked")
+    private CacheConfiguration cacheConfiguration(@Nullable String name) throws Exception
{
+        CacheConfiguration cfg = defaultCacheConfiguration();
+
+        cfg.setIndexedTypes(Integer.class, Integer.class);
+
+        cfg.setName(name);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGridsMultiThreaded(GRID_CNT);
+
+        Class.forName("org.apache.ignite.IgniteJdbcDriver");
+
+        Ignite ignite = ignite(0);
+
+        IgniteCache<Integer, Integer> cache1 = ignite.cache(CACHE1_NAME);
+        IgniteCache<Integer, Integer> cache2 = ignite.cache(CACHE2_NAME);
+
+        for (int i = 0; i < 10; i++) {
+            cache1.put(i, i * 2);
+            cache2.put(i, i * 3);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDefaults() throws Exception {
+        String url = URL;
+
+        try (Connection conn = DriverManager.getConnection(url)) {
+            assertNotNull(conn);
+        }
+
+        try (Connection conn = DriverManager.getConnection(url + '/')) {
+            assertNotNull(conn);
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNoCacheNameQuery() throws Exception {
+        Statement stmt;
+
+        stmt = DriverManager.getConnection(URL).createStatement();
+
+        assertNotNull(stmt);
+        assertFalse(stmt.isClosed());
+
+        stmt.execute("select t._key, t._val from \"cache1\".Integer t");
+
+        ResultSet rs = stmt.getResultSet();
+
+        while(rs.next())
+            assertEquals(rs.getInt(2), rs.getInt(1) * 2);
+
+        stmt.execute("select t._key, t._val from \"cache2\".Integer t");
+
+        rs = stmt.getResultSet();
+
+        while(rs.next())
+            assertEquals(rs.getInt(2), rs.getInt(1) * 3);
+
+        stmt.execute("select t._key, t._val, v._val " +
+            "from \"cache1\".Integer t join \"cache2\".Integer v on t._key = v._key");
+
+        rs = stmt.getResultSet();
+
+        while(rs.next()) {
+            assertEquals(rs.getInt(2), rs.getInt(1) * 2);
+            assertEquals(rs.getInt(3), rs.getInt(1) * 3);
+        }
+
+        stmt.close();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/6bd04533/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcDriverTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcDriverTestSuite.java
b/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcDriverTestSuite.java
index bac2f60..603ee81 100644
--- a/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcDriverTestSuite.java
+++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcDriverTestSuite.java
@@ -23,6 +23,7 @@ import org.apache.ignite.jdbc.JdbcConnectionSelfTest;
 import org.apache.ignite.jdbc.JdbcEmptyCacheSelfTest;
 import org.apache.ignite.jdbc.JdbcLocalCachesSelfTest;
 import org.apache.ignite.jdbc.JdbcMetadataSelfTest;
+import org.apache.ignite.jdbc.JdbcNoDefaultCacheTest;
 import org.apache.ignite.jdbc.JdbcPreparedStatementSelfTest;
 import org.apache.ignite.jdbc.JdbcResultSetSelfTest;
 import org.apache.ignite.jdbc.JdbcStatementSelfTest;
@@ -47,6 +48,7 @@ public class IgniteJdbcDriverTestSuite extends TestSuite {
         suite.addTest(new TestSuite(JdbcMetadataSelfTest.class));
         suite.addTest(new TestSuite(JdbcEmptyCacheSelfTest.class));
         suite.addTest(new TestSuite(JdbcLocalCachesSelfTest.class));
+        suite.addTest(new TestSuite(JdbcNoDefaultCacheTest.class));
 
         // Ignite client node based driver tests
         suite.addTest(new TestSuite(org.apache.ignite.internal.jdbc2.JdbcConnectionSelfTest.class));
@@ -57,6 +59,7 @@ public class IgniteJdbcDriverTestSuite extends TestSuite {
         suite.addTest(new TestSuite(org.apache.ignite.internal.jdbc2.JdbcMetadataSelfTest.class));
         suite.addTest(new TestSuite(org.apache.ignite.internal.jdbc2.JdbcEmptyCacheSelfTest.class));
         suite.addTest(new TestSuite(org.apache.ignite.internal.jdbc2.JdbcLocalCachesSelfTest.class));
+        suite.addTest(new TestSuite(org.apache.ignite.internal.jdbc2.JdbcNoDefaultCacheTest.class));
 
         return suite;
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/6bd04533/modules/core/src/main/java/org/apache/ignite/IgniteJdbcDriver.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteJdbcDriver.java b/modules/core/src/main/java/org/apache/ignite/IgniteJdbcDriver.java
index 7f8b523..567ff9f 100644
--- a/modules/core/src/main/java/org/apache/ignite/IgniteJdbcDriver.java
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteJdbcDriver.java
@@ -461,7 +461,7 @@ public class IgniteJdbcDriver implements Driver {
 
         if (url.startsWith(URL_PREFIX) && url.length() > URL_PREFIX.length())
             return parseJdbcUrl(url, props);
-        else if (url.startsWith(CFG_URL_PREFIX) && url.length() > CFG_URL_PREFIX.length())
+        else if (url.startsWith(CFG_URL_PREFIX) && url.length() >= CFG_URL_PREFIX.length())
             return parseJdbcConfigUrl(url, props);
 
         return false;

http://git-wip-us.apache.org/repos/asf/ignite/blob/6bd04533/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcConnection.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcConnection.java
b/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcConnection.java
index 00eb6b5..2d2ce5d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcConnection.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcConnection.java
@@ -76,6 +76,9 @@ import static org.apache.ignite.IgniteJdbcDriver.PROP_NODE_ID;
  * JDBC connection implementation.
  */
 public class JdbcConnection implements Connection {
+    /** Null stub. */
+    private static final String NULL = "null";
+
     /**
      * Ignite nodes cache.
      *
@@ -136,7 +139,9 @@ public class JdbcConnection implements Connection {
             this.nodeId = UUID.fromString(nodeIdProp);
 
         try {
-            cfg = props.getProperty(PROP_CFG);
+            String cfgUrl = props.getProperty(PROP_CFG);
+
+            cfg = cfgUrl == null || cfgUrl.isEmpty() ? NULL : cfgUrl;
 
             ignite = getIgnite(cfg);
 
@@ -169,7 +174,15 @@ public class JdbcConnection implements Connection {
                     fut = old;
                 else {
                     try {
-                        Ignite ignite = Ignition.start(loadConfiguration(cfgUrl));
+                        Ignite ignite;
+
+                        if (NULL.equals(cfg)) {
+                            Ignition.setClientMode(true);
+
+                            ignite = Ignition.start();
+                        }
+                        else
+                            ignite = Ignition.start(loadConfiguration(cfgUrl));
 
                         fut.onDone(ignite);
                     }
@@ -201,6 +214,8 @@ public class JdbcConnection implements Connection {
             if (cfg.getGridName() == null)
                 cfg.setGridName("ignite-jdbc-driver-" + UUID.randomUUID().toString());
 
+            cfg.setClientMode(true); // Force client mode.
+
             return cfg;
         }
         catch (IgniteCheckedException e) {
@@ -733,7 +748,7 @@ public class JdbcConnection implements Connection {
 
         /** {@inheritDoc} */
         @Override public Boolean call() {
-            return ignite.cache(cacheName) != null;
+            return cacheName == null || ignite.cache(cacheName) != null;
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/6bd04533/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcQueryTask.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcQueryTask.java
b/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcQueryTask.java
index ac711b8..1a5793a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcQueryTask.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcQueryTask.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.internal.jdbc2;
 
 import java.io.Serializable;
+import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
@@ -34,6 +35,7 @@ import org.apache.ignite.IgniteJdbcDriver;
 import org.apache.ignite.IgniteSystemProperties;
 import org.apache.ignite.cache.query.QueryCursor;
 import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.internal.IgniteKernal;
 import org.apache.ignite.internal.processors.cache.QueryCursorImpl;
 import org.apache.ignite.internal.processors.query.GridQueryFieldMetadata;
 import org.apache.ignite.internal.util.typedef.CAX;
@@ -127,6 +129,19 @@ class JdbcQueryTask implements IgniteCallable<JdbcQueryTask.QueryResult>
{
         if (first = (cursor == null)) {
             IgniteCache<?, ?> cache = ignite.cache(cacheName);
 
+            // Don't create caches on server nodes in order to avoid of data rebalancing.
+            boolean start = ignite.configuration().isClientMode();
+
+            if (cache == null && cacheName == null)
+                cache = ((IgniteKernal)ignite).context().cache().getOrStartPublicCache(start,
!loc && locQry);
+
+            if (cache == null) {
+                if (cacheName == null)
+                    throw new SQLException("Failed to execute query. No suitable caches found.");
+                else
+                    throw new SQLException("Cache not found [cacheName=" + cacheName + ']');
+            }
+
             SqlFieldsQuery qry = new SqlFieldsQuery(sql).setArgs(args);
 
             qry.setPageSize(fetchSize);

http://git-wip-us.apache.org/repos/asf/ignite/blob/6bd04533/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
index 0f8e3f6..5711366 100755
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
@@ -105,7 +105,6 @@ import org.apache.ignite.internal.util.future.GridFinishedFuture;
 import org.apache.ignite.internal.util.future.GridFutureAdapter;
 import org.apache.ignite.internal.util.lang.IgniteOutClosureX;
 import org.apache.ignite.internal.util.tostring.GridToStringInclude;
-import org.apache.ignite.internal.util.typedef.CIX1;
 import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.X;
 import org.apache.ignite.internal.util.typedef.internal.CU;
@@ -1521,6 +1520,42 @@ public class GridCacheProcessor extends GridProcessorAdapter {
     }
 
     /**
+     * Gets public cache that can be used for query execution.
+     * If cache isn't created on current node it will be started.
+     *
+     * @param start Start cache.
+     * @param inclLoc Include local caches.
+     * @return Cache or {@code null} if there is no suitable cache.
+     */
+    public IgniteCacheProxy<?, ?> getOrStartPublicCache(boolean start, boolean inclLoc)
throws IgniteCheckedException {
+        // Try to find started cache first.
+        for (Map.Entry<String, GridCacheAdapter<?, ?>> e : caches.entrySet())
{
+            CacheConfiguration ccfg = e.getValue().configuration();
+
+            String cacheName = ccfg.getName();
+
+            if ((inclLoc || ccfg.getCacheMode() != LOCAL) && GridQueryProcessor.isEnabled(ccfg))
+                return publicJCache(cacheName);
+        }
+
+        if (start) {
+            for (Map.Entry<String, DynamicCacheDescriptor> e : registeredCaches.entrySet())
{
+                DynamicCacheDescriptor desc = e.getValue();
+
+                CacheConfiguration ccfg = desc.cacheConfiguration();
+
+                if (ccfg.getCacheMode() != LOCAL && GridQueryProcessor.isEnabled(ccfg))
{
+                    dynamicStartCache(null, ccfg.getName(), null, false, true, true).get();
+
+                    return publicJCache(ccfg.getName());
+                }
+            }
+        }
+
+        return null;
+    }
+
+    /**
      * Gets a collection of currently started public cache names.
      *
      * @return Collection of currently started public cache names
@@ -3384,9 +3419,11 @@ public class GridCacheProcessor extends GridProcessorAdapter {
      * @throws IgniteCheckedException In case of error.
      */
     public void createMissingCaches() throws IgniteCheckedException {
-        for (String cacheName : registeredCaches.keySet()) {
-            if (!CU.isSystemCache(cacheName) && !caches.containsKey(cacheName))
-                dynamicStartCache(null, cacheName, null, false, true, true).get();
+        for (Map.Entry<String, DynamicCacheDescriptor> e : registeredCaches.entrySet())
{
+            CacheConfiguration ccfg = e.getValue().cacheConfiguration();
+
+            if (!caches.containsKey(maskNull(ccfg.getName())) && GridQueryProcessor.isEnabled(ccfg))
+                dynamicStartCache(null, ccfg.getName(), null, false, true, true).get();
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/6bd04533/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/jdbc/GridCacheQueryJdbcTask.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/jdbc/GridCacheQueryJdbcTask.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/jdbc/GridCacheQueryJdbcTask.java
index 5c60762..26d4b82 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/jdbc/GridCacheQueryJdbcTask.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/jdbc/GridCacheQueryJdbcTask.java
@@ -55,6 +55,7 @@ import org.apache.ignite.marshaller.Marshaller;
 import org.apache.ignite.marshaller.jdk.JdkMarshaller;
 import org.apache.ignite.resources.IgniteInstanceResource;
 import org.apache.ignite.resources.LoggerResource;
+import org.jetbrains.annotations.Nullable;
 
 import static org.apache.ignite.compute.ComputeJobResultPolicy.WAIT;
 
@@ -74,6 +75,7 @@ public class GridCacheQueryJdbcTask extends ComputeTaskAdapter<byte[],
byte[]> {
     /** Scheduler. */
     private static final ScheduledExecutorService SCHEDULER = Executors.newScheduledThreadPool(1);
 
+    /** Ignite. */
     @IgniteInstanceResource
     private Ignite ignite;
 
@@ -104,14 +106,22 @@ public class GridCacheQueryJdbcTask extends ComputeTaskAdapter<byte[],
byte[]> {
             else {
                 String cache = (String)args.get("cache");
 
-                GridDiscoveryManager discoMgr = ((IgniteKernal)ignite).context().discovery();
+                Map<? extends ComputeJob, ClusterNode> node = mapToNode(subgrid, args,
first, cache);
 
-                for (ClusterNode n : subgrid) {
-                    if (discoMgr.cacheAffinityNode(n, cache))
-                        return F.asMap(new JdbcDriverJob(args, first), n);
+                if (node == null && cache == null) {
+                    boolean start = ignite.configuration().isClientMode();
+
+                    IgniteCache<?, ?> cache0 =
+                            ((IgniteKernal)ignite).context().cache().getOrStartPublicCache(start,
false);
+
+                    if (cache0 != null)
+                        node = mapToNode(subgrid, args, first, cache0.getName());
                 }
 
-                throw new IgniteException("Can't find node with cache: " + cache);
+                if (node != null)
+                    return node;
+                else
+                    throw new IgniteException("Can't find node with cache: " + cache);
             }
         }
         catch (IgniteCheckedException e) {
@@ -119,6 +129,31 @@ public class GridCacheQueryJdbcTask extends ComputeTaskAdapter<byte[],
byte[]> {
         }
     }
 
+    /**
+     * @param subgrid Subgrid.
+     * @param args Args.
+     * @param first First.
+     * @param cache Cache.
+     */
+    @Nullable private Map<? extends ComputeJob, ClusterNode> mapToNode(
+        List<ClusterNode> subgrid,
+        Map<String, Object> args,
+        boolean first,
+        String cache
+    ) {
+        GridDiscoveryManager discoMgr = ((IgniteKernal)ignite).context().discovery();
+
+        for (ClusterNode n : subgrid) {
+            if (discoMgr.cacheAffinityNode(n, cache)) {
+                args.put("cache", cache);
+
+                return F.asMap(new JdbcDriverJob(args, first), n);
+            }
+        }
+
+        return null;
+    }
+
     /** {@inheritDoc} */
     @Override public byte[] reduce(List<ComputeJobResult> results) throws IgniteException
{
         try {
@@ -215,6 +250,20 @@ public class GridCacheQueryJdbcTask extends ComputeTaskAdapter<byte[],
byte[]> {
 
                 IgniteCache<?, ?> cache = ignite.cache(cacheName);
 
+                if (cache == null && cacheName == null) {
+                    try {
+                        boolean start = ignite.configuration().isClientMode();
+
+                        cache = ((IgniteKernal)ignite).context().cache().getOrStartPublicCache(start,
false);
+                    }
+                    catch (IgniteCheckedException e) {
+                        throw new IgniteException(e);
+                    }
+                }
+
+                if (cache == null)
+                    throw new IgniteException(new SQLException("Cache not found [cacheName="
+ cacheName + ']'));
+
                 SqlFieldsQuery qry = new SqlFieldsQuery(sql).setArgs(args.toArray());
 
                 qry.setPageSize(pageSize);

http://git-wip-us.apache.org/repos/asf/ignite/blob/6bd04533/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/jdbc/GridCacheQueryJdbcValidationTask.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/jdbc/GridCacheQueryJdbcValidationTask.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/jdbc/GridCacheQueryJdbcValidationTask.java
index 692d01c..886211d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/jdbc/GridCacheQueryJdbcValidationTask.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/jdbc/GridCacheQueryJdbcValidationTask.java
@@ -40,14 +40,15 @@ public class GridCacheQueryJdbcValidationTask extends ComputeTaskSplitAdapter<St
     private static final long serialVersionUID = 0L;
 
     /** {@inheritDoc} */
-    @Override protected Collection<? extends ComputeJob> split(int gridSize,
-        @Nullable final String cacheName) {
-        // Register big data usage.
+    @Override protected Collection<? extends ComputeJob> split(int gridSize, @Nullable
final String cacheName) {
         return Collections.singleton(new ComputeJobAdapter() {
             @IgniteInstanceResource
             private Ignite ignite;
 
             @Override public Object execute() {
+                if (cacheName == null)
+                    return true;
+
                 GridDiscoveryManager discoMgr = ((IgniteKernal)ignite).context().discovery();
 
                 for (ClusterNode n : ignite.cluster().nodes())


Mime
View raw message