You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by dm...@apache.org on 2016/11/17 01:11:38 UTC
ignite git commit: Added geospatial example
Repository: ignite
Updated Branches:
refs/heads/ignite-4238 17316f934 -> 54e754bd8
Added geospatial example
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/54e754bd
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/54e754bd
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/54e754bd
Branch: refs/heads/ignite-4238
Commit: 54e754bd8706dea22bed1803b57b632fcee9bc74
Parents: 17316f9
Author: Denis Magda <dm...@gridgain.com>
Authored: Wed Nov 16 17:11:30 2016 -0800
Committer: Denis Magda <dm...@gridgain.com>
Committed: Wed Nov 16 17:11:30 2016 -0800
----------------------------------------------------------------------
examples/pom.xml | 8 ++
.../examples/datagrid/SpatialQueryExample.java | 89 ++++++++++++++++++++
.../SpatialQueryExampleMultiNodeSelfTest.java | 14 +++
.../examples/SpatialQueryExampleSelfTest.java | 16 ++++
.../IgniteLgplExamplesSelfTestSuite.java | 4 +
...butedQueryStopOnCancelOrTimeoutSelfTest.java | 3 +-
...nCancelOrTimeoutDistributedJoinSelfTest.java | 3 +-
7 files changed, 135 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/54e754bd/examples/pom.xml
----------------------------------------------------------------------
diff --git a/examples/pom.xml b/examples/pom.xml
index 5c4ead3..fd036b4 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -210,6 +210,14 @@
<lgpl.folder>src/main/java-lgpl</lgpl.folder>
<lgpl.test.folder>src/test/java-lgpl</lgpl.test.folder>
</properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.ignite</groupId>
+ <artifactId>ignite-geospatial</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
</profile>
</profiles>
http://git-wip-us.apache.org/repos/asf/ignite/blob/54e754bd/examples/src/main/java-lgpl/org/apache/ignite/examples/datagrid/SpatialQueryExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java-lgpl/org/apache/ignite/examples/datagrid/SpatialQueryExample.java b/examples/src/main/java-lgpl/org/apache/ignite/examples/datagrid/SpatialQueryExample.java
new file mode 100644
index 0000000..cf484b2
--- /dev/null
+++ b/examples/src/main/java-lgpl/org/apache/ignite/examples/datagrid/SpatialQueryExample.java
@@ -0,0 +1,89 @@
+package org.apache.ignite.examples.datagrid;
+
+import com.vividsolutions.jts.geom.*;
+import com.vividsolutions.jts.io.*;
+import org.apache.ignite.*;
+import org.apache.ignite.cache.query.SqlQuery;
+import org.apache.ignite.cache.query.annotations.*;
+import org.apache.ignite.configuration.*;
+
+import javax.cache.*;
+import java.util.*;
+import org.apache.ignite.examples.ExampleNodeStartup;
+
+/**
+ * This examples shows the usage of geospatial queries and indexes in Apache Ignite.
+ * For more information please refer to the following technical documentation:
+ * http://apacheignite.readme.io/docs/geospatial-queries
+ * <p>
+ * Remote nodes should be started using {@link ExampleNodeStartup} which will
+ * start node with {@code examples/config/example-ignite.xml} configuration.
+ */
+public class SpatialQueryExample {
+ /** Cache name. */
+ private static final String CACHE_NAME = SpatialQueryExample.class.getSimpleName();
+
+ /**
+ * @param args Command line arguments, none required.
+ */
+ public static void main(String[] args) throws Exception {
+ // Starting Ignite node.
+ try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
+ // Preparing the cache configuration.
+ CacheConfiguration<Integer, MapPoint> cc = new CacheConfiguration<>(CACHE_NAME);
+
+ // Setting the indexed types.
+ cc.setIndexedTypes(Integer.class, MapPoint.class);
+
+ // Starting the cache.
+ try (IgniteCache<Integer, MapPoint> cache = ignite.createCache(cc)) {
+ Random rnd = new Random();
+
+ WKTReader r = new WKTReader();
+
+ // Adding geometry points into the cache.
+ for (int i = 0; i < 1000; i++) {
+ int x = rnd.nextInt(10000);
+ int y = rnd.nextInt(10000);
+
+ Geometry geo = r.read("POINT(" + x + " " + y + ")");
+
+ cache.put(i, new MapPoint(geo));
+ }
+
+ // Query to fetch the points that fit into a specific polygon.
+ SqlQuery<Integer, MapPoint> query = new SqlQuery<>(MapPoint.class, "coords && ?");
+
+ // Selecting points that fit into a specific polygon.
+ for (int i = 0; i < 10; i++) {
+ // Defining the next polygon boundaries.
+ Geometry cond = r.read("POLYGON((0 0, 0 " + rnd.nextInt(10000) + ", " +
+ rnd.nextInt(10000) + " " + rnd.nextInt(10000) + ", " +
+ rnd.nextInt(10000) + " 0, 0 0))");
+
+ // Executing the query.
+ Collection<Cache.Entry<Integer, MapPoint>> entries = cache.query(query.setArgs(cond)).getAll();
+
+ // Printing number of points that fit into the area defined by the polygon.
+ System.out.println("Fetched points [cond=" + cond + ", cnt=" + entries.size() + ']');
+ }
+ }
+ }
+ }
+
+ /**
+ * MapPoint with indexed coordinates.
+ */
+ private static class MapPoint {
+ /** Coordinates. */
+ @QuerySqlField(index = true)
+ private Geometry coords;
+
+ /**
+ * @param coords Coordinates.
+ */
+ private MapPoint(Geometry coords) {
+ this.coords = coords;
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/54e754bd/examples/src/test/java-lgpl/org/apache/ignite/examples/SpatialQueryExampleMultiNodeSelfTest.java
----------------------------------------------------------------------
diff --git a/examples/src/test/java-lgpl/org/apache/ignite/examples/SpatialQueryExampleMultiNodeSelfTest.java b/examples/src/test/java-lgpl/org/apache/ignite/examples/SpatialQueryExampleMultiNodeSelfTest.java
new file mode 100644
index 0000000..81a89c4
--- /dev/null
+++ b/examples/src/test/java-lgpl/org/apache/ignite/examples/SpatialQueryExampleMultiNodeSelfTest.java
@@ -0,0 +1,14 @@
+package org.apache.ignite.examples;
+
+import org.apache.ignite.examples.datagrid.SpatialQueryExample;
+
+/**
+ * * Tests {@link SpatialQueryExample} in the multi node mode.
+ */
+public class SpatialQueryExampleMultiNodeSelfTest extends SpatialQueryExampleSelfTest {
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ for (int i = 0; i < RMT_NODES_CNT; i++)
+ startGrid("node-" + i, "examples/config/example-ignite.xml");
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/54e754bd/examples/src/test/java-lgpl/org/apache/ignite/examples/SpatialQueryExampleSelfTest.java
----------------------------------------------------------------------
diff --git a/examples/src/test/java-lgpl/org/apache/ignite/examples/SpatialQueryExampleSelfTest.java b/examples/src/test/java-lgpl/org/apache/ignite/examples/SpatialQueryExampleSelfTest.java
new file mode 100644
index 0000000..b5e1f40
--- /dev/null
+++ b/examples/src/test/java-lgpl/org/apache/ignite/examples/SpatialQueryExampleSelfTest.java
@@ -0,0 +1,16 @@
+package org.apache.ignite.examples;
+
+import org.apache.ignite.examples.datagrid.SpatialQueryExample;
+import org.apache.ignite.testframework.junits.common.GridAbstractExamplesTest;
+
+/**
+ * Tests {@link SpatialQueryExample}.
+ */
+public class SpatialQueryExampleSelfTest extends GridAbstractExamplesTest {
+ /**
+ * @throws Exception If failed.
+ */
+ public void testSpatialQueryExample() throws Exception {
+ SpatialQueryExample.main(EMPTY_ARGS);
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/54e754bd/examples/src/test/java-lgpl/org/apache/ignite/testsuites/IgniteLgplExamplesSelfTestSuite.java
----------------------------------------------------------------------
diff --git a/examples/src/test/java-lgpl/org/apache/ignite/testsuites/IgniteLgplExamplesSelfTestSuite.java b/examples/src/test/java-lgpl/org/apache/ignite/testsuites/IgniteLgplExamplesSelfTestSuite.java
index 7c99712..3c9101a 100644
--- a/examples/src/test/java-lgpl/org/apache/ignite/testsuites/IgniteLgplExamplesSelfTestSuite.java
+++ b/examples/src/test/java-lgpl/org/apache/ignite/testsuites/IgniteLgplExamplesSelfTestSuite.java
@@ -20,6 +20,8 @@ package org.apache.ignite.testsuites;
import junit.framework.TestSuite;
import org.apache.ignite.examples.HibernateL2CacheExampleMultiNodeSelfTest;
import org.apache.ignite.examples.HibernateL2CacheExampleSelfTest;
+import org.apache.ignite.examples.SpatialQueryExampleMultiNodeSelfTest;
+import org.apache.ignite.examples.SpatialQueryExampleSelfTest;
import org.apache.ignite.testframework.GridTestUtils;
import static org.apache.ignite.IgniteSystemProperties.IGNITE_OVERRIDE_MCAST_GRP;
@@ -39,9 +41,11 @@ public class IgniteLgplExamplesSelfTestSuite extends TestSuite {
TestSuite suite = new TestSuite("Ignite Examples Test Suite");
suite.addTest(new TestSuite(HibernateL2CacheExampleSelfTest.class));
+ suite.addTest(new TestSuite(SpatialQueryExampleSelfTest.class));
// Multi-node.
suite.addTest(new TestSuite(HibernateL2CacheExampleMultiNodeSelfTest.class));
+ suite.addTest(new TestSuite(SpatialQueryExampleMultiNodeSelfTest.class));
return suite;
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/54e754bd/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheDistributedQueryStopOnCancelOrTimeoutSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheDistributedQueryStopOnCancelOrTimeoutSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheDistributedQueryStopOnCancelOrTimeoutSelfTest.java
index a92bf2b..e410dcd 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheDistributedQueryStopOnCancelOrTimeoutSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheDistributedQueryStopOnCancelOrTimeoutSelfTest.java
@@ -26,6 +26,7 @@ import java.util.concurrent.TimeUnit;
import javax.cache.CacheException;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.cache.query.QueryCursor;
import org.apache.ignite.cache.query.SqlFieldsQuery;
import org.apache.ignite.configuration.CacheConfiguration;
@@ -232,7 +233,7 @@ public class IgniteCacheDistributedQueryStopOnCancelOrTimeoutSelfTest extends Gr
* Validates clean state on all participating nodes after query cancellation.
*/
@SuppressWarnings("unchecked")
- private void checkCleanState() {
+ private void checkCleanState() throws IgniteCheckedException {
for (int i = 0; i < GRIDS_CNT; i++) {
IgniteEx grid = grid(i);
http://git-wip-us.apache.org/repos/asf/ignite/blob/54e754bd/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheQueryStopOnCancelOrTimeoutDistributedJoinSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheQueryStopOnCancelOrTimeoutDistributedJoinSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheQueryStopOnCancelOrTimeoutDistributedJoinSelfTest.java
index 4baaf8f..769ef28 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheQueryStopOnCancelOrTimeoutDistributedJoinSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheQueryStopOnCancelOrTimeoutDistributedJoinSelfTest.java
@@ -25,6 +25,7 @@ import java.util.concurrent.TimeUnit;
import javax.cache.CacheException;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.cache.query.QueryCancelledException;
import org.apache.ignite.cache.query.QueryCursor;
import org.apache.ignite.cache.query.SqlFieldsQuery;
@@ -117,7 +118,7 @@ public class IgniteCacheQueryStopOnCancelOrTimeoutDistributedJoinSelfTest extend
* Validates clean state on all participating nodes after query cancellation.
*/
@SuppressWarnings("unchecked")
- private void checkCleanState() {
+ private void checkCleanState() throws IgniteCheckedException {
for (int i = 0; i < GRID_CNT; i++) {
IgniteEx grid = grid(i);