ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [28/39] incubator-ignite git commit: IGNITE-891 - Cache store improvements
Date Tue, 02 Jun 2015 08:57:53 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/f0b980cb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/f0b980cb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/f0b980cb

Branch: refs/heads/ignite-876-2
Commit: f0b980cb500a77617cfe42fe166ada086d7464af
Parents: e6cc139
Author: Valentin Kulichenko <vkulichenko@gridgain.com>
Authored: Sun May 24 23:53:44 2015 -0700
Committer: Valentin Kulichenko <vkulichenko@gridgain.com>
Committed: Sun May 24 23:53:44 2015 -0700

----------------------------------------------------------------------
 .../ignite/cache/store/CacheStoreSession.java    | 19 ++++++++++++++++++-
 .../jdbc/CacheJdbcStoreSessionListener.java      |  4 +---
 .../store/GridCacheStoreManagerAdapter.java      | 11 +++++++----
 .../junits/cache/TestCacheSession.java           |  6 +++++-
 .../cache/TestThreadLocalCacheSession.java       |  5 ++---
 .../CacheHibernateStoreSessionListener.java      |  4 +---
 .../spring/CacheSpringStoreSessionListener.java  |  4 +---
 7 files changed, 35 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f0b980cb/modules/core/src/main/java/org/apache/ignite/cache/store/CacheStoreSession.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/store/CacheStoreSession.java
b/modules/core/src/main/java/org/apache/ignite/cache/store/CacheStoreSession.java
index 980c6df..329e994 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/store/CacheStoreSession.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/store/CacheStoreSession.java
@@ -52,8 +52,25 @@ public interface CacheStoreSession {
      */
     public boolean isWithinTransaction();
 
-    public void attach(@Nullable Object attachment);
+    /**
+     * Attaches the given object to this session.
+     * <p>
+     * An attached object may later be retrieved via the {@link #attachment()}
+     * method. Invoking this method causes any previous attachment to be
+     * discarded. To attach additional objects use {@link #properties()} map.
+     * <p>
+     * The current attachment may be discarded by attaching {@code null}.
+     *
+     * @param attachment The object to be attached (or {@code null} to discard current attachment).
+     * @return Previously attached object, if any.
+     */
+    @Nullable public <T> T attach(@Nullable Object attachment);
 
+    /**
+     * Retrieves the current attachment or {@code null} if there is no attachment.
+     *
+     * @return Currently attached object, if any.
+     */
     @Nullable public <T> T attachment();
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f0b980cb/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheJdbcStoreSessionListener.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheJdbcStoreSessionListener.java
b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheJdbcStoreSessionListener.java
index c59e86f..a20e535 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheJdbcStoreSessionListener.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheJdbcStoreSessionListener.java
@@ -121,11 +121,9 @@ public class CacheJdbcStoreSessionListener implements CacheStoreSessionListener,
 
     /** {@inheritDoc} */
     @Override public void onSessionEnd(CacheStoreSession ses, boolean commit) {
-        Connection conn = ses.attachment();
+        Connection conn = ses.attach(null);
 
         if (conn != null) {
-            ses.attach(null);
-
             try {
                 if (commit)
                     conn.commit();

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f0b980cb/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/store/GridCacheStoreManagerAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/store/GridCacheStoreManagerAdapter.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/store/GridCacheStoreManagerAdapter.java
index bc5a0a2..b4a146a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/store/GridCacheStoreManagerAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/store/GridCacheStoreManagerAdapter.java
@@ -889,8 +889,12 @@ public abstract class GridCacheStoreManagerAdapter extends GridCacheManagerAdapt
         /**
          * @param attachment Attachment.
          */
-        private void attach(Object attachment) {
+        private Object attach(Object attachment) {
+            Object prev = this.attachment;
+
             this.attachment = attachment;
+
+            return prev;
         }
 
         /**
@@ -962,11 +966,10 @@ public abstract class GridCacheStoreManagerAdapter extends GridCacheManagerAdapt
         }
 
         /** {@inheritDoc} */
-        @Override public void attach(@Nullable Object attachment) {
+        @Override public Object attach(@Nullable Object attachment) {
             SessionData ses0 = sesHolder.get();
 
-            if (ses0 != null)
-                ses0.attach(attachment);
+            return ses0 != null ? ses0.attach(attachment) : null;
         }
 
         /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f0b980cb/modules/core/src/test/java/org/apache/ignite/testframework/junits/cache/TestCacheSession.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/cache/TestCacheSession.java
b/modules/core/src/test/java/org/apache/ignite/testframework/junits/cache/TestCacheSession.java
index bc7bf7d..31cbefa 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/cache/TestCacheSession.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/cache/TestCacheSession.java
@@ -58,8 +58,12 @@ public class TestCacheSession implements CacheStoreSession {
     }
 
     /** {@inheritDoc} */
-    @Override public void attach(@Nullable Object attachment) {
+    @Override public Object attach(@Nullable Object attachment) {
+        Object prev = this.attachment;
+
         this.attachment = attachment;
+
+        return prev;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f0b980cb/modules/core/src/test/java/org/apache/ignite/testframework/junits/cache/TestThreadLocalCacheSession.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/cache/TestThreadLocalCacheSession.java
b/modules/core/src/test/java/org/apache/ignite/testframework/junits/cache/TestThreadLocalCacheSession.java
index 2047600..dc876d3 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/cache/TestThreadLocalCacheSession.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/cache/TestThreadLocalCacheSession.java
@@ -54,11 +54,10 @@ public class TestThreadLocalCacheSession implements CacheStoreSession
{
     }
 
     /** {@inheritDoc} */
-    @Override public void attach(@Nullable Object attachment) {
+    @Override public Object attach(@Nullable Object attachment) {
         TestCacheSession ses = sesHolder.get();
 
-        if (ses != null)
-            ses.attach(attachment);
+        return ses != null ? ses.attach(attachment) : null;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f0b980cb/modules/hibernate/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListener.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListener.java
b/modules/hibernate/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListener.java
index 61f7265..cfad322 100644
--- a/modules/hibernate/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListener.java
+++ b/modules/hibernate/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListener.java
@@ -190,11 +190,9 @@ public class CacheHibernateStoreSessionListener implements CacheStoreSessionList
 
     /** {@inheritDoc} */
     @Override public void onSessionEnd(CacheStoreSession ses, boolean commit) {
-        Session hibSes = ses.attachment();
+        Session hibSes = ses.attach(null);
 
         if (hibSes != null) {
-            ses.attach(null);
-
             try {
                 Transaction tx = hibSes.getTransaction();
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f0b980cb/modules/spring/src/main/java/org/apache/ignite/cache/store/spring/CacheSpringStoreSessionListener.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/main/java/org/apache/ignite/cache/store/spring/CacheSpringStoreSessionListener.java
b/modules/spring/src/main/java/org/apache/ignite/cache/store/spring/CacheSpringStoreSessionListener.java
index 90431d7..53fc599 100644
--- a/modules/spring/src/main/java/org/apache/ignite/cache/store/spring/CacheSpringStoreSessionListener.java
+++ b/modules/spring/src/main/java/org/apache/ignite/cache/store/spring/CacheSpringStoreSessionListener.java
@@ -169,11 +169,9 @@ public class CacheSpringStoreSessionListener implements CacheStoreSessionListene
     /** {@inheritDoc} */
     @Override public void onSessionEnd(CacheStoreSession ses, boolean commit) {
         if (ses.isWithinTransaction()) {
-            TransactionStatus tx = ses.attachment();
+            TransactionStatus tx = ses.attach(null);
 
             if (tx != null) {
-                ses.attach(null);
-
                 try {
                     if (commit)
                         txMgr.commit(tx);


Mime
View raw message