ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject ignite git commit: ignite-1794
Date Mon, 10 Apr 2017 11:13:27 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-1794 11afee16e -> b709ddf38


ignite-1794


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/b709ddf3
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/b709ddf3
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/b709ddf3

Branch: refs/heads/ignite-1794
Commit: b709ddf384d8ab9e85210e25d38586beec2a4ad0
Parents: 11afee1
Author: sboikov <sboikov@gridgain.com>
Authored: Mon Apr 10 14:11:22 2017 +0300
Committer: sboikov <sboikov@gridgain.com>
Committed: Mon Apr 10 14:11:22 2017 +0300

----------------------------------------------------------------------
 .../cache/hibernate/HibernateKeyWrapper.java    | 34 ++++++----
 .../cache/hibernate/HibernateRegionFactory.java |  3 +-
 .../hibernate/HibernateCollectionRegion.java    |  5 +-
 .../cache/hibernate/HibernateEntityRegion.java  |  4 +-
 .../cache/hibernate/HibernateKeyWrapper.java    | 70 ++++++++++++++++----
 .../cache/hibernate/HibernateRegionFactory.java |  9 ---
 6 files changed, 86 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/b709ddf3/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyWrapper.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyWrapper.java
b/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyWrapper.java
index e0f2766..1b730d2 100644
--- a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyWrapper.java
+++ b/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyWrapper.java
@@ -17,6 +17,8 @@
 
 package org.apache.ignite.cache.hibernate;
 
+import org.apache.ignite.internal.util.typedef.internal.S;
+
 /**
  *
  */
@@ -27,36 +29,44 @@ public class HibernateKeyWrapper {
     /** Entry. */
     private final String entry;
 
+    /** */
+    private final String tenantId;
+
     /**
      * @param key Key.
      * @param entry Entry.
+     * @param tenantId Tenant ID.
      */
-    public HibernateKeyWrapper(Object key, String entry) {
+    HibernateKeyWrapper(Object key, String entry, String tenantId) {
         this.key = key;
         this.entry = entry;
+        this.tenantId = tenantId;
     }
 
     /** {@inheritDoc} */
     @Override public boolean equals(Object o) {
-        if (this == o)
-            return true;
+        if (this == o) return true;
+
         if (o == null || getClass() != o.getClass())
             return false;
 
-        HibernateKeyWrapper wrapper = (HibernateKeyWrapper)o;
-
-        if (key != null ? !key.equals(wrapper.key) : wrapper.key != null)
-            return false;
+        HibernateKeyWrapper that = (HibernateKeyWrapper) o;
 
-        return entry != null ? entry.equals(wrapper.entry) : wrapper.entry == null;
+        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 result = key != null ? key.hashCode() : 0;
-
-        result = 31 * result + (entry != null ? entry.hashCode() : 0);
+        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;
+    }
 
-        return result;
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(HibernateKeyWrapper.class, this);
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/b709ddf3/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegionFactory.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegionFactory.java
b/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegionFactory.java
index c23d6e5..263359b 100644
--- a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegionFactory.java
+++ b/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegionFactory.java
@@ -117,7 +117,8 @@ public class HibernateRegionFactory implements RegionFactory {
 
                 return new HibernateKeyWrapper(
                     cacheKey.getKey(),
-                    cacheKey.getEntityOrRoleName()
+                    cacheKey.getEntityOrRoleName(),
+                    cacheKey.getTenantId()
                 );
             }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/b709ddf3/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateCollectionRegion.java
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateCollectionRegion.java
b/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateCollectionRegion.java
index d3d2965..be99e98 100644
--- a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateCollectionRegion.java
+++ b/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateCollectionRegion.java
@@ -19,7 +19,6 @@ 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.CollectionRegion;
 import org.hibernate.cache.spi.access.AccessType;
@@ -99,12 +98,12 @@ public class HibernateCollectionRegion extends HibernateTransactionalDataRegion
         @Override public Object generateCacheKey(Object id,
             CollectionPersister persister,
             SessionFactoryImplementor factory, String tenantIdentifier) {
-            return DefaultCacheKeysFactory.staticCreateCollectionKey(id, persister, factory,tenantIdentifier);
+            return HibernateKeyWrapper.staticCreateCollectionKey(id, persister, tenantIdentifier);
         }
 
         /** {@inheritDoc} */
         @Override public Object getCacheKeyId(Object cacheKey) {
-            return DefaultCacheKeysFactory.staticGetCollectionId(cacheKey);
+            return ((HibernateKeyWrapper)cacheKey).id();
         }
 
         /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/b709ddf3/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateEntityRegion.java
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateEntityRegion.java
b/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateEntityRegion.java
index 75ecdb0..1842a63 100644
--- a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateEntityRegion.java
+++ b/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateEntityRegion.java
@@ -91,12 +91,12 @@ public class HibernateEntityRegion extends HibernateTransactionalDataRegion
impl
             EntityPersister persister,
             SessionFactoryImplementor factory,
             String tenantIdentifier) {
-            return DefaultCacheKeysFactory.staticCreateEntityKey(id, persister, factory,
tenantIdentifier);
+            return HibernateKeyWrapper.staticCreateEntityKey(id, persister, tenantIdentifier);
         }
 
         /** {@inheritDoc} */
         @Override public Object getCacheKeyId(Object cacheKey) {
-            return DefaultCacheKeysFactory.staticGetEntityId(cacheKey);
+            return ((HibernateKeyWrapper)cacheKey).id();
         }
 
         /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/b709ddf3/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyWrapper.java
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyWrapper.java
b/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyWrapper.java
index e0f2766..3f2b97f 100644
--- a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyWrapper.java
+++ b/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyWrapper.java
@@ -17,6 +17,12 @@
 
 package org.apache.ignite.cache.hibernate;
 
+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;
+
 /**
  *
  */
@@ -27,36 +33,76 @@ public class HibernateKeyWrapper {
     /** Entry. */
     private final String entry;
 
+    /** */
+    private final String tenantId;
+
     /**
      * @param key Key.
      * @param entry Entry.
+     * @param tenantId Tenant ID.
      */
-    public HibernateKeyWrapper(Object key, String entry) {
+    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 (this == o) return true;
+
         if (o == null || getClass() != o.getClass())
             return false;
 
-        HibernateKeyWrapper wrapper = (HibernateKeyWrapper)o;
+        HibernateKeyWrapper that = (HibernateKeyWrapper) o;
 
-        if (key != null ? !key.equals(wrapper.key) : wrapper.key != null)
-            return false;
-
-        return entry != null ? entry.equals(wrapper.entry) : wrapper.entry == null;
+        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 result = key != null ? key.hashCode() : 0;
-
-        result = 31 * result + (entry != null ? entry.hashCode() : 0);
+        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;
+    }
 
-        return result;
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(HibernateKeyWrapper.class, this);
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/b709ddf3/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegionFactory.java
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegionFactory.java
b/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegionFactory.java
index 0329688..0cf03d7 100644
--- a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegionFactory.java
+++ b/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegionFactory.java
@@ -111,15 +111,6 @@ public class HibernateRegionFactory implements RegionFactory {
     /** Key transformer. */
     private final HibernateKeyTransformer hibernate4transformer = new HibernateKeyTransformer()
{
         @Override public Object transform(Object key) {
-//            if (key instanceof CacheKey) {
-//                CacheKey cacheKey = (CacheKey)key;
-//
-//                return new HibernateKeyWrapper(
-//                    cacheKey.getKey(),
-//                    cacheKey.getEntityOrRoleName()
-//                );
-//            }
-
             return key;
         }
     };


Mime
View raw message