Repository: ignite Updated Branches: refs/heads/ignite-1794 e1accc027 -> 6f8f4ee80
ignite-1794 hibernate 5.1 Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/6f8f4ee8 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/6f8f4ee8 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/6f8f4ee8 Branch: refs/heads/ignite-1794 Commit: 6f8f4ee80d02b229bc29bd3e48fbe911a6afe8c2 Parents: e1accc0 Author: sboikov <sboi...@gridgain.com> Authored: Thu Apr 20 18:19:12 2017 +0300 Committer: sboikov <sboi...@gridgain.com> Committed: Thu Apr 20 18:19:12 2017 +0300 ---------------------------------------------------------------------- .../hibernate/HibernateL2CacheMultiJvmTest.java | 128 +++--- .../hibernate/HibernateL2CacheSelfTest.java | 37 +- modules/hibernate-5.1/pom.xml | 7 + .../hibernate/HibernateL2CacheMultiJvmTest.java | 423 +++++++++++++++++++ .../hibernate/HibernateL2CacheSelfTest.java | 34 +- .../HibernateAccessStrategyFactory.java | 2 +- .../hibernate/HibernateKeyTransformer.java | 1 + .../HibernateReadOnlyAccessStrategy.java | 1 - 8 files changed, 540 insertions(+), 93 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/6f8f4ee8/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheMultiJvmTest.java ---------------------------------------------------------------------- diff --git a/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheMultiJvmTest.java b/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheMultiJvmTest.java index bd976ad..5160220 100644 --- a/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheMultiJvmTest.java +++ b/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheMultiJvmTest.java @@ -17,6 +17,7 @@ package org.apache.ignite.cache.hibernate; +import java.util.Map; import javax.persistence.Cacheable; import javax.persistence.Id; import org.apache.ignite.Ignite; @@ -33,29 +34,20 @@ import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.annotations.CacheConcurrencyStrategy; -import org.hibernate.cache.spi.access.AccessType; import org.hibernate.cfg.Configuration; import org.hibernate.service.ServiceRegistryBuilder; import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC; -import static org.apache.ignite.cache.hibernate.HibernateAccessStrategyFactory.DFLT_ACCESS_TYPE_PROPERTY; import static org.apache.ignite.cache.hibernate.HibernateAccessStrategyFactory.DFLT_CACHE_NAME_PROPERTY; -import static org.apache.ignite.cache.hibernate.HibernateAccessStrategyFactory.IGNITE_INSTANCE_NAME_PROPERTY; -import static org.hibernate.cfg.AvailableSettings.CACHE_REGION_FACTORY; -import static org.hibernate.cfg.AvailableSettings.GENERATE_STATISTICS; -import static org.hibernate.cfg.AvailableSettings.HBM2DDL_AUTO; -import static org.hibernate.cfg.AvailableSettings.RELEASE_CONNECTIONS; -import static org.hibernate.cfg.AvailableSettings.USE_QUERY_CACHE; -import static org.hibernate.cfg.AvailableSettings.USE_SECOND_LEVEL_CACHE; +import static org.apache.ignite.cache.hibernate.HibernateL2CacheSelfTest.CONNECTION_URL; +import static org.apache.ignite.cache.hibernate.HibernateL2CacheSelfTest.hibernateProperties; +import static org.hibernate.cache.spi.access.AccessType.NONSTRICT_READ_WRITE; /** * */ public class HibernateL2CacheMultiJvmTest extends GridCommonAbstractTest { /** */ - static final String CONNECTION_URL = "jdbc:h2:mem:example;DB_CLOSE_DELAY=-1"; - - /** */ private static final String CACHE_NAME = "hibernateCache"; /** {@inheritDoc} */ @@ -73,6 +65,7 @@ public class HibernateL2CacheMultiJvmTest extends GridCommonAbstractTest { cfg.setCacheConfiguration(ccfg); cfg.setMarshaller(new BinaryMarshaller()); + cfg.setPeerClassLoadingEnabled(false); return cfg; @@ -106,21 +99,32 @@ public class HibernateL2CacheMultiJvmTest extends GridCommonAbstractTest { public void testL2Cache() throws Exception { Ignite srv = ignite(0); - IgniteCompute client1Compute = - srv.compute(srv.cluster().forNodeId(ignite(1).cluster().localNode().id())); + { + IgniteCompute client1Compute = + srv.compute(srv.cluster().forNodeId(ignite(1).cluster().localNode().id())); + + client1Compute.run(new HibernateInsertRunnable()); + } + + { + IgniteCompute client2Compute = + srv.compute(srv.cluster().forNodeId(ignite(2).cluster().localNode().id())); - client1Compute.run(new HibernateRunnable()); + client2Compute.run(new HibernateLoadRunnable()); + } - IgniteCompute client2Compute = - srv.compute(srv.cluster().forNodeId(ignite(2).cluster().localNode().id())); + { + IgniteCompute srvCompute = srv.compute(srv.cluster().forLocal()); - client2Compute.run(new HibernateRunnable2()); + srvCompute.run(new HibernateLoadRunnable()); + } } /** * */ - private static class HibernateRunnable2 extends HibernateRunnable { + private static class HibernateInsertRunnable extends HibernateBaseRunnable { + /** {@inheritDoc} */ @Override public void run() { SessionFactory sesFactory = startHibernate(ignite.name()); @@ -131,19 +135,27 @@ public class HibernateL2CacheMultiJvmTest extends GridCommonAbstractTest { for (int i = 0; i < 1; i++) { { - Entity1 e = (Entity1)ses.load(Entity1.class, i); + Entity1 e = new Entity1(); + e.setId(i); + e.setName("name-" + i); - log.info("Found: " + e.getName()); + ses.save(e); } + { - Entity2 e = (Entity2)ses.load(Entity2.class, String.valueOf(i)); + Entity2 e = new Entity2(); + e.setId(String.valueOf(i)); + e.setName("name-" + i); - log.info("Found: " + e.getName()); + ses.save(e); } + { - Entity3 e = (Entity3)ses.load(Entity3.class, (double)i); + Entity3 e = new Entity3(); + e.setId(i); + e.setName("name-" + i); - log.info("Found: " + e.getName()); + ses.save(e); } } @@ -158,14 +170,7 @@ public class HibernateL2CacheMultiJvmTest extends GridCommonAbstractTest { /** * */ - private static class HibernateRunnable implements IgniteRunnable { - /** */ - @IgniteInstanceResource - protected Ignite ignite; - - @LoggerResource - protected IgniteLogger log; - + private static class HibernateLoadRunnable extends HibernateBaseRunnable { /** {@inheritDoc} */ @Override public void run() { SessionFactory sesFactory = startHibernate(ignite.name()); @@ -177,27 +182,19 @@ public class HibernateL2CacheMultiJvmTest extends GridCommonAbstractTest { for (int i = 0; i < 1; i++) { { - Entity1 e = new Entity1(); - e.setId(i); - e.setName("name-" + i); + Entity1 e = (Entity1)ses.load(Entity1.class, i); - ses.save(e); + log.info("Found: " + e.getName()); } - { - Entity2 e = new Entity2(); - e.setId(String.valueOf(i)); - e.setName("name-" + i); + Entity2 e = (Entity2)ses.load(Entity2.class, String.valueOf(i)); - ses.save(e); + log.info("Found: " + e.getName()); } - { - Entity3 e = new Entity3(); - e.setId(i); - e.setName("name-" + i); + Entity3 e = (Entity3)ses.load(Entity3.class, (double)i); - ses.save(e); + log.info("Found: " + e.getName()); } } @@ -207,12 +204,25 @@ public class HibernateL2CacheMultiJvmTest extends GridCommonAbstractTest { ses.close(); } } + } + + /** + * + */ + private abstract static class HibernateBaseRunnable implements IgniteRunnable { + /** */ + @IgniteInstanceResource + protected Ignite ignite; + + /** */ + @LoggerResource + IgniteLogger log; /** * @param igniteInstanceName Name of the grid providing caches. * @return Session factory. */ - protected SessionFactory startHibernate(String igniteInstanceName) { + SessionFactory startHibernate(String igniteInstanceName) { log.info("Start hibernate on node: " + igniteInstanceName); Configuration cfg = hibernateConfiguration(igniteInstanceName); @@ -220,37 +230,23 @@ public class HibernateL2CacheMultiJvmTest extends GridCommonAbstractTest { ServiceRegistryBuilder builder = new ServiceRegistryBuilder(); builder.applySetting("hibernate.connection.url", CONNECTION_URL); - builder.applySetting("hibernate.show_sql", true); return cfg.buildSessionFactory(builder.buildServiceRegistry()); } /** - * @param igniteInstanceName Ignite instance name. + * @param nodeName Ignite instance name. * @return Hibernate configuration. */ - protected Configuration hibernateConfiguration(String igniteInstanceName) { + private Configuration hibernateConfiguration(String nodeName) { Configuration cfg = new Configuration(); cfg.addAnnotatedClass(Entity1.class); cfg.addAnnotatedClass(Entity2.class); cfg.addAnnotatedClass(Entity3.class); - cfg.setProperty(DFLT_ACCESS_TYPE_PROPERTY, AccessType.NONSTRICT_READ_WRITE.name()); - - cfg.setProperty(HBM2DDL_AUTO, "create"); - - cfg.setProperty(GENERATE_STATISTICS, "true"); - - cfg.setProperty(USE_SECOND_LEVEL_CACHE, "true"); - - cfg.setProperty(USE_QUERY_CACHE, "true"); - - cfg.setProperty(CACHE_REGION_FACTORY, HibernateRegionFactory.class.getName()); - - cfg.setProperty(RELEASE_CONNECTIONS, "on_close"); - - cfg.setProperty(IGNITE_INSTANCE_NAME_PROPERTY, igniteInstanceName); + for (Map.Entry<String, String> e : hibernateProperties(nodeName, NONSTRICT_READ_WRITE.name()).entrySet()) + cfg.setProperty(e.getKey(), e.getValue()); cfg.setProperty(DFLT_CACHE_NAME_PROPERTY, CACHE_NAME); http://git-wip-us.apache.org/repos/asf/ignite/blob/6f8f4ee8/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheSelfTest.java b/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheSelfTest.java index bab21aa..7ac790c 100644 --- a/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheSelfTest.java +++ b/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheSelfTest.java @@ -495,25 +495,12 @@ public class HibernateL2CacheSelfTest extends GridCommonAbstractTest { cfg.setCacheConcurrencyStrategy(PARENT_ENTITY_NAME, accessType.getExternalName()); cfg.setCollectionCacheConcurrencyStrategy(CHILD_COLLECTION_REGION, accessType.getExternalName()); - cfg.setProperty(HBM2DDL_AUTO, "create"); - - cfg.setProperty(GENERATE_STATISTICS, "true"); - - cfg.setProperty(USE_SECOND_LEVEL_CACHE, "true"); - - cfg.setProperty(USE_QUERY_CACHE, "true"); - - cfg.setProperty(CACHE_REGION_FACTORY, HibernateRegionFactory.class.getName()); - - cfg.setProperty(RELEASE_CONNECTIONS, "on_close"); - - cfg.setProperty(IGNITE_INSTANCE_NAME_PROPERTY, igniteInstanceName); + for (Map.Entry<String, String> e : hibernateProperties(igniteInstanceName, accessType.name()).entrySet()) + cfg.setProperty(e.getKey(), e.getValue()); // Use the same cache for Entity and Entity2. cfg.setProperty(REGION_CACHE_PROPERTY + ENTITY2_NAME, ENTITY_NAME); - cfg.setProperty(DFLT_ACCESS_TYPE_PROPERTY, accessType.name()); - return cfg; } @@ -1944,4 +1931,24 @@ public class HibernateL2CacheSelfTest extends GridCommonAbstractTest { for (IgniteCacheProxy<?, ?> cache : ((IgniteKernal)grid(0)).caches()) cache.clear(); } + + /** + * @param igniteInstanceName Node name. + * @param dfltAccessType Default cache access type. + * @return Properties map. + */ + static Map<String, String> hibernateProperties(String igniteInstanceName, String dfltAccessType) { + Map<String, String> map = new HashMap<>(); + + map.put(HBM2DDL_AUTO, "create"); + map.put(GENERATE_STATISTICS, "true"); + map.put(USE_SECOND_LEVEL_CACHE, "true"); + map.put(USE_QUERY_CACHE, "true"); + map.put(CACHE_REGION_FACTORY, HibernateRegionFactory.class.getName()); + map.put(RELEASE_CONNECTIONS, "on_close"); + map.put(IGNITE_INSTANCE_NAME_PROPERTY, igniteInstanceName); + map.put(DFLT_ACCESS_TYPE_PROPERTY, dfltAccessType); + + return map; + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/6f8f4ee8/modules/hibernate-5.1/pom.xml ---------------------------------------------------------------------- diff --git a/modules/hibernate-5.1/pom.xml b/modules/hibernate-5.1/pom.xml index aa86486..80299bc 100644 --- a/modules/hibernate-5.1/pom.xml +++ b/modules/hibernate-5.1/pom.xml @@ -123,6 +123,13 @@ <version>${spring.version}</version> <scope>test</scope> </dependency> + + <dependency> + <groupId>com.thoughtworks.xstream</groupId> + <artifactId>xstream</artifactId> + <version>1.4.8</version> + <scope>test</scope> + </dependency> </dependencies> <build> http://git-wip-us.apache.org/repos/asf/ignite/blob/6f8f4ee8/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheMultiJvmTest.java ---------------------------------------------------------------------- diff --git a/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheMultiJvmTest.java b/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheMultiJvmTest.java new file mode 100644 index 0000000..eadcdf8 --- /dev/null +++ b/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheMultiJvmTest.java @@ -0,0 +1,423 @@ +/* + * 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 javax.persistence.Cacheable; +import javax.persistence.Id; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCompute; +import org.apache.ignite.IgniteLogger; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.binary.BinaryMarshaller; +import org.apache.ignite.lang.IgniteRunnable; +import org.apache.ignite.resources.IgniteInstanceResource; +import org.apache.ignite.resources.LoggerResource; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.annotations.CacheConcurrencyStrategy; +import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; + +import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC; +import static org.apache.ignite.cache.hibernate.HibernateAccessStrategyFactory.DFLT_CACHE_NAME_PROPERTY; +import static org.apache.ignite.cache.hibernate.HibernateL2CacheSelfTest.CONNECTION_URL; + +/** + * + */ +public class HibernateL2CacheMultiJvmTest extends GridCommonAbstractTest { + /** */ + private static final String CACHE_NAME = "hibernateCache"; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); + + if (!getTestIgniteInstanceName(0).equals(igniteInstanceName)) + cfg.setClientMode(true); + + CacheConfiguration ccfg = new CacheConfiguration(); + + ccfg.setName(CACHE_NAME); + ccfg.setWriteSynchronizationMode(FULL_SYNC); + + cfg.setCacheConfiguration(ccfg); + + cfg.setMarshaller(new BinaryMarshaller()); + + cfg.setPeerClassLoadingEnabled(false); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected boolean isMultiJvm() { + return true; + } + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + super.beforeTestsStarted(); + + startGrid(0); + + startGrid(1); + startGrid(2); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + stopAllGrids(); + + super.afterTestsStopped(); + } + + /** + * @throws Exception If failed. + */ + public void testL2Cache() throws Exception { + Ignite srv = ignite(0); + + { + IgniteCompute client1Compute = + srv.compute(srv.cluster().forNodeId(ignite(1).cluster().localNode().id())); + + client1Compute.run(new HibernateInsertRunnable()); + } + + { + IgniteCompute client2Compute = + srv.compute(srv.cluster().forNodeId(ignite(2).cluster().localNode().id())); + + client2Compute.run(new HibernateLoadRunnable()); + } + + { + IgniteCompute srvCompute = srv.compute(srv.cluster().forLocal()); + + srvCompute.run(new HibernateLoadRunnable()); + } + } + + /** + * + */ + private static class HibernateInsertRunnable extends HibernateBaseRunnable { + /** {@inheritDoc} */ + @Override public void run() { + SessionFactory sesFactory = startHibernate(ignite.name()); + + Session ses = sesFactory.openSession(); + + try { + Transaction tx = ses.beginTransaction(); + + for (int i = 0; i < 1; i++) { + { + Entity1 e = new Entity1(); + e.setId(i); + e.setName("name-" + i); + + ses.save(e); + } + + { + Entity2 e = new Entity2(); + e.setId(String.valueOf(i)); + e.setName("name-" + i); + + ses.save(e); + } + + { + Entity3 e = new Entity3(); + e.setId(i); + e.setName("name-" + i); + + ses.save(e); + } + } + + tx.commit(); + } + finally { + ses.close(); + } + } + } + + /** + * + */ + private static class HibernateLoadRunnable extends HibernateBaseRunnable { + /** {@inheritDoc} */ + @Override public void run() { + SessionFactory sesFactory = startHibernate(ignite.name()); + + Session ses = sesFactory.openSession(); + + try { + Transaction tx = ses.beginTransaction(); + + for (int i = 0; i < 1; i++) { + { + Entity1 e = (Entity1)ses.load(Entity1.class, i); + + log.info("Found: " + e.getName()); + } + { + Entity2 e = (Entity2)ses.load(Entity2.class, String.valueOf(i)); + + log.info("Found: " + e.getName()); + } + { + Entity3 e = (Entity3)ses.load(Entity3.class, (double)i); + + log.info("Found: " + e.getName()); + } + } + + tx.commit(); + } + finally { + ses.close(); + } + } + } + + /** + * + */ + private abstract static class HibernateBaseRunnable implements IgniteRunnable { + /** */ + @IgniteInstanceResource + protected Ignite ignite; + + /** */ + @LoggerResource + IgniteLogger log; + + /** + * @param igniteInstanceName Name of the grid providing caches. + * @return Session factory. + */ + SessionFactory startHibernate(String igniteInstanceName) { + log.info("Start hibernate on node: " + igniteInstanceName); + + StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder(); + + builder.applySetting("hibernate.connection.url", CONNECTION_URL); + builder.applySetting(DFLT_CACHE_NAME_PROPERTY, CACHE_NAME); + + MetadataSources metadataSources = new MetadataSources(builder.build()); + + metadataSources.addAnnotatedClass(Entity1.class); + metadataSources.addAnnotatedClass(Entity2.class); + metadataSources.addAnnotatedClass(Entity3.class); + + return metadataSources.buildMetadata().buildSessionFactory(); + } + } + + /** + * Test Hibernate entity1. + */ + @javax.persistence.Entity + @Cacheable + @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) + public static class Entity1 { + /** */ + @Id + private int id; + + /** */ + private String name; + + /** + * @return ID. + */ + public int getId() { + return id; + } + + /** + * @param id ID. + */ + public void setId(int id) { + this.id = id; + } + + /** + * @return Name. + */ + public String getName() { + return name; + } + + /** + * @param name Name. + */ + public void setName(String name) { + this.name = name; + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + if (this == o) + return true; + + if (o == null || getClass() != o.getClass()) + return false; + + Entity1 entity1 = (Entity1)o; + + return id == entity1.id; + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + return id; + } + } + + /** + * Test Hibernate entity1. + */ + @javax.persistence.Entity + @Cacheable + @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) + public static class Entity2 { + /** */ + @Id + private String id; + + /** */ + private String name; + + /** + * @return ID. + */ + public String getId() { + return id; + } + + /** + * @param id ID. + */ + public void setId(String id) { + this.id = id; + } + + /** + * @return Name. + */ + public String getName() { + return name; + } + + /** + * @param name Name. + */ + public void setName(String name) { + this.name = name; + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + if (this == o) + return true; + + if (o == null || getClass() != o.getClass()) + return false; + + Entity2 entity2 = (Entity2)o; + + return id.equals(entity2.id); + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + return id.hashCode(); + } + } + + /** + * Test Hibernate entity1. + */ + @javax.persistence.Entity + @Cacheable + @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) + public static class Entity3 { + /** */ + @Id + private double id; + + /** */ + private String name; + + /** + * @return ID. + */ + public double getId() { + return id; + } + + /** + * @param id ID. + */ + public void setId(double id) { + this.id = id; + } + + /** + * @return Name. + */ + public String getName() { + return name; + } + + /** + * @param name Name. + */ + public void setName(String name) { + this.name = name; + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + if (this == o) + return true; + + if (o == null || getClass() != o.getClass()) + return false; + + Entity3 entity3 = (Entity3)o; + + return Double.compare(entity3.id, id) == 0; + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + long temp = Double.doubleToLongBits(id); + return (int)(temp ^ (temp >>> 32)); + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/6f8f4ee8/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheSelfTest.java b/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheSelfTest.java index 289fafb..f227af1 100644 --- a/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheSelfTest.java +++ b/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheSelfTest.java @@ -68,6 +68,7 @@ import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC; import static org.apache.ignite.cache.hibernate.HibernateAccessStrategyFactory.DFLT_ACCESS_TYPE_PROPERTY; import static org.apache.ignite.cache.hibernate.HibernateAccessStrategyFactory.IGNITE_INSTANCE_NAME_PROPERTY; import static org.apache.ignite.cache.hibernate.HibernateAccessStrategyFactory.REGION_CACHE_PROPERTY; +import static org.hibernate.cache.spi.access.AccessType.NONSTRICT_READ_WRITE; import static org.hibernate.cfg.Environment.CACHE_REGION_FACTORY; import static org.hibernate.cfg.Environment.GENERATE_STATISTICS; import static org.hibernate.cfg.Environment.HBM2DDL_AUTO; @@ -1884,18 +1885,11 @@ public class HibernateL2CacheSelfTest extends GridCommonAbstractTest { private SessionFactory startHibernate(org.hibernate.cache.spi.access.AccessType accessType, String igniteInstanceName) { StandardServiceRegistryBuilder builder = registryBuilder(); - builder.applySetting(HBM2DDL_AUTO, "create"); - builder.applySetting(GENERATE_STATISTICS, "true"); - builder.applySetting(USE_SECOND_LEVEL_CACHE, "true"); - builder.applySetting(USE_QUERY_CACHE, "true"); - builder.applySetting(CACHE_REGION_FACTORY, HibernateRegionFactory.class.getName()); - builder.applySetting(RELEASE_CONNECTIONS, "on_close"); - builder.applySetting(IGNITE_INSTANCE_NAME_PROPERTY, igniteInstanceName); + for (Map.Entry<String, String> e : hibernateProperties(igniteInstanceName, accessType.name()).entrySet()) + builder.applySetting(e.getKey(), e.getValue()); + // Use the same cache for Entity and Entity2. builder.applySetting(REGION_CACHE_PROPERTY + ENTITY2_NAME, ENTITY_NAME); - builder.applySetting(DFLT_ACCESS_TYPE_PROPERTY, accessType.name()); - builder.applySetting(Environment.DIALECT, "org.hibernate.dialect.H2Dialect"); - builder.applySetting("hibernate.show_sql", false); StandardServiceRegistry srvcRegistry = builder.build(); @@ -1943,4 +1937,24 @@ public class HibernateL2CacheSelfTest extends GridCommonAbstractTest { for (IgniteCacheProxy<?, ?> cache : ((IgniteKernal)grid(0)).caches()) cache.clear(); } + + /** + * @param igniteInstanceName Node name. + * @param dfltAccessType Default cache access type. + * @return Properties map. + */ + static Map<String, String> hibernateProperties(String igniteInstanceName, String dfltAccessType) { + Map<String, String> map = new HashMap<>(); + + map.put(HBM2DDL_AUTO, "create"); + map.put(GENERATE_STATISTICS, "true"); + map.put(USE_SECOND_LEVEL_CACHE, "true"); + map.put(USE_QUERY_CACHE, "true"); + map.put(CACHE_REGION_FACTORY, HibernateRegionFactory.class.getName()); + map.put(RELEASE_CONNECTIONS, "on_close"); + map.put(IGNITE_INSTANCE_NAME_PROPERTY, igniteInstanceName); + map.put(DFLT_ACCESS_TYPE_PROPERTY, dfltAccessType); + + return map; + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/6f8f4ee8/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateAccessStrategyFactory.java ---------------------------------------------------------------------- diff --git a/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateAccessStrategyFactory.java b/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateAccessStrategyFactory.java index 512a656..0226c1c 100644 --- a/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateAccessStrategyFactory.java +++ b/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateAccessStrategyFactory.java @@ -33,7 +33,7 @@ import org.apache.ignite.internal.util.typedef.G; import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL; /** - * + * Access strategy factory. */ public class HibernateAccessStrategyFactory { /** */ http://git-wip-us.apache.org/repos/asf/ignite/blob/6f8f4ee8/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyTransformer.java ---------------------------------------------------------------------- diff --git a/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyTransformer.java b/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyTransformer.java index ecad0b6..97fc0e9 100644 --- a/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyTransformer.java +++ b/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyTransformer.java @@ -23,6 +23,7 @@ package org.apache.ignite.cache.hibernate; public interface HibernateKeyTransformer { /** * @param key Hibernate key. + * @return Transformed key. */ public Object transform(Object key); } http://git-wip-us.apache.org/repos/asf/ignite/blob/6f8f4ee8/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateReadOnlyAccessStrategy.java ---------------------------------------------------------------------- diff --git a/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateReadOnlyAccessStrategy.java b/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateReadOnlyAccessStrategy.java index ed3a13f..a0957fd 100644 --- a/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateReadOnlyAccessStrategy.java +++ b/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateReadOnlyAccessStrategy.java @@ -47,7 +47,6 @@ import org.apache.ignite.IgniteCheckedException; * @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_ONLY) * public class Entity { ... } * </pre> - * */ public class HibernateReadOnlyAccessStrategy extends HibernateAccessStrategyAdapter {