ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [12/18] ignite git commit: fixed https://issues.apache.org/jira/browse/IGNITE-2158
Date Thu, 17 Dec 2015 09:16:04 GMT
fixed https://issues.apache.org/jira/browse/IGNITE-2158


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

Branch: refs/heads/ignite-1537
Commit: d8c8214181b2fce4f069b2f8f1bb06ae3fc6d492
Parents: b028a26
Author: Yakov Zhdanov <yzhdanov@gridgain.com>
Authored: Wed Dec 16 17:19:37 2015 +0300
Committer: Yakov Zhdanov <yzhdanov@gridgain.com>
Committed: Wed Dec 16 17:19:37 2015 +0300

----------------------------------------------------------------------
 .../store/dummy/CacheDummyPersonStore.java      | 113 --------------
 .../store/dummy/CacheDummyStoreExample.java     | 133 -----------------
 .../datagrid/store/dummy/package-info.java      |  22 ---
 .../store/jdbc/CacheJdbcPersonStore.java        |  43 +-----
 .../store/jdbc/CacheJdbcStoreExample.java       |  25 +++-
 .../store/spring/CacheSpringPersonStore.java    | 131 -----------------
 .../store/spring/CacheSpringStoreExample.java   | 147 -------------------
 .../datagrid/store/spring/package-info.java     |  22 ---
 .../ignite/examples/CacheExamplesSelfTest.java  |  10 +-
 9 files changed, 30 insertions(+), 616 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/d8c82141/examples/src/main/java/org/apache/ignite/examples/datagrid/store/dummy/CacheDummyPersonStore.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/dummy/CacheDummyPersonStore.java
b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/dummy/CacheDummyPersonStore.java
deleted file mode 100644
index 6c0fecb..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/dummy/CacheDummyPersonStore.java
+++ /dev/null
@@ -1,113 +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.dummy;
-
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.cache.store.CacheStoreAdapter;
-import org.apache.ignite.cache.store.CacheStoreSession;
-import org.apache.ignite.examples.model.Person;
-import org.apache.ignite.lang.IgniteBiInClosure;
-import org.apache.ignite.resources.CacheNameResource;
-import org.apache.ignite.resources.CacheStoreSessionResource;
-import org.apache.ignite.resources.IgniteInstanceResource;
-import org.apache.ignite.transactions.Transaction;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Dummy cache store implementation.
- */
-public class CacheDummyPersonStore extends CacheStoreAdapter<Long, Person> {
-    /** Auto-inject ignite instance. */
-    @IgniteInstanceResource
-    private Ignite ignite;
-
-    /** Auto-inject cache name. */
-    @CacheNameResource
-    private String cacheName;
-
-    /** */
-    @CacheStoreSessionResource
-    private CacheStoreSession ses;
-
-    /** Dummy database. */
-    private Map<Long, Person> dummyDB = new ConcurrentHashMap<>();
-
-    /** {@inheritDoc} */
-    @Override public Person load(Long key) {
-        Transaction tx = transaction();
-
-        System.out.println(">>> Store load [key=" + key + ", xid=" + (tx == null
? null : tx.xid()) + ']');
-
-        return dummyDB.get(key);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void write(javax.cache.Cache.Entry<? extends Long, ? extends Person>
entry) {
-        Transaction tx = transaction();
-
-        Long key = entry.getKey();
-        Person val = entry.getValue();
-
-        System.out.println(">>> Store put [key=" + key + ", val=" + val + ", xid="
+ (tx == null ? null : tx.xid()) + ']');
-
-        dummyDB.put(key, val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void delete(Object key) {
-        Transaction tx = transaction();
-
-        System.out.println(">>> Store remove [key=" + key + ", xid=" + (tx == null
? null : tx.xid()) + ']');
-
-        dummyDB.remove(key);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void loadCache(IgniteBiInClosure<Long, Person> clo, Object...
args) {
-        int cnt = (Integer)args[0];
-
-        System.out.println(">>> Store loadCache for entry count: " + cnt);
-
-        for (long i = 0; i < cnt; i++) {
-            // Generate dummy person on the fly.
-            Person p = new Person(i, "first-" + i, "last-" + 1);
-
-            // Ignite will automatically discard entries that don't belong on this node,
-            // but we check if local node is primary or backup anyway just to demonstrate
that we can.
-            // Ideally, partition ID of a key would be stored  in the database and only keys
-            // for partitions that belong on this node would be loaded from database.
-            if (ignite.affinity(cacheName).isPrimaryOrBackup(ignite.cluster().localNode(),
p.id)) {
-                // Update dummy database.
-                // In real life data would be loaded from database.
-                dummyDB.put(p.id, p);
-
-                // Pass data to cache.
-                clo.apply(p.id, p);
-            }
-        }
-    }
-
-    /**
-     * @return Current transaction.
-     */
-    @Nullable private Transaction transaction() {
-        return ses != null ? ses.transaction() : null;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d8c82141/examples/src/main/java/org/apache/ignite/examples/datagrid/store/dummy/CacheDummyStoreExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/dummy/CacheDummyStoreExample.java
b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/dummy/CacheDummyStoreExample.java
deleted file mode 100644
index a631df3..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/dummy/CacheDummyStoreExample.java
+++ /dev/null
@@ -1,133 +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.dummy;
-
-import java.util.UUID;
-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.configuration.CacheConfiguration;
-import org.apache.ignite.examples.ExampleNodeStartup;
-import org.apache.ignite.examples.ExamplesUtils;
-import org.apache.ignite.examples.model.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 CacheDummyPersonStore} 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 CacheDummyStoreExample {
-    /** Cache name. */
-    private static final String CACHE_NAME = CacheDummyStoreExample.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 Dummy store.
-            cacheCfg.setCacheStoreFactory(FactoryBuilder.factoryOf(CacheDummyPersonStore.class));
-
-            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));
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d8c82141/examples/src/main/java/org/apache/ignite/examples/datagrid/store/dummy/package-info.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/dummy/package-info.java
b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/dummy/package-info.java
deleted file mode 100644
index 42c3899..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/dummy/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 dummy cache store implementation.
- */
-package org.apache.ignite.examples.datagrid.store.dummy;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/d8c82141/examples/src/main/java/org/apache/ignite/examples/datagrid/store/jdbc/CacheJdbcPersonStore.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/jdbc/CacheJdbcPersonStore.java
b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/jdbc/CacheJdbcPersonStore.java
index 6ba181e..f93a49f 100644
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/jdbc/CacheJdbcPersonStore.java
+++ b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/jdbc/CacheJdbcPersonStore.java
@@ -24,62 +24,29 @@ import java.sql.SQLException;
 import javax.cache.Cache;
 import javax.cache.integration.CacheLoaderException;
 import javax.cache.integration.CacheWriterException;
-import javax.sql.DataSource;
-import org.apache.ignite.IgniteException;
 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.model.Person;
 import org.apache.ignite.lang.IgniteBiInClosure;
 import org.apache.ignite.resources.CacheStoreSessionResource;
-import org.h2.jdbcx.JdbcConnectionPool;
 
 /**
  * Example of {@link CacheStore} implementation that uses JDBC
  * transaction with cache transactions and maps {@link Long} to {@link Person}.
  */
 public class CacheJdbcPersonStore extends CacheStoreAdapter<Long, Person> {
-    /** Data source. */
-    public static final DataSource DATA_SRC =
-        JdbcConnectionPool.create("jdbc:h2:mem:example;DB_CLOSE_DELAY=-1", "", "");
-
     /** Store session. */
     @CacheStoreSessionResource
     private CacheStoreSession ses;
 
-    /**
-     * Constructor.
-     *
-     * @throws IgniteException If failed.
-     */
-    public CacheJdbcPersonStore() throws IgniteException {
-        prepareDb();
-    }
-
-    /**
-     * Prepares database for example execution. This method will create a
-     * table called "PERSONS" so it can be used by store implementation.
-     *
-     * @throws IgniteException If failed.
-     */
-    private void prepareDb() throws IgniteException {
-        try (Connection conn = DATA_SRC.getConnection()) {
-            conn.createStatement().execute(
-                "create table if not exists PERSONS (" +
-                "id number unique, firstName varchar(255), lastName varchar(255))");
-        }
-        catch (SQLException e) {
-            throw new IgniteException("Failed to create database table.", e);
-        }
-    }
-
     /** {@inheritDoc} */
     @Override public Person load(Long key) {
         System.out.println(">>> Store load [key=" + key + ']');
 
         Connection conn = ses.attachment();
 
-        try (PreparedStatement st = conn.prepareStatement("select * from PERSONS where id
= ?")) {
+        try (PreparedStatement st = conn.prepareStatement("select * from PERSON where id
= ?")) {
             st.setString(1, key.toString());
 
             ResultSet rs = st.executeQuery();
@@ -106,7 +73,7 @@ public class CacheJdbcPersonStore extends CacheStoreAdapter<Long, Person>
{
             // Try update first. If it does not work, then try insert.
             // Some databases would allow these to be done in one 'upsert' operation.
             try (PreparedStatement st = conn.prepareStatement(
-                "update PERSONS set firstName = ?, lastName = ? where id = ?")) {
+                "update PERSON set first_name = ?, last_name = ? where id = ?")) {
                 st.setString(1, val.firstName);
                 st.setString(2, val.lastName);
                 st.setLong(3, val.id);
@@ -117,7 +84,7 @@ public class CacheJdbcPersonStore extends CacheStoreAdapter<Long, Person>
{
             // If update failed, try to insert.
             if (updated == 0) {
                 try (PreparedStatement st = conn.prepareStatement(
-                    "insert into PERSONS (id, firstName, lastName) values (?, ?, ?)")) {
+                    "insert into PERSON (id, first_name, last_name) values (?, ?, ?)")) {
                     st.setLong(1, val.id);
                     st.setString(2, val.firstName);
                     st.setString(3, val.lastName);
@@ -137,7 +104,7 @@ public class CacheJdbcPersonStore extends CacheStoreAdapter<Long, Person>
{
 
         Connection conn = ses.attachment();
 
-        try (PreparedStatement st = conn.prepareStatement("delete from PERSONS where id=?"))
{
+        try (PreparedStatement st = conn.prepareStatement("delete from PERSON where id=?"))
{
             st.setLong(1, (Long)key);
 
             st.executeUpdate();
@@ -156,7 +123,7 @@ public class CacheJdbcPersonStore extends CacheStoreAdapter<Long, Person>
{
 
         Connection conn = ses.attachment();
 
-        try (PreparedStatement stmt = conn.prepareStatement("select * from PERSONS limit
?")) {
+        try (PreparedStatement stmt = conn.prepareStatement("select * from PERSON limit ?"))
{
             stmt.setInt(1, entryCnt);
 
             ResultSet rs = stmt.executeQuery();

http://git-wip-us.apache.org/repos/asf/ignite/blob/d8c82141/examples/src/main/java/org/apache/ignite/examples/datagrid/store/jdbc/CacheJdbcStoreExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/jdbc/CacheJdbcStoreExample.java
b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/jdbc/CacheJdbcStoreExample.java
index 55ad5df..0034410 100644
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/jdbc/CacheJdbcStoreExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/jdbc/CacheJdbcStoreExample.java
@@ -30,7 +30,10 @@ import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.examples.ExampleNodeStartup;
 import org.apache.ignite.examples.ExamplesUtils;
 import org.apache.ignite.examples.model.Person;
+import org.apache.ignite.examples.util.DbH2ServerStartup;
+import org.apache.ignite.scalar.lang.ScalarOutClosure;
 import org.apache.ignite.transactions.Transaction;
+import org.h2.jdbcx.JdbcConnectionPool;
 
 import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
 
@@ -39,6 +42,13 @@ import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
  * <p>
  * This example uses {@link CacheJdbcPersonStore} as a persistent store.
  * <p>
+ * To start the example, you should:
+ * <ul>
+ *     <li>Start H2 database TCP server using {@link DbH2ServerStartup}.</li>
+ *     <li>Start a few nodes using {@link ExampleNodeStartup}.</li>
+ *     <li>Start example using {@link CacheJdbcStoreExample}.</li>
+ * </ul>
+ * <p>
  * Remote nodes can be started with {@link ExampleNodeStartup} in another JVM which will
  * start node with {@code examples/config/example-ignite.xml} configuration.
  */
@@ -82,7 +92,7 @@ public class CacheJdbcStoreExample {
                 @Override public CacheStoreSessionListener create() {
                     CacheJdbcStoreSessionListener lsnr = new CacheJdbcStoreSessionListener();
 
-                    lsnr.setDataSource(CacheJdbcPersonStore.DATA_SRC);
+                    lsnr.setDataSource(JdbcConnectionPool.create("jdbc:h2:tcp://localhost/mem:ExampleDb",
"sa", ""));
 
                     return lsnr;
                 }
@@ -143,5 +153,18 @@ public class CacheJdbcStoreExample {
         }
 
         System.out.println("Read value after commit: " + cache.get(id));
+
+        // Clear entry from memory, but keep it in store.
+        cache.clear(id);
+
+        // Operations on this cache will not affect store.
+        IgniteCache<Long, Person> cacheSkipStore = cache.withSkipStore();
+
+        System.out.println("Read value skipping store (expecting null): " + cacheSkipStore.get(id));
+
+        System.out.println("Read value with store lookup (expecting NOT null): " + cache.get(id));
+
+        // Expecting not null, since entry should be in memory since last call.
+        System.out.println("Read value skipping store (expecting NOT null): " + cacheSkipStore.get(id));
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/d8c82141/examples/src/main/java/org/apache/ignite/examples/datagrid/store/spring/CacheSpringPersonStore.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/spring/CacheSpringPersonStore.java
b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/spring/CacheSpringPersonStore.java
deleted file mode 100644
index 0029890..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/spring/CacheSpringPersonStore.java
+++ /dev/null
@@ -1,131 +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.spring;
-
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.concurrent.atomic.AtomicInteger;
-import javax.cache.Cache;
-import javax.cache.integration.CacheLoaderException;
-import javax.sql.DataSource;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.cache.store.CacheStore;
-import org.apache.ignite.cache.store.CacheStoreAdapter;
-import org.apache.ignite.examples.model.Person;
-import org.apache.ignite.lang.IgniteBiInClosure;
-import org.springframework.dao.EmptyResultDataAccessException;
-import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.jdbc.core.RowCallbackHandler;
-import org.springframework.jdbc.core.RowMapper;
-import org.springframework.jdbc.datasource.DriverManagerDataSource;
-
-/**
- * Example of {@link CacheStore} implementation that uses JDBC
- * transaction with cache transactions and maps {@link Long} to {@link Person}.
- */
-public class CacheSpringPersonStore extends CacheStoreAdapter<Long, Person> {
-    /** Data source. */
-    public static final DataSource DATA_SRC = new DriverManagerDataSource("jdbc:h2:mem:example;DB_CLOSE_DELAY=-1");
-
-    /** Spring JDBC template. */
-    private JdbcTemplate jdbcTemplate;
-
-    /**
-     * Constructor.
-     *
-     * @throws IgniteException If failed.
-     */
-    public CacheSpringPersonStore() throws IgniteException {
-        jdbcTemplate = new JdbcTemplate(DATA_SRC);
-
-        prepareDb();
-    }
-
-    /**
-     * Prepares database for example execution. This method will create a
-     * table called "PERSONS" so it can be used by store implementation.
-     *
-     * @throws IgniteException If failed.
-     */
-    private void prepareDb() throws IgniteException {
-        jdbcTemplate.update(
-            "create table if not exists PERSONS (" +
-            "id number unique, firstName varchar(255), lastName varchar(255))");
-    }
-
-    /** {@inheritDoc} */
-    @Override public Person load(Long key) {
-        System.out.println(">>> Store load [key=" + key + ']');
-
-        try {
-            return jdbcTemplate.queryForObject("select * from PERSONS where id = ?", new
RowMapper<Person>() {
-                @Override public Person mapRow(ResultSet rs, int rowNum) throws SQLException
{
-                    return new Person(rs.getLong(1), rs.getString(2), rs.getString(3));
-                }
-            }, key);
-        }
-        catch (EmptyResultDataAccessException ignored) {
-            return null;
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public void write(Cache.Entry<? extends Long, ? extends Person> entry)
{
-        Long key = entry.getKey();
-        Person val = entry.getValue();
-
-        System.out.println(">>> Store write [key=" + key + ", val=" + val + ']');
-
-        int updated = jdbcTemplate.update("update PERSONS set firstName = ?, lastName = ?
where id = ?",
-            val.firstName, val.lastName, val.id);
-
-        if (updated == 0) {
-            jdbcTemplate.update("insert into PERSONS (id, firstName, lastName) values (?,
?, ?)",
-                val.id, val.firstName, val.lastName);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public void delete(Object key) {
-        System.out.println(">>> Store delete [key=" + key + ']');
-
-        jdbcTemplate.update("delete from PERSONS where id = ?", key);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void loadCache(final 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.");
-
-        int entryCnt = (Integer)args[0];
-
-        final AtomicInteger cnt = new AtomicInteger();
-
-        jdbcTemplate.query("select * from PERSONS limit ?", new RowCallbackHandler() {
-            @Override public void processRow(ResultSet rs) throws SQLException {
-                Person person = new Person(rs.getLong(1), rs.getString(2), rs.getString(3));
-
-                clo.apply(person.id, person);
-
-                cnt.incrementAndGet();
-            }
-        }, entryCnt);
-
-        System.out.println(">>> Loaded " + cnt + " values into cache.");
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d8c82141/examples/src/main/java/org/apache/ignite/examples/datagrid/store/spring/CacheSpringStoreExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/spring/CacheSpringStoreExample.java
b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/spring/CacheSpringStoreExample.java
deleted file mode 100644
index 273ea1c..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/spring/CacheSpringStoreExample.java
+++ /dev/null
@@ -1,147 +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.spring;
-
-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.jdbc.CacheJdbcStoreSessionListener;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.examples.ExampleNodeStartup;
-import org.apache.ignite.examples.ExamplesUtils;
-import org.apache.ignite.examples.model.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 CacheSpringPersonStore} 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 CacheSpringStoreExample {
-    /** Cache name. */
-    private static final String CACHE_NAME = CacheSpringStoreExample.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 Spring store.
-            cacheCfg.setCacheStoreFactory(FactoryBuilder.factoryOf(CacheSpringPersonStore.class));
-
-            // Configure Spring session listener.
-            cacheCfg.setCacheStoreSessionListenerFactories(new Factory<CacheStoreSessionListener>()
{
-                @Override public CacheStoreSessionListener create() {
-                    CacheJdbcStoreSessionListener lsnr = new CacheJdbcStoreSessionListener();
-
-                    lsnr.setDataSource(CacheSpringPersonStore.DATA_SRC);
-
-                    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));
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d8c82141/examples/src/main/java/org/apache/ignite/examples/datagrid/store/spring/package-info.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/spring/package-info.java
b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/spring/package-info.java
deleted file mode 100644
index 3f03bde..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/spring/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 Spring-based cache store implementation.
- */
-package org.apache.ignite.examples.datagrid.store.spring;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/d8c82141/examples/src/test/java/org/apache/ignite/examples/CacheExamplesSelfTest.java
----------------------------------------------------------------------
diff --git a/examples/src/test/java/org/apache/ignite/examples/CacheExamplesSelfTest.java
b/examples/src/test/java/org/apache/ignite/examples/CacheExamplesSelfTest.java
index c11fa1a..050c59f 100644
--- a/examples/src/test/java/org/apache/ignite/examples/CacheExamplesSelfTest.java
+++ b/examples/src/test/java/org/apache/ignite/examples/CacheExamplesSelfTest.java
@@ -25,14 +25,13 @@ import org.apache.ignite.examples.datagrid.CachePutGetExample;
 import org.apache.ignite.examples.datagrid.CacheQueryExample;
 import org.apache.ignite.examples.datagrid.CacheTransactionExample;
 import org.apache.ignite.examples.datagrid.starschema.CacheStarSchemaExample;
-import org.apache.ignite.examples.datagrid.store.dummy.CacheDummyStoreExample;
 import org.apache.ignite.examples.datastructures.IgniteAtomicLongExample;
 import org.apache.ignite.examples.datastructures.IgniteAtomicReferenceExample;
 import org.apache.ignite.examples.datastructures.IgniteAtomicSequenceExample;
 import org.apache.ignite.examples.datastructures.IgniteAtomicStampedExample;
 import org.apache.ignite.examples.datastructures.IgniteCountDownLatchExample;
-import org.apache.ignite.examples.datastructures.IgniteSemaphoreExample;
 import org.apache.ignite.examples.datastructures.IgniteQueueExample;
+import org.apache.ignite.examples.datastructures.IgniteSemaphoreExample;
 import org.apache.ignite.examples.datastructures.IgniteSetExample;
 import org.apache.ignite.testframework.junits.common.GridAbstractExamplesTest;
 
@@ -106,13 +105,6 @@ public class CacheExamplesSelfTest extends GridAbstractExamplesTest {
     /**
      * @throws Exception If failed.
      */
-    public void testCacheDummyStoreExample() throws Exception {
-        CacheDummyStoreExample.main(EMPTY_ARGS);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
     public void testCacheQueryExample() throws Exception {
         CacheQueryExample.main(EMPTY_ARGS);
     }


Mime
View raw message