[jboss-cvs] jboss-seam/src/ioc/org/jboss/seam/ioc/spring ...
Michael Youngstrom
youngm at gmail.com
Tue Jul 17 14:43:56 EDT 2007
User: myoungstrom
Date: 07/07/17 14:43:56
Modified: src/ioc/org/jboss/seam/ioc/spring
SeamManagedSessionFactoryBean.java
Log:
JBSEAM-1568
Revision Changes Path
1.3 +47 -20 jboss-seam/src/ioc/org/jboss/seam/ioc/spring/SeamManagedSessionFactoryBean.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: SeamManagedSessionFactoryBean.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/ioc/org/jboss/seam/ioc/spring/SeamManagedSessionFactoryBean.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- SeamManagedSessionFactoryBean.java 16 Jul 2007 17:42:30 -0000 1.2
+++ SeamManagedSessionFactoryBean.java 17 Jul 2007 18:43:56 -0000 1.3
@@ -5,10 +5,13 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
import org.hibernate.HibernateException;
+import org.hibernate.Session;
import org.hibernate.SessionFactory;
-import org.hibernate.classic.Session;
import org.jboss.seam.Component;
import org.jboss.seam.log.LogProvider;
import org.jboss.seam.log.Logging;
@@ -18,19 +21,23 @@
import org.springframework.util.ClassUtils;
/**
- * A SessionFactory that delegates requests to open a Session to a "managed-hibernate-session".
+ * A SessionFactory that delegates requests to open a Session to a
+ * "managed-hibernate-session".
+ *
* @author Mike Youngstrom
*/
public class SeamManagedSessionFactoryBean extends AbstractFactoryBean
{
private String sessionName;
+
private SessionFactory baseSessionFactory;
@Override
public void afterPropertiesSet() throws Exception
{
super.afterPropertiesSet();
- if(sessionName == null || "".equals(sessionName)) {
+ if (sessionName == null || "".equals(sessionName))
+ {
throw new IllegalArgumentException("SesssionName cannot be empty");
}
}
@@ -39,14 +46,18 @@
protected Object createInstance() throws Exception
{
Class[] sessionFactoryInterfaces;
- if(baseSessionFactory != null) {
+ if (baseSessionFactory != null)
+ {
sessionFactoryInterfaces = ClassUtils.getAllInterfaces(baseSessionFactory);
- } else {
- sessionFactoryInterfaces = new Class[] {SessionFactory.class};
}
- //Create proxy of SessionFactory to implement all interfaces the baseSessionFactory did.
- return Proxy.newProxyInstance(getClass().getClassLoader(),
- sessionFactoryInterfaces, new SeamManagedSessionFactoryHandler(sessionName, baseSessionFactory));
+ else
+ {
+ sessionFactoryInterfaces = new Class[] { SessionFactory.class };
+ }
+ // Create proxy of SessionFactory to implement all interfaces the
+ // baseSessionFactory did.
+ return Proxy.newProxyInstance(getClass().getClassLoader(), sessionFactoryInterfaces,
+ new SeamManagedSessionFactoryHandler(sessionName, baseSessionFactory));
}
@Override
@@ -60,8 +71,10 @@
}
/**
- * Optionally provide an instance of the SessionFactory we are wrapping. Only necessary if the proxy
- * needs to expose access to any interfaces besides SessionFactory.class.
+ * Optionally provide an instance of the SessionFactory we are wrapping. Only
+ * necessary if the proxy needs to expose access to any interfaces besides
+ * SessionFactory.class.
+ *
* @param baseSessionFactory
*/
public void setBaseSessionFactory(SessionFactory baseSessionFactory)
@@ -71,6 +84,7 @@
/**
* The name of the Seam "managed-hibernate-session" component.
+ *
* @param sessionName
*/
@Required
@@ -80,7 +94,9 @@
}
/**
- * Proxy for a SessionFactory. Returning a close suppressing proxy on calls to "openSession".
+ * Proxy for a SessionFactory. Returning a close suppressing proxy on calls
+ * to "openSession".
+ *
* @author Mike Youngstrom
*
*/
@@ -157,7 +173,7 @@
{
try
{
- return SessionFactoryUtils.doGetSession((SessionFactory)proxy, false);
+ return SessionFactoryUtils.doGetSession((SessionFactory) proxy, false);
}
catch (IllegalStateException ex)
{
@@ -169,10 +185,16 @@
if (method.getParameterTypes().length == 0)
{
Session session = getSession();
- // Return close suppressing Session Proxy that implements all interfaces the original did
- return Proxy.newProxyInstance(this.getClass().getClassLoader(), ClassUtils
- .getAllInterfaces(session), new SeamManagedSessionHandler((SessionFactory)proxy,
- session));
+ // Return close suppressing Session Proxy that implements all
+ // interfaces the original did
+ ClassUtils.getAllInterfaces(session);
+ List<Class> interfaces = new ArrayList<Class>(Arrays.asList(ClassUtils
+ .getAllInterfaces(session)));
+ //Have to bend Session implementation since HiberanteSessionProxy doesn't implement classic.Session.
+ interfaces.add(org.hibernate.classic.Session.class);
+ return Proxy.newProxyInstance(this.getClass().getClassLoader(), interfaces
+ .toArray(new Class[interfaces.size()]), new SeamManagedSessionHandler(
+ (SessionFactory) proxy, session));
}
else
{
@@ -191,6 +213,10 @@
}
try
{
+ if(method.getDeclaringClass().equals(org.hibernate.classic.Session.class) &&
+ !(delegate instanceof org.hibernate.classic.Session)) {
+ throw new UnsupportedOperationException("Unable to execute method: "+method.toString()+" Seam managed session does not support classic.Session methods.");
+ }
return method.invoke(delegate, args);
}
catch (InvocationTargetException ex)
@@ -202,6 +228,7 @@
/**
* Delegates calls to a hibernate session and suppresses calls to close.
+ *
* @author Mike Youngstrom
*/
public static class SeamManagedSessionHandler implements InvocationHandler, Serializable
More information about the jboss-cvs-commits
mailing list