You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2015/10/16 13:02:47 UTC
[09/20] ignite git commit: IGNITE-1653
http://git-wip-us.apache.org/repos/asf/ignite/blob/c4b0877f/examples-lgpl/src/main/java8/org/apache/ignite/examples/java8/streaming/StreamVisitorExample.java
----------------------------------------------------------------------
diff --git a/examples-lgpl/src/main/java8/org/apache/ignite/examples/java8/streaming/StreamVisitorExample.java b/examples-lgpl/src/main/java8/org/apache/ignite/examples/java8/streaming/StreamVisitorExample.java
new file mode 100644
index 0000000..cef9f2f
--- /dev/null
+++ b/examples-lgpl/src/main/java8/org/apache/ignite/examples/java8/streaming/StreamVisitorExample.java
@@ -0,0 +1,172 @@
+/*
+ * 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.examples.java8.streaming;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Random;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteDataStreamer;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.cache.query.annotations.QuerySqlField;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.examples.ExampleNodeStartup;
+import org.apache.ignite.examples.ExamplesUtils;
+import org.apache.ignite.stream.StreamVisitor;
+
+/**
+ * Stream random numbers into the streaming cache.
+ * To start the example, you should:
+ * <ul>
+ * <li>Start a few nodes using {@link ExampleNodeStartup} or by starting remote nodes as specified below.</li>
+ * <li>Start streaming using {@link StreamVisitorExample}.</li>
+ * </ul>
+ * <p>
+ * You should start remote nodes by running {@link ExampleNodeStartup} in another JVM.
+ */
+public class StreamVisitorExample {
+ /** Random number generator. */
+ private static final Random RAND = new Random();
+
+ /** The list of instruments. */
+ private static final String[] INSTRUMENTS = {"IBM", "GOOG", "MSFT", "GE", "EBAY", "YHOO", "ORCL", "CSCO", "AMZN", "RHT"};
+
+ /** The list of initial instrument prices. */
+ private static final double[] INITIAL_PRICES = {194.9, 893.49, 34.21, 23.24, 57.93, 45.03, 44.41, 28.44, 378.49, 69.50};
+
+ public static void main(String[] args) throws Exception {
+ // Mark this cluster member as client.
+ Ignition.setClientMode(true);
+
+ try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
+ if (!ExamplesUtils.hasServerNodes(ignite))
+ return;
+
+ // Market data cache with default configuration.
+ CacheConfiguration<String, Double> mktDataCfg = new CacheConfiguration<>("marketTicks");
+
+ // Financial instrument cache configuration.
+ CacheConfiguration<String, Instrument> instCfg = new CacheConfiguration<>("instCache");
+
+ // Index key and value for querying financial instruments.
+ // Note that Instrument class has @QuerySqlField annotation for secondary field indexing.
+ instCfg.setIndexedTypes(String.class, Instrument.class);
+
+ // Auto-close caches at the end of the example.
+ try (
+ IgniteCache<String, Double> mktCache = ignite.getOrCreateCache(mktDataCfg);
+ IgniteCache<String, Instrument> instCache = ignite.getOrCreateCache(instCfg)
+ ) {
+ try (IgniteDataStreamer<String, Double> mktStmr = ignite.dataStreamer(mktCache.getName())) {
+ // Note that we receive market data, but do not populate 'mktCache' (it remains empty).
+ // Instead we update the instruments in the 'instCache'.
+ // Since both, 'instCache' and 'mktCache' use the same key, updates are collocated.
+ mktStmr.receiver(StreamVisitor.from((cache, e) -> {
+ String symbol = e.getKey();
+ Double tick = e.getValue();
+
+ Instrument inst = instCache.get(symbol);
+
+ if (inst == null)
+ inst = new Instrument(symbol);
+
+ // Don't populate market cache, as we don't use it for querying.
+ // Update cached instrument based on the latest market tick.
+ inst.update(tick);
+
+ instCache.put(symbol, inst);
+ }));
+
+ // Stream 10 million market data ticks into the system.
+ for (int i = 1; i <= 10_000_000; i++) {
+ int idx = RAND.nextInt(INSTRUMENTS.length);
+
+ // Use gaussian distribution to ensure that
+ // numbers closer to 0 have higher probability.
+ double price = round2(INITIAL_PRICES[idx] + RAND.nextGaussian());
+
+ mktStmr.addData(INSTRUMENTS[idx], price);
+
+ if (i % 500_000 == 0)
+ System.out.println("Number of tuples streamed into Ignite: " + i);
+ }
+ }
+
+ // Select top 3 best performing instruments.
+ SqlFieldsQuery top3qry = new SqlFieldsQuery(
+ "select symbol, (latest - open) from Instrument order by (latest - open) desc limit 3");
+
+ // Execute queries.
+ List<List<?>> top3 = instCache.query(top3qry).getAll();
+
+ System.out.println("Top performing financial instruments: ");
+
+ // Print top 10 words.
+ ExamplesUtils.printQueryResults(top3);
+ }
+ }
+ }
+
+ /**
+ * Rounds double value to two significant signs.
+ *
+ * @param val value to be rounded.
+ * @return rounded double value.
+ */
+ private static double round2(double val) {
+ return Math.floor(100 * val + 0.5) / 100;
+ }
+
+ /**
+ * Financial instrument.
+ */
+ public static class Instrument implements Serializable {
+ /** Instrument symbol. */
+ @QuerySqlField(index = true)
+ private final String symbol;
+
+ /** Open price. */
+ @QuerySqlField(index = true)
+ private double open;
+
+ /** Close price. */
+ @QuerySqlField(index = true)
+ private double latest;
+
+ /**
+ * @param symbol Symbol.
+ */
+ public Instrument(String symbol) {
+ this.symbol = symbol;
+ }
+
+ /**
+ * Updates this instrument based on the latest market tick price.
+ *
+ * @param price Latest price.
+ */
+ public void update(double price) {
+ if (open == 0)
+ open = price;
+
+ this.latest = price;
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/c4b0877f/examples-lgpl/src/main/java8/org/apache/ignite/examples/java8/streaming/package-info.java
----------------------------------------------------------------------
diff --git a/examples-lgpl/src/main/java8/org/apache/ignite/examples/java8/streaming/package-info.java b/examples-lgpl/src/main/java8/org/apache/ignite/examples/java8/streaming/package-info.java
new file mode 100644
index 0000000..d215d2f
--- /dev/null
+++ b/examples-lgpl/src/main/java8/org/apache/ignite/examples/java8/streaming/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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 description. -->
+ * Demonstrates usage of data streamer.
+ */
+package org.apache.ignite.examples.java8.streaming;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/c4b0877f/examples-lgpl/src/test/java/org/apache/ignite/examples/HibernateL2CacheExampleMultiNodeSelfTest.java
----------------------------------------------------------------------
diff --git a/examples-lgpl/src/test/java/org/apache/ignite/examples/HibernateL2CacheExampleMultiNodeSelfTest.java b/examples-lgpl/src/test/java/org/apache/ignite/examples/HibernateL2CacheExampleMultiNodeSelfTest.java
new file mode 100644
index 0000000..8a40d4a
--- /dev/null
+++ b/examples-lgpl/src/test/java/org/apache/ignite/examples/HibernateL2CacheExampleMultiNodeSelfTest.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.examples;
+
+import org.apache.ignite.examples.datagrid.hibernate.HibernateL2CacheExample;
+
+/**
+ * Multi-node test for {@link HibernateL2CacheExample}.
+ */
+public class HibernateL2CacheExampleMultiNodeSelfTest extends HibernateL2CacheExampleSelfTest {
+ /** {@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/c4b0877f/examples-lgpl/src/test/java/org/apache/ignite/examples/HibernateL2CacheExampleSelfTest.java
----------------------------------------------------------------------
diff --git a/examples-lgpl/src/test/java/org/apache/ignite/examples/HibernateL2CacheExampleSelfTest.java b/examples-lgpl/src/test/java/org/apache/ignite/examples/HibernateL2CacheExampleSelfTest.java
new file mode 100644
index 0000000..68767d7
--- /dev/null
+++ b/examples-lgpl/src/test/java/org/apache/ignite/examples/HibernateL2CacheExampleSelfTest.java
@@ -0,0 +1,33 @@
+/*
+ * 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.examples;
+
+import org.apache.ignite.examples.datagrid.hibernate.HibernateL2CacheExample;
+import org.apache.ignite.testframework.junits.common.GridAbstractExamplesTest;
+
+/**
+ * Tests the {@link HibernateL2CacheExample}.
+ */
+public class HibernateL2CacheExampleSelfTest extends GridAbstractExamplesTest {
+ /**
+ * @throws Exception If failed.
+ */
+ public void testHibernateL2CacheExample() throws Exception {
+ HibernateL2CacheExample.main(EMPTY_ARGS);
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/c4b0877f/examples-lgpl/src/test/java/org/apache/ignite/testsuites/IgniteLgplExamplesSelfTestSuite.java
----------------------------------------------------------------------
diff --git a/examples-lgpl/src/test/java/org/apache/ignite/testsuites/IgniteLgplExamplesSelfTestSuite.java b/examples-lgpl/src/test/java/org/apache/ignite/testsuites/IgniteLgplExamplesSelfTestSuite.java
new file mode 100644
index 0000000..7c99712
--- /dev/null
+++ b/examples-lgpl/src/test/java/org/apache/ignite/testsuites/IgniteLgplExamplesSelfTestSuite.java
@@ -0,0 +1,48 @@
+/*
+ * 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.testsuites;
+
+import junit.framework.TestSuite;
+import org.apache.ignite.examples.HibernateL2CacheExampleMultiNodeSelfTest;
+import org.apache.ignite.examples.HibernateL2CacheExampleSelfTest;
+import org.apache.ignite.testframework.GridTestUtils;
+
+import static org.apache.ignite.IgniteSystemProperties.IGNITE_OVERRIDE_MCAST_GRP;
+
+/**
+ * Examples test suite. <p> Contains only Spring ignite examples tests.
+ */
+public class IgniteLgplExamplesSelfTestSuite extends TestSuite {
+ /**
+ * @return Suite.
+ * @throws Exception If failed.
+ */
+ public static TestSuite suite() throws Exception {
+ System.setProperty(IGNITE_OVERRIDE_MCAST_GRP,
+ GridTestUtils.getNextMulticastGroup(IgniteLgplExamplesSelfTestSuite.class));
+
+ TestSuite suite = new TestSuite("Ignite Examples Test Suite");
+
+ suite.addTest(new TestSuite(HibernateL2CacheExampleSelfTest.class));
+
+ // Multi-node.
+ suite.addTest(new TestSuite(HibernateL2CacheExampleMultiNodeSelfTest.class));
+
+ return suite;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/c4b0877f/examples-lgpl/src/test/java8/org/apache/ignite/java8/examples/HibernateL2CacheExampleMultiNodeSelfTest.java
----------------------------------------------------------------------
diff --git a/examples-lgpl/src/test/java8/org/apache/ignite/java8/examples/HibernateL2CacheExampleMultiNodeSelfTest.java b/examples-lgpl/src/test/java8/org/apache/ignite/java8/examples/HibernateL2CacheExampleMultiNodeSelfTest.java
new file mode 100644
index 0000000..edfba3d
--- /dev/null
+++ b/examples-lgpl/src/test/java8/org/apache/ignite/java8/examples/HibernateL2CacheExampleMultiNodeSelfTest.java
@@ -0,0 +1,29 @@
+/*
+ * 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.java8.examples;
+
+/**
+ * Multi-node test for {@link org.apache.ignite.examples.java8.datagrid.hibernate.HibernateL2CacheExample}.
+ */
+public class HibernateL2CacheExampleMultiNodeSelfTest extends HibernateL2CacheExampleSelfTest {
+ /** {@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/c4b0877f/examples-lgpl/src/test/java8/org/apache/ignite/java8/examples/HibernateL2CacheExampleSelfTest.java
----------------------------------------------------------------------
diff --git a/examples-lgpl/src/test/java8/org/apache/ignite/java8/examples/HibernateL2CacheExampleSelfTest.java b/examples-lgpl/src/test/java8/org/apache/ignite/java8/examples/HibernateL2CacheExampleSelfTest.java
new file mode 100644
index 0000000..8c7a2de
--- /dev/null
+++ b/examples-lgpl/src/test/java8/org/apache/ignite/java8/examples/HibernateL2CacheExampleSelfTest.java
@@ -0,0 +1,37 @@
+/*
+ * 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.java8.examples;
+
+//import org.apache.ignite.examples.java8.datagrid.hibernate.*;
+
+import org.apache.ignite.testframework.junits.common.GridAbstractExamplesTest;
+
+/**
+ * Tests the {@link org.apache.ignite.examples.java8.datagrid.hibernate.HibernateL2CacheExample}.
+ */
+public class HibernateL2CacheExampleSelfTest extends GridAbstractExamplesTest {
+ /**
+ * TODO: IGNITE-711 next example(s) should be implemented for java 8
+ * or testing method(s) should be removed if example(s) does not applicable for java 8.
+ *
+ * @throws Exception If failed.
+ */
+// public void testHibernateL2CacheExample() throws Exception {
+// HibernateL2CacheExample.main(EMPTY_ARGS);
+// }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/c4b0877f/examples-lgpl/src/test/java8/org/apache/ignite/java8/testsuites/IgniteLgplExamplesJ8SelfTestSuite.java
----------------------------------------------------------------------
diff --git a/examples-lgpl/src/test/java8/org/apache/ignite/java8/testsuites/IgniteLgplExamplesJ8SelfTestSuite.java b/examples-lgpl/src/test/java8/org/apache/ignite/java8/testsuites/IgniteLgplExamplesJ8SelfTestSuite.java
new file mode 100644
index 0000000..bdda5f6
--- /dev/null
+++ b/examples-lgpl/src/test/java8/org/apache/ignite/java8/testsuites/IgniteLgplExamplesJ8SelfTestSuite.java
@@ -0,0 +1,46 @@
+/*
+ * 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.java8.testsuites;
+
+import junit.framework.TestSuite;
+import org.apache.ignite.testframework.GridTestUtils;
+
+import static org.apache.ignite.IgniteSystemProperties.IGNITE_OVERRIDE_MCAST_GRP;
+
+/**
+ * Examples test suite. <p> Contains only Spring ignite examples tests.
+ */
+public class IgniteLgplExamplesJ8SelfTestSuite extends TestSuite {
+ /**
+ * @return Suite.
+ * @throws Exception If failed.
+ */
+ public static TestSuite suite() throws Exception {
+ System.setProperty(IGNITE_OVERRIDE_MCAST_GRP,
+ GridTestUtils.getNextMulticastGroup(IgniteLgplExamplesJ8SelfTestSuite.class));
+
+ TestSuite suite = new TestSuite("Ignite Examples Test Suite");
+
+// suite.addTest(new TestSuite(HibernateL2CacheExampleSelfTest.class));
+
+ // Multi-node.
+// suite.addTest(new TestSuite(HibernateL2CacheExampleMultiNodeSelfTest.class));
+
+ return suite;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/c4b0877f/examples/pom-standalone.xml
----------------------------------------------------------------------
diff --git a/examples/pom-standalone.xml b/examples/pom-standalone.xml
index 996753e..e314acb 100644
--- a/examples/pom-standalone.xml
+++ b/examples/pom-standalone.xml
@@ -49,12 +49,6 @@
<dependency>
<groupId>org.apache.ignite</groupId>
- <artifactId>ignite-hibernate</artifactId>
- <version>to_be_replaced_by_ignite_version</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.ignite</groupId>
<artifactId>ignite-spring</artifactId>
<version>to_be_replaced_by_ignite_version</version>
</dependency>
@@ -72,12 +66,6 @@
</dependency>
<dependency>
- <groupId>org.apache.ignite</groupId>
- <artifactId>ignite-schedule</artifactId>
- <version>to_be_replaced_by_ignite_version</version>
- </dependency>
-
- <dependency>
<groupId>com.google.code.simple-spring-memcached</groupId>
<artifactId>spymemcached</artifactId>
<version>2.7.3</version>
http://git-wip-us.apache.org/repos/asf/ignite/blob/c4b0877f/examples/pom.xml
----------------------------------------------------------------------
diff --git a/examples/pom.xml b/examples/pom.xml
index e4ec73a..34ba05a 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -45,12 +45,6 @@
<dependency>
<groupId>org.apache.ignite</groupId>
- <artifactId>ignite-hibernate</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.ignite</groupId>
<artifactId>ignite-spring</artifactId>
<version>${project.version}</version>
</dependency>
@@ -68,12 +62,6 @@
</dependency>
<dependency>
- <groupId>org.apache.ignite</groupId>
- <artifactId>ignite-schedule</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <dependency>
<groupId>com.google.code.simple-spring-memcached</groupId>
<artifactId>spymemcached</artifactId>
<version>2.7.3</version>
http://git-wip-us.apache.org/repos/asf/ignite/blob/c4b0877f/examples/src/main/java/org/apache/ignite/examples/datagrid/hibernate/HibernateL2CacheExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/hibernate/HibernateL2CacheExample.java b/examples/src/main/java/org/apache/ignite/examples/datagrid/hibernate/HibernateL2CacheExample.java
deleted file mode 100644
index 2f271c8..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/hibernate/HibernateL2CacheExample.java
+++ /dev/null
@@ -1,245 +0,0 @@
-/*
- * 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.examples.datagrid.hibernate;
-
-import java.net.URL;
-import java.util.Arrays;
-import java.util.List;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.Ignition;
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.examples.ExampleNodeStartup;
-import org.apache.ignite.examples.ExamplesUtils;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-import org.hibernate.Transaction;
-import org.hibernate.cache.spi.access.AccessType;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.service.ServiceRegistryBuilder;
-import org.hibernate.stat.SecondLevelCacheStatistics;
-
-import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
-import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
-import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
-
-/**
- * This example demonstrates the use of Ignite In-Memory Data Ignite cluster as a Hibernate
- * Second-Level cache provider.
- * <p>
- * The Hibernate Second-Level cache (or "L2 cache" shortly) lets you significantly
- * reduce the number of requests to the underlying SQL database. Because database
- * access is known to be an expansive operation, using L2 cache may improve
- * performance dramatically.
- * <p>
- * This example defines 2 entity classes: {@link User} and {@link Post}, with
- * 1 <-> N relation, and marks them with appropriate annotations for Hibernate
- * object-relational mapping to SQL tables of an underlying H2 in-memory database.
- * The example launches node in the same JVM and registers it in
- * Hibernate configuration as an L2 cache implementation. It then stores and
- * queries instances of the entity classes to and from the database, having
- * Hibernate SQL output, L2 cache statistics output, and Ignite cache metrics
- * output enabled.
- * <p>
- * When running example, it's easy to notice that when an object is first
- * put into a database, the L2 cache is not used and it's contents is empty.
- * However, when an object is first read from the database, it is immediately
- * stored in L2 cache (which is Ignite In-Memory Data Ignite cluster in fact), which can
- * be seen in stats output. Further requests of the same object only read the data
- * from L2 cache and do not hit the database.
- * <p>
- * In this example, the Hibernate query cache is also enabled. Query cache lets you
- * avoid hitting the database in case of repetitive queries with the same parameter
- * values. You may notice that when the example runs the same query repeatedly in
- * loop, only the first query hits the database and the successive requests take the
- * data from L2 cache.
- * <p>
- * Note: this example uses {@link AccessType#READ_ONLY} L2 cache access type, but you
- * can experiment with other access types by modifying the Hibernate configuration file
- * {@code IGNITE_HOME/examples/config/hibernate/example-hibernate-L2-cache.xml}, used by the example.
- * <p>
- * Remote nodes should always be started with special configuration file which
- * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-ignite.xml'}.
- * <p>
- * Alternatively you can run {@link ExampleNodeStartup} in another JVM which will
- * start node with {@code examples/config/example-ignite.xml} configuration.
- */
-public class HibernateL2CacheExample {
- /** JDBC URL for backing database (an H2 in-memory database is used). */
- private static final String JDBC_URL = "jdbc:h2:mem:example;DB_CLOSE_DELAY=-1";
-
- /** Path to hibernate configuration file (will be resolved from application {@code CLASSPATH}). */
- private static final String HIBERNATE_CFG = "hibernate/example-hibernate-L2-cache.xml";
-
- /** Entity names for stats output. */
- private static final List<String> ENTITY_NAMES =
- Arrays.asList(User.class.getName(), Post.class.getName(), User.class.getName() + ".posts");
-
- /**
- * Executes example.
- *
- * @param args Command line arguments, none required.
- * @throws IgniteException If example execution failed.
- */
- public static void main(String[] args) throws IgniteException {
- // Start the node, run the example, and stop the node when finished.
- try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
- // We use a single session factory, but create a dedicated session
- // for each transaction or query. This way we ensure that L1 cache
- // is not used (L1 cache has per-session scope only).
- System.out.println();
- System.out.println(">>> Hibernate L2 cache example started.");
-
- try (
- // Create all required caches.
- IgniteCache c1 = createCache("org.hibernate.cache.spi.UpdateTimestampsCache", ATOMIC);
- IgniteCache c2 = createCache("org.hibernate.cache.internal.StandardQueryCache", ATOMIC);
- IgniteCache c3 = createCache("org.apache.ignite.examples.datagrid.hibernate.User", TRANSACTIONAL);
- IgniteCache c4 = createCache("org.apache.ignite.examples.datagrid.hibernate.User.posts", TRANSACTIONAL);
- IgniteCache c5 = createCache("org.apache.ignite.examples.datagrid.hibernate.Post", TRANSACTIONAL)
- ) {
- URL hibernateCfg = ExamplesUtils.url(HIBERNATE_CFG);
-
- SessionFactory sesFactory = createHibernateSessionFactory(hibernateCfg);
-
- System.out.println();
- System.out.println(">>> Creating objects.");
-
- final long userId;
-
- Session ses = sesFactory.openSession();
-
- try {
- Transaction tx = ses.beginTransaction();
-
- User user = new User("jedi", "Luke", "Skywalker");
-
- user.getPosts().add(new Post(user, "Let the Force be with you."));
-
- ses.save(user);
-
- tx.commit();
-
- // Create a user object, store it in DB, and save the database-generated
- // object ID. You may try adding more objects in a similar way.
- userId = user.getId();
- }
- finally {
- ses.close();
- }
-
- // Output L2 cache and Ignite cache stats. You may notice that
- // at this point the object is not yet stored in L2 cache, because
- // the read was not yet performed.
- printStats(sesFactory);
-
- System.out.println();
- System.out.println(">>> Querying object by ID.");
-
- // Query user by ID several times. First time we get an L2 cache
- // miss, and the data is queried from DB, but it is then stored
- // in cache and successive queries hit the cache and return
- // immediately, no SQL query is made.
- for (int i = 0; i < 3; i++) {
- ses = sesFactory.openSession();
-
- try {
- Transaction tx = ses.beginTransaction();
-
- User user = (User)ses.get(User.class, userId);
-
- System.out.println("User: " + user);
-
- for (Post post : user.getPosts())
- System.out.println("\tPost: " + post);
-
- tx.commit();
- }
- finally {
- ses.close();
- }
- }
-
- // Output the stats. We should see 1 miss and 2 hits for
- // User and Collection object (stored separately in L2 cache).
- // The Post is loaded with the collection, so it won't imply
- // a miss.
- printStats(sesFactory);
- }
- }
- }
-
- /**
- * Creates cache.
- *
- * @param name Cache name.
- * @param atomicityMode Atomicity mode.
- * @return Cache configuration.
- */
- private static IgniteCache createCache(String name, CacheAtomicityMode atomicityMode) {
- CacheConfiguration ccfg = new CacheConfiguration(name);
-
- ccfg.setAtomicityMode(atomicityMode);
- ccfg.setWriteSynchronizationMode(FULL_SYNC);
-
- return Ignition.ignite().getOrCreateCache(ccfg);
- }
-
- /**
- * Creates a new Hibernate {@link SessionFactory} using a programmatic
- * configuration.
- *
- * @param hibernateCfg Hibernate configuration file.
- * @return New Hibernate {@link SessionFactory}.
- */
- private static SessionFactory createHibernateSessionFactory(URL hibernateCfg) {
- ServiceRegistryBuilder builder = new ServiceRegistryBuilder();
-
- builder.applySetting("hibernate.connection.url", JDBC_URL);
- builder.applySetting("hibernate.show_sql", true);
-
- return new Configuration()
- .configure(hibernateCfg)
- .buildSessionFactory(builder.buildServiceRegistry());
- }
-
- /**
- * Prints Hibernate L2 cache statistics to standard output.
- *
- * @param sesFactory Hibernate {@link SessionFactory}, for which to print
- * statistics.
- */
- private static void printStats(SessionFactory sesFactory) {
- System.out.println("=== Hibernate L2 cache statistics ===");
-
- for (String entityName : ENTITY_NAMES) {
- System.out.println("\tEntity: " + entityName);
-
- SecondLevelCacheStatistics stats =
- sesFactory.getStatistics().getSecondLevelCacheStatistics(entityName);
-
- System.out.println("\t\tL2 cache entries: " + stats.getEntries());
- System.out.println("\t\tHits: " + stats.getHitCount());
- System.out.println("\t\tMisses: " + stats.getMissCount());
- }
-
- System.out.println("=====================================");
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/c4b0877f/examples/src/main/java/org/apache/ignite/examples/datagrid/hibernate/Post.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/hibernate/Post.java b/examples/src/main/java/org/apache/ignite/examples/datagrid/hibernate/Post.java
deleted file mode 100644
index 798411a..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/hibernate/Post.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * 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.examples.datagrid.hibernate;
-
-import java.util.Date;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.ManyToOne;
-
-/**
- * An entity class representing a post, that a
- * {@link User} has made on some public service.
- */
-@Entity
-class Post {
- /** ID. */
- @Id
- @GeneratedValue(strategy=GenerationType.AUTO)
- private long id;
-
- /** Author. */
- @ManyToOne
- private User author;
-
- /** Text. */
- private String text;
-
- /** Created timestamp. */
- private Date created;
-
- /**
- * Default constructor (required by Hibernate).
- */
- Post() {
- // No-op.
- }
-
- /**
- * Constructor.
- *
- * @param author Author.
- * @param text Text.
- */
- Post(User author, String text) {
- this.author = author;
- this.text = text;
- created = new Date();
- }
-
- /**
- * @return ID.
- */
- public long getId() {
- return id;
- }
-
- /**
- * @param id New ID.
- */
- public void setId(long id) {
- this.id = id;
- }
-
- /**
- * @return Author.
- */
- public User getAuthor() {
- return author;
- }
-
- /**
- * @param author New author.
- */
- public void setAuthor(User author) {
- this.author = author;
- }
-
- /**
- * @return Text.
- */
- public String getText() {
- return text;
- }
-
- /**
- * @param text New text.
- */
- public void setText(String text) {
- this.text = text;
- }
-
- /**
- * @return Created timestamp.
- */
- public Date getCreated() {
- return (Date)created.clone();
- }
-
- /**
- * @param created New created timestamp.
- */
- public void setCreated(Date created) {
- this.created = (Date)created.clone();
- }
-
- /** {@inheritDoc} */
- @Override public String toString() {
- return "Post [id=" + id +
- ", text=" + text +
- ", created=" + created +
- ']';
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/c4b0877f/examples/src/main/java/org/apache/ignite/examples/datagrid/hibernate/User.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/hibernate/User.java b/examples/src/main/java/org/apache/ignite/examples/datagrid/hibernate/User.java
deleted file mode 100644
index b7d5299..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/hibernate/User.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * 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.examples.datagrid.hibernate;
-
-import java.util.HashSet;
-import java.util.Set;
-import javax.persistence.CascadeType;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.OneToMany;
-import org.hibernate.annotations.NaturalId;
-
-/**
- * A user entity class. Represents a user of some public service,
- * having a number of personal information fields as well as a
- * number of posts written.
- */
-@Entity
-class User {
- /** ID. */
- @Id
- @GeneratedValue(strategy=GenerationType.AUTO)
- private long id;
-
- /** Login. */
- @NaturalId
- private String login;
-
- /** First name. */
- private String firstName;
-
- /** Last name. */
- private String lastName;
-
- /** Posts. */
- @OneToMany(mappedBy = "author", cascade = CascadeType.ALL)
- private Set<Post> posts = new HashSet<>();
-
- /**
- * Default constructor (required by Hibernate).
- */
- User() {
- // No-op.
- }
-
- /**
- * Constructor.
- *
- * @param login Login.
- * @param firstName First name.
- * @param lastName Last name.
- */
- User(String login, String firstName, String lastName) {
- this.login = login;
- this.firstName = firstName;
- this.lastName = lastName;
- }
-
- /**
- * @return ID.
- */
- public long getId() {
- return id;
- }
-
- /**
- * @param id New ID.
- */
- public void setId(long id) {
- this.id = id;
- }
-
- /**
- * @return Login.
- */
- public String getLogin() {
- return login;
- }
-
- /**
- * @param login New login.
- */
- public void setLogin(String login) {
- this.login = login;
- }
-
- /**
- * @return First name.
- */
- public String getFirstName() {
- return firstName;
- }
-
- /**
- * @param firstName New first name.
- */
- public void setFirstName(String firstName) {
- this.firstName = firstName;
- }
-
- /**
- * @return Last name.
- */
- public String getLastName() {
- return lastName;
- }
-
- /**
- * @param lastName New last name.
- */
- public void setLastName(String lastName) {
- this.lastName = lastName;
- }
-
- /**
- * @return Posts.
- */
- public Set<Post> getPosts() {
- return posts;
- }
-
- /**
- * @param posts New posts.
- */
- public void setPosts(Set<Post> posts) {
- this.posts = posts;
- }
-
- /** {@inheritDoc} */
- @Override public String toString() {
- return "User [id=" + id +
- ", login=" + login +
- ", firstName=" + firstName +
- ", lastName=" + lastName +
- ']';
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/c4b0877f/examples/src/main/java/org/apache/ignite/examples/datagrid/hibernate/package-info.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/hibernate/package-info.java b/examples/src/main/java/org/apache/ignite/examples/datagrid/hibernate/package-info.java
deleted file mode 100644
index 4bb876b..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/hibernate/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * 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 description. -->
- * Hibernate example.
- */
-package org.apache.ignite.examples.datagrid.hibernate;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/c4b0877f/examples/src/main/java/org/apache/ignite/examples/datagrid/store/hibernate/CacheHibernatePersonStore.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/hibernate/CacheHibernatePersonStore.java b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/hibernate/CacheHibernatePersonStore.java
deleted file mode 100644
index f8831ab..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/hibernate/CacheHibernatePersonStore.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * 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.examples.datagrid.store.hibernate;
-
-import java.util.List;
-import java.util.UUID;
-import javax.cache.integration.CacheLoaderException;
-import javax.cache.integration.CacheWriterException;
-import org.apache.ignite.cache.store.CacheStore;
-import org.apache.ignite.cache.store.CacheStoreAdapter;
-import org.apache.ignite.cache.store.CacheStoreSession;
-import org.apache.ignite.examples.datagrid.store.Person;
-import org.apache.ignite.lang.IgniteBiInClosure;
-import org.apache.ignite.resources.CacheStoreSessionResource;
-import org.hibernate.HibernateException;
-import org.hibernate.Session;
-
-/**
- * Example of {@link CacheStore} implementation that uses Hibernate
- * and deals with maps {@link UUID} to {@link Person}.
- */
-public class CacheHibernatePersonStore extends CacheStoreAdapter<Long, Person> {
- /** Auto-injected store session. */
- @CacheStoreSessionResource
- private CacheStoreSession ses;
-
- /** {@inheritDoc} */
- @Override public Person load(Long key) {
- System.out.println(">>> Store load [key=" + key + ']');
-
- Session hibSes = ses.attachment();
-
- try {
- return (Person)hibSes.get(Person.class, key);
- }
- catch (HibernateException e) {
- throw new CacheLoaderException("Failed to load value from cache store [key=" + key + ']', e);
- }
- }
-
- /** {@inheritDoc} */
- @Override public void write(javax.cache.Cache.Entry<? extends Long, ? extends Person> entry) {
- Long key = entry.getKey();
- Person val = entry.getValue();
-
- System.out.println(">>> Store write [key=" + key + ", val=" + val + ']');
-
- Session hibSes = ses.attachment();
-
- try {
- hibSes.saveOrUpdate(val);
- }
- catch (HibernateException e) {
- throw new CacheWriterException("Failed to put value to cache store [key=" + key + ", val" + val + "]", e);
- }
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings({"JpaQueryApiInspection"})
- @Override public void delete(Object key) {
- System.out.println(">>> Store delete [key=" + key + ']');
-
- Session hibSes = ses.attachment();
-
- try {
- hibSes.createQuery("delete " + Person.class.getSimpleName() + " where key = :key").
- setParameter("key", key).
- executeUpdate();
- }
- catch (HibernateException e) {
- throw new CacheWriterException("Failed to remove value from cache store [key=" + key + ']', e);
- }
- }
-
- /** {@inheritDoc} */
- @Override public void loadCache(IgniteBiInClosure<Long, Person> clo, Object... args) {
- if (args == null || args.length == 0 || args[0] == null)
- throw new CacheLoaderException("Expected entry count parameter is not provided.");
-
- final int entryCnt = (Integer)args[0];
-
- Session hibSes = ses.attachment();
-
- try {
- int cnt = 0;
-
- List list = hibSes.createCriteria(Person.class).
- setMaxResults(entryCnt).
- list();
-
- if (list != null) {
- for (Object obj : list) {
- Person person = (Person)obj;
-
- clo.apply(person.getId(), person);
-
- cnt++;
- }
- }
-
- System.out.println(">>> Loaded " + cnt + " values into cache.");
- }
- catch (HibernateException e) {
- throw new CacheLoaderException("Failed to load values from cache store.", e);
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/c4b0877f/examples/src/main/java/org/apache/ignite/examples/datagrid/store/hibernate/CacheHibernateStoreExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/hibernate/CacheHibernateStoreExample.java b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/hibernate/CacheHibernateStoreExample.java
deleted file mode 100644
index fbb761a..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/hibernate/CacheHibernateStoreExample.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * 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.examples.datagrid.store.hibernate;
-
-import java.util.UUID;
-import javax.cache.configuration.Factory;
-import javax.cache.configuration.FactoryBuilder;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.Ignition;
-import org.apache.ignite.cache.store.CacheStoreSessionListener;
-import org.apache.ignite.cache.store.hibernate.CacheHibernateStoreSessionListener;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.examples.ExampleNodeStartup;
-import org.apache.ignite.examples.ExamplesUtils;
-import org.apache.ignite.examples.datagrid.store.Person;
-import org.apache.ignite.transactions.Transaction;
-
-import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
-
-/**
- * Demonstrates usage of cache with underlying persistent store configured.
- * <p>
- * This example uses {@link CacheHibernatePersonStore} as a persistent store.
- * <p>
- * Remote nodes can be started with {@link ExampleNodeStartup} in another JVM which will
- * start node with {@code examples/config/example-ignite.xml} configuration.
- */
-public class CacheHibernateStoreExample {
- /** Hibernate configuration resource path. */
- private static final String HIBERNATE_CFG =
- "/org/apache/ignite/examples/datagrid/store/hibernate/hibernate.cfg.xml";
-
- /** Cache name. */
- private static final String CACHE_NAME = CacheHibernateStoreExample.class.getSimpleName();
-
- /** Heap size required to run this example. */
- public static final int MIN_MEMORY = 1024 * 1024 * 1024;
-
- /** Number of entries to load. */
- private static final int ENTRY_COUNT = 100_000;
-
- /** Global person ID to use across entire example. */
- private static final Long id = Math.abs(UUID.randomUUID().getLeastSignificantBits());
-
- /**
- * Executes example.
- *
- * @param args Command line arguments, none required.
- * @throws IgniteException If example execution failed.
- */
- public static void main(String[] args) throws IgniteException {
- ExamplesUtils.checkMinMemory(MIN_MEMORY);
-
- // To start ignite with desired configuration uncomment the appropriate line.
- try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
- System.out.println();
- System.out.println(">>> Cache store example started.");
-
- CacheConfiguration<Long, Person> cacheCfg = new CacheConfiguration<>(CACHE_NAME);
-
- // Set atomicity as transaction, since we are showing transactions in example.
- cacheCfg.setAtomicityMode(TRANSACTIONAL);
-
- // Configure Hibernate store.
- cacheCfg.setCacheStoreFactory(FactoryBuilder.factoryOf(CacheHibernatePersonStore.class));
-
- // Configure Hibernate session listener.
- cacheCfg.setCacheStoreSessionListenerFactories(new Factory<CacheStoreSessionListener>() {
- @Override public CacheStoreSessionListener create() {
- CacheHibernateStoreSessionListener lsnr = new CacheHibernateStoreSessionListener();
-
- lsnr.setHibernateConfigurationPath(HIBERNATE_CFG);
-
- return lsnr;
- }
- });
-
- cacheCfg.setReadThrough(true);
- cacheCfg.setWriteThrough(true);
-
- try (IgniteCache<Long, Person> cache = ignite.getOrCreateCache(cacheCfg)) {
- // Make initial cache loading from persistent store. This is a
- // distributed operation and will call CacheStore.loadCache(...)
- // method on all nodes in topology.
- loadCache(cache);
-
- // Start transaction and execute several cache operations with
- // read/write-through to persistent store.
- executeTransaction(cache);
- }
- }
- }
-
- /**
- * Makes initial cache loading.
- *
- * @param cache Cache to load.
- */
- private static void loadCache(IgniteCache<Long, Person> cache) {
- long start = System.currentTimeMillis();
-
- // Start loading cache from persistent store on all caching nodes.
- cache.loadCache(null, ENTRY_COUNT);
-
- long end = System.currentTimeMillis();
-
- System.out.println(">>> Loaded " + cache.size() + " keys with backups in " + (end - start) + "ms.");
- }
-
- /**
- * Executes transaction with read/write-through to persistent store.
- *
- * @param cache Cache to execute transaction on.
- */
- private static void executeTransaction(IgniteCache<Long, Person> cache) {
- try (Transaction tx = Ignition.ignite().transactions().txStart()) {
- Person val = cache.get(id);
-
- System.out.println("Read value: " + val);
-
- val = cache.getAndPut(id, new Person(id, "Isaac", "Newton"));
-
- System.out.println("Overwrote old value: " + val);
-
- val = cache.get(id);
-
- System.out.println("Read value: " + val);
-
- tx.commit();
- }
-
- System.out.println("Read value after commit: " + cache.get(id));
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/c4b0877f/examples/src/main/java/org/apache/ignite/examples/datagrid/store/hibernate/Person.hbm.xml
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/hibernate/Person.hbm.xml b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/hibernate/Person.hbm.xml
deleted file mode 100644
index 035ab98..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/hibernate/Person.hbm.xml
+++ /dev/null
@@ -1,34 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<!--
- 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.
--->
-
-
-<!DOCTYPE hibernate-mapping PUBLIC
- "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
- "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
-
-<hibernate-mapping default-access="field">
- <class name="org.apache.ignite.examples.datagrid.store.Person" table="PERSONS">
- <!-- ID. -->
- <id name="id"/>
-
- <!-- We only map data we are interested in. -->
- <property name="firstName"/>
- <property name="lastName"/>
- </class>
-</hibernate-mapping>
http://git-wip-us.apache.org/repos/asf/ignite/blob/c4b0877f/examples/src/main/java/org/apache/ignite/examples/datagrid/store/hibernate/hibernate.cfg.xml
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/hibernate/hibernate.cfg.xml b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/hibernate/hibernate.cfg.xml
deleted file mode 100644
index 80a43e7..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/hibernate/hibernate.cfg.xml
+++ /dev/null
@@ -1,41 +0,0 @@
-<?xml version='1.0' encoding='utf-8'?>
-
-<!--
- 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.
--->
-
-<!DOCTYPE hibernate-configuration PUBLIC
- "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
- "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
-
-<!--
- Hibernate configuration.
--->
-<hibernate-configuration>
- <session-factory>
- <!-- Database connection settings (private in-memory database). -->
- <property name="connection.url">jdbc:h2:mem:example;DB_CLOSE_DELAY=-1</property>
-
- <!-- Only validate the database schema on startup in production mode. -->
- <property name="hbm2ddl.auto">update</property>
-
- <!-- Do not output SQL. -->
- <property name="show_sql">false</property>
-
- <!-- Mappings. -->
- <mapping resource="org/apache/ignite/examples/datagrid/store/hibernate/Person.hbm.xml"/>
- </session-factory>
-</hibernate-configuration>
http://git-wip-us.apache.org/repos/asf/ignite/blob/c4b0877f/examples/src/main/java/org/apache/ignite/examples/datagrid/store/hibernate/package-info.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/hibernate/package-info.java b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/hibernate/package-info.java
deleted file mode 100644
index 7a6d6de..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/hibernate/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * 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 description. -->
- * Contains Hibernate-based cache store implementation.
- */
-package org.apache.ignite.examples.datagrid.store.hibernate;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/c4b0877f/examples/src/test/java/org/apache/ignite/examples/HibernateL2CacheExampleMultiNodeSelfTest.java
----------------------------------------------------------------------
diff --git a/examples/src/test/java/org/apache/ignite/examples/HibernateL2CacheExampleMultiNodeSelfTest.java b/examples/src/test/java/org/apache/ignite/examples/HibernateL2CacheExampleMultiNodeSelfTest.java
deleted file mode 100644
index 1ca9b59..0000000
--- a/examples/src/test/java/org/apache/ignite/examples/HibernateL2CacheExampleMultiNodeSelfTest.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * 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.examples;
-
-import org.apache.ignite.examples.datagrid.hibernate.HibernateL2CacheExample;
-
-/**
- * Multi-node test for {@link HibernateL2CacheExample}.
- */
-public class HibernateL2CacheExampleMultiNodeSelfTest extends HibernateL2CacheExampleSelfTest {
- /** {@inheritDoc} */
- @Override protected void beforeTest() throws Exception {
- for (int i = 0; i < RMT_NODES_CNT; i++)
- startGrid("node-" + i, "examples/config/example-ignite.xml");
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/c4b0877f/examples/src/test/java/org/apache/ignite/examples/HibernateL2CacheExampleSelfTest.java
----------------------------------------------------------------------
diff --git a/examples/src/test/java/org/apache/ignite/examples/HibernateL2CacheExampleSelfTest.java b/examples/src/test/java/org/apache/ignite/examples/HibernateL2CacheExampleSelfTest.java
deleted file mode 100644
index 5f55e82..0000000
--- a/examples/src/test/java/org/apache/ignite/examples/HibernateL2CacheExampleSelfTest.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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.examples;
-
-import org.apache.ignite.examples.datagrid.hibernate.HibernateL2CacheExample;
-import org.apache.ignite.testframework.junits.common.GridAbstractExamplesTest;
-
-/**
- * Tests the {@link HibernateL2CacheExample}.
- */
-public class HibernateL2CacheExampleSelfTest extends GridAbstractExamplesTest {
- /**
- * @throws Exception If failed.
- */
- public void testHibernateL2CacheExample() throws Exception {
- HibernateL2CacheExample.main(EMPTY_ARGS);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/c4b0877f/examples/src/test/java/org/apache/ignite/testsuites/IgniteExamplesSelfTestSuite.java
----------------------------------------------------------------------
diff --git a/examples/src/test/java/org/apache/ignite/testsuites/IgniteExamplesSelfTestSuite.java b/examples/src/test/java/org/apache/ignite/testsuites/IgniteExamplesSelfTestSuite.java
index 4669ae4..57ff3ff 100644
--- a/examples/src/test/java/org/apache/ignite/testsuites/IgniteExamplesSelfTestSuite.java
+++ b/examples/src/test/java/org/apache/ignite/testsuites/IgniteExamplesSelfTestSuite.java
@@ -32,8 +32,6 @@ import org.apache.ignite.examples.DeploymentExamplesMultiNodeSelfTest;
import org.apache.ignite.examples.DeploymentExamplesSelfTest;
import org.apache.ignite.examples.EventsExamplesMultiNodeSelfTest;
import org.apache.ignite.examples.EventsExamplesSelfTest;
-import org.apache.ignite.examples.HibernateL2CacheExampleMultiNodeSelfTest;
-import org.apache.ignite.examples.HibernateL2CacheExampleSelfTest;
import org.apache.ignite.examples.IgfsExamplesSelfTest;
import org.apache.ignite.examples.LifecycleExamplesSelfTest;
import org.apache.ignite.examples.MemcacheRestExamplesMultiNodeSelfTest;
@@ -78,7 +76,6 @@ public class IgniteExamplesSelfTestSuite extends TestSuite {
suite.addTest(new TestSuite(SpringBeanExamplesSelfTest.class));
suite.addTest(new TestSuite(IgfsExamplesSelfTest.class));
suite.addTest(new TestSuite(CheckpointExamplesSelfTest.class));
- suite.addTest(new TestSuite(HibernateL2CacheExampleSelfTest.class));
suite.addTest(new TestSuite(ClusterGroupExampleSelfTest.class));
// Multi-node.
@@ -91,7 +88,6 @@ public class IgniteExamplesSelfTestSuite extends TestSuite {
suite.addTest(new TestSuite(TaskExamplesMultiNodeSelfTest.class));
suite.addTest(new TestSuite(MemcacheRestExamplesMultiNodeSelfTest.class));
suite.addTest(new TestSuite(MonteCarloExamplesMultiNodeSelfTest.class));
- suite.addTest(new TestSuite(HibernateL2CacheExampleMultiNodeSelfTest.class));
return suite;
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/c4b0877f/examples/src/test/java8/org/apache/ignite/java8/examples/HibernateL2CacheExampleMultiNodeSelfTest.java
----------------------------------------------------------------------
diff --git a/examples/src/test/java8/org/apache/ignite/java8/examples/HibernateL2CacheExampleMultiNodeSelfTest.java b/examples/src/test/java8/org/apache/ignite/java8/examples/HibernateL2CacheExampleMultiNodeSelfTest.java
deleted file mode 100644
index 737d498..0000000
--- a/examples/src/test/java8/org/apache/ignite/java8/examples/HibernateL2CacheExampleMultiNodeSelfTest.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * 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.java8.examples;
-
-/**
- * Multi-node test for {@link org.apache.ignite.examples.java8.datagrid.hibernate.HibernateL2CacheExample}.
- */
-public class HibernateL2CacheExampleMultiNodeSelfTest extends HibernateL2CacheExampleSelfTest {
- /** {@inheritDoc} */
- @Override protected void beforeTest() throws Exception {
- for (int i = 0; i < RMT_NODES_CNT; i++)
- startGrid("node-" + i, "examples/config/example-ignite.xml");
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/c4b0877f/examples/src/test/java8/org/apache/ignite/java8/examples/HibernateL2CacheExampleSelfTest.java
----------------------------------------------------------------------
diff --git a/examples/src/test/java8/org/apache/ignite/java8/examples/HibernateL2CacheExampleSelfTest.java b/examples/src/test/java8/org/apache/ignite/java8/examples/HibernateL2CacheExampleSelfTest.java
deleted file mode 100644
index 8c7a2de..0000000
--- a/examples/src/test/java8/org/apache/ignite/java8/examples/HibernateL2CacheExampleSelfTest.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * 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.java8.examples;
-
-//import org.apache.ignite.examples.java8.datagrid.hibernate.*;
-
-import org.apache.ignite.testframework.junits.common.GridAbstractExamplesTest;
-
-/**
- * Tests the {@link org.apache.ignite.examples.java8.datagrid.hibernate.HibernateL2CacheExample}.
- */
-public class HibernateL2CacheExampleSelfTest extends GridAbstractExamplesTest {
- /**
- * TODO: IGNITE-711 next example(s) should be implemented for java 8
- * or testing method(s) should be removed if example(s) does not applicable for java 8.
- *
- * @throws Exception If failed.
- */
-// public void testHibernateL2CacheExample() throws Exception {
-// HibernateL2CacheExample.main(EMPTY_ARGS);
-// }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/c4b0877f/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 208dbbc..7b8763f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -458,7 +458,6 @@
</modules>
</profile>
-
<profile>
<id>lgpl</id>
<modules>
@@ -466,6 +465,63 @@
<module>modules/geospatial</module>
<module>modules/schedule</module>
</modules>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.apache.resources</groupId>
+ <artifactId>apache-source-release-assembly-descriptor</artifactId>
+ <version>1.0.4</version>
+ </dependency>
+ </dependencies>
+ <executions>
+ <execution>
+ <id>release-lgpl</id>
+ <phase>prepare-package</phase>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ <configuration>
+ <descriptors>
+ <descriptor>assembly/release-${ignite.edition}-lgpl.xml</descriptor>
+ </descriptors>
+ <finalName>release-package</finalName>
+ <appendAssemblyId>false</appendAssemblyId>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <version>1.7</version>
+ <inherited>false</inherited>
+ <executions>
+ <execution>
+ <id>release-postprocessing-lgpl</id>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <phase>package</phase>
+ <configuration>
+ <target>
+ <replaceregexp file="${basedir}/target/release-package/examples-lgpl/pom.xml"
+ byline="true">
+ <regexp pattern="to_be_replaced_by_ignite_version"/>
+ <substitution expression="${project.version}"/>
+ </replaceregexp>
+ </target>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ </plugins>
+ </build>
</profile>
<profile>
@@ -477,6 +533,13 @@
</profile>
<profile>
+ <id>examples-lgpl</id>
+ <modules>
+ <module>examples-lgpl</module>
+ </modules>
+ </profile>
+
+ <profile>
<id>apache-release</id>
<build>
<plugins>