ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [27/50] incubator-ignite git commit: # ignite-330 Fixed examples.
Date Mon, 23 Mar 2015 11:23:32 GMT
# ignite-330 Fixed examples.


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

Branch: refs/heads/ignite-497-stick
Commit: fee55c559a919dcefc8c597fdc56abba12c108d6
Parents: 18db0a4
Author: anovikov <anovikov@gridgain.com>
Authored: Mon Mar 23 13:21:38 2015 +0700
Committer: anovikov <anovikov@gridgain.com>
Committed: Mon Mar 23 13:21:38 2015 +0700

----------------------------------------------------------------------
 .../store/auto/CacheAutoStoreExample.java       |  7 +-
 .../auto/CacheAutoStoreLoadDataExample.java     | 42 ++---------
 .../datagrid/store/auto/CacheConfig.java        |  2 +-
 .../datagrid/store/auto/DbH2ServerStartup.java  | 78 ++++++++++++++++++++
 .../examples/datagrid/store/auto/H2Startup.java | 66 -----------------
 5 files changed, 91 insertions(+), 104 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fee55c55/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheAutoStoreExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheAutoStoreExample.java
b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheAutoStoreExample.java
index 12c80dc..abc5fc5 100644
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheAutoStoreExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheAutoStoreExample.java
@@ -31,7 +31,12 @@ import java.util.*;
  * <p>
  * This example uses {@link CacheJdbcPojoStore} as a persistent store.
  * <p>
- * To run this example your should start {@link H2Startup} first.
+ * 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} or by starting remote
nodes as specified below.</li>
+ *     <li>Start example using {@link CacheAutoStoreExample}.</li>
+ * </ul>
  * <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'}.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fee55c55/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheAutoStoreLoadDataExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheAutoStoreLoadDataExample.java
b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheAutoStoreLoadDataExample.java
index ed9ebc0..8a3b5c0 100644
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheAutoStoreLoadDataExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheAutoStoreLoadDataExample.java
@@ -22,18 +22,18 @@ import org.apache.ignite.cache.store.jdbc.*;
 import org.apache.ignite.configuration.*;
 import org.apache.ignite.examples.*;
 import org.apache.ignite.examples.datagrid.store.*;
-import org.h2.jdbcx.*;
-import org.h2.tools.*;
-
-import java.io.*;
-import java.sql.*;
 
 /**
  * Demonstrates how to load data from database.
  * <p>
  * This example uses {@link CacheJdbcPojoStore} as a persistent store.
  * <p>
- * To run this example your should start {@link H2Startup} first.
+ * 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} or by starting remote
nodes as specified below.</li>
+ *     <li>Start example using {@link CacheAutoStoreLoadDataExample}.</li>
+ * </ul>
  * <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'}.
@@ -45,16 +45,6 @@ public class CacheAutoStoreLoadDataExample {
     /** Heap size required to run this example. */
     public static final int MIN_MEMORY = 1024 * 1024 * 1024;
 
-    /** */
-    private static final String DB_SCRIPT =
-        "delete from PERSON;\n" +
-        "insert into PERSON(id, first_name, last_name) values(1, 'Johannes', 'Kepler');\n"
+
-        "insert into PERSON(id, first_name, last_name) values(2, 'Galileo', 'Galilei');\n"
+
-        "insert into PERSON(id, first_name, last_name) values(3, 'Henry', 'More');\n" +
-        "insert into PERSON(id, first_name, last_name) values(4, 'Polish', 'Brethren');\n"
+
-        "insert into PERSON(id, first_name, last_name) values(5, 'Robert', 'Boyle');\n" +
-        "insert into PERSON(id, first_name, last_name) values(6, 'Isaac', 'Newton');";
-
     /**
      * Executes example.
      *
@@ -64,8 +54,6 @@ public class CacheAutoStoreLoadDataExample {
     public static void main(String[] args) throws IgniteException {
         ExamplesUtils.checkMinMemory(MIN_MEMORY);
 
-        initializeDatabase();
-
         try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
             System.out.println();
             System.out.println(">>> Cache auto store load data example started.");
@@ -87,22 +75,4 @@ public class CacheAutoStoreLoadDataExample {
             }
         }
     }
-
-    /**
-     * Prepares database for load example execution.
-     *
-     * @throws IgniteException If failed.
-     */
-    private static void initializeDatabase() throws IgniteException {
-        try {
-            // Try to connect to database server.
-            JdbcConnectionPool dataSrc = JdbcConnectionPool.create("jdbc:h2:tcp://localhost/mem:ExampleDb",
"sa", "");
-
-            // Load sample data into database.
-            RunScript.execute(dataSrc.getConnection(), new StringReader(DB_SCRIPT));
-        }
-        catch (SQLException e) {
-            throw new IgniteException("Failed to initialize database", e);
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fee55c55/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheConfig.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheConfig.java
b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheConfig.java
index f4ad8f9..1e26188 100644
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheConfig.java
+++ b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheConfig.java
@@ -35,7 +35,7 @@ import static org.apache.ignite.cache.CacheAtomicityMode.*;
  */
 public class CacheConfig {
     /**
-     * Configure cache with JDBC mappings.
+     * Configure cache with store.
      */
     public static CacheConfiguration<Long, Person> jdbcPojoStoreCache() {
         CacheConfiguration<Long, Person> cfg = new CacheConfiguration<>();

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fee55c55/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/DbH2ServerStartup.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/DbH2ServerStartup.java
b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/DbH2ServerStartup.java
new file mode 100644
index 0000000..96e4622
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/DbH2ServerStartup.java
@@ -0,0 +1,78 @@
+/*
+ * 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.auto;
+
+import org.apache.ignite.*;
+import org.h2.jdbcx.*;
+import org.h2.tools.*;
+
+import java.io.*;
+import java.sql.*;
+
+/**
+ * Start H2 database TCP server in order to access sample in-memory database from other processes.
+ */
+public class DbH2ServerStartup {
+    /** Create table script. */
+    private static final String CREATE_TABLE =
+        "create table PERSON(id bigint not null, first_name varchar(50), last_name varchar(50),
PRIMARY KEY(id));";
+
+    /** Sample data script. */
+    private static final String POPULATE_TABLE =
+        "insert into PERSON(id, first_name, last_name) values(1, 'Johannes', 'Kepler');\n"
+
+        "insert into PERSON(id, first_name, last_name) values(2, 'Galileo', 'Galilei');\n"
+
+        "insert into PERSON(id, first_name, last_name) values(3, 'Henry', 'More');\n" +
+        "insert into PERSON(id, first_name, last_name) values(4, 'Polish', 'Brethren');\n"
+
+        "insert into PERSON(id, first_name, last_name) values(5, 'Robert', 'Boyle');\n" +
+        "insert into PERSON(id, first_name, last_name) values(6, 'Isaac', 'Newton');";
+
+    /**
+     * Start H2 database TCP server.
+     *
+     * @param args Command line arguments, none required.
+     * @throws IgniteException If start H2 database TCP server failed.
+     */
+    public static void main(String[] args) throws IgniteException {
+        try {
+            // Start H2 database TCP server in order to access sample in-memory database
from other processes.
+            Server.createTcpServer("-tcpDaemon").start();
+
+            // Try to connect to database TCP server.
+            JdbcConnectionPool dataSrc = JdbcConnectionPool.create("jdbc:h2:tcp://localhost/mem:ExampleDb",
"sa", "");
+
+            // Create Person table in database.
+            RunScript.execute(dataSrc.getConnection(), new StringReader(CREATE_TABLE));
+
+            // Populates Person table with sample data in database.
+            RunScript.execute(dataSrc.getConnection(), new StringReader(POPULATE_TABLE));
+        }
+        catch (SQLException e) {
+            throw new IgniteException("Failed to start database TCP server", e);
+        }
+
+        try {
+            do {
+                System.out.println("Type 'q' and press 'Enter' to stop H2 TCP server...");
+            }
+            while ('q' != System.in.read());
+        }
+        catch (IOException ignored) {
+            // No-op.
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fee55c55/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/H2Startup.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/H2Startup.java
b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/H2Startup.java
deleted file mode 100644
index 1b7c5e9..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/H2Startup.java
+++ /dev/null
@@ -1,66 +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.auto;
-
-import org.apache.ignite.*;
-import org.h2.jdbcx.*;
-import org.h2.tools.*;
-
-import java.io.*;
-import java.sql.*;
-
-/**
- * Start H2 database TCP server in order to access sample in-memory database from other processes.
- */
-public class H2Startup {
-    /** */
-    private static final String DB_SCRIPT =
-        "create table PERSON(id bigint not null, first_name varchar(50), last_name varchar(50),
PRIMARY KEY(id));";
-
-    /**
-     * Start H2 database TCP server.
-     *
-     * @param args Command line arguments, none required.
-     * @throws IgniteException If start H2 database TCP server failed.
-     */
-    public static void main(String[] args) throws IgniteException {
-        try {
-            // Start H2 database TCP server in order to access sample in-memory database
from other processes.
-            Server.createTcpServer("-tcpDaemon").start();
-
-            // Try to connect to database TCP server.
-            JdbcConnectionPool dataSrc = JdbcConnectionPool.create("jdbc:h2:tcp://localhost/mem:ExampleDb",
"sa", "");
-
-            // Load sample data into database.
-            RunScript.execute(dataSrc.getConnection(), new StringReader(DB_SCRIPT));
-        }
-        catch (SQLException e) {
-            throw new IgniteException("Failed to start database TCP server", e);
-        }
-
-        try {
-            do {
-                System.out.println("Type 'q' and press 'Enter' to stop H2 TCP server...");
-            }
-            while ('q' != System.in.read());
-        }
-        catch (IOException ignored) {
-            // No-op.
-        }
-    }
-}


Mime
View raw message