Repository: incubator-ignite Updated Branches: refs/heads/ignite-329 566625312 -> 958bfebff
# ignite-329 Fixed H2 server start. Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/958bfebf Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/958bfebf Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/958bfebf Branch: refs/heads/ignite-329 Commit: 958bfebffa03b94adf7438b438d270a6d76b6883 Parents: 5666253 Author: anovikov <anovi...@gridgain.com> Authored: Wed Mar 11 11:46:45 2015 +0700 Committer: anovikov <anovi...@gridgain.com> Committed: Wed Mar 11 11:46:45 2015 +0700 ---------------------------------------------------------------------- .../config/store/example-jdbc-pojo-store.xml | 14 +------- .../store/jdbc/CacheJdbcPojoPersonStore.java | 33 +++++++++--------- modules/schema-import/readme.txt | 36 ++++++++++++++++++++ 3 files changed, 53 insertions(+), 30 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/958bfebf/examples/config/store/example-jdbc-pojo-store.xml ---------------------------------------------------------------------- diff --git a/examples/config/store/example-jdbc-pojo-store.xml b/examples/config/store/example-jdbc-pojo-store.xml index 80e5fe1..4fc089f 100644 --- a/examples/config/store/example-jdbc-pojo-store.xml +++ b/examples/config/store/example-jdbc-pojo-store.xml @@ -59,19 +59,7 @@ <property name="cacheStoreFactory"> <bean class="javax.cache.configuration.FactoryBuilder$SingletonFactory"> <constructor-arg> - <bean class="org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStore"> - <property name="dialect"> - <bean class="org.apache.ignite.cache.store.jdbc.dialect.H2Dialect"/> - </property> - - <property name="dataSource"> - <bean class="org.h2.jdbcx.JdbcConnectionPool" factory-method="create"> - <constructor-arg value="jdbc:h2:tcp://localhost/mem:ExampleDb"/> - <constructor-arg value="sa"/> - <constructor-arg value=""/> - </bean> - </property> - </bean> + <bean class="org.apache.ignite.examples.datagrid.store.jdbc.CacheJdbcPojoPersonStore"/> </constructor-arg> </bean> </property> http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/958bfebf/examples/src/main/java/org/apache/ignite/examples/datagrid/store/jdbc/CacheJdbcPojoPersonStore.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/jdbc/CacheJdbcPojoPersonStore.java b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/jdbc/CacheJdbcPojoPersonStore.java index dd15184..0160203 100644 --- a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/jdbc/CacheJdbcPojoPersonStore.java +++ b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/jdbc/CacheJdbcPojoPersonStore.java @@ -25,6 +25,7 @@ import org.apache.ignite.lang.*; import org.h2.tools.*; import org.jetbrains.annotations.*; +import javax.cache.*; import javax.cache.integration.*; import java.io.*; import java.sql.*; @@ -34,19 +35,24 @@ import java.sql.*; * transaction with cache transactions and maps {@link Long} to {@link Person}. */ public class CacheJdbcPojoPersonStore extends CacheJdbcPojoStore<Long, Person> { - /** H2 database TCP server. */ - private Server srv; - /** * Constructor. * * @throws IgniteException If failed. */ public CacheJdbcPojoPersonStore() throws IgniteException { - // Construct example database in memory. - dataSrc = org.h2.jdbcx.JdbcConnectionPool.create("jdbc:h2:mem:ExampleDb;DB_CLOSE_DELAY=-1", "sa", ""); + try { + // Try to connect to database server. + dataSrc = org.h2.jdbcx.JdbcConnectionPool.create("jdbc:h2:tcp://localhost/mem:ExampleDb", "sa", ""); + + resolveDialect(); + } + catch (CacheException ignore) { + // Construct example database in memory. + dataSrc = org.h2.jdbcx.JdbcConnectionPool.create("jdbc:h2:mem:ExampleDb;DB_CLOSE_DELAY=-1", "sa", ""); - prepareDb(); + prepareDb(); + } } /** @@ -63,10 +69,11 @@ public class CacheJdbcPojoPersonStore extends CacheJdbcPojoStore<Long, Person> { "examples/config/store/example-database.script"); try { - RunScript.execute(dataSrc.getConnection(), new FileReader(script)); - // Start H2 database TCP server in order to access sample in-memory database from other processes. - srv = Server.createTcpServer().start(); + Server.createTcpServer("-tcpDaemon").start(); + + // Load sample data into database. + RunScript.execute(dataSrc.getConnection(), new FileReader(script)); } catch (SQLException e) { throw new IgniteException("Failed to initialize database", e); @@ -86,12 +93,4 @@ public class CacheJdbcPojoPersonStore extends CacheJdbcPojoStore<Long, Person> { super.loadCache(clo, "java.lang.Long", "select * from PERSONS limit " + entryCnt); } - - /** {@inheritDoc} */ - @Override public void stop() throws IgniteException { - if (srv != null) - srv.stop(); - - super.stop(); - } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/958bfebf/modules/schema-import/readme.txt ---------------------------------------------------------------------- diff --git a/modules/schema-import/readme.txt b/modules/schema-import/readme.txt index 51ec399..1494499 100644 --- a/modules/schema-import/readme.txt +++ b/modules/schema-import/readme.txt @@ -176,3 +176,39 @@ Or you can load data from database to cache with custom SQL: cache.loadCache(null, "java.lang.Long", "select * from PERSON where id = 2") Also if you put data into cache it will be inserted / updated in underlying database. + + +Performance optimization. +------------------------------------------ + +1. Use DataSource with connection pool. +2. Enable write-behind feature by default write-behind is disabled. + +Example of spring configuration: + +<bean class="org.apache.ignite.configuration.IgniteConfiguration"> + ... + <!-- Cache configuration. --> + <property name="cacheConfiguration"> + <list> + <bean class="org.apache.ignite.configuration.CacheConfiguration"> + ... + <!-- Sets flag indicating whether write-behind is enabled.. --> + <property name="writeBehindEnabled" value="true/> + ... + </bean> + </list> + </property> + ... +</bean> + +Example of java code configuration: + +IgniteConfiguration cfg = new IgniteConfiguration(); +... +CacheConfiguration ccfg = new CacheConfiguration<>(); +... +ccfg.setWriteBehindEnabled(true); +... +// Start Ignite node. +Ignition.start(cfg);