Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id ADDFC18AAC for ; Tue, 16 Jun 2015 16:18:53 +0000 (UTC) Received: (qmail 44038 invoked by uid 500); 16 Jun 2015 16:18:53 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 44006 invoked by uid 500); 16 Jun 2015 16:18:53 -0000 Mailing-List: contact commits-help@ignite.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.incubator.apache.org Delivered-To: mailing list commits@ignite.incubator.apache.org Received: (qmail 43997 invoked by uid 99); 16 Jun 2015 16:18:53 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 Jun 2015 16:18:53 +0000 X-ASF-Spam-Status: No, hits=-2000.4 required=5.0 tests=ALL_TRUSTED,RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Tue, 16 Jun 2015 16:16:40 +0000 Received: (qmail 41233 invoked by uid 99); 16 Jun 2015 16:18:26 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 Jun 2015 16:18:26 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 9D12EE027F; Tue, 16 Jun 2015 16:18:26 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sboikov@apache.org To: commits@ignite.incubator.apache.org Date: Tue, 16 Jun 2015 16:18:27 -0000 Message-Id: <1d2e70f9860a4c9d82e962dbb861c974@git.apache.org> In-Reply-To: <2adbf731f79e4890be546fad8ccf2f25@git.apache.org> References: <2adbf731f79e4890be546fad8ccf2f25@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [03/25] incubator-ignite git commit: #ignite-960: Add CacheJdbcBlobStoreFactory. X-Virus-Checked: Checked by ClamAV on apache.org #ignite-960: Add CacheJdbcBlobStoreFactory. Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/f4a122cd Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/f4a122cd Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/f4a122cd Branch: refs/heads/ignite-sprint-6 Commit: f4a122cd420b474350c784e726282c4ffe6cc276 Parents: 83f7723 Author: ivasilinets Authored: Mon Jun 1 18:29:40 2015 +0300 Committer: ivasilinets Committed: Mon Jun 1 18:29:40 2015 +0300 ---------------------------------------------------------------------- .../store/jdbc/CacheJdbcBlobStoreFactory.java | 218 +++++++++++++++++++ modules/spring/src/test/config/store-cache.xml | 61 ++++++ .../jdbc/CacheJdbcBlobStoreFactorySelfTest.java | 42 ++++ 3 files changed, 321 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f4a122cd/modules/spring/src/main/java/org/apache/ignite/cache/store/jdbc/CacheJdbcBlobStoreFactory.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/main/java/org/apache/ignite/cache/store/jdbc/CacheJdbcBlobStoreFactory.java b/modules/spring/src/main/java/org/apache/ignite/cache/store/jdbc/CacheJdbcBlobStoreFactory.java new file mode 100644 index 0000000..fab5ee8 --- /dev/null +++ b/modules/spring/src/main/java/org/apache/ignite/cache/store/jdbc/CacheJdbcBlobStoreFactory.java @@ -0,0 +1,218 @@ +/* + * 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.cache.store.jdbc; + +import org.apache.ignite.internal.util.tostring.*; +import org.springframework.beans.factory.annotation.*; +import org.springframework.context.*; + +import javax.cache.configuration.*; +import javax.sql.*; + +/** + * {@link Factory} implementation for {@link CacheJdbcBlobStore}. + * + * Use this factory to pass {@link CacheJdbcBlobStore} to {@link org.apache.ignite.configuration.CacheConfiguration}. + * + *

Spring Example

+ *
+ *     <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
+ *
+ *     <bean id= "simpleDataSource" class="org.h2.jdbcx.JdbcDataSource"/>
+ *
+ *     <bean id="cache.jdbc.store"
+ *         class="org.apache.ignite.cache.store.jdbc.CacheJdbcBlobStore">
+ *         <property name="connectionUrl" value="jdbc:h2:mem:"/>
+ *         <property name="createTableQuery"
+ *             value="create table if not exists ENTRIES (key other, val other)"/>
+ *     </bean>
+ *
+ *     <bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
+ *          ...
+ *          <property name="cacheConfiguration">
+ *               <list>
+ *                  <bean class="org.apache.ignite.configuration.CacheConfiguration">
+ *                      ...
+ *                      <property name="cacheStoreFactory">
+ *                          <bean class="org.apache.ignite.cache.store.jdbc.CacheJdbcBlobStoreFactory">
+ *                              <property name="user" value = "GridGain" />
+ *                              <property name="dataSourceBean" value = "simpleDataSource" />
+ *                          </bean>
+ *                      </property>
+ *                  </bean>
+ *               </list>
+ *          </property>
+ *     </bean>
+ * 
+ *

+ * + *
+ * For information about Spring framework visit www.springframework.org + */ +public class CacheJdbcBlobStoreFactory implements Factory { + /** Connection URL. */ + private String connUrl = CacheJdbcBlobStore.DFLT_CONN_URL; + + /** Query to create table. */ + private String createTblQry = CacheJdbcBlobStore.DFLT_CREATE_TBL_QRY; + + /** Query to load entry. */ + private String loadQry = CacheJdbcBlobStore.DFLT_LOAD_QRY; + + /** Query to update entry. */ + private String updateQry = CacheJdbcBlobStore.DFLT_UPDATE_QRY; + + /** Query to insert entries. */ + private String insertQry = CacheJdbcBlobStore.DFLT_INSERT_QRY; + + /** Query to delete entries. */ + private String delQry = CacheJdbcBlobStore.DFLT_DEL_QRY; + + /** User name for database access. */ + private String user; + + /** Password for database access. */ + @GridToStringExclude + private String passwd; + + /** Flag for schema initialization. */ + private boolean initSchema = true; + + /** Name of data source bean. */ + private String dataSrcBean; + + /** Application context. */ + @Autowired + private ApplicationContext appContext; + + /** {@inheritDoc} */ + @Override public CacheJdbcBlobStore create() { + CacheJdbcBlobStore store = new CacheJdbcBlobStore(); + + store.setInitSchema(initSchema); + store.setConnectionUrl(connUrl); + store.setCreateTableQuery(createTblQry); + store.setLoadQuery(loadQry); + store.setUpdateQuery(updateQry); + store.setInsertQuery(insertQry); + store.setDeleteQuery(delQry); + store.setUser(user); + store.setPassword(passwd); + + if (dataSrcBean != null) { + DataSource data = (DataSource) appContext.getBean(dataSrcBean); + + store.setDataSource(data); + } + + return store; + } + + /** + * See {@link org.apache.ignite.cache.store.jdbc.CacheJdbcBlobStore#setInitSchema(boolean)}. + * + * @param initSchema Initialized schema flag. + */ + public void setInitSchema(boolean initSchema) { + this.initSchema = initSchema; + } + + /** + * See {@link org.apache.ignite.cache.store.jdbc.CacheJdbcBlobStore#setConnectionUrl(String)}. + * + * @param connUrl Connection URL. + */ + public void setConnectionUrl(String connUrl) { + this.connUrl = connUrl; + } + + /** + * See {@link org.apache.ignite.cache.store.jdbc.CacheJdbcBlobStore#setCreateTableQuery(String)}. + * + * @param createTblQry Create table query. + */ + public void setCreateTableQuery(String createTblQry) { + this.createTblQry = createTblQry; + } + + /** + * See {@link org.apache.ignite.cache.store.jdbc.CacheJdbcBlobStore#setLoadQuery(String)}. + * + * @param loadQry Load query + */ + public void setLoadQuery(String loadQry) { + this.loadQry = loadQry; + } + + /** + * See {@link org.apache.ignite.cache.store.jdbc.CacheJdbcBlobStore#setUpdateQuery(String)}. + * + * @param updateQry Update entry query. + */ + public void setUpdateQuery(String updateQry) { + this.updateQry = updateQry; + } + + /** + * See {@link org.apache.ignite.cache.store.jdbc.CacheJdbcBlobStore#setInsertQuery(String)}. + * + * @param insertQry Insert entry query. + */ + public void setInsertQuery(String insertQry) { + this.insertQry = insertQry; + } + + /** + * See {@link org.apache.ignite.cache.store.jdbc.CacheJdbcBlobStore#setDeleteQuery(String)}. + * + * @param delQry Delete entry query. + */ + public void setDeleteQuery(String delQry) { + this.delQry = delQry; + } + + /** + * See {@link org.apache.ignite.cache.store.jdbc.CacheJdbcBlobStore#setUser(String)}. + * + * @param user User name. + */ + public void setUser(String user) { + this.user = user; + } + + /** + * See {@link org.apache.ignite.cache.store.jdbc.CacheJdbcBlobStore#setPassword(String)}. + * + * @param passwd Password. + */ + public void setPassword(String passwd) { + this.passwd = passwd; + } + + /** + * Sets name of the data source bean. + * + * See {@link org.apache.ignite.cache.store.jdbc.CacheJdbcBlobStore#setDataSource(javax.sql.DataSource)} + * for more information. + * + * @param dataSrcBean Data source bean name. + */ + public void setDataSourceBean(String dataSrcBean) { + this.dataSrcBean = dataSrcBean; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f4a122cd/modules/spring/src/test/config/store-cache.xml ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/config/store-cache.xml b/modules/spring/src/test/config/store-cache.xml new file mode 100644 index 0000000..23cf3ea --- /dev/null +++ b/modules/spring/src/test/config/store-cache.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 127.0.0.1:47500..47509 + + + + + + + + http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f4a122cd/modules/spring/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcBlobStoreFactorySelfTest.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcBlobStoreFactorySelfTest.java b/modules/spring/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcBlobStoreFactorySelfTest.java new file mode 100644 index 0000000..cadd899 --- /dev/null +++ b/modules/spring/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcBlobStoreFactorySelfTest.java @@ -0,0 +1,42 @@ +/* + * 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.cache.store.jdbc; + +import org.apache.ignite.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.testframework.*; +import org.apache.ignite.testframework.junits.common.*; + +/** + * Test for Cache jdbc blob store factory. + */ +public class CacheJdbcBlobStoreFactorySelfTest extends GridCommonAbstractTest { + public void testXmlConfiguration() throws Exception { + try (Ignite ignite = Ignition.start("modules/spring/src/test/config/store-cache.xml")) { + try (IgniteCache cache = ignite.getOrCreateCache("test")) { + CacheJdbcBlobStore store = (CacheJdbcBlobStore)cache.getConfiguration(CacheConfiguration.class). + getCacheStoreFactory().create(); + + assertEquals("GridGain", GridTestUtils.getFieldValue(store, CacheJdbcBlobStore.class, "user")); + + assertEquals(CacheJdbcBlobStoreFactory.class, + GridTestUtils.getFieldValue(store, CacheJdbcBlobStore.class, "dataSrc").getClass()); + } + } + } +}