Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id A4A8C200C63 for ; Wed, 26 Apr 2017 15:25:18 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id A2FF5160B95; Wed, 26 Apr 2017 13:25:18 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 8274D160BDB for ; Wed, 26 Apr 2017 15:25:14 +0200 (CEST) Received: (qmail 99229 invoked by uid 500); 26 Apr 2017 13:25:13 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 98942 invoked by uid 99); 26 Apr 2017 13:25:13 -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; Wed, 26 Apr 2017 13:25:13 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 5714FE1892; Wed, 26 Apr 2017 13:25:13 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: vozerov@apache.org To: commits@ignite.apache.org Date: Wed, 26 Apr 2017 13:25:52 -0000 Message-Id: <14c30915d0494e9caa825f1b836d0cd5@git.apache.org> In-Reply-To: <74ede65a043548339e50a758c6cba90c@git.apache.org> References: <74ede65a043548339e50a758c6cba90c@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [41/50] [abbrv] ignite git commit: ignite-1794 Refactored hibernate modules, switched to hibernate 5.1 archived-at: Wed, 26 Apr 2017 13:25:18 -0000 http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListenerSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListenerSelfTest.java b/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListenerSelfTest.java new file mode 100644 index 0000000..880d12a --- /dev/null +++ b/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListenerSelfTest.java @@ -0,0 +1,238 @@ +/* + * 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.hibernate; + +import java.io.Serializable; +import java.util.Map; +import javax.cache.Cache; +import javax.cache.configuration.Factory; +import javax.cache.integration.CacheLoaderException; +import javax.cache.integration.CacheWriterException; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; +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.cache.store.CacheStoreSessionListener; +import org.apache.ignite.cache.store.CacheStoreSessionListenerAbstractSelfTest; +import org.apache.ignite.cache.store.jdbc.CacheJdbcStoreSessionListener; +import org.apache.ignite.lang.IgniteBiInClosure; +import org.apache.ignite.resources.CacheStoreSessionResource; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.cfg.Configuration; + +/** + * Tests for {@link CacheJdbcStoreSessionListener}. + */ +public class CacheHibernateStoreSessionListenerSelfTest extends CacheStoreSessionListenerAbstractSelfTest { + /** {@inheritDoc} */ + @Override protected Factory> storeFactory() { + return new Factory>() { + @Override public CacheStore create() { + return new Store(); + } + }; + } + + /** {@inheritDoc} */ + @Override protected Factory sessionListenerFactory() { + return new Factory() { + @Override public CacheStoreSessionListener create() { + CacheHibernateStoreSessionListener lsnr = new CacheHibernateStoreSessionListener(); + + SessionFactory sesFactory = new Configuration(). + setProperty("hibernate.connection.url", URL). + addAnnotatedClass(Table1.class). + addAnnotatedClass(Table2.class). + buildSessionFactory(); + + lsnr.setSessionFactory(sesFactory); + + return lsnr; + } + }; + } + + /** + */ + private static class Store extends CacheStoreAdapter { + /** */ + private static String SES_CONN_KEY = "ses_conn"; + + /** */ + @CacheStoreSessionResource + private CacheStoreSession ses; + + /** {@inheritDoc} */ + @Override public void loadCache(IgniteBiInClosure clo, Object... args) { + loadCacheCnt.incrementAndGet(); + + checkSession(); + } + + /** {@inheritDoc} */ + @Override public Integer load(Integer key) throws CacheLoaderException { + loadCnt.incrementAndGet(); + + checkSession(); + + return null; + } + + /** {@inheritDoc} */ + @Override public void write(Cache.Entry entry) + throws CacheWriterException { + writeCnt.incrementAndGet(); + + checkSession(); + + if (write.get()) { + Session hibSes = ses.attachment(); + + switch (ses.cacheName()) { + case "cache1": + hibSes.save(new Table1(entry.getKey(), entry.getValue())); + + break; + + case "cache2": + if (fail.get()) + throw new CacheWriterException("Expected failure."); + + hibSes.save(new Table2(entry.getKey(), entry.getValue())); + + break; + + default: + throw new CacheWriterException("Wring cache: " + ses.cacheName()); + } + } + } + + /** {@inheritDoc} */ + @Override public void delete(Object key) throws CacheWriterException { + deleteCnt.incrementAndGet(); + + checkSession(); + } + + /** {@inheritDoc} */ + @Override public void sessionEnd(boolean commit) { + assertNull(ses.attachment()); + } + + /** + */ + private void checkSession() { + Session hibSes = ses.attachment(); + + assertNotNull(hibSes); + + assertTrue(hibSes.isOpen()); + + Transaction tx = hibSes.getTransaction(); + + assertNotNull(tx); + + if (ses.isWithinTransaction()) + assertTrue(tx.isActive()); + else + assertFalse(tx.isActive()); + + verifySameInstance(hibSes); + } + + /** + * @param hibSes Session. + */ + private void verifySameInstance(Session hibSes) { + Map props = ses.properties(); + + Session sesConn = props.get(SES_CONN_KEY); + + if (sesConn == null) + props.put(SES_CONN_KEY, hibSes); + else { + assertSame(hibSes, sesConn); + + reuseCnt.incrementAndGet(); + } + } + } + + /** + */ + @Entity + @Table(name = "Table1") + private static class Table1 implements Serializable { + /** */ + @Id @GeneratedValue + @Column(name = "id") + private Integer id; + + /** */ + @Column(name = "key") + private int key; + + /** */ + @Column(name = "value") + private int value; + + /** + * @param key Key. + * @param value Value. + */ + private Table1(int key, int value) { + this.key = key; + this.value = value; + } + } + + /** + */ + @Entity + @Table(name = "Table2") + private static class Table2 implements Serializable { + /** */ + @Id @GeneratedValue + @Column(name = "id") + private Integer id; + + /** */ + @Column(name = "key") + private int key; + + /** */ + @Column(name = "value") + private int value; + + /** + * @param key Key. + * @param value Value. + */ + private Table2(int key, int value) { + this.key = key; + this.value = value; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml ---------------------------------------------------------------------- diff --git a/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml b/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml new file mode 100644 index 0000000..3822b31 --- /dev/null +++ b/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + true + + + jdbc:h2:mem:example;DB_CLOSE_DELAY=-1 + + + update + + + org.hibernate.dialect.H2Dialect + + + + + http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/store/hibernate/package-info.java ---------------------------------------------------------------------- diff --git a/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/store/hibernate/package-info.java b/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/store/hibernate/package-info.java new file mode 100644 index 0000000..8af9886 --- /dev/null +++ b/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/store/hibernate/package-info.java @@ -0,0 +1,22 @@ +/* + * 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. + */ + +/** + * + * Contains internal tests or test related classes and interfaces. + */ +package org.apache.ignite.cache.store.hibernate; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/src/test/java/org/apache/ignite/testsuites/IgniteBinaryHibernateTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/hibernate-4.2/src/test/java/org/apache/ignite/testsuites/IgniteBinaryHibernateTestSuite.java b/modules/hibernate-4.2/src/test/java/org/apache/ignite/testsuites/IgniteBinaryHibernateTestSuite.java new file mode 100644 index 0000000..3791bae --- /dev/null +++ b/modules/hibernate-4.2/src/test/java/org/apache/ignite/testsuites/IgniteBinaryHibernateTestSuite.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.testsuites; + +import junit.framework.TestSuite; +import org.apache.ignite.internal.binary.BinaryMarshaller; +import org.apache.ignite.testframework.config.GridTestProperties; + +/** + * + */ +public class IgniteBinaryHibernateTestSuite extends TestSuite { + /** + * @return Test suite. + * @throws Exception If failed. + */ + public static TestSuite suite() throws Exception { + GridTestProperties.setProperty(GridTestProperties.MARSH_CLASS_NAME, BinaryMarshaller.class.getName()); + + return IgniteHibernateTestSuite.suite(); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/src/test/java/org/apache/ignite/testsuites/IgniteHibernateTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/hibernate-4.2/src/test/java/org/apache/ignite/testsuites/IgniteHibernateTestSuite.java b/modules/hibernate-4.2/src/test/java/org/apache/ignite/testsuites/IgniteHibernateTestSuite.java new file mode 100644 index 0000000..99fea56 --- /dev/null +++ b/modules/hibernate-4.2/src/test/java/org/apache/ignite/testsuites/IgniteHibernateTestSuite.java @@ -0,0 +1,57 @@ +/* + * 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.testsuites; + +import junit.framework.TestSuite; +import org.apache.ignite.cache.hibernate.HibernateL2CacheConfigurationSelfTest; +import org.apache.ignite.cache.hibernate.HibernateL2CacheSelfTest; +import org.apache.ignite.cache.hibernate.HibernateL2CacheTransactionalSelfTest; +import org.apache.ignite.cache.hibernate.HibernateL2CacheTransactionalUseSyncSelfTest; +import org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreNodeRestartTest; +import org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreSelfTest; +import org.apache.ignite.cache.store.hibernate.CacheHibernateStoreFactorySelfTest; +import org.apache.ignite.cache.store.hibernate.CacheHibernateStoreSessionListenerSelfTest; + +/** + * Hibernate integration tests. + */ +public class IgniteHibernateTestSuite extends TestSuite { + /** + * @return Test suite. + * @throws Exception Thrown in case of the failure. + */ + public static TestSuite suite() throws Exception { + TestSuite suite = new TestSuite("Hibernate Integration Test Suite"); + + // Hibernate L2 cache. + suite.addTestSuite(HibernateL2CacheSelfTest.class); + suite.addTestSuite(HibernateL2CacheTransactionalSelfTest.class); + suite.addTestSuite(HibernateL2CacheTransactionalUseSyncSelfTest.class); + suite.addTestSuite(HibernateL2CacheConfigurationSelfTest.class); + + suite.addTestSuite(CacheHibernateBlobStoreSelfTest.class); + + suite.addTestSuite(CacheHibernateBlobStoreNodeRestartTest.class); + + suite.addTestSuite(CacheHibernateStoreSessionListenerSelfTest.class); + + suite.addTestSuite(CacheHibernateStoreFactorySelfTest.class); + + return suite; + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/README.txt ---------------------------------------------------------------------- diff --git a/modules/hibernate-5.1/README.txt b/modules/hibernate-5.1/README.txt new file mode 100644 index 0000000..53c5d18 --- /dev/null +++ b/modules/hibernate-5.1/README.txt @@ -0,0 +1,48 @@ +Apache Ignite Hibernate Module +------------------------------ + +Apache Ignite Hibernate module provides Hibernate second-level cache (L2 cache) implementation based +on Apache Ignite In-Memory Data Grid. + +To enable Hibernate module when starting a standalone node, move 'optional/ignite-hibernate5' folder to +'libs' folder before running 'ignite.{sh|bat}' script. The content of the module folder will +be added to classpath in this case. + +Importing Hibernate Module In Maven Project +------------------------------------------- + +If you are using Maven to manage dependencies of your project, you can add Hibernate module +dependency like this (replace '${ignite.version}' with actual Ignite version you are +interested in): + + + ... + + ... + + org.apache.ignite + ignite-hibernate_5.1 + ${ignite.version} + + ... + + ... + + + +LGPL dependencies +----------------- + +Ignite includes the following optional LGPL dependencies: + - Hibernate L2 Cache Integration, http://hibernate.org/orm/ + - JTS Topology Suite for Geospatial indexing, http://tsusiatsoftware.net/jts/main.html + - cron4j for cron-based task scheduling, http://www.sauronsoftware.it/projects/cron4j + +Apache binary releases cannot include LGPL dependencies. If you would like include +optional LGPL dependencies into your release, you should download the source release +from Ignite website and do the build with the following maven command: + +mvn clean package -DskipTests -Prelease,lgpl http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/licenses/apache-2.0.txt ---------------------------------------------------------------------- diff --git a/modules/hibernate-5.1/licenses/apache-2.0.txt b/modules/hibernate-5.1/licenses/apache-2.0.txt new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/modules/hibernate-5.1/licenses/apache-2.0.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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. http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/pom.xml ---------------------------------------------------------------------- diff --git a/modules/hibernate-5.1/pom.xml b/modules/hibernate-5.1/pom.xml new file mode 100644 index 0000000..80299bc --- /dev/null +++ b/modules/hibernate-5.1/pom.xml @@ -0,0 +1,159 @@ + + + + + + + 4.0.0 + + + org.apache.ignite + ignite-parent + 1 + ../../parent + + + ignite-hibernate_5.1 + 2.0.0-SNAPSHOT + http://ignite.apache.org + + + + org.apache.ignite + ignite-core + ${project.version} + + + + org.apache.ignite + ignite-hibernate-core + ${project.version} + + + + org.hibernate + hibernate-core + 5.1.5.Final + + + + org.apache.ignite + ignite-jta + ${project.version} + test + + + + org.ow2.jotm + jotm-core + 2.1.9 + test + + + + commons-dbcp + commons-dbcp + 1.4 + test + + + + com.h2database + h2 + ${h2.version} + test + + + + javax.resource + connector-api + 1.5 + test + + + + org.apache.ignite + ignite-core + ${project.version} + test-jar + test + + + + org.apache.ignite + ignite-spring + ${project.version} + test + + + + org.apache.ignite + ignite-log4j + ${project.version} + test + + + + org.springframework + spring-beans + ${spring.version} + test + + + + org.springframework + spring-context + ${spring.version} + test + + + + com.thoughtworks.xstream + xstream + 1.4.8 + test + + + + + + + src/main/java + + **/*.java + + + + src/test/java + + **/*.java + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateAbstractRegionAccessStrategy.java ---------------------------------------------------------------------- diff --git a/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateAbstractRegionAccessStrategy.java b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateAbstractRegionAccessStrategy.java new file mode 100644 index 0000000..c5829bf --- /dev/null +++ b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateAbstractRegionAccessStrategy.java @@ -0,0 +1,103 @@ +/* + * 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.hibernate; + +import org.hibernate.cache.CacheException; +import org.hibernate.cache.spi.access.RegionAccessStrategy; +import org.hibernate.cache.spi.access.SoftLock; +import org.hibernate.engine.spi.SessionImplementor; +import org.jetbrains.annotations.Nullable; + +/** + * Implementation of L2 cache access strategy delegating to {@link HibernateAccessStrategyAdapter}. + */ +public abstract class HibernateAbstractRegionAccessStrategy implements RegionAccessStrategy { + /** */ + protected final HibernateAccessStrategyAdapter stgy; + + /** + * @param stgy Access strategy implementation. + */ + protected HibernateAbstractRegionAccessStrategy(HibernateAccessStrategyAdapter stgy) { + this.stgy = stgy; + } + + /** {@inheritDoc} */ + @Nullable @Override public Object get(SessionImplementor ses, Object key, long txTs) throws CacheException { + return stgy.get(key); + } + + /** {@inheritDoc} */ + @Override public boolean putFromLoad(SessionImplementor ses, Object key, Object val, long txTs, Object ver) throws CacheException { + stgy.putFromLoad(key, val); + + return true; + } + + /** {@inheritDoc} */ + @Override public boolean putFromLoad(SessionImplementor ses, Object key, Object val, long txTs, Object ver, boolean minimalPutOverride) + throws CacheException { + stgy.putFromLoad(key, val, minimalPutOverride); + + return true; + } + + /** {@inheritDoc} */ + @Nullable @Override public SoftLock lockItem(SessionImplementor ses, Object key, Object ver) throws CacheException { + stgy.lock(key); + + return null; + } + + /** {@inheritDoc} */ + @Nullable @Override public SoftLock lockRegion() throws CacheException { + stgy.lockRegion(); + + return null; + } + + /** {@inheritDoc} */ + @Override public void unlockRegion(SoftLock lock) throws CacheException { + stgy.unlockRegion(); + } + + /** {@inheritDoc} */ + @Override public void unlockItem(SessionImplementor ses, Object key, SoftLock lock) throws CacheException { + stgy.unlock(key); + } + + /** {@inheritDoc} */ + @Override public void remove(SessionImplementor ses, Object key) throws CacheException { + stgy.remove(key); + } + + /** {@inheritDoc} */ + @Override public void removeAll() throws CacheException { + stgy.removeAll(); + } + + /** {@inheritDoc} */ + @Override public void evict(Object key) throws CacheException { + stgy.evict(key); + } + + /** {@inheritDoc} */ + @Override public void evictAll() throws CacheException { + stgy.evictAll(); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateCollectionRegion.java ---------------------------------------------------------------------- diff --git a/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateCollectionRegion.java b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateCollectionRegion.java new file mode 100644 index 0000000..be99e98 --- /dev/null +++ b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateCollectionRegion.java @@ -0,0 +1,114 @@ +/* + * 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.hibernate; + +import org.apache.ignite.Ignite; +import org.hibernate.cache.CacheException; +import org.hibernate.cache.spi.CacheDataDescription; +import org.hibernate.cache.spi.CollectionRegion; +import org.hibernate.cache.spi.access.AccessType; +import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.persister.collection.CollectionPersister; + +/** + * Implementation of {@link CollectionRegion}. This region is used to store collection data. + *

+ * L2 cache for collection can be enabled in the Hibernate configuration file: + *

+ * <hibernate-configuration>
+ *     <!-- Enable L2 cache. -->
+ *     <property name="cache.use_second_level_cache">true</property>
+ *
+ *     <!-- Use Ignite as L2 cache provider. -->
+ *     <property name="cache.region.factory_class">org.apache.ignite.cache.hibernate.HibernateRegionFactory</property>
+ *
+ *     <!-- Specify entities. -->
+ *     <mapping class="com.example.Entity"/>
+ *     <mapping class="com.example.ChildEntity"/>
+ *
+ *     <!-- Enable L2 cache with nonstrict-read-write access strategy for entities and collection. -->
+ *     <collection-cache collection="com.example.Entity" usage="nonstrict-read-write"/>
+ *     <collection-cache collection="com.example.ChildEntity" usage="nonstrict-read-write"/>
+ *     <collection-cache collection="com.example.Entity.children" usage="nonstrict-read-write"/>
+ * </hibernate-configuration>
+ * 
+ * Also cache for collection can be enabled using annotations: + *
+ * @javax.persistence.Entity
+ * public class Entity {
+ *    ...
+ *
+ *    @javax.persistence.OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
+ *    @javax.persistence.JoinColumn(name="PARENT_ID")
+ *    @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
+ *    public List<ChildEntity> getChildren() {...}
+ * }
+ * 
+ * Note: the collection cache does not cache the state of the actual entities in the cache, it caches only identifier + * values. For this reason, the collection cache should always be used in conjunction with + * the second-level cache for those entities expected to be cached as part of a collection cache. + */ +public class HibernateCollectionRegion extends HibernateTransactionalDataRegion implements CollectionRegion { + /** + * @param factory Region factory. + * @param name Region name. + * @param ignite Grid. + * @param cache Region cache. + * @param dataDesc Region data description. + */ + public HibernateCollectionRegion(HibernateRegionFactory factory, String name, + Ignite ignite, HibernateCacheProxy cache, CacheDataDescription dataDesc) { + super(factory, name, ignite, cache, dataDesc); + } + + /** {@inheritDoc} */ + @Override public CollectionRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException { + return new AccessStrategy(createAccessStrategy(accessType)); + } + + /** + * Collection region access strategy. + */ + private class AccessStrategy extends HibernateAbstractRegionAccessStrategy + implements CollectionRegionAccessStrategy { + /** + * @param stgy Access strategy implementation. + */ + private AccessStrategy(HibernateAccessStrategyAdapter stgy) { + super(stgy); + } + + /** {@inheritDoc} */ + @Override public Object generateCacheKey(Object id, + CollectionPersister persister, + SessionFactoryImplementor factory, String tenantIdentifier) { + return HibernateKeyWrapper.staticCreateCollectionKey(id, persister, tenantIdentifier); + } + + /** {@inheritDoc} */ + @Override public Object getCacheKeyId(Object cacheKey) { + return ((HibernateKeyWrapper)cacheKey).id(); + } + + /** {@inheritDoc} */ + @Override public CollectionRegion getRegion() { + return HibernateCollectionRegion.this; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateEntityRegion.java ---------------------------------------------------------------------- diff --git a/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateEntityRegion.java b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateEntityRegion.java new file mode 100644 index 0000000..c669400 --- /dev/null +++ b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateEntityRegion.java @@ -0,0 +1,128 @@ +/* + * 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.hibernate; + +import org.apache.ignite.Ignite; +import org.hibernate.cache.CacheException; +import org.hibernate.cache.spi.CacheDataDescription; +import org.hibernate.cache.spi.EntityRegion; +import org.hibernate.cache.spi.access.AccessType; +import org.hibernate.cache.spi.access.EntityRegionAccessStrategy; +import org.hibernate.cache.spi.access.SoftLock; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.engine.spi.SessionImplementor; +import org.hibernate.persister.entity.EntityPersister; + +/** + * Implementation of {@link EntityRegion}. This region is used to store entity data. + *

+ * L2 cache for entity can be enabled in the Hibernate configuration file: + *

+ * <hibernate-configuration>
+ *     <!-- Enable L2 cache. -->
+ *     <property name="cache.use_second_level_cache">true</property>
+ *
+ *     <!-- Use Ignite as L2 cache provider. -->
+ *     <property name="cache.region.factory_class">org.apache.ignite.cache.hibernate.HibernateRegionFactory</property>
+ *
+ *     <!-- Specify entity. -->
+ *     <mapping class="com.example.Entity"/>
+ *
+ *     <!-- Enable L2 cache with nonstrict-read-write access strategy for entity. -->
+ *     <class-cache class="com.example.Entity" usage="nonstrict-read-write"/>
+ * </hibernate-configuration>
+ * 
+ * Also cache for entity can be enabled using annotations: + *
+ * @javax.persistence.Entity
+ * @javax.persistence.Cacheable
+ * @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
+ * public class Entity { ... }
+ * 
+ */ +public class HibernateEntityRegion extends HibernateTransactionalDataRegion implements EntityRegion { + /** + * @param factory Region factory. + * @param name Region name. + * @param ignite Grid. + * @param cache Region cache, + * @param dataDesc Region data description. + */ + public HibernateEntityRegion(HibernateRegionFactory factory, String name, Ignite ignite, + HibernateCacheProxy cache, CacheDataDescription dataDesc) { + super(factory, name, ignite, cache, dataDesc); + } + + /** {@inheritDoc} */ + @Override public EntityRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException { + return new AccessStrategy(createAccessStrategy(accessType)); + } + + /** + * Entity region access strategy. + */ + private class AccessStrategy extends HibernateAbstractRegionAccessStrategy + implements EntityRegionAccessStrategy { + /** + * @param stgy Access strategy implementation. + */ + private AccessStrategy(HibernateAccessStrategyAdapter stgy) { + super(stgy); + } + + /** {@inheritDoc} */ + @Override public Object generateCacheKey(Object id, + EntityPersister persister, + SessionFactoryImplementor factory, + String tenantIdentifier) { + return HibernateKeyWrapper.staticCreateEntityKey(id, persister, tenantIdentifier); + } + + /** {@inheritDoc} */ + @Override public Object getCacheKeyId(Object cacheKey) { + return ((HibernateKeyWrapper)cacheKey).id(); + } + + /** {@inheritDoc} */ + @Override public EntityRegion getRegion() { + return HibernateEntityRegion.this; + } + + /** {@inheritDoc} */ + @Override public boolean insert(SessionImplementor ses, Object key, Object val, Object ver) throws CacheException { + return stgy.insert(key, val); + } + + /** {@inheritDoc} */ + @Override public boolean afterInsert(SessionImplementor ses, Object key, Object val, Object ver) throws CacheException { + return stgy.afterInsert(key, val); + } + + /** {@inheritDoc} */ + @Override public boolean update(SessionImplementor ses, Object key, Object val, Object currVer, Object previousVer) + throws CacheException { + return stgy.update(key, val); + } + + /** {@inheritDoc} */ + @Override public boolean afterUpdate(SessionImplementor ses, Object key, Object val, Object currVer, Object previousVer, SoftLock lock) + throws CacheException { + return stgy.afterUpdate(key, val); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateGeneralDataRegion.java ---------------------------------------------------------------------- diff --git a/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateGeneralDataRegion.java b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateGeneralDataRegion.java new file mode 100644 index 0000000..9365157 --- /dev/null +++ b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateGeneralDataRegion.java @@ -0,0 +1,79 @@ +/* + * 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.hibernate; + +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCheckedException; +import org.hibernate.cache.CacheException; +import org.hibernate.cache.spi.GeneralDataRegion; +import org.hibernate.cache.spi.QueryResultsRegion; +import org.hibernate.cache.spi.TimestampsRegion; +import org.hibernate.engine.spi.SessionImplementor; +import org.jetbrains.annotations.Nullable; + +/** + * Implementation of {@link GeneralDataRegion}. This interface defines common contract for {@link QueryResultsRegion} + * and {@link TimestampsRegion}. + */ +public class HibernateGeneralDataRegion extends HibernateRegion implements GeneralDataRegion { + /** + * @param factory Region factory. + * @param name Region name. + * @param ignite Grid. + * @param cache Region cache. + */ + HibernateGeneralDataRegion(HibernateRegionFactory factory, String name, + Ignite ignite, HibernateCacheProxy cache) { + super(factory, name, ignite, cache); + } + + /** {@inheritDoc} */ + @Nullable @Override public Object get(SessionImplementor ses, Object key) throws CacheException { + try { + return cache.get(key); + } + catch (IgniteCheckedException e) { + throw new CacheException(e); + } + } + + /** {@inheritDoc} */ + @Override public void put(SessionImplementor ses, Object key, Object val) throws CacheException { + try { + cache.put(key, val); + } + catch (IgniteCheckedException e) { + throw new CacheException(e); + } + } + + /** {@inheritDoc} */ + @Override public void evict(Object key) throws CacheException { + HibernateAccessStrategyAdapter.evict(ignite, cache, key); + } + + /** {@inheritDoc} */ + @Override public void evictAll() throws CacheException { + try { + HibernateAccessStrategyAdapter.evictAll(cache); + } + catch (IgniteCheckedException e) { + throw HibernateRegionFactory.EXCEPTION_CONVERTER.convert(e); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyWrapper.java ---------------------------------------------------------------------- diff --git a/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyWrapper.java b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyWrapper.java new file mode 100644 index 0000000..45d00e4 --- /dev/null +++ b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyWrapper.java @@ -0,0 +1,109 @@ +/* + * 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.hibernate; + +import java.io.Serializable; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.hibernate.cache.internal.DefaultCacheKeysFactory; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.persister.collection.CollectionPersister; +import org.hibernate.persister.entity.EntityPersister; + +/** + * Hibernate cache key wrapper. + */ +public class HibernateKeyWrapper implements Serializable { + /** Key. */ + private final Object key; + + /** Entry. */ + private final String entry; + + /** */ + private final String tenantId; + + /** + * @param key Key. + * @param entry Entry. + * @param tenantId Tenant ID. + */ + HibernateKeyWrapper(Object key, String entry, String tenantId) { + this.key = key; + this.entry = entry; + this.tenantId = tenantId; + } + + /** + * @return ID. + */ + Object id() { + return key; + } + + /** + * @param id ID. + * @param persister Persister. + * @param tenantIdentifier Tenant ID. + * @return Cache key. + * @see DefaultCacheKeysFactory#staticCreateCollectionKey(Object, CollectionPersister, SessionFactoryImplementor, String) + */ + static Object staticCreateCollectionKey(Object id, + CollectionPersister persister, + String tenantIdentifier) { + return new HibernateKeyWrapper(id, persister.getRole(), tenantIdentifier); + } + + /** + * @param id ID. + * @param persister Persister. + * @param tenantIdentifier Tenant ID. + * @return Cache key. + * @see DefaultCacheKeysFactory#staticCreateEntityKey(Object, EntityPersister, SessionFactoryImplementor, String) + */ + public static Object staticCreateEntityKey(Object id, EntityPersister persister, String tenantIdentifier) { + return new HibernateKeyWrapper(id, persister.getRootEntityName(), tenantIdentifier); + } + + + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + if (this == o) return true; + + if (o == null || getClass() != o.getClass()) + return false; + + HibernateKeyWrapper that = (HibernateKeyWrapper) o; + + return (key != null ? key.equals(that.key) : that.key == null) && + (entry != null ? entry.equals(that.entry) : that.entry == null) && + (tenantId != null ? tenantId.equals(that.tenantId) : that.tenantId == null); + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + int res = key != null ? key.hashCode() : 0; + res = 31 * res + (entry != null ? entry.hashCode() : 0); + res = 31 * res + (tenantId != null ? tenantId.hashCode() : 0); + return res; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(HibernateKeyWrapper.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateNaturalIdRegion.java ---------------------------------------------------------------------- diff --git a/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateNaturalIdRegion.java b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateNaturalIdRegion.java new file mode 100644 index 0000000..68816de --- /dev/null +++ b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateNaturalIdRegion.java @@ -0,0 +1,113 @@ +/* + * 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.hibernate; + +import org.apache.ignite.Ignite; +import org.hibernate.cache.CacheException; +import org.hibernate.cache.internal.DefaultCacheKeysFactory; +import org.hibernate.cache.spi.CacheDataDescription; +import org.hibernate.cache.spi.NaturalIdRegion; +import org.hibernate.cache.spi.access.AccessType; +import org.hibernate.cache.spi.access.NaturalIdRegionAccessStrategy; +import org.hibernate.cache.spi.access.SoftLock; +import org.hibernate.engine.spi.SessionImplementor; +import org.hibernate.persister.entity.EntityPersister; + +/** + * Implementation of {@link NaturalIdRegion}. This region is used to store naturalId data. + *

+ * L2 cache for entity naturalId and target cache region can be set using annotations: + *

+ * @javax.persistence.Entity
+ * @javax.persistence.Cacheable
+ * @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
+ * @org.hibernate.annotations.NaturalIdCache
+ * public class Entity {
+ *     @org.hibernate.annotations.NaturalId
+ *     private String entityCode;
+ *
+ *     ...
+ * }
+ * 
+ */ +public class HibernateNaturalIdRegion extends HibernateTransactionalDataRegion implements NaturalIdRegion { + /** + * @param factory Region factory. + * @param name Region name. + * @param ignite Grid. + * @param cache Region cache, + * @param dataDesc Region data description. + */ + public HibernateNaturalIdRegion(HibernateRegionFactory factory, String name, + Ignite ignite, HibernateCacheProxy cache, CacheDataDescription dataDesc) { + super(factory, name, ignite, cache, dataDesc); + } + + /** {@inheritDoc} */ + @Override public NaturalIdRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException { + return new AccessStrategy(createAccessStrategy(accessType)); + } + + /** + * NaturalId region access strategy. + */ + private class AccessStrategy extends HibernateAbstractRegionAccessStrategy implements + NaturalIdRegionAccessStrategy { + /** + * @param stgy Access strategy implementation. + */ + private AccessStrategy(HibernateAccessStrategyAdapter stgy) { + super(stgy); + } + + /** {@inheritDoc} */ + @Override public Object generateCacheKey(Object[] naturalIdValues, EntityPersister persister, SessionImplementor ses) { + return DefaultCacheKeysFactory.staticCreateNaturalIdKey(naturalIdValues, persister, ses); + } + + /** {@inheritDoc} */ + @Override public Object[] getNaturalIdValues(Object cacheKey) { + return DefaultCacheKeysFactory.staticGetNaturalIdValues(cacheKey); + } + + /** {@inheritDoc} */ + @Override public NaturalIdRegion getRegion() { + return HibernateNaturalIdRegion.this; + } + + /** {@inheritDoc} */ + @Override public boolean insert(SessionImplementor ses, Object key, Object val) throws CacheException { + return stgy.insert(key, val); + } + + /** {@inheritDoc} */ + @Override public boolean afterInsert(SessionImplementor ses, Object key, Object val) throws CacheException { + return stgy.afterInsert(key, val); + } + + /** {@inheritDoc} */ + @Override public boolean update(SessionImplementor ses, Object key, Object val) throws CacheException { + return stgy.update(key, val); + } + + /** {@inheritDoc} */ + @Override public boolean afterUpdate(SessionImplementor ses, Object key, Object val, SoftLock lock) throws CacheException { + return stgy.afterUpdate(key, val); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateQueryResultsRegion.java ---------------------------------------------------------------------- diff --git a/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateQueryResultsRegion.java b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateQueryResultsRegion.java new file mode 100644 index 0000000..0b9a43d --- /dev/null +++ b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateQueryResultsRegion.java @@ -0,0 +1,70 @@ +/* + * 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.hibernate; + +import org.apache.ignite.Ignite; +import org.hibernate.Query; +import org.hibernate.cache.spi.QueryResultsRegion; + +/** + * Implementation of {@link QueryResultsRegion}. This region is used to store query results. + *

+ * Query results caching can be enabled in the Hibernate configuration file: + *

+ * <hibernate-configuration>
+ *     <!-- Enable L2 cache. -->
+ *     <property name="cache.use_second_level_cache">true</property>
+ *
+ *     <!-- Enable query cache. -->
+ *     <property name="cache.use_second_level_cache">true</property>
+
+ *     <!-- Use Ignite as L2 cache provider. -->
+ *     <property name="cache.region.factory_class">org.apache.ignite.cache.hibernate.HibernateRegionFactory</property>
+ *
+ *     <!-- Specify entity. -->
+ *     <mapping class="com.example.Entity"/>
+ *
+ *     <!-- Enable L2 cache with nonstrict-read-write access strategy for entity. -->
+ *     <class-cache class="com.example.Entity" usage="nonstrict-read-write"/>
+ * </hibernate-configuration>
+ * 
+ * By default queries are not cached even after enabling query caching, to enable results caching for a particular + * query, call {@link Query#setCacheable(boolean)}: + *
+ *     Session ses = getSession();
+ *
+ *     Query qry = ses.createQuery("...");
+ *
+ *     qry.setCacheable(true); // Enable L2 cache for query.
+ * 
+ * Note: the query cache does not cache the state of the actual entities in the cache, it caches only identifier + * values. For this reason, the query cache should always be used in conjunction with + * the second-level cache for those entities expected to be cached as part of a query result cache + */ +public class HibernateQueryResultsRegion extends HibernateGeneralDataRegion implements QueryResultsRegion { + /** + * @param factory Region factory. + * @param name Region name. + * @param ignite Grid. + * @param cache Region cache. + */ + public HibernateQueryResultsRegion(HibernateRegionFactory factory, String name, + Ignite ignite, HibernateCacheProxy cache) { + super(factory, name, ignite, cache); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegion.java ---------------------------------------------------------------------- diff --git a/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegion.java b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegion.java new file mode 100644 index 0000000..11a96d0 --- /dev/null +++ b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegion.java @@ -0,0 +1,99 @@ +/* + * 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.hibernate; + +import java.util.Collections; +import java.util.Map; +import org.apache.ignite.Ignite; +import org.hibernate.cache.CacheException; +import org.hibernate.cache.spi.Region; + +/** + * Implementation of {@link Region}. This interface defines base contract for all L2 cache regions. + */ +public class HibernateRegion implements Region { + /** */ + protected final HibernateRegionFactory factory; + + /** */ + private final String name; + + /** Cache instance. */ + protected final HibernateCacheProxy cache; + + /** Grid instance. */ + protected Ignite ignite; + + /** + * @param factory Region factory. + * @param name Region name. + * @param ignite Grid. + * @param cache Region cache. + */ + public HibernateRegion(HibernateRegionFactory factory, String name, Ignite ignite, HibernateCacheProxy cache) { + this.factory = factory; + this.name = name; + this.ignite = ignite; + this.cache = cache; + } + + /** {@inheritDoc} */ + @Override public String getName() { + return name; + } + + /** {@inheritDoc} */ + @Override public void destroy() throws CacheException { + // No-op. + } + + /** {@inheritDoc} */ + @Override public boolean contains(Object key) { + return cache.containsKey(key); + } + + /** {@inheritDoc} */ + @Override public long getSizeInMemory() { + return -1; + } + + /** {@inheritDoc} */ + @Override public long getElementCountInMemory() { + return cache.size(); + } + + /** {@inheritDoc} */ + @Override public long getElementCountOnDisk() { + return -1; + } + + /** {@inheritDoc} */ + @Override public Map toMap() { + return Collections.emptyMap(); + } + + /** {@inheritDoc} */ + @Override public long nextTimestamp() { + return System.currentTimeMillis(); + } + + /** {@inheritDoc} */ + @Override public int getTimeout() { + return 0; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegionFactory.java ---------------------------------------------------------------------- diff --git a/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegionFactory.java b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegionFactory.java new file mode 100644 index 0000000..bf7d7e9 --- /dev/null +++ b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegionFactory.java @@ -0,0 +1,168 @@ +/* + * 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.hibernate; + +import java.util.Properties; +import org.apache.ignite.internal.processors.cache.IgniteInternalCache; +import org.hibernate.boot.spi.SessionFactoryOptions; +import org.hibernate.cache.CacheException; +import org.hibernate.cache.spi.CacheDataDescription; +import org.hibernate.cache.spi.CollectionRegion; +import org.hibernate.cache.spi.EntityRegion; +import org.hibernate.cache.spi.NaturalIdRegion; +import org.hibernate.cache.spi.QueryResultsRegion; +import org.hibernate.cache.spi.RegionFactory; +import org.hibernate.cache.spi.TimestampsRegion; +import org.hibernate.cache.spi.access.AccessType; + +import static org.apache.ignite.cache.hibernate.HibernateAccessStrategyFactory.DFLT_ACCESS_TYPE_PROPERTY; +import static org.hibernate.cache.spi.access.AccessType.NONSTRICT_READ_WRITE; + +/** + * Hibernate L2 cache region factory. + *

+ * Following Hibernate settings should be specified to enable second level cache and to use this + * region factory for caching: + *

+ * hibernate.cache.use_second_level_cache=true
+ * hibernate.cache.region.factory_class=org.apache.ignite.cache.hibernate.HibernateRegionFactory
+ * 
+ * Note that before region factory is started you need to start properly configured Ignite node in the same JVM. + * For example to start Ignite node one of loader provided in {@code org.apache.ignite.grid.startup} package can be used. + *

+ * Name of Ignite instance to be used for region factory must be specified as following Hibernate property: + *

+ * org.apache.ignite.hibernate.ignite_instance_name=<Ignite instance name>
+ * 
+ * Each Hibernate cache region must be associated with some {@link IgniteInternalCache}, by default it is assumed that + * for each cache region there is a {@link IgniteInternalCache} with the same name. Also it is possible to define + * region to cache mapping using properties with prefix {@code org.apache.ignite.hibernate.region_cache}. + * For example if for region with name "region1" cache with name "cache1" should be used then following + * Hibernate property should be specified: + *
+ * org.apache.ignite.hibernate.region_cache.region1=cache1
+ * 
+ */ +public class HibernateRegionFactory implements RegionFactory { + /** */ + private static final long serialVersionUID = 0L; + + /** */ + static final HibernateExceptionConverter EXCEPTION_CONVERTER = new HibernateExceptionConverter() { + @Override public RuntimeException convert(Exception e) { + return new CacheException(e); + } + }; + + /** Default region access type. */ + private AccessType dfltAccessType; + + /** Key transformer. */ + private final HibernateKeyTransformer hibernate4transformer = new HibernateKeyTransformer() { + @Override public Object transform(Object key) { + return key; + } + }; + + /** */ + private final HibernateAccessStrategyFactory accessStgyFactory = + new HibernateAccessStrategyFactory(hibernate4transformer, EXCEPTION_CONVERTER); + + /** {@inheritDoc} */ + @Override public void start(SessionFactoryOptions settings, Properties props) throws CacheException { + String accessType = props.getProperty(DFLT_ACCESS_TYPE_PROPERTY, NONSTRICT_READ_WRITE.name()); + + dfltAccessType = AccessType.valueOf(accessType); + + accessStgyFactory.start(props); + } + + /** + * @return Access strategy factory. + */ + HibernateAccessStrategyFactory accessStrategyFactory() { + return accessStgyFactory; + } + + /** {@inheritDoc} */ + @Override public void stop() { + // No-op. + } + + /** {@inheritDoc} */ + @Override public boolean isMinimalPutsEnabledByDefault() { + return false; + } + + /** {@inheritDoc} */ + @Override public AccessType getDefaultAccessType() { + return dfltAccessType; + } + + /** {@inheritDoc} */ + @Override public long nextTimestamp() { + return System.currentTimeMillis(); + } + + /** {@inheritDoc} */ + @Override public EntityRegion buildEntityRegion(String regionName, Properties props, CacheDataDescription metadata) + throws CacheException { + return new HibernateEntityRegion(this, + regionName, + accessStgyFactory.node(), + accessStgyFactory.regionCache(regionName), + metadata); + } + + /** {@inheritDoc} */ + @Override public NaturalIdRegion buildNaturalIdRegion(String regionName, Properties props, + CacheDataDescription metadata) throws CacheException { + return new HibernateNaturalIdRegion(this, + regionName, + accessStgyFactory.node(), + accessStgyFactory.regionCache(regionName), + metadata); + } + + /** {@inheritDoc} */ + @Override public CollectionRegion buildCollectionRegion(String regionName, Properties props, + CacheDataDescription metadata) throws CacheException { + return new HibernateCollectionRegion(this, + regionName, + accessStgyFactory.node(), + accessStgyFactory.regionCache(regionName), + metadata); + } + + /** {@inheritDoc} */ + @Override public QueryResultsRegion buildQueryResultsRegion(String regionName, Properties props) + throws CacheException { + return new HibernateQueryResultsRegion(this, + regionName, + accessStgyFactory.node(), + accessStgyFactory.regionCache(regionName)); + } + + /** {@inheritDoc} */ + @Override public TimestampsRegion buildTimestampsRegion(String regionName, Properties props) throws CacheException { + return new HibernateTimestampsRegion(this, + regionName, + accessStgyFactory.node(), + accessStgyFactory.regionCache(regionName)); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateTimestampsRegion.java ---------------------------------------------------------------------- diff --git a/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateTimestampsRegion.java b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateTimestampsRegion.java new file mode 100644 index 0000000..8b4c243 --- /dev/null +++ b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateTimestampsRegion.java @@ -0,0 +1,39 @@ +/* + * 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.hibernate; + +import org.apache.ignite.Ignite; +import org.hibernate.cache.spi.TimestampsRegion; + +/** + * Implementation of {@link TimestampsRegion}. This region is automatically created when query + * caching is enabled and it holds most recent updates timestamps to queryable tables. + * Name of timestamps region is {@code "org.hibernate.cache.spi.UpdateTimestampsCache"}. + */ +public class HibernateTimestampsRegion extends HibernateGeneralDataRegion implements TimestampsRegion { + /** + * @param factory Region factory. + * @param name Region name. + * @param ignite Grid. + * @param cache Region cache. + */ + public HibernateTimestampsRegion(HibernateRegionFactory factory, String name, + Ignite ignite, HibernateCacheProxy cache) { + super(factory, name, ignite, cache); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateTransactionalDataRegion.java ---------------------------------------------------------------------- diff --git a/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateTransactionalDataRegion.java b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateTransactionalDataRegion.java new file mode 100644 index 0000000..275ea9e --- /dev/null +++ b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateTransactionalDataRegion.java @@ -0,0 +1,84 @@ +/* + * 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.hibernate; + +import org.apache.ignite.Ignite; +import org.hibernate.cache.spi.CacheDataDescription; +import org.hibernate.cache.spi.CollectionRegion; +import org.hibernate.cache.spi.EntityRegion; +import org.hibernate.cache.spi.NaturalIdRegion; +import org.hibernate.cache.spi.TransactionalDataRegion; +import org.hibernate.cache.spi.access.AccessType; + +/** + * Implementation of {@link TransactionalDataRegion} (transactional means that + * data in the region is updated in connection with database transaction). + * This interface defines base contract for {@link EntityRegion}, {@link CollectionRegion} + * and {@link NaturalIdRegion}. + */ +public class HibernateTransactionalDataRegion extends HibernateRegion implements TransactionalDataRegion { + /** */ + private final CacheDataDescription dataDesc; + + /** + * @param factory Region factory. + * @param name Region name. + * @param ignite Grid. + * @param cache Region cache. + * @param dataDesc Region data description. + */ + HibernateTransactionalDataRegion(HibernateRegionFactory factory, String name, + Ignite ignite, HibernateCacheProxy cache, CacheDataDescription dataDesc) { + super(factory, name, ignite, cache); + + this.dataDesc = dataDesc; + } + + /** {@inheritDoc} */ + @Override public boolean isTransactionAware() { + return false; // This method is not used by Hibernate. + } + + /** {@inheritDoc} */ + @Override public CacheDataDescription getCacheDataDescription() { + return dataDesc; + } + + /** + * @param accessType Hibernate L2 cache access type. + * @return Access strategy for given access type. + */ + HibernateAccessStrategyAdapter createAccessStrategy(AccessType accessType) { + switch (accessType) { + case READ_ONLY: + return factory.accessStrategyFactory().createReadOnlyStrategy(cache); + + case NONSTRICT_READ_WRITE: + return factory.accessStrategyFactory().createNonStrictReadWriteStrategy(cache); + + case READ_WRITE: + return factory.accessStrategyFactory().createReadWriteStrategy(cache); + + case TRANSACTIONAL: + return factory.accessStrategyFactory().createTransactionalStrategy(cache); + + default: + throw new IllegalArgumentException("Unknown Hibernate access type: " + accessType); + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/package-info.java ---------------------------------------------------------------------- diff --git a/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/package-info.java b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/package-info.java new file mode 100644 index 0000000..1179aec --- /dev/null +++ b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/package-info.java @@ -0,0 +1,24 @@ +/* + * 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. + */ + +/** + * + * Contains implementation of Hibernate L2 cache. Refer to + * org.apache.ignite.examples.datagrid.hibernate.HibernateL2CacheExample for more information on how to + * configure and use Ignite with Hibernate. + */ +package org.apache.ignite.cache.hibernate; \ No newline at end of file