[hibernate-commits] Hibernate SVN: r11474 - in trunk/HibernateExt/shards/src: test/org/hibernate/shards/integration/model and 1 other directory.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Mon May 7 01:03:56 EDT 2007
Author: max.ross
Date: 2007-05-07 01:03:55 -0400 (Mon, 07 May 2007)
New Revision: 11474
Modified:
trunk/HibernateExt/shards/src/java/org/hibernate/shards/session/ShardedSessionImpl.java
trunk/HibernateExt/shards/src/test/org/hibernate/shards/integration/model/ModelPermutedIntegrationTest.java
Log:
http://opensource.atlassian.com/projects/hibernate/browse/HSHARDS-31
Implemented ShardedSessionImpl.getEntityName()
Modified: trunk/HibernateExt/shards/src/java/org/hibernate/shards/session/ShardedSessionImpl.java
===================================================================
--- trunk/HibernateExt/shards/src/java/org/hibernate/shards/session/ShardedSessionImpl.java 2007-05-07 04:13:58 UTC (rev 11473)
+++ trunk/HibernateExt/shards/src/java/org/hibernate/shards/session/ShardedSessionImpl.java 2007-05-07 05:03:55 UTC (rev 11474)
@@ -967,19 +967,13 @@
throw new UnsupportedOperationException();
}
- public LockMode getCurrentLockMode(Object object) throws HibernateException {
- ShardId shardId = getShardIdForObject(object);
- Session sessionToUse;
- if (shardId == null) {
- // just ask this question of a random shard so we get the proper error
- sessionToUse = getSomeSession();
- if (sessionToUse == null) {
- sessionToUse = shards.get(0).establishSession();
+ public LockMode getCurrentLockMode(final Object object) throws HibernateException {
+ SessionMethodInvoker<LockMode> invoker = new SessionMethodInvoker<LockMode>() {
+ public LockMode invoke(Session s, Object obj) {
+ return s.getCurrentLockMode(object);
}
- } else {
- sessionToUse = shardIdsToShards.get(shardId).establishSession();
- }
- return sessionToUse.getCurrentLockMode(object);
+ };
+ return invokeOnSessionWithObject(invoker, object);
}
public Transaction beginTransaction() throws HibernateException {
@@ -1067,13 +1061,40 @@
}
}
+ private interface SessionMethodInvoker<T> {
+ T invoke(Session s, Object obj);
+ }
+
/**
- * Unsupported. This is a scope decision, not a technical decision.
+ * Helper method we can use when we need to find the Session with which a
+ * specified object is associated and invoke the method on that Session.
+ * If the object isn't associated with a Session we just invoke it on a
+ * random Session with the expectation that this will cause an error.
*/
- public String getEntityName(Object object) throws HibernateException {
- throw new UnsupportedOperationException();
+ <T> T invokeOnSessionWithObject(SessionMethodInvoker<T> smi, Object object) throws HibernateException {
+ ShardId shardId = getShardIdForObject(object);
+ Session sessionToUse;
+ if (shardId == null) {
+ // just ask this question of a random shard so we get the proper error
+ sessionToUse = getSomeSession();
+ if (sessionToUse == null) {
+ sessionToUse = shards.get(0).establishSession();
+ }
+ } else {
+ sessionToUse = shardIdsToShards.get(shardId).establishSession();
+ }
+ return smi.invoke(sessionToUse, object);
}
+ public String getEntityName(final Object object) throws HibernateException {
+ SessionMethodInvoker<String> invoker = new SessionMethodInvoker<String>() {
+ public String invoke(Session s, Object obj) {
+ return s.getEntityName(object);
+ }
+ };
+ return invokeOnSessionWithObject(invoker, object);
+ }
+
public Filter enableFilter(String filterName) {
EnableFilterOpenSessionEvent event = new EnableFilterOpenSessionEvent(
filterName);
Modified: trunk/HibernateExt/shards/src/test/org/hibernate/shards/integration/model/ModelPermutedIntegrationTest.java
===================================================================
--- trunk/HibernateExt/shards/src/test/org/hibernate/shards/integration/model/ModelPermutedIntegrationTest.java 2007-05-07 04:13:58 UTC (rev 11473)
+++ trunk/HibernateExt/shards/src/test/org/hibernate/shards/integration/model/ModelPermutedIntegrationTest.java 2007-05-07 05:03:55 UTC (rev 11474)
@@ -930,6 +930,18 @@
assertNull(b);
}
+ public void testGetEntityName() {
+ Building b = building("b1");
+ try {
+ session.getEntityName(b);
+ fail("expected he");
+ } catch (HibernateException he) {
+ // good
+ }
+ session.save(b);
+ assertEquals(Building.class.getName(), session.getEntityName(b));
+ }
+
public void testGetCurrentLockMode() {
session.beginTransaction();
Building b = building("b1");
More information about the hibernate-commits
mailing list