You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ir...@apache.org on 2020/02/12 17:45:46 UTC

[ignite] branch master updated: IGNITE-12649 HibernateL2CacheExample throws IllegalArgumentException for ignite-hibernate_5.3 - Fixes #7393.

This is an automated email from the ASF dual-hosted git repository.

irakov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new 0ba6b36  IGNITE-12649 HibernateL2CacheExample throws IllegalArgumentException for ignite-hibernate_5.3 - Fixes #7393.
0ba6b36 is described below

commit 0ba6b3642fd63977485e87def89e035ca0a0525c
Author: Slava Koptilin <sl...@gmail.com>
AuthorDate: Wed Feb 12 20:45:29 2020 +0300

    IGNITE-12649 HibernateL2CacheExample throws IllegalArgumentException for ignite-hibernate_5.3 - Fixes #7393.
    
    Signed-off-by: Ivan Rakov <ir...@apache.org>
---
 .../hibernate/HibernateL2CacheExample.java         | 52 +++++++++++++++++++---
 1 file changed, 46 insertions(+), 6 deletions(-)

diff --git a/examples/src/main/java-lgpl/org/apache/ignite/examples/datagrid/hibernate/HibernateL2CacheExample.java b/examples/src/main/java-lgpl/org/apache/ignite/examples/datagrid/hibernate/HibernateL2CacheExample.java
index 551e5d0..0426800 100644
--- a/examples/src/main/java-lgpl/org/apache/ignite/examples/datagrid/hibernate/HibernateL2CacheExample.java
+++ b/examples/src/main/java-lgpl/org/apache/ignite/examples/datagrid/hibernate/HibernateL2CacheExample.java
@@ -93,8 +93,6 @@ public class HibernateL2CacheExample {
         Arrays.asList(User.class.getName(), Post.class.getName(), User.class.getName() + ".posts");
 
     /** Caches' names. */
-    private static final String UPDATE_TIMESTAMPS_CACHE_NAME = "org.hibernate.cache.spi.UpdateTimestampsCache";
-    private static final String STANDART_QUERY_CACHE_NAME = "org.hibernate.cache.internal.StandardQueryCache";
     private static final String USER_CACHE_NAME = "org.apache.ignite.examples.datagrid.hibernate.User";
     private static final String USER_POSTS_CACHE_NAME = "org.apache.ignite.examples.datagrid.hibernate.User.posts";
     private static final String POST_CACHE_NAME = "org.apache.ignite.examples.datagrid.hibernate.Post";
@@ -117,8 +115,8 @@ public class HibernateL2CacheExample {
             // Auto-close cache at the end of the example.
             try (
                 // Create all required caches.
-                IgniteCache c1 = createCache(UPDATE_TIMESTAMPS_CACHE_NAME, ATOMIC);
-                IgniteCache c2 = createCache(STANDART_QUERY_CACHE_NAME, ATOMIC);
+                IgniteCache c1 = createCache(timestampsCacheName(), ATOMIC);
+                IgniteCache c2 = createCache(queryResultsCacheName(), ATOMIC);
                 IgniteCache c3 = createCache(USER_CACHE_NAME, TRANSACTIONAL);
                 IgniteCache c4 = createCache(USER_POSTS_CACHE_NAME, TRANSACTIONAL);
                 IgniteCache c5 = createCache(POST_CACHE_NAME, TRANSACTIONAL)
@@ -193,8 +191,8 @@ public class HibernateL2CacheExample {
             }
             finally {
                 // Distributed cache could be removed from cluster only by #destroyCache() call.
-                ignite.destroyCache(UPDATE_TIMESTAMPS_CACHE_NAME);
-                ignite.destroyCache(STANDART_QUERY_CACHE_NAME);
+                ignite.destroyCache(timestampsCacheName());
+                ignite.destroyCache(queryResultsCacheName());
                 ignite.destroyCache(USER_CACHE_NAME);
                 ignite.destroyCache(USER_POSTS_CACHE_NAME);
                 ignite.destroyCache(POST_CACHE_NAME);
@@ -258,4 +256,46 @@ public class HibernateL2CacheExample {
 
         System.out.println("=====================================");
     }
+
+    /**
+     * Returns the name of the timestamps cache to a specific version of apache-hibernate.
+     *
+     * @return Name of the update timestamps cache.
+     */
+    private static String timestampsCacheName() {
+        return isIgniteHibernate51orBelowEnabled() ?
+            // Represents the name of timestamps region specific to hibernate 5.1 {@see HibernateTimestampsRegion}.
+            "org.hibernate.cache.spi.UpdateTimestampsCache":
+            // Represents the name of timestamps region specific to hibernate 5.3 {@see IgniteTimestampsRegion}.
+            "default-update-timestamps-region";
+    }
+
+    /**
+     * Returns the name of the query results cache to a specific version of apache-hibernate.
+     *
+     * @return Name of the update timestamps cache.
+     */
+    private static String queryResultsCacheName() {
+        return isIgniteHibernate51orBelowEnabled() ?
+            // Represents the name of query results region specific to hibernate 5.1 {@see HibernateQueryResultsRegion}.
+            "org.hibernate.cache.internal.StandardQueryCache":
+            // Represents the name of query results region specific to hibernate 5.3 {@see IgniteQueryResultsRegion}.
+            "default-query-results-region";
+    }
+
+    /**
+     * Returns {@code true} if ignite-hibernate 5.1 is enabled.
+     *
+     * @return {@code true} if ignite-hibernate 5.1 is enabled.
+     */
+    private static boolean isIgniteHibernate51orBelowEnabled() {
+        try {
+            Class.forName("org.apache.ignite.cache.hibernate.HibernateTimestampsRegion");
+
+            return true;
+        }
+        catch (ClassNotFoundException ignore) {
+            return false;
+        }
+    }
 }