1
22
23 package com.liferay.portal.spring.hibernate;
24
25 import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
26
27 import java.lang.Object;
28 import java.lang.String;
29 import java.lang.reflect.InvocationHandler;
30 import java.lang.reflect.InvocationTargetException;
31 import java.lang.reflect.Method;
32
33 import org.hibernate.classic.Session;
34
35
44 public class SessionInvocationHandler implements InvocationHandler {
45
46 public SessionInvocationHandler(Session session) {
47 _session = session;
48 }
49
50 public Session getSession() {
51 return _session;
52 }
53
54 @SuppressWarnings("deprecation")
55 public Object invoke(Object proxy, Method method, Object[] args)
56 throws Throwable {
57
58 String methodName = method.getName();
59
60 if (methodName.equals(_CONNECTION)) {
61 Thread currentThread = Thread.currentThread();
62
63 ClassLoader contextClassLoader =
64 currentThread.getContextClassLoader();
65
66 try {
67 ClassLoader portalClassLoader =
68 PortalClassLoaderUtil.getClassLoader();
69
70 currentThread.setContextClassLoader(portalClassLoader);
71
72 return _session.connection();
73 }
74 finally {
75 currentThread.setContextClassLoader(contextClassLoader);
76 }
77 }
78 else if (methodName.equals(_EQUALS)) {
79 if (proxy == args[0]) {
80 return Boolean.TRUE;
81 }
82 else {
83 return Boolean.FALSE;
84 }
85 }
86 else if (methodName.equals(_HASHCODE)) {
87 return new Integer(hashCode());
88 }
89
90 try {
91 return method.invoke(_session, args);
92 }
93 catch (InvocationTargetException ite) {
94 throw ite.getTargetException();
95 }
96 }
97
98 private static final String _CONNECTION = "connection";
99
100 private static final String _EQUALS = "equals";
101
102 private static final String _HASHCODE = "hashCode";
103
104 private final Session _session;
105
106 }