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