# ignite-45 - demo fix.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/4e7eef34 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/4e7eef34 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/4e7eef34 Branch: refs/heads/ignite-45-ipc-debug Commit: 4e7eef349c7f87bba1b1ba081cfb7522cf6ffb12 Parents: d99f272 Author: Dmitiry Setrakyan <dsetrak...@gridgain.com> Authored: Tue Mar 24 09:56:44 2015 -0700 Committer: Dmitiry Setrakyan <dsetrak...@gridgain.com> Committed: Tue Mar 24 09:56:44 2015 -0700 ---------------------------------------------------------------------- .../org/apache/ignite/schema/CacheConfig.java | 2 +- .../java/org/apache/ignite/schema/Demo.java | 55 +++++++++----------- .../java/org/apache/ignite/schema/DemoNode.java | 37 +++++++++++++ 3 files changed, 62 insertions(+), 32 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4e7eef34/examples/schema-import/src/main/java/org/apache/ignite/schema/CacheConfig.java ---------------------------------------------------------------------- diff --git a/examples/schema-import/src/main/java/org/apache/ignite/schema/CacheConfig.java b/examples/schema-import/src/main/java/org/apache/ignite/schema/CacheConfig.java index 44359dd..cd758ee 100644 --- a/examples/schema-import/src/main/java/org/apache/ignite/schema/CacheConfig.java +++ b/examples/schema-import/src/main/java/org/apache/ignite/schema/CacheConfig.java @@ -32,7 +32,7 @@ public class CacheConfig { * @param name Cache name. * @param storeFactory Cache store factory. */ - public static CacheConfiguration cache(String name, Factory<CacheStore> storeFactory) { + public static <K, V> CacheConfiguration<K, V> cache(String name, Factory<CacheStore<K, V>> storeFactory) { throw new IllegalStateException("CacheConfig should be generated by Ignite Schema Import Utility"); } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4e7eef34/examples/schema-import/src/main/java/org/apache/ignite/schema/Demo.java ---------------------------------------------------------------------- diff --git a/examples/schema-import/src/main/java/org/apache/ignite/schema/Demo.java b/examples/schema-import/src/main/java/org/apache/ignite/schema/Demo.java index 6c15141..c44d285 100644 --- a/examples/schema-import/src/main/java/org/apache/ignite/schema/Demo.java +++ b/examples/schema-import/src/main/java/org/apache/ignite/schema/Demo.java @@ -28,23 +28,20 @@ import javax.cache.*; import javax.cache.configuration.*; /** - * Demo for CacheJdbcPojoStore. - * - * This example demonstrates the use of cache with {@link CacheJdbcPojoStore}. - * - * Custom SQL will be executed to populate cache with data from database. + * This demo demonstrates the use of cache with {@link CacheJdbcPojoStore} + * together with automatic Ignite shema-import utility. + * <p> + * This Demo can work stand-alone. You can also choose to start + * several {@link DemoNode} cluster nodes as well. */ public class Demo { - /** */ - private static final String CACHE_NAME = "Person"; - /** * Constructs and returns a fully configured instance of a {@link CacheJdbcPojoStore}. */ - private static class H2DemoStoreFactory implements Factory<CacheStore> { + private static class H2DemoStoreFactory<K, V> implements Factory<CacheStore<K, V>> { /** {@inheritDoc} */ - @Override public CacheStore create() { - CacheJdbcPojoStore store = new CacheJdbcPojoStore<>(); + @Override public CacheStore<K, V> create() { + CacheJdbcPojoStore<K, V> store = new CacheJdbcPojoStore<>(); store.setDataSource(JdbcConnectionPool.create("jdbc:h2:tcp://localhost/~/schema-import/demo", "sa", "")); @@ -61,27 +58,23 @@ public class Demo { public static void main(String[] args) throws IgniteException { System.out.println(">>> Start demo..."); - IgniteConfiguration cfg = new IgniteConfiguration(); - - // Configure cache store. - CacheConfiguration ccfg = CacheConfig.cache(CACHE_NAME, new H2DemoStoreFactory()); - - cfg.setCacheConfiguration(ccfg); - // Start Ignite node. - try (Ignite ignite = Ignition.start(cfg)) { - IgniteCache<PersonKey, Person> cache = ignite.cache(CACHE_NAME); - - // Preload cache from database. - preload(cache); - - // Read-through from database - // and store in cache. - readThrough(cache); - - // Perform transaction and - // write-through to database. - transaction(ignite, cache); + try (Ignite ignite = Ignition.start()) { + // Configure cache store. + CacheConfiguration<PersonKey, Person> cfg = CacheConfig.cache("PersonCache", new H2DemoStoreFactory<>()); + + try (IgniteCache<PersonKey, Person> cache = ignite.getOrCreateCache(cfg)) { + // Preload cache from database. + preload(cache); + + // Read-through from database + // and store in cache. + readThrough(cache); + + // Perform transaction and + // write-through to database. + transaction(ignite, cache); + } } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4e7eef34/examples/schema-import/src/main/java/org/apache/ignite/schema/DemoNode.java ---------------------------------------------------------------------- diff --git a/examples/schema-import/src/main/java/org/apache/ignite/schema/DemoNode.java b/examples/schema-import/src/main/java/org/apache/ignite/schema/DemoNode.java new file mode 100644 index 0000000..24a5486 --- /dev/null +++ b/examples/schema-import/src/main/java/org/apache/ignite/schema/DemoNode.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.schema; + +import org.apache.ignite.*; + +/** + * Starts demo node. You can start as many demo nodes as you like for the demo. + */ +public class DemoNode { + /** + * Starts demo node. + * + * @param args Command line arguments, none required. + * @throws IgniteException If example execution failed. + */ + public static void main(String[] args) throws IgniteException { + System.out.println(">>> Start demo node..."); + + Ignition.start(); + } +}