1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.core.ojb;
17
18 import java.util.Collection;
19
20 import org.apache.ojb.broker.PBKey;
21 import org.apache.ojb.broker.PersistenceBrokerException;
22 import org.apache.ojb.broker.core.proxy.CollectionProxyDefaultImpl;
23 import org.apache.ojb.broker.query.Query;
24 import org.kuali.rice.core.util.ClassLoaderUtils;
25 import org.kuali.rice.core.util.ContextClassLoaderBinder;
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 public class ContextClassLoaderCollectionProxy extends CollectionProxyDefaultImpl {
48
49 private static final long serialVersionUID = 6425238292133556808L;
50
51
52
53 private transient ClassLoader contextClassLoader;
54
55 public ContextClassLoaderCollectionProxy(PBKey aKey, Class aCollClass, Query aQuery) {
56 super(aKey, aCollClass, aQuery);
57 this.contextClassLoader = ClassLoaderUtils.getDefaultClassLoader();
58 }
59
60 public ContextClassLoaderCollectionProxy(PBKey aKey, Query aQuery) {
61 super(aKey, aQuery);
62 this.contextClassLoader = ClassLoaderUtils.getDefaultClassLoader();
63 }
64
65 @Override
66 protected void beforeLoading() {
67 ContextClassLoaderBinder.bind(this.contextClassLoader);
68 super.beforeLoading();
69 }
70
71 @Override
72 protected Collection loadData() throws PersistenceBrokerException {
73 try {
74 return super.loadData();
75 } catch (Throwable t) {
76 ContextClassLoaderBinder.unbind();
77 if (t instanceof PersistenceBrokerException) {
78 throw (PersistenceBrokerException)t;
79 } else if (t instanceof Error) {
80 throw (Error)t;
81 } else if (t instanceof RuntimeException) {
82 throw (RuntimeException)t;
83 } else {
84 throw new PersistenceBrokerException("Invalid exception type thrown!", t);
85 }
86 }
87 }
88
89 @Override
90 protected void afterLoading() {
91 super.afterLoading();
92 ContextClassLoaderBinder.unbind();
93 }
94
95 }