ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vkuliche...@apache.org
Subject [13/34] incubator-ignite git commit: IGNITE-891 - Cache store improvements
Date Tue, 02 Jun 2015 03:51:07 GMT
IGNITE-891 - Cache store improvements


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

Branch: refs/heads/ignite-sprint-5
Commit: 1e3238c76a3f32de31d8297082bd3eb9c7b4c332
Parents: d4bcd19
Author: Valentin Kulichenko <vkulichenko@gridgain.com>
Authored: Wed May 20 18:53:45 2015 -0700
Committer: Valentin Kulichenko <vkulichenko@gridgain.com>
Committed: Wed May 20 18:53:45 2015 -0700

----------------------------------------------------------------------
 ...cheStoreSessionListenerAbstractSelfTest.java |  4 +-
 .../CacheStoreSessionHibernateListener.java     |  5 +-
 ...heStoreSessionHibernateListenerSelfTest.java | 97 +++++++++++++++++++-
 3 files changed, 96 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1e3238c7/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreSessionListenerAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreSessionListenerAbstractSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreSessionListenerAbstractSelfTest.java
index 5df8f68..adac0b2 100644
--- a/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreSessionListenerAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreSessionListenerAbstractSelfTest.java
@@ -93,8 +93,8 @@ public abstract class CacheStoreSessionListenerAbstractSelfTest extends
GridComm
             conn.createStatement().executeUpdate("DROP TABLE IF EXISTS Table1");
             conn.createStatement().executeUpdate("DROP TABLE IF EXISTS Table2");
 
-            conn.createStatement().executeUpdate("CREATE TABLE Table1 (key INT, value INT)");
-            conn.createStatement().executeUpdate("CREATE TABLE Table2 (key INT, value INT)");
+            conn.createStatement().executeUpdate("CREATE TABLE Table1 (id INT AUTO_INCREMENT,
key INT, value INT)");
+            conn.createStatement().executeUpdate("CREATE TABLE Table2 (id INT AUTO_INCREMENT,
key INT, value INT)");
         }
 
         loadCacheCnt.set(0);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1e3238c7/modules/hibernate/src/main/java/org/apache/ignite/cache/store/hibernate/CacheStoreSessionHibernateListener.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/main/java/org/apache/ignite/cache/store/hibernate/CacheStoreSessionHibernateListener.java
b/modules/hibernate/src/main/java/org/apache/ignite/cache/store/hibernate/CacheStoreSessionHibernateListener.java
index 06af03a..fc9eb91 100644
--- a/modules/hibernate/src/main/java/org/apache/ignite/cache/store/hibernate/CacheStoreSessionHibernateListener.java
+++ b/modules/hibernate/src/main/java/org/apache/ignite/cache/store/hibernate/CacheStoreSessionHibernateListener.java
@@ -19,7 +19,6 @@ package org.apache.ignite.cache.store.hibernate;
 
 import org.apache.ignite.cache.store.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
-import org.apache.ignite.resources.*;
 import org.hibernate.*;
 
 import javax.cache.integration.*;
@@ -85,10 +84,10 @@ public class CacheStoreSessionHibernateListener implements CacheStoreSessionList
                 if (commit) {
                     hibSes.flush();
 
-                    if (tx != null)
+                    if (tx.isActive())
                         tx.commit();
                 }
-                else if (tx != null)
+                else if (tx.isActive())
                     tx.rollback();
             }
             catch (HibernateException e) {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1e3238c7/modules/hibernate/src/test/java/org/apache/ignite/cache/store/hibernate/CacheStoreSessionHibernateListenerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/test/java/org/apache/ignite/cache/store/hibernate/CacheStoreSessionHibernateListenerSelfTest.java
b/modules/hibernate/src/test/java/org/apache/ignite/cache/store/hibernate/CacheStoreSessionHibernateListenerSelfTest.java
index d631393..a9d465e 100644
--- a/modules/hibernate/src/test/java/org/apache/ignite/cache/store/hibernate/CacheStoreSessionHibernateListenerSelfTest.java
+++ b/modules/hibernate/src/test/java/org/apache/ignite/cache/store/hibernate/CacheStoreSessionHibernateListenerSelfTest.java
@@ -27,6 +27,8 @@ import org.hibernate.cfg.Configuration;
 import javax.cache.Cache;
 import javax.cache.configuration.*;
 import javax.cache.integration.*;
+import javax.persistence.*;
+import java.io.*;
 import java.util.*;
 
 /**
@@ -48,10 +50,13 @@ public class CacheStoreSessionHibernateListenerSelfTest extends CacheStoreSessio
             @Override public CacheStoreSessionListener create() {
                 CacheStoreSessionHibernateListener lsnr = new CacheStoreSessionHibernateListener();
 
-                Configuration cfg = new Configuration().
-                    setProperty("hibernate.connection.url", URL);
+                SessionFactory sesFactory = new Configuration().
+                    setProperty("hibernate.connection.url", URL).
+                    addAnnotatedClass(Table1.class).
+                    addAnnotatedClass(Table2.class).
+                    buildSessionFactory();
 
-                lsnr.setSessionFactory(cfg.buildSessionFactory());
+                lsnr.setSessionFactory(sesFactory);
 
                 return lsnr;
             }
@@ -90,6 +95,28 @@ public class CacheStoreSessionHibernateListenerSelfTest extends CacheStoreSessio
             writeCnt.incrementAndGet();
 
             checkSession();
+
+            if (write.get()) {
+                Session hibSes = session();
+
+                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} */
@@ -113,10 +140,14 @@ public class CacheStoreSessionHibernateListenerSelfTest extends CacheStoreSessio
 
             assertTrue(hibSes.isOpen());
 
+            Transaction tx = hibSes.getTransaction();
+
+            assertNotNull(tx);
+
             if (ses.isWithinTransaction())
-                assertNotNull(hibSes.getTransaction());
+                assertTrue(tx.isActive());
             else
-                assertNull(hibSes.getTransaction());
+                assertFalse(tx.isActive());
 
             verifySameInstance(hibSes);
         }
@@ -145,4 +176,60 @@ public class CacheStoreSessionHibernateListenerSelfTest extends CacheStoreSessio
             return ses.<String, Session>properties().get(CacheStoreSessionHibernateListener.HIBERNATE_SES_KEY);
         }
     }
+
+    /**
+     */
+    @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;
+        }
+    }
 }


Mime
View raw message