You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by se...@apache.org on 2015/03/04 12:29:55 UTC
incubator-ignite git commit: # ignite-379 Replace
CacheStoreSession.properties() with CacheStoreSession.attach(Object) &
CacheStoreSession.getAttach().
Repository: incubator-ignite
Updated Branches:
refs/heads/ignite-379 b4779991d -> 3a8fa44eb
# ignite-379 Replace CacheStoreSession.properties() with CacheStoreSession.attach(Object) & CacheStoreSession.getAttach().
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/3a8fa44e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/3a8fa44e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/3a8fa44e
Branch: refs/heads/ignite-379
Commit: 3a8fa44eb55be1ebab729261b8ddc54e79645f66
Parents: b477999
Author: sevdokimov <se...@gridgain.com>
Authored: Wed Mar 4 14:29:10 2015 +0300
Committer: sevdokimov <se...@gridgain.com>
Committed: Wed Mar 4 14:29:10 2015 +0300
----------------------------------------------------------------------
.../hibernate/CacheHibernatePersonStore.java | 13 ++----
.../store/jdbc/CacheJdbcPersonStore.java | 13 ++----
.../ignite/cache/store/CacheStoreSession.java | 16 ++++++--
.../store/jdbc/CacheAbstractJdbcStore.java | 11 ++---
.../cache/store/jdbc/CacheJdbcBlobStore.java | 16 ++------
.../processors/cache/GridCacheStoreManager.java | 43 +++++++++++++-------
.../IgniteCacheStoreSessionAbstractTest.java | 16 +++-----
.../junits/cache/TestCacheSession.java | 22 +++++-----
.../cache/TestThreadLocalCacheSession.java | 12 ++++--
.../hibernate/CacheHibernateBlobStore.java | 13 ++----
10 files changed, 82 insertions(+), 93 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a8fa44e/examples/src/main/java/org/apache/ignite/examples/datagrid/store/hibernate/CacheHibernatePersonStore.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/hibernate/CacheHibernatePersonStore.java b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/hibernate/CacheHibernatePersonStore.java
index 98c6b8a..51615f0 100644
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/hibernate/CacheHibernatePersonStore.java
+++ b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/hibernate/CacheHibernatePersonStore.java
@@ -37,9 +37,6 @@ public class CacheHibernatePersonStore extends CacheStoreAdapter<Long, Person> {
/** Default hibernate configuration resource path. */
private static final String DFLT_HIBERNATE_CFG = "/org/apache/ignite/examples/datagrid/store/hibernate/hibernate.cfg.xml";
- /** Session attribute name. */
- private static final String ATTR_SES = "HIBERNATE_STORE_SESSION";
-
/** Session factory. */
private SessionFactory sesFactory;
@@ -207,9 +204,7 @@ public class CacheHibernatePersonStore extends CacheStoreAdapter<Long, Person> {
Transaction tx = storeSes.transaction();
- Map<String, Session> props = storeSes.properties();
-
- Session ses = props.remove(ATTR_SES);
+ Session ses = (Session)storeSes.attach(null);
if (ses != null) {
org.hibernate.Transaction hTx = ses.getTransaction();
@@ -247,9 +242,7 @@ public class CacheHibernatePersonStore extends CacheStoreAdapter<Long, Person> {
Session ses;
if (tx != null) {
- Map<String, Session> props = session().properties();
-
- ses = props.get(ATTR_SES);
+ ses = (Session)session().getAttached();
if (ses == null) {
ses = sesFactory.openSession();
@@ -258,7 +251,7 @@ public class CacheHibernatePersonStore extends CacheStoreAdapter<Long, Person> {
// Store session in session properties, so it can be accessed
// for other operations on the same transaction.
- props.put(ATTR_SES, ses);
+ session().attach(ses);
System.out.println("Hibernate session open [ses=" + ses + ", tx=" + tx.xid() + "]");
}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a8fa44e/examples/src/main/java/org/apache/ignite/examples/datagrid/store/jdbc/CacheJdbcPersonStore.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/jdbc/CacheJdbcPersonStore.java b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/jdbc/CacheJdbcPersonStore.java
index 0c920f4..ba5d037 100644
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/jdbc/CacheJdbcPersonStore.java
+++ b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/jdbc/CacheJdbcPersonStore.java
@@ -35,9 +35,6 @@ import java.util.*;
*
*/
public class CacheJdbcPersonStore extends CacheStoreAdapter<Long, Person> {
- /** Transaction metadata attribute name. */
- private static final String ATTR_NAME = "SIMPLE_STORE_CONNECTION";
-
/** Auto-injected store session. */
@CacheStoreSessionResource
private CacheStoreSession ses;
@@ -71,9 +68,7 @@ public class CacheJdbcPersonStore extends CacheStoreAdapter<Long, Person> {
/** {@inheritDoc} */
@Override public void sessionEnd(boolean commit) {
- Map<String, Connection> props = ses.properties();
-
- try (Connection conn = props.remove(ATTR_NAME)) {
+ try (Connection conn = (Connection)ses.attach(null)) {
if (conn != null) {
if (commit)
conn.commit();
@@ -222,16 +217,14 @@ public class CacheJdbcPersonStore extends CacheStoreAdapter<Long, Person> {
// If there is an ongoing transaction,
// we must reuse the same connection.
if (ses.isWithinTransaction()) {
- Map<Object, Object> props = ses.properties();
-
- Connection conn = (Connection)props.get(ATTR_NAME);
+ Connection conn = (Connection)ses.getAttached();
if (conn == null) {
conn = openConnection(false);
// Store connection in session properties, so it can be accessed
// for other operations on the same transaction.
- props.put(ATTR_NAME, conn);
+ ses.attach(conn);
}
return conn;
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a8fa44e/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 640d4a3..519e4dc 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
@@ -19,6 +19,7 @@ package org.apache.ignite.cache.store;
import org.apache.ignite.resources.*;
import org.apache.ignite.transactions.*;
+import org.jetbrains.annotations.*;
import java.util.*;
@@ -52,12 +53,19 @@ public interface CacheStoreSession {
public boolean isWithinTransaction();
/**
- * Gets current session properties. You can add properties directly to the
- * returned map.
+ * Attaches the given object to this session.
*
- * @return Current session properties.
+ * @param obj The object to be attached.
+ * @return Previously attached object.
*/
- public <K, V> Map<K, V> properties();
+ public Object attach(@Nullable Object obj);
+
+ /**
+ * Returns the current attached object.
+ *
+ * @return The object currently attached to this session, or {@code null} if there is no attachment.
+ */
+ public Object getAttached();
/**
* Cache name for the current store operation. Note that if the same store
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a8fa44e/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheAbstractJdbcStore.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheAbstractJdbcStore.java b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheAbstractJdbcStore.java
index fd409fa..e252545 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheAbstractJdbcStore.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheAbstractJdbcStore.java
@@ -86,9 +86,6 @@ public abstract class CacheAbstractJdbcStore<K, V> implements CacheStore<K, V>,
/** Default batch size for put and remove operations. */
protected static final int DFLT_PARALLEL_LOAD_CACHE_MINIMUM_THRESHOLD = 512;
- /** Connection attribute property name. */
- protected static final String ATTR_CONN_PROP = "JDBC_STORE_CONNECTION";
-
/** Empty column value. */
protected static final Object[] EMPTY_COLUMN_VALUE = new Object[] { null };
@@ -257,15 +254,13 @@ public abstract class CacheAbstractJdbcStore<K, V> implements CacheStore<K, V>,
CacheStoreSession ses = session();
if (ses.transaction() != null) {
- Map<String, Connection> prop = ses.properties();
-
- Connection conn = prop.get(ATTR_CONN_PROP);
+ Connection conn = (Connection)ses.getAttached();
if (conn == null) {
conn = openConnection(false);
// Store connection in session to used it for other operations in the same session.
- prop.put(ATTR_CONN_PROP, conn);
+ ses.attach(conn);
}
return conn;
@@ -306,7 +301,7 @@ public abstract class CacheAbstractJdbcStore<K, V> implements CacheStore<K, V>,
Transaction tx = ses.transaction();
- Connection conn = ses.<String, Connection>properties().remove(ATTR_CONN_PROP);
+ Connection conn = (Connection)ses.attach(null);
if (conn != null) {
assert tx != null;
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a8fa44e/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheJdbcBlobStore.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheJdbcBlobStore.java b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheJdbcBlobStore.java
index 3116309..c607f3f 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheJdbcBlobStore.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheJdbcBlobStore.java
@@ -32,7 +32,6 @@ import javax.cache.*;
import javax.cache.integration.*;
import javax.sql.*;
import java.sql.*;
-import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
@@ -108,9 +107,6 @@ public class CacheJdbcBlobStore<K, V> extends CacheStoreAdapter<K, V> {
/** Default delete entry query (value is <tt>delete from ENTRIES where key=?</tt>). */
public static final String DFLT_DEL_QRY = "delete from ENTRIES where key=?";
- /** Connection attribute name. */
- private static final String ATTR_CONN = "JDBC_STORE_CONNECTION";
-
/** Connection URL. */
private String connUrl = DFLT_CONN_URL;
@@ -183,9 +179,7 @@ public class CacheJdbcBlobStore<K, V> extends CacheStoreAdapter<K, V> {
Transaction tx = transaction();
- Map<String, Connection> props = session().properties();
-
- Connection conn = props.remove(ATTR_CONN);
+ Connection conn = (Connection)session().attach(null);
if (conn != null) {
try {
@@ -322,16 +316,14 @@ public class CacheJdbcBlobStore<K, V> extends CacheStoreAdapter<K, V> {
*/
private Connection connection(@Nullable Transaction tx) throws SQLException {
if (tx != null) {
- Map<String, Connection> props = session().properties();
-
- Connection conn = props.get(ATTR_CONN);
+ Connection conn = (Connection)session().getAttached();
if (conn == null) {
conn = openConnection(false);
// Store connection in session properties, so it can be accessed
// for other operations on the same transaction.
- props.put(ATTR_CONN, conn);
+ session().attach(conn);
}
return conn;
@@ -581,7 +573,7 @@ public class CacheJdbcBlobStore<K, V> extends CacheStoreAdapter<K, V> {
/**
* @return Current transaction.
*/
- @Nullable private Transaction transaction() {
+ private Transaction transaction() {
CacheStoreSession ses = session();
return ses != null ? ses.transaction() : null;
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a8fa44e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheStoreManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheStoreManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheStoreManager.java
index e8e3bd0..5a3e46e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheStoreManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheStoreManager.java
@@ -24,7 +24,6 @@ import org.apache.ignite.internal.*;
import org.apache.ignite.internal.processors.cache.store.*;
import org.apache.ignite.internal.processors.cache.transactions.*;
import org.apache.ignite.internal.processors.cache.version.*;
-import org.apache.ignite.internal.util.*;
import org.apache.ignite.internal.util.lang.*;
import org.apache.ignite.internal.util.tostring.*;
import org.apache.ignite.internal.util.typedef.*;
@@ -842,7 +841,7 @@ public class GridCacheStoreManager<K, V> extends GridCacheManagerAdapter<K, V> {
/** */
@GridToStringInclude
- private Map<Object, Object> props;
+ private Object attach;
/**
* @param tx Current transaction.
@@ -861,16 +860,6 @@ public class GridCacheStoreManager<K, V> extends GridCacheManagerAdapter<K, V> {
}
/**
- * @return Properties.
- */
- private Map<Object, Object> properties() {
- if (props == null)
- props = new GridLeanMap<>();
-
- return props;
- }
-
- /**
* @return Cache name.
*/
private String cacheName() {
@@ -884,6 +873,20 @@ public class GridCacheStoreManager<K, V> extends GridCacheManagerAdapter<K, V> {
this.cacheName = cacheName;
}
+ /**
+ * @return Attachment.
+ */
+ public Object attachment() {
+ return attach;
+ }
+
+ /**
+ * @param attach New attachment.
+ */
+ public void attachment(Object attach) {
+ this.attach = attach;
+ }
+
/** {@inheritDoc} */
@Override public String toString() {
return S.toString(SessionData.class, this, "tx", CU.txString(tx));
@@ -917,11 +920,21 @@ public class GridCacheStoreManager<K, V> extends GridCacheManagerAdapter<K, V> {
}
/** {@inheritDoc} */
- @SuppressWarnings("unchecked")
- @Override public <K1, V1> Map<K1, V1> properties() {
+ @Override public Object attach(@Nullable Object obj) {
+ SessionData sesData = sesHolder.get();
+
+ Object oldAttach = sesData.attach;
+
+ sesData.attachment(obj);
+
+ return oldAttach;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Object getAttached() {
SessionData ses0 = sesHolder.get();
- return ses0 != null ? (Map<K1, V1>)ses0.properties() : null;
+ return ses0 != null ? ses0.attachment() : null;
}
/** {@inheritDoc} */
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a8fa44e/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/integration/IgniteCacheStoreSessionAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/integration/IgniteCacheStoreSessionAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/integration/IgniteCacheStoreSessionAbstractTest.java
index ae00ba4..122e8f7 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/integration/IgniteCacheStoreSessionAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/integration/IgniteCacheStoreSessionAbstractTest.java
@@ -205,7 +205,7 @@ public abstract class IgniteCacheStoreSessionAbstractTest extends IgniteCacheAbs
private final String expMtd;
/** */
- private final Map<Object, Object> expProps;
+ private final Object expAttach;
/** */
private final String expCacheName;
@@ -213,13 +213,13 @@ public abstract class IgniteCacheStoreSessionAbstractTest extends IgniteCacheAbs
/**
* @param tx {@code True} if transaction is enabled.
* @param expMtd Expected method.
- * @param expProps Expected properties.
+ * @param expAttach Expected properties.
* @param expCacheName Expected cache name.
*/
- public ExpectedData(boolean tx, String expMtd, Map<Object, Object> expProps, String expCacheName) {
+ ExpectedData(boolean tx, String expMtd, Object expAttach, String expCacheName) {
this.tx = tx;
this.expMtd = expMtd;
- this.expProps = expProps;
+ this.expAttach = expAttach;
this.expCacheName = expCacheName;
}
}
@@ -329,13 +329,7 @@ public abstract class IgniteCacheStoreSessionAbstractTest extends IgniteCacheAbs
else
assertNull(ses.transaction());
- Map<Object, Object> props = ses.properties();
-
- assertNotNull(props);
-
- assertEquals(exp.expProps, props);
-
- props.put(props.size(), mtd);
+ assertEquals(exp.expAttach, ses.getAttached());
assertEquals(exp.expCacheName, ses.cacheName());
}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a8fa44e/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 0709880..0eba380 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
@@ -18,12 +18,9 @@
package org.apache.ignite.testframework.junits.cache;
import org.apache.ignite.cache.store.*;
-import org.apache.ignite.internal.util.typedef.internal.*;
import org.apache.ignite.transactions.*;
import org.jetbrains.annotations.*;
-import java.util.*;
-
/**
*
*/
@@ -32,7 +29,7 @@ public class TestCacheSession implements CacheStoreSession {
private Transaction tx;
/** */
- private Map<Object, Object> props;
+ private Object attach;
/**
*
@@ -41,7 +38,7 @@ public class TestCacheSession implements CacheStoreSession {
public void newSession(@Nullable Transaction tx) {
this.tx = tx;
- props = null;
+ attach = null;
}
/** {@inheritDoc} */
@@ -55,12 +52,17 @@ public class TestCacheSession implements CacheStoreSession {
}
/** {@inheritDoc} */
- @SuppressWarnings("unchecked")
- @Override public <K, V> Map<K, V> properties() {
- if (props == null)
- props = U.newHashMap(1);
+ @Override public Object attach(@Nullable Object obj) {
+ Object oldAttach = attach;
+
+ attach = obj;
- return (Map<K, V>)props;
+ return oldAttach;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Object getAttached() {
+ return attach;
}
/** {@inheritDoc} */
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a8fa44e/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 2bbcf1b..416cf5e 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,17 @@ public class TestThreadLocalCacheSession implements CacheStoreSession {
}
/** {@inheritDoc} */
- @SuppressWarnings("unchecked")
- @Override public <K, V> Map<K, V> properties() {
+ @Override public Object attach(@Nullable Object obj) {
TestCacheSession ses = sesHolder.get();
- return ses != null ? (Map<K, V>)ses.properties() : null;
+ return ses.attach(obj);
+ }
+
+ /** {@inheritDoc} */
+ @Override public Object getAttached() {
+ TestCacheSession ses = sesHolder.get();
+
+ return ses != null ? ses.getAttached() : null;
}
/** {@inheritDoc} */
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a8fa44e/modules/hibernate/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStore.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStore.java b/modules/hibernate/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStore.java
index faba711..038e6e1 100644
--- a/modules/hibernate/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStore.java
+++ b/modules/hibernate/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStore.java
@@ -158,9 +158,6 @@ public class CacheHibernateBlobStore<K, V> extends CacheStoreAdapter<K, V> {
/** Default <tt>hibernate.hbm2ddl.auto</tt> property value (value is <tt>true</tt>). */
public static final String DFLT_HBM2DDL_AUTO = "update";
- /** Session attribute name. */
- private static final String ATTR_SES = "HIBERNATE_STORE_SESSION";
-
/** Name of Hibarname mapping resource. */
private static final String MAPPING_RESOURCE =
"org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.hbm.xml";
@@ -332,9 +329,7 @@ public class CacheHibernateBlobStore<K, V> extends CacheStoreAdapter<K, V> {
Transaction tx = transaction();
- Map<String, Session> props = session().properties();
-
- Session ses = props.remove(ATTR_SES);
+ Session ses = (Session)session().attach(null);
if (ses != null) {
org.hibernate.Transaction hTx = ses.getTransaction();
@@ -373,9 +368,7 @@ public class CacheHibernateBlobStore<K, V> extends CacheStoreAdapter<K, V> {
Session ses;
if (tx != null) {
- Map<String, Session> props = session().properties();
-
- ses = props.get(ATTR_SES);
+ ses = (Session)session().getAttached();
if (ses == null) {
ses = sesFactory.openSession();
@@ -384,7 +377,7 @@ public class CacheHibernateBlobStore<K, V> extends CacheStoreAdapter<K, V> {
// Store session in transaction metadata, so it can be accessed
// for other operations on the same transaction.
- props.put(ATTR_SES, ses);
+ session().attach(ses);
if (log.isDebugEnabled())
log.debug("Hibernate session open [ses=" + ses + ", tx=" + tx.xid() + "]");