Revision f6eae72a
Added by Cherian Mathew about 10 years ago
.gitattributes | ||
---|---|---|
140 | 140 |
eu.etaxonomy.taxeditor.cdmlib/.classpath -text |
141 | 141 |
eu.etaxonomy.taxeditor.cdmlib/.project -text |
142 | 142 |
eu.etaxonomy.taxeditor.cdmlib/META-INF/MANIFEST.MF -text |
143 |
eu.etaxonomy.taxeditor.cdmlib/META-INF/aop.xml -text |
|
143 | 144 |
eu.etaxonomy.taxeditor.cdmlib/README.txt -text |
144 | 145 |
eu.etaxonomy.taxeditor.cdmlib/build.properties -text |
145 | 146 |
eu.etaxonomy.taxeditor.cdmlib/lib/activation-1.1.1.jar -text |
146 | 147 |
eu.etaxonomy.taxeditor.cdmlib/lib/antlr-2.7.7.jar -text |
147 | 148 |
eu.etaxonomy.taxeditor.cdmlib/lib/aopalliance-1.0.jar -text |
149 |
eu.etaxonomy.taxeditor.cdmlib/lib/aspectjrt-1.7.1-sources.jar -text |
|
148 | 150 |
eu.etaxonomy.taxeditor.cdmlib/lib/aspectjrt-1.7.1.jar -text |
151 |
eu.etaxonomy.taxeditor.cdmlib/lib/aspectjweaver-1.7.1-sources.jar -text |
|
149 | 152 |
eu.etaxonomy.taxeditor.cdmlib/lib/aspectjweaver-1.7.1.jar -text |
150 | 153 |
eu.etaxonomy.taxeditor.cdmlib/lib/avro-1.6.3.jar -text |
151 | 154 |
eu.etaxonomy.taxeditor.cdmlib/lib/batik-anim-1.7.jar -text |
... | ... | |
299 | 302 |
eu.etaxonomy.taxeditor.cdmlib/lib/spring-modules-cache-0.7.jar -text |
300 | 303 |
eu.etaxonomy.taxeditor.cdmlib/lib/spring-security-config-3.1.3.RELEASE.jar -text |
301 | 304 |
eu.etaxonomy.taxeditor.cdmlib/lib/spring-security-core-3.1.3.RELEASE.jar -text |
305 |
eu.etaxonomy.taxeditor.cdmlib/lib/spring-security-remoting-3.1.3.RELEASE.jar -text |
|
302 | 306 |
eu.etaxonomy.taxeditor.cdmlib/lib/stax-1.2.0.jar -text |
303 | 307 |
eu.etaxonomy.taxeditor.cdmlib/lib/stax-api-1.0.1.jar -text |
304 | 308 |
eu.etaxonomy.taxeditor.cdmlib/lib/unitils-core-3.3.jar -text |
... | ... | |
329 | 333 |
eu.etaxonomy.taxeditor.cdmlib/lib/xstream-1.4.4.jar -text |
330 | 334 |
eu.etaxonomy.taxeditor.cdmlib/lib/yjp-controller-api-redist-9.0.8.jar -text |
331 | 335 |
eu.etaxonomy.taxeditor.cdmlib/pom.xml -text |
336 |
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/lazyloading/CdmLazyLoader.java -text |
|
337 |
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/remote/api/application/CdmApplicationRemoteConfiguration.java -text |
|
338 |
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/remote/api/application/CdmApplicationRemoteController.java -text |
|
339 |
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/remote/api/application/ICdmApplicationRemoteConfiguration.java -text |
|
340 |
eu.etaxonomy.taxeditor.cdmlib/src/main/java/org/hibernate/collection/internal/AbstractPersistentCollection.java -text |
|
341 |
eu.etaxonomy.taxeditor.cdmlib/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java -text |
|
342 |
eu.etaxonomy.taxeditor.cdmlib/src/main/resources/eu/etaxonomy/cdm/httpInvokerServiceClients.xml -text |
|
343 |
eu.etaxonomy.taxeditor.cdmlib/src/main/resources/eu/etaxonomy/cdm/remotingApplicationContext.xml -text |
|
344 |
eu.etaxonomy.taxeditor.cdmlib/src/main/resources/eu/etaxonomy/cdm/remoting_persistence_security.xml -text |
|
345 |
eu.etaxonomy.taxeditor.cdmlib/src/main/resources/eu/etaxonomy/cdm/remoting_services_security.xml -text |
|
346 |
eu.etaxonomy.taxeditor.cdmlib/src/test/java/eu/etaxonomy/taxeditor/remoting/CdmApplicationRemoteControllerTest.java -text |
|
347 |
eu.etaxonomy.taxeditor.cdmlib/src/test/java/eu/etaxonomy/taxeditor/remoting/RemoteLazyLoadingTest.java -text |
|
332 | 348 |
eu.etaxonomy.taxeditor.editor/.classpath -text |
333 | 349 |
eu.etaxonomy.taxeditor.editor/.project -text |
334 | 350 |
eu.etaxonomy.taxeditor.editor/META-INF/MANIFEST.MF -text |
eu.etaxonomy.taxeditor.cdmlib/.classpath | ||
---|---|---|
1 | 1 |
<?xml version="1.0" encoding="UTF-8"?> |
2 | 2 |
<classpath> |
3 |
<classpathentry kind="src" path="src/main/java"/> |
|
4 |
<classpathentry kind="src" path="src/test/java"/> |
|
5 |
<classpathentry kind="src" path="src/main/resources"/> |
|
3 | 6 |
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> |
4 | 7 |
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> |
5 | 8 |
<classpathentry exported="true" kind="lib" path="lib/activation-1.1.1.jar"/> |
... | ... | |
30 | 33 |
<classpathentry exported="true" kind="lib" path="lib/cdmlib-ext-3.3.1-SNAPSHOT-sources.jar"/> |
31 | 34 |
<classpathentry exported="true" kind="lib" path="lib/cdmlib-ext-3.3.1-SNAPSHOT.jar"/> |
32 | 35 |
<classpathentry exported="true" kind="lib" path="lib/cdmlib-io-3.3.1-SNAPSHOT-sources.jar"/> |
33 |
<classpathentry exported="true" kind="lib" path="lib/cdmlib-io-3.3.1-SNAPSHOT.jar"/> |
|
36 |
<classpathentry exported="true" kind="lib" path="lib/cdmlib-io-3.3.1-SNAPSHOT.jar" sourcepath="lib/cdmlib-io-3.3.1-SNAPSHOT-sources.jar"/>
|
|
34 | 37 |
<classpathentry exported="true" kind="lib" path="lib/cdmlib-model-3.3.1-SNAPSHOT-sources.jar"/> |
35 | 38 |
<classpathentry exported="true" kind="lib" path="lib/cdmlib-model-3.3.1-SNAPSHOT.jar" sourcepath="lib/cdmlib-model-3.3.1-SNAPSHOT-sources.jar"/> |
36 | 39 |
<classpathentry exported="true" kind="lib" path="lib/cdmlib-persistence-3.3.1-SNAPSHOT-sources.jar"/> |
... | ... | |
204 | 207 |
<classpathentry exported="true" kind="lib" path="lib/google-api-translate-java-0.92.jar"/> |
205 | 208 |
<classpathentry exported="true" kind="lib" path="lib/odfdom-0.8.jar"/> |
206 | 209 |
<classpathentry exported="true" kind="lib" path="lib/h2mig_pagestore_addon.jar"/> |
210 |
<classpathentry exported="true" kind="lib" path="lib/spring-security-remoting-3.1.3.RELEASE.jar"/> |
|
207 | 211 |
<classpathentry kind="output" path="target/classes"/> |
208 | 212 |
</classpath> |
eu.etaxonomy.taxeditor.cdmlib/META-INF/MANIFEST.MF | ||
---|---|---|
124 | 124 |
eu.etaxonomy.cdm.print.out.pdf, |
125 | 125 |
eu.etaxonomy.cdm.print.out.taxpub, |
126 | 126 |
eu.etaxonomy.cdm.print.out.xml, |
127 |
eu.etaxonomy.cdm.remote.api.application, |
|
127 | 128 |
eu.etaxonomy.cdm.remote.config, |
128 | 129 |
eu.etaxonomy.cdm.remote.controller, |
129 | 130 |
eu.etaxonomy.cdm.remote.controller.csv, |
... | ... | |
349 | 350 |
org.springframework.security.core.context, |
350 | 351 |
org.springframework.security.core.userdetails, |
351 | 352 |
org.springframework.security.provisioning, |
353 |
org.springframework.security.remoting.httpinvoker, |
|
352 | 354 |
org.springframework.stereotype, |
353 | 355 |
org.springframework.transaction;uses:="org.springframework.core", |
354 | 356 |
org.springframework.transaction.annotation;uses:="javax.ejb,org.springframework.transaction.interceptor", |
... | ... | |
599 | 601 |
lib/yjp-controller-api-redist-9.0.8.jar, |
600 | 602 |
lib/google-api-translate-java-0.92.jar, |
601 | 603 |
lib/odfdom-0.8.jar, |
602 |
lib/h2mig_pagestore_addon.jar |
|
604 |
lib/h2mig_pagestore_addon.jar, |
|
605 |
lib/spring-security-remoting-3.1.3.RELEASE.jar |
|
606 |
Import-Package: eu.etaxonomy.cdm.api.application |
eu.etaxonomy.taxeditor.cdmlib/META-INF/aop.xml | ||
---|---|---|
1 |
<!DOCTYPE aspectj PUBLIC |
|
2 |
"-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd"> |
|
3 |
<aspectj> |
|
4 |
<weaver options="-verbose -showWeaveInfo"> |
|
5 |
<include within="org.hibernate.proxy.*" /> |
|
6 |
<include within="org.hibernate.collection.internal.*" /> |
|
7 |
<include within="eu.etaxonomy.cdm.api.lazyloading.*" /> |
|
8 |
</weaver> |
|
9 |
<aspects> |
|
10 |
<!-- use only this aspect for weaving --> |
|
11 |
<aspect name="eu.etaxonomy.cdm.api.lazyloading.CdmLazyLoader" /> |
|
12 |
|
|
13 |
</aspects> |
|
14 |
|
|
15 |
</aspectj> |
|
16 |
|
eu.etaxonomy.taxeditor.cdmlib/build.properties | ||
---|---|---|
200 | 200 |
lib/yjp-controller-api-redist-9.0.8.jar,\ |
201 | 201 |
lib/google-api-translate-java-0.92.jar,\ |
202 | 202 |
lib/odfdom-0.8.jar,\ |
203 |
lib/h2mig_pagestore_addon.jar |
|
203 |
lib/h2mig_pagestore_addon.jar,\ |
|
204 |
lib/spring-security-remoting-3.1.3.RELEASE.jar |
|
205 |
jars.compile.order = . |
|
206 |
output.. = bin/ |
|
207 |
source.. = src/main/java/,\ |
|
208 |
src/main/resources/,\ |
|
209 |
src/test/java/ |
|
204 | 210 |
|
eu.etaxonomy.taxeditor.cdmlib/pom.xml | ||
---|---|---|
141 | 141 |
<artifactId>cdmlib-ext</artifactId> |
142 | 142 |
<version>${cdmlib.version}</version> |
143 | 143 |
</dependency> |
144 |
<dependency> |
|
145 |
<groupId>org.aspectj</groupId> |
|
146 |
<artifactId>aspectjrt</artifactId> |
|
147 |
<version>1.7.1</version> |
|
148 |
</dependency> |
|
149 |
<dependency> |
|
150 |
<groupId>org.aspectj</groupId> |
|
151 |
<artifactId>aspectjweaver</artifactId> |
|
152 |
<version>1.7.1</version> |
|
153 |
</dependency> |
|
144 | 154 |
<!-- for ikey-plus |
145 | 155 |
TODO this should not be needed but the utils class contained in this jar |
146 | 156 |
seems to be loaded as bean by spring |
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/lazyloading/CdmLazyLoader.java | ||
---|---|---|
1 |
package eu.etaxonomy.cdm.api.lazyloading; |
|
2 |
|
|
3 |
import java.beans.Transient; |
|
4 |
import java.lang.reflect.Field; |
|
5 |
import java.util.ArrayList; |
|
6 |
import java.util.Collection; |
|
7 |
import java.util.HashMap; |
|
8 |
import java.util.HashSet; |
|
9 |
import java.util.List; |
|
10 |
import java.util.Map; |
|
11 |
import java.util.Set; |
|
12 |
import java.util.TreeMap; |
|
13 |
import java.util.TreeSet; |
|
14 |
|
|
15 |
import org.aspectj.lang.ProceedingJoinPoint; |
|
16 |
import org.aspectj.lang.annotation.Around; |
|
17 |
import org.aspectj.lang.annotation.Aspect; |
|
18 |
import org.aspectj.lang.annotation.Pointcut; |
|
19 |
import org.hibernate.collection.internal.PersistentList; |
|
20 |
import org.hibernate.collection.internal.PersistentMap; |
|
21 |
import org.hibernate.collection.internal.PersistentSet; |
|
22 |
import org.hibernate.collection.internal.PersistentSortedMap; |
|
23 |
import org.hibernate.collection.internal.PersistentSortedSet; |
|
24 |
import org.hibernate.collection.spi.PersistentCollection; |
|
25 |
import org.hibernate.proxy.LazyInitializer; |
|
26 |
import org.springframework.beans.factory.annotation.Autowire; |
|
27 |
import org.springframework.beans.factory.annotation.Autowired; |
|
28 |
import org.springframework.beans.factory.annotation.Configurable; |
|
29 |
import org.springframework.stereotype.Component; |
|
30 |
|
|
31 |
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration; |
|
32 |
import eu.etaxonomy.cdm.api.service.ICommonService; |
|
33 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
34 |
import eu.etaxonomy.cdm.model.common.PersistentMultiLanguageText; |
|
35 |
|
|
36 |
|
|
37 |
@Aspect |
|
38 |
@Component |
|
39 |
@Configurable(autowire = Autowire.BY_TYPE) |
|
40 |
public class CdmLazyLoader { |
|
41 |
|
|
42 |
|
|
43 |
private Set classes = new HashSet(); |
|
44 |
|
|
45 |
public static boolean enableWeaving = true; |
|
46 |
private static Set<String> classesToIgnore = new HashSet<String>(); |
|
47 |
|
|
48 |
|
|
49 |
@Autowired |
|
50 |
private ICommonService commonService; |
|
51 |
|
|
52 |
public CdmLazyLoader() { |
|
53 |
//classesToIgnore.add("eu.etaxonomy.cdm.model.common.TermVocabulary"); |
|
54 |
//classesToIgnore.add("eu.etaxonomy.cdm.model.common.OrderedTermVocabulary"); |
|
55 |
|
|
56 |
} |
|
57 |
|
|
58 |
/** |
|
59 |
* Point cut for the 'initialize' method of the AbstractLazyInitializer. |
|
60 |
* |
|
61 |
*/ |
|
62 |
@Pointcut("execution(* org.hibernate.proxy.AbstractLazyInitializer.initialize())") |
|
63 |
public void possibleEntityLazyInitializationException() { |
|
64 |
} |
|
65 |
|
|
66 |
|
|
67 |
/** |
|
68 |
* 'Around' advice for the initialization of CDM Entity Objects |
|
69 |
* |
|
70 |
*/ |
|
71 |
@Around(value = "possibleEntityLazyInitializationException()") |
|
72 |
public Object preloadEntityOnDemand(ProceedingJoinPoint pjp) throws Throwable { |
|
73 |
if(enableWeaving) { |
|
74 |
LazyInitializer ll = (LazyInitializer)pjp.getTarget(); |
|
75 |
if(ll.isUninitialized()) { |
|
76 |
int classid = ((Integer)ll.getIdentifier()).intValue(); |
|
77 |
System.out.print("--> AspectJ Compile-Time Weaving " + ll.getEntityName() + " with id " + classid); |
|
78 |
Class clazz = (Class<? extends CdmBase>) Class.forName(ll.getEntityName()); |
|
79 |
CdmBase cdmBase = CdmBase.deproxy(commonService.find(clazz,classid),clazz); |
|
80 |
ll.setImplementation(cdmBase); |
|
81 |
System.out.println("....Done"); |
|
82 |
} |
|
83 |
} |
|
84 |
return pjp.proceed(); |
|
85 |
} |
|
86 |
|
|
87 |
|
|
88 |
/** |
|
89 |
* Point cut for the 'initialize' method of the AbstractPersistentCollection. |
|
90 |
* |
|
91 |
*/ |
|
92 |
@Pointcut("execution(protected final void org.hibernate.collection.internal.AbstractPersistentCollection.initialize(..))") |
|
93 |
public void possibleCollectionLazyInitializationException() { |
|
94 |
} |
|
95 |
|
|
96 |
/** |
|
97 |
* 'Around' advice for the initialization of Collection objects |
|
98 |
* |
|
99 |
*/ |
|
100 |
@Around(value = "possibleCollectionLazyInitializationException()") |
|
101 |
@Transient |
|
102 |
public Object preloadCollectionOnDemand(ProceedingJoinPoint pjp) throws Throwable { |
|
103 |
if(enableWeaving) { |
|
104 |
PersistentCollection ps = (PersistentCollection) pjp.getTarget(); |
|
105 |
if (ps.getOwner() != null && !classesToIgnore.contains(ps.getOwner().getClass().getName()) && !ps.wasInitialized() && !classes.contains(ps.getKey())) { |
|
106 |
System.out.print("--> AspectJCompile-Time Weaving " + ps.getRole()); |
|
107 |
classes.add(ps.getKey()); |
|
108 |
try { |
|
109 |
String role = ps.getRole(); |
|
110 |
String fieldName = role.substring(role.lastIndexOf(".") + 1); |
|
111 |
System.out.print(", field : " + fieldName); |
|
112 |
Object owner = ps.getOwner(); |
|
113 |
|
|
114 |
PersistentCollection col = commonService.initializeCollection(ps); |
|
115 |
ps.afterInitialize(); |
|
116 |
|
|
117 |
Class<?> clazz = ps.getClass(); |
|
118 |
if (clazz != null) { |
|
119 |
CollectionField cf = getCollectionField(col); |
|
120 |
Field field = clazz.getDeclaredField(cf.getFieldName()); |
|
121 |
field.setAccessible(true); |
|
122 |
field.set(ps, cf.getCollection()); |
|
123 |
} |
|
124 |
} catch (Exception ex) { |
|
125 |
ex.printStackTrace(); |
|
126 |
System.out.println("Error in ReattachSessionAspect : " + ex.getMessage()); |
|
127 |
} finally { |
|
128 |
classes.remove(ps.getKey()); |
|
129 |
System.out.println("....Done"); |
|
130 |
} |
|
131 |
} |
|
132 |
} |
|
133 |
return pjp.proceed(); |
|
134 |
|
|
135 |
} |
|
136 |
|
|
137 |
private CollectionField getCollectionField(PersistentCollection pc) { |
|
138 |
if(pc != null) { |
|
139 |
if(pc instanceof PersistentSet) { |
|
140 |
return new CollectionField(new HashSet((Set)pc), "set"); |
|
141 |
} |
|
142 |
if(pc instanceof PersistentSortedSet) { |
|
143 |
return new CollectionField(new TreeSet((Set)pc), "set"); |
|
144 |
} |
|
145 |
if(pc instanceof PersistentList) { |
|
146 |
return new CollectionField(new ArrayList((List)pc), "list"); |
|
147 |
} |
|
148 |
if(pc instanceof PersistentMap || pc instanceof PersistentMultiLanguageText) { |
|
149 |
return new CollectionField(new HashMap((Map)pc), "map"); |
|
150 |
} |
|
151 |
if(pc instanceof PersistentSortedMap) { |
|
152 |
return new CollectionField(new TreeMap((Map)pc), "map"); |
|
153 |
} |
|
154 |
} |
|
155 |
return null; |
|
156 |
} |
|
157 |
|
|
158 |
private String getCollectionFieldName(PersistentCollection pc) { |
|
159 |
if(pc != null) { |
|
160 |
if(pc instanceof PersistentSet || pc instanceof PersistentSortedSet) { |
|
161 |
return "set"; |
|
162 |
} |
|
163 |
|
|
164 |
if(pc instanceof PersistentList) { |
|
165 |
return "list"; |
|
166 |
} |
|
167 |
if(pc instanceof PersistentMap || pc instanceof PersistentMultiLanguageText) { |
|
168 |
return "map"; |
|
169 |
} |
|
170 |
} |
|
171 |
return null; |
|
172 |
} |
|
173 |
|
|
174 |
private class CollectionField { |
|
175 |
private Object col; |
|
176 |
private String fieldName; |
|
177 |
public CollectionField(Object col, String fieldName) { |
|
178 |
this.col = col; |
|
179 |
this.fieldName = fieldName; |
|
180 |
} |
|
181 |
|
|
182 |
public Object getCollection() { |
|
183 |
return this.col; |
|
184 |
} |
|
185 |
|
|
186 |
public String getFieldName() { |
|
187 |
return this.fieldName; |
|
188 |
} |
|
189 |
} |
|
190 |
|
|
191 |
} |
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/remote/api/application/CdmApplicationRemoteConfiguration.java | ||
---|---|---|
1 |
// $Id: CdmApplicationDefaultConfiguration.java 11680 2011-04-04 17:07:39Z a.mueller $ |
|
2 |
/** |
|
3 |
* Copyright (C) 2007 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
|
|
11 |
package eu.etaxonomy.cdm.remote.api.application; |
|
12 |
|
|
13 |
import org.apache.log4j.Logger; |
|
14 |
import org.springframework.context.ApplicationContextAware; |
|
15 |
import org.springframework.stereotype.Component; |
|
16 |
|
|
17 |
import eu.etaxonomy.cdm.api.application.CdmApplicationConfiguration; |
|
18 |
import eu.etaxonomy.cdm.api.application.CdmApplicationDefaultConfiguration; |
|
19 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
|
20 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolderMock; |
|
21 |
|
|
22 |
/** |
|
23 |
* @author a.mueller |
|
24 |
* @created 21.05.2008 |
|
25 |
* @version 1.0 |
|
26 |
*/ |
|
27 |
/** |
|
28 |
* @author a.mueller |
|
29 |
* @author j.koch |
|
30 |
*/ |
|
31 |
@Component |
|
32 |
public class CdmApplicationRemoteConfiguration extends CdmApplicationConfiguration implements ICdmApplicationRemoteConfiguration, ApplicationContextAware { |
|
33 |
|
|
34 |
@SuppressWarnings("unused") |
|
35 |
private static final Logger logger = Logger.getLogger(CdmApplicationRemoteConfiguration.class); |
|
36 |
|
|
37 |
public CdmApplicationRemoteConfiguration() { |
|
38 |
} |
|
39 |
|
|
40 |
@Override |
|
41 |
public ConversationHolder NewConversation() { |
|
42 |
// TODO Auto-generated method stub |
|
43 |
return new ConversationHolderMock(); |
|
44 |
} |
|
45 |
} |
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/remote/api/application/CdmApplicationRemoteController.java | ||
---|---|---|
1 |
// $Id: CdmApplicationController.java 11680 2011-04-04 17:07:39Z a.mueller $ |
|
2 |
/** |
|
3 |
* Copyright (C) 2007 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
|
|
11 |
|
|
12 |
package eu.etaxonomy.cdm.remote.api.application; |
|
13 |
|
|
14 |
import java.util.UUID; |
|
15 |
|
|
16 |
import org.apache.log4j.Logger; |
|
17 |
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; |
|
18 |
import org.springframework.context.support.AbstractApplicationContext; |
|
19 |
import org.springframework.context.support.GenericApplicationContext; |
|
20 |
import org.springframework.core.io.ClassPathResource; |
|
21 |
import org.springframework.core.io.Resource; |
|
22 |
import org.springframework.security.access.PermissionEvaluator; |
|
23 |
import org.springframework.security.authentication.ProviderManager; |
|
24 |
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; |
|
25 |
import org.springframework.security.core.Authentication; |
|
26 |
import org.springframework.security.core.context.SecurityContext; |
|
27 |
import org.springframework.security.core.context.SecurityContextHolder; |
|
28 |
import org.springframework.transaction.PlatformTransactionManager; |
|
29 |
//import org.springframework.transaction.PlatformTransactionManager; |
|
30 |
import org.springframework.transaction.TransactionStatus; |
|
31 |
|
|
32 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
|
33 |
import eu.etaxonomy.cdm.api.service.IAgentService; |
|
34 |
import eu.etaxonomy.cdm.api.service.IClassificationService; |
|
35 |
import eu.etaxonomy.cdm.api.service.ICollectionService; |
|
36 |
import eu.etaxonomy.cdm.api.service.ICommonService; |
|
37 |
import eu.etaxonomy.cdm.api.service.IDatabaseService; |
|
38 |
import eu.etaxonomy.cdm.api.service.IDescriptionService; |
|
39 |
import eu.etaxonomy.cdm.api.service.IFeatureNodeService; |
|
40 |
import eu.etaxonomy.cdm.api.service.IFeatureTreeService; |
|
41 |
import eu.etaxonomy.cdm.api.service.IGrantedAuthorityService; |
|
42 |
import eu.etaxonomy.cdm.api.service.IGroupService; |
|
43 |
import eu.etaxonomy.cdm.api.service.IIdentificationKeyService; |
|
44 |
import eu.etaxonomy.cdm.api.service.ILocationService; |
|
45 |
import eu.etaxonomy.cdm.api.service.IMediaService; |
|
46 |
import eu.etaxonomy.cdm.api.service.INameService; |
|
47 |
import eu.etaxonomy.cdm.api.service.IOccurrenceService; |
|
48 |
import eu.etaxonomy.cdm.api.service.IPolytomousKeyNodeService; |
|
49 |
import eu.etaxonomy.cdm.api.service.IPolytomousKeyService; |
|
50 |
import eu.etaxonomy.cdm.api.service.IReferenceService; |
|
51 |
import eu.etaxonomy.cdm.api.service.IService; |
|
52 |
import eu.etaxonomy.cdm.api.service.ITaxonNodeService; |
|
53 |
import eu.etaxonomy.cdm.api.service.ITaxonService; |
|
54 |
import eu.etaxonomy.cdm.api.service.ITermService; |
|
55 |
import eu.etaxonomy.cdm.api.service.IUserService; |
|
56 |
import eu.etaxonomy.cdm.api.service.IVocabularyService; |
|
57 |
import eu.etaxonomy.cdm.api.service.IWorkingSetService; |
|
58 |
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor; |
|
59 |
import eu.etaxonomy.cdm.common.monitor.NullProgressMonitor; |
|
60 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
61 |
import eu.etaxonomy.cdm.model.common.DefinedTermBase; |
|
62 |
import eu.etaxonomy.cdm.persistence.hibernate.permission.ICdmPermissionEvaluator; |
|
63 |
|
|
64 |
|
|
65 |
/** |
|
66 |
* @author a.mueller |
|
67 |
* @author j.koch |
|
68 |
* |
|
69 |
*/ |
|
70 |
public class CdmApplicationRemoteController implements ICdmApplicationRemoteConfiguration { |
|
71 |
private static final Logger logger = Logger.getLogger(CdmApplicationRemoteController.class); |
|
72 |
|
|
73 |
public static final String DEFAULT_APPLICATION_CONTEXT_RESOURCE = "/eu/etaxonomy/cdm/remotingApplicationContext.xml"; |
|
74 |
|
|
75 |
public AbstractApplicationContext applicationContext; |
|
76 |
private ICdmApplicationRemoteConfiguration configuration; |
|
77 |
private Resource applicationContextResource; |
|
78 |
private IProgressMonitor progressMonitor; |
|
79 |
|
|
80 |
/** |
|
81 |
* Constructor, opens a spring ApplicationContext with defaults |
|
82 |
*/ |
|
83 |
public static CdmApplicationRemoteController NewInstance() { |
|
84 |
logger.info("Configure CdmApplicationRemoteController with defaults"); |
|
85 |
return new CdmApplicationRemoteController(null, null); |
|
86 |
} |
|
87 |
|
|
88 |
/** |
|
89 |
* Constructor, opens a spring ApplicationContext with given application context |
|
90 |
* @param applicationContextResource |
|
91 |
*/ |
|
92 |
public static CdmApplicationRemoteController NewInstance(Resource applicationContextResource, IProgressMonitor progressMonitor) { |
|
93 |
logger.info("Configure CdmApplicationRemoteController with given application context"); |
|
94 |
return new CdmApplicationRemoteController(applicationContextResource, progressMonitor); |
|
95 |
} |
|
96 |
|
|
97 |
/** |
|
98 |
* Constructor, starts the application remote controller |
|
99 |
* @param applicationContextResource |
|
100 |
*/ |
|
101 |
private CdmApplicationRemoteController(Resource applicationContextResource, IProgressMonitor progressMonitor){ |
|
102 |
logger.info("Start CdmApplicationRemoteController"); |
|
103 |
this.applicationContextResource = applicationContextResource != null ? applicationContextResource : new ClassPathResource(DEFAULT_APPLICATION_CONTEXT_RESOURCE); |
|
104 |
this.progressMonitor = progressMonitor != null ? progressMonitor : new NullProgressMonitor(); |
|
105 |
setNewApplicationContext(); |
|
106 |
} |
|
107 |
|
|
108 |
/** |
|
109 |
* Sets the application context to a new spring ApplicationContext and initializes the Controller |
|
110 |
*/ |
|
111 |
private boolean setNewApplicationContext(){ |
|
112 |
logger.info("Set new application context"); |
|
113 |
progressMonitor.beginTask("Start application context.", 6); |
|
114 |
progressMonitor.worked(1); |
|
115 |
|
|
116 |
GenericApplicationContext applicationContext = new GenericApplicationContext(); |
|
117 |
|
|
118 |
XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(applicationContext); |
|
119 |
progressMonitor.subTask("Registering resources."); |
|
120 |
xmlReader.loadBeanDefinitions(applicationContextResource); |
|
121 |
progressMonitor.worked(1); |
|
122 |
|
|
123 |
progressMonitor.subTask("This might take a while ..."); |
|
124 |
applicationContext.refresh(); |
|
125 |
applicationContext.start(); |
|
126 |
progressMonitor.worked(1); |
|
127 |
|
|
128 |
progressMonitor.subTask("Cleaning up."); |
|
129 |
setApplicationContext(applicationContext); |
|
130 |
progressMonitor.done(); |
|
131 |
return true; |
|
132 |
} |
|
133 |
|
|
134 |
/** |
|
135 |
* Tests if some DefinedTermsAreMissing. |
|
136 |
* @return true, if at least one is missing, else false |
|
137 |
*/ |
|
138 |
public boolean testDefinedTermsAreMissing(){ |
|
139 |
UUID englishUuid = UUID.fromString("e9f8cdb7-6819-44e8-95d3-e2d0690c3523"); |
|
140 |
DefinedTermBase<?> english = this.getTermService().find(englishUuid); |
|
141 |
if ( english == null || ! english.getUuid().equals(englishUuid)){ |
|
142 |
return true; |
|
143 |
}else{ |
|
144 |
return false; |
|
145 |
} |
|
146 |
} |
|
147 |
|
|
148 |
/** |
|
149 |
* Sets a new application Context. |
|
150 |
* @param ac |
|
151 |
*/ |
|
152 |
public void setApplicationContext(AbstractApplicationContext ac){ |
|
153 |
closeApplicationContext(); //closes old application context if necessary |
|
154 |
applicationContext = ac; |
|
155 |
applicationContext.registerShutdownHook(); |
|
156 |
init(); |
|
157 |
} |
|
158 |
|
|
159 |
/* (non-Javadoc) |
|
160 |
* @see java.lang.Object#finalize() |
|
161 |
*/ |
|
162 |
public void finalize(){ |
|
163 |
close(); |
|
164 |
} |
|
165 |
|
|
166 |
/** |
|
167 |
* closes the application |
|
168 |
*/ |
|
169 |
public void close(){ |
|
170 |
closeApplicationContext(); |
|
171 |
} |
|
172 |
|
|
173 |
/** |
|
174 |
* closes the application context |
|
175 |
*/ |
|
176 |
private void closeApplicationContext(){ |
|
177 |
if (applicationContext != null){ |
|
178 |
logger.info("Close ApplicationContext"); |
|
179 |
applicationContext.close(); |
|
180 |
} |
|
181 |
} |
|
182 |
|
|
183 |
private void init(){ |
|
184 |
logger.info("Init " + this.getClass().getName() + " ... "); |
|
185 |
if (logger.isInfoEnabled()){for (String beanName : applicationContext.getBeanDefinitionNames()){ logger.debug(beanName);}} |
|
186 |
//TODO delete next row (was just for testing) |
|
187 |
if (logger.isInfoEnabled()){ |
|
188 |
logger.info("Registered Beans: "); |
|
189 |
String[] beanNames = applicationContext.getBeanDefinitionNames(); |
|
190 |
for (String beanName : beanNames){ |
|
191 |
logger.info(beanName); |
|
192 |
} |
|
193 |
} |
|
194 |
configuration = new CdmApplicationRemoteConfiguration(); |
|
195 |
} |
|
196 |
|
|
197 |
|
|
198 |
|
|
199 |
/* ****** Services *********/ |
|
200 |
|
|
201 |
public final INameService getNameService(){ |
|
202 |
return configuration.getNameService(); |
|
203 |
} |
|
204 |
|
|
205 |
public final ITaxonService getTaxonService(){ |
|
206 |
return configuration.getTaxonService(); |
|
207 |
} |
|
208 |
|
|
209 |
public final IClassificationService getClassificationService(){ |
|
210 |
return configuration.getClassificationService(); |
|
211 |
} |
|
212 |
|
|
213 |
public final ITaxonNodeService getTaxonNodeService(){ |
|
214 |
return configuration.getTaxonNodeService(); |
|
215 |
} |
|
216 |
|
|
217 |
public final IReferenceService getReferenceService(){ |
|
218 |
return configuration.getReferenceService(); |
|
219 |
} |
|
220 |
|
|
221 |
public final IAgentService getAgentService(){ |
|
222 |
return configuration.getAgentService(); |
|
223 |
} |
|
224 |
|
|
225 |
public final ITermService getTermService(){ |
|
226 |
return configuration.getTermService(); |
|
227 |
} |
|
228 |
|
|
229 |
public final IDescriptionService getDescriptionService(){ |
|
230 |
return configuration.getDescriptionService(); |
|
231 |
} |
|
232 |
|
|
233 |
public final IOccurrenceService getOccurrenceService(){ |
|
234 |
return configuration.getOccurrenceService(); |
|
235 |
} |
|
236 |
|
|
237 |
public final IMediaService getMediaService(){ |
|
238 |
return configuration.getMediaService(); |
|
239 |
} |
|
240 |
|
|
241 |
public final ICommonService getCommonService(){ |
|
242 |
return configuration.getCommonService(); |
|
243 |
} |
|
244 |
|
|
245 |
public final ILocationService getLocationService(){ |
|
246 |
return configuration.getLocationService(); |
|
247 |
} |
|
248 |
|
|
249 |
public final IUserService getUserService(){ |
|
250 |
return configuration.getUserService(); |
|
251 |
} |
|
252 |
|
|
253 |
public IGroupService getGroupService() { |
|
254 |
return configuration.getGroupService(); |
|
255 |
} |
|
256 |
|
|
257 |
public final ICollectionService getCollectionService(){ |
|
258 |
return configuration.getCollectionService(); |
|
259 |
} |
|
260 |
|
|
261 |
public final IFeatureTreeService getFeatureTreeService(){ |
|
262 |
return configuration.getFeatureTreeService(); |
|
263 |
} |
|
264 |
|
|
265 |
public final IFeatureNodeService getFeatureNodeService(){ |
|
266 |
return configuration.getFeatureNodeService(); |
|
267 |
} |
|
268 |
|
|
269 |
public final IVocabularyService getVocabularyService(){ |
|
270 |
return configuration.getVocabularyService(); |
|
271 |
} |
|
272 |
|
|
273 |
public final IIdentificationKeyService getIdentificationKeyService(){ |
|
274 |
return configuration.getIdentificationKeyService(); |
|
275 |
} |
|
276 |
|
|
277 |
public final IPolytomousKeyService getPolytomousKeyService(){ |
|
278 |
return configuration.getPolytomousKeyService(); |
|
279 |
} |
|
280 |
|
|
281 |
public final IPolytomousKeyNodeService getPolytomousKeyNodeService(){ |
|
282 |
return configuration.getPolytomousKeyNodeService(); |
|
283 |
} |
|
284 |
|
|
285 |
public final IService<CdmBase> getMainService(){ |
|
286 |
return configuration.getMainService(); |
|
287 |
} |
|
288 |
|
|
289 |
public final IWorkingSetService getWorkingSetService(){ |
|
290 |
return configuration.getWorkingSetService(); |
|
291 |
} |
|
292 |
|
|
293 |
|
|
294 |
@Override |
|
295 |
public ProviderManager getAuthenticationManager() { |
|
296 |
return configuration.getAuthenticationManager(); |
|
297 |
} |
|
298 |
|
|
299 |
|
|
300 |
|
|
301 |
@Override |
|
302 |
public ConversationHolder NewConversation() { |
|
303 |
return configuration.NewConversation(); |
|
304 |
} |
|
305 |
|
|
306 |
@Override |
|
307 |
public Object getBean(String name) { |
|
308 |
return configuration.getBean(name); |
|
309 |
} |
|
310 |
|
|
311 |
@Override |
|
312 |
public IGrantedAuthorityService getGrantedAuthorityService() { |
|
313 |
return configuration.getGrantedAuthorityService(); |
|
314 |
} |
|
315 |
|
|
316 |
@Override |
|
317 |
public ICdmPermissionEvaluator getPermissionEvaluator() { |
|
318 |
return configuration.getPermissionEvaluator(); |
|
319 |
} |
|
320 |
|
|
321 |
@Override |
|
322 |
public void authenticate(String username, String password) { |
|
323 |
configuration.authenticate(username, password); |
|
324 |
|
|
325 |
} |
|
326 |
|
|
327 |
|
|
328 |
} |
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/remote/api/application/ICdmApplicationRemoteConfiguration.java | ||
---|---|---|
1 |
package eu.etaxonomy.cdm.remote.api.application; |
|
2 |
|
|
3 |
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration; |
|
4 |
|
|
5 |
|
|
6 |
public interface ICdmApplicationRemoteConfiguration extends ICdmApplicationConfiguration { |
|
7 |
|
|
8 |
|
|
9 |
} |
eu.etaxonomy.taxeditor.cdmlib/src/main/java/org/hibernate/collection/internal/AbstractPersistentCollection.java | ||
---|---|---|
1 |
|
|
2 |
|
|
3 |
/* |
|
4 |
* Hibernate, Relational Persistence for Idiomatic Java |
|
5 |
* |
|
6 |
* Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as |
|
7 |
* indicated by the @author tags or express copyright attribution |
|
8 |
* statements applied by the authors. All third-party contributions are |
|
9 |
* distributed under license by Red Hat Inc. |
|
10 |
* |
|
11 |
* This copyrighted material is made available to anyone wishing to use, modify, |
|
12 |
* copy, or redistribute it subject to the terms and conditions of the GNU |
|
13 |
* Lesser General Public License, as published by the Free Software Foundation. |
|
14 |
* |
|
15 |
* This program is distributed in the hope that it will be useful, |
|
16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
|
17 |
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License |
|
18 |
* for more details. |
|
19 |
* |
|
20 |
* You should have received a copy of the GNU Lesser General Public License |
|
21 |
* along with this distribution; if not, write to: |
|
22 |
* Free Software Foundation, Inc. |
|
23 |
* 51 Franklin Street, Fifth Floor |
|
24 |
* Boston, MA 02110-1301 USA |
|
25 |
*/ |
|
26 |
package org.hibernate.collection.internal; |
|
27 |
|
|
28 |
import java.io.Serializable; |
|
29 |
import java.util.ArrayList; |
|
30 |
import java.util.Collection; |
|
31 |
import java.util.Collections; |
|
32 |
import java.util.HashSet; |
|
33 |
import java.util.Iterator; |
|
34 |
import java.util.List; |
|
35 |
import java.util.ListIterator; |
|
36 |
|
|
37 |
import javax.naming.NamingException; |
|
38 |
|
|
39 |
import org.hibernate.AssertionFailure; |
|
40 |
import org.hibernate.HibernateException; |
|
41 |
import org.hibernate.LazyInitializationException; |
|
42 |
import org.hibernate.Session; |
|
43 |
import org.hibernate.collection.spi.PersistentCollection; |
|
44 |
import org.hibernate.engine.internal.ForeignKeys; |
|
45 |
import org.hibernate.engine.spi.CollectionEntry; |
|
46 |
import org.hibernate.engine.spi.EntityEntry; |
|
47 |
import org.hibernate.engine.spi.SessionFactoryImplementor; |
|
48 |
import org.hibernate.engine.spi.SessionImplementor; |
|
49 |
import org.hibernate.engine.spi.Status; |
|
50 |
import org.hibernate.engine.spi.TypedValue; |
|
51 |
import org.hibernate.internal.SessionFactoryRegistry; |
|
52 |
import org.hibernate.internal.util.MarkerObject; |
|
53 |
import org.hibernate.internal.util.collections.EmptyIterator; |
|
54 |
import org.hibernate.internal.util.collections.IdentitySet; |
|
55 |
import org.hibernate.persister.collection.CollectionPersister; |
|
56 |
import org.hibernate.persister.entity.EntityPersister; |
|
57 |
import org.hibernate.pretty.MessageHelper; |
|
58 |
import org.hibernate.type.Type; |
|
59 |
import org.jboss.logging.Logger; |
|
60 |
|
|
61 |
/** |
|
62 |
* Base class implementing {@link org.hibernate.collection.spi.PersistentCollection} |
|
63 |
* |
|
64 |
* @author Gavin King |
|
65 |
*/ |
|
66 |
public abstract class AbstractPersistentCollection implements Serializable, PersistentCollection { |
|
67 |
private static final Logger log = Logger.getLogger( AbstractPersistentCollection.class ); |
|
68 |
|
|
69 |
private static final long serialVersionUID = -7238232378593030571L; |
|
70 |
|
|
71 |
private transient SessionImplementor session; |
|
72 |
private boolean initialized; |
|
73 |
private transient List<DelayedOperation> operationQueue; |
|
74 |
private transient boolean directlyAccessible; |
|
75 |
private transient boolean initializing; |
|
76 |
private Object owner; |
|
77 |
private int cachedSize = -1; |
|
78 |
|
|
79 |
private String role; |
|
80 |
private Serializable key; |
|
81 |
// collections detect changes made via their public interface and mark |
|
82 |
// themselves as dirty as a performance optimization |
|
83 |
private boolean dirty; |
|
84 |
private Serializable storedSnapshot; |
|
85 |
|
|
86 |
private String sessionFactoryUuid; |
|
87 |
private boolean specjLazyLoad = false; |
|
88 |
|
|
89 |
public final String getRole() { |
|
90 |
return role; |
|
91 |
} |
|
92 |
|
|
93 |
public final Serializable getKey() { |
|
94 |
return key; |
|
95 |
} |
|
96 |
|
|
97 |
public final boolean isUnreferenced() { |
|
98 |
return role == null; |
|
99 |
} |
|
100 |
|
|
101 |
public final boolean isDirty() { |
|
102 |
return dirty; |
|
103 |
} |
|
104 |
|
|
105 |
public final void clearDirty() { |
|
106 |
dirty = false; |
|
107 |
} |
|
108 |
|
|
109 |
public final void dirty() { |
|
110 |
dirty = true; |
|
111 |
} |
|
112 |
|
|
113 |
public final Serializable getStoredSnapshot() { |
|
114 |
return storedSnapshot; |
|
115 |
} |
|
116 |
|
|
117 |
//Careful: these methods do not initialize the collection. |
|
118 |
|
|
119 |
/** |
|
120 |
* Is the initialized collection empty? |
|
121 |
*/ |
|
122 |
public abstract boolean empty(); |
|
123 |
|
|
124 |
/** |
|
125 |
* Called by any read-only method of the collection interface |
|
126 |
*/ |
|
127 |
protected final void read() { |
|
128 |
initialize( false ); |
|
129 |
} |
|
130 |
|
|
131 |
/** |
|
132 |
* Called by the {@link Collection#size} method |
|
133 |
*/ |
|
134 |
@SuppressWarnings({"JavaDoc"}) |
|
135 |
protected boolean readSize() { |
|
136 |
if ( !initialized ) { |
|
137 |
if ( cachedSize != -1 && !hasQueuedOperations() ) { |
|
138 |
return true; |
|
139 |
} |
|
140 |
else { |
|
141 |
boolean isExtraLazy = withTemporarySessionIfNeeded( |
|
142 |
new LazyInitializationWork<Boolean>() { |
|
143 |
@Override |
|
144 |
public Boolean doWork() { |
|
145 |
CollectionEntry entry = session.getPersistenceContext().getCollectionEntry( AbstractPersistentCollection.this ); |
|
146 |
|
|
147 |
if ( entry != null ) { |
|
148 |
CollectionPersister persister = entry.getLoadedPersister(); |
|
149 |
if ( persister.isExtraLazy() ) { |
|
150 |
if ( hasQueuedOperations() ) { |
|
151 |
session.flush(); |
|
152 |
} |
|
153 |
cachedSize = persister.getSize( entry.getLoadedKey(), session ); |
|
154 |
return true; |
|
155 |
} |
|
156 |
else { |
|
157 |
read(); |
|
158 |
} |
|
159 |
} |
|
160 |
else{ |
|
161 |
throwLazyInitializationExceptionIfNotConnected(); |
|
162 |
} |
|
163 |
return false; |
|
164 |
} |
|
165 |
} |
|
166 |
); |
|
167 |
if ( isExtraLazy ) { |
|
168 |
return true; |
|
169 |
} |
|
170 |
} |
|
171 |
} |
|
172 |
return false; |
|
173 |
} |
|
174 |
|
|
175 |
public static interface LazyInitializationWork<T> { |
|
176 |
public T doWork(); |
|
177 |
} |
|
178 |
|
|
179 |
private <T> T withTemporarySessionIfNeeded(LazyInitializationWork<T> lazyInitializationWork) { |
|
180 |
SessionImplementor originalSession = null; |
|
181 |
boolean isTempSession = false; |
|
182 |
boolean isJTA = false; |
|
183 |
|
|
184 |
if ( session == null ) { |
|
185 |
if ( specjLazyLoad ) { |
|
186 |
session = openTemporarySessionForLoading(); |
|
187 |
isTempSession = true; |
|
188 |
} |
|
189 |
else { |
|
190 |
throwLazyInitializationException( "could not initialize proxy - no Session" ); |
|
191 |
} |
|
192 |
} |
|
193 |
else if ( !session.isOpen() ) { |
|
194 |
if ( specjLazyLoad ) { |
|
195 |
originalSession = session; |
|
196 |
session = openTemporarySessionForLoading(); |
|
197 |
isTempSession = true; |
|
198 |
} |
|
199 |
else { |
|
200 |
throwLazyInitializationException( "could not initialize proxy - the owning Session was closed" ); |
|
201 |
} |
|
202 |
} |
|
203 |
else if ( !session.isConnected() ) { |
|
204 |
if ( specjLazyLoad ) { |
|
205 |
originalSession = session; |
|
206 |
session = openTemporarySessionForLoading(); |
|
207 |
isTempSession = true; |
|
208 |
} |
|
209 |
else { |
|
210 |
throwLazyInitializationException( "could not initialize proxy - the owning Session is disconnected" ); |
|
211 |
} |
|
212 |
} |
|
213 |
|
|
214 |
if ( isTempSession ) { |
|
215 |
// TODO: On the next major release, add an |
|
216 |
// 'isJTA' or 'getTransactionFactory' method to Session. |
|
217 |
isJTA = session.getTransactionCoordinator() |
|
218 |
.getTransactionContext().getTransactionEnvironment() |
|
219 |
.getTransactionFactory() |
|
220 |
.compatibleWithJtaSynchronization(); |
|
221 |
|
|
222 |
if ( !isJTA ) { |
|
223 |
// Explicitly handle the transactions only if we're not in |
|
224 |
// a JTA environment. A lazy loading temporary session can |
|
225 |
// be created even if a current session and transaction are |
|
226 |
// open (ex: session.clear() was used). We must prevent |
|
227 |
// multiple transactions. |
|
228 |
( ( Session) session ).beginTransaction(); |
|
229 |
} |
|
230 |
|
|
231 |
session.getPersistenceContext().addUninitializedDetachedCollection( |
|
232 |
session.getFactory().getCollectionPersister( getRole() ), |
|
233 |
this |
|
234 |
); |
|
235 |
} |
|
236 |
|
|
237 |
try { |
|
238 |
return lazyInitializationWork.doWork(); |
|
239 |
} |
|
240 |
finally { |
|
241 |
if ( isTempSession ) { |
|
242 |
// make sure the just opened temp session gets closed! |
|
243 |
try { |
|
244 |
if ( !isJTA ) { |
|
245 |
( ( Session) session ).getTransaction().commit(); |
|
246 |
} |
|
247 |
( (Session) session ).close(); |
|
248 |
} |
|
249 |
catch (Exception e) { |
|
250 |
log.warn( "Unable to close temporary session used to load lazy collection associated to no session" ); |
|
251 |
} |
|
252 |
session = originalSession; |
|
253 |
} |
|
254 |
} |
|
255 |
} |
|
256 |
|
|
257 |
private SessionImplementor openTemporarySessionForLoading() { |
|
258 |
if ( sessionFactoryUuid == null ) { |
|
259 |
throwLazyInitializationException( "SessionFactory UUID not known to create temporary Session for loading" ); |
|
260 |
} |
|
261 |
|
|
262 |
SessionFactoryImplementor sf = (SessionFactoryImplementor) |
|
263 |
SessionFactoryRegistry.INSTANCE.getSessionFactory( sessionFactoryUuid ); |
|
264 |
return (SessionImplementor) sf.openSession(); |
|
265 |
} |
|
266 |
|
|
267 |
protected Boolean readIndexExistence(final Object index) { |
|
268 |
if ( !initialized ) { |
|
269 |
Boolean extraLazyExistenceCheck = withTemporarySessionIfNeeded( |
|
270 |
new LazyInitializationWork<Boolean>() { |
|
271 |
@Override |
|
272 |
public Boolean doWork() { |
|
273 |
CollectionEntry entry = session.getPersistenceContext().getCollectionEntry( AbstractPersistentCollection.this ); |
|
274 |
CollectionPersister persister = entry.getLoadedPersister(); |
|
275 |
if ( persister.isExtraLazy() ) { |
|
276 |
if ( hasQueuedOperations() ) { |
|
277 |
session.flush(); |
|
278 |
} |
|
279 |
return persister.indexExists( entry.getLoadedKey(), index, session ); |
|
280 |
} |
|
281 |
else { |
|
282 |
read(); |
|
283 |
} |
|
284 |
return null; |
|
285 |
} |
|
286 |
} |
|
287 |
); |
|
288 |
if ( extraLazyExistenceCheck != null ) { |
|
289 |
return extraLazyExistenceCheck; |
|
290 |
} |
|
291 |
} |
|
292 |
return null; |
|
293 |
} |
|
294 |
|
|
295 |
protected Boolean readElementExistence(final Object element) { |
|
296 |
if ( !initialized ) { |
|
297 |
Boolean extraLazyExistenceCheck = withTemporarySessionIfNeeded( |
|
298 |
new LazyInitializationWork<Boolean>() { |
|
299 |
@Override |
|
300 |
public Boolean doWork() { |
|
301 |
CollectionEntry entry = session.getPersistenceContext().getCollectionEntry( AbstractPersistentCollection.this ); |
|
302 |
CollectionPersister persister = entry.getLoadedPersister(); |
|
303 |
if ( persister.isExtraLazy() ) { |
|
304 |
if ( hasQueuedOperations() ) { |
|
305 |
session.flush(); |
|
306 |
} |
|
307 |
return persister.elementExists( entry.getLoadedKey(), element, session ); |
|
308 |
} |
|
309 |
else { |
|
310 |
read(); |
|
311 |
} |
|
312 |
return null; |
|
313 |
} |
|
314 |
} |
|
315 |
); |
|
316 |
if ( extraLazyExistenceCheck != null ) { |
|
317 |
return extraLazyExistenceCheck; |
|
318 |
} |
|
319 |
} |
|
320 |
return null; |
|
321 |
} |
|
322 |
|
|
323 |
protected static final Object UNKNOWN = new MarkerObject( "UNKNOWN" ); |
|
324 |
|
|
325 |
protected Object readElementByIndex(final Object index) { |
|
326 |
if ( !initialized ) { |
|
327 |
class ExtraLazyElementByIndexReader implements LazyInitializationWork { |
|
328 |
private boolean isExtraLazy; |
|
329 |
private Object element; |
|
330 |
|
|
331 |
@Override |
|
332 |
public Object doWork() { |
|
333 |
CollectionEntry entry = session.getPersistenceContext().getCollectionEntry( AbstractPersistentCollection.this ); |
|
334 |
CollectionPersister persister = entry.getLoadedPersister(); |
|
335 |
isExtraLazy = persister.isExtraLazy(); |
|
336 |
if ( isExtraLazy ) { |
|
337 |
if ( hasQueuedOperations() ) { |
|
338 |
session.flush(); |
|
339 |
} |
|
340 |
element = persister.getElementByIndex( entry.getLoadedKey(), index, session, owner ); |
|
341 |
} |
|
342 |
else { |
|
343 |
read(); |
|
344 |
} |
|
345 |
return null; |
|
346 |
} |
|
347 |
} |
|
348 |
|
|
349 |
ExtraLazyElementByIndexReader reader = new ExtraLazyElementByIndexReader(); |
|
350 |
//noinspection unchecked |
|
351 |
withTemporarySessionIfNeeded( reader ); |
|
352 |
if ( reader.isExtraLazy ) { |
|
353 |
return reader.element; |
|
354 |
} |
|
355 |
} |
|
356 |
return UNKNOWN; |
|
357 |
|
|
358 |
} |
|
359 |
|
|
360 |
protected int getCachedSize() { |
|
361 |
return cachedSize; |
|
362 |
} |
|
363 |
|
|
364 |
private boolean isConnectedToSession() { |
|
365 |
return session != null && |
|
366 |
session.isOpen() && |
|
367 |
session.getPersistenceContext().containsCollection( this ); |
|
368 |
} |
|
369 |
|
|
370 |
/** |
|
371 |
* Called by any writer method of the collection interface |
|
372 |
*/ |
|
373 |
protected final void write() { |
|
374 |
initialize( true ); |
|
375 |
dirty(); |
|
376 |
} |
|
377 |
|
|
378 |
/** |
|
379 |
* Is this collection in a state that would allow us to |
|
380 |
* "queue" operations? |
|
381 |
*/ |
|
382 |
@SuppressWarnings({"JavaDoc"}) |
|
383 |
protected boolean isOperationQueueEnabled() { |
|
384 |
return !initialized && |
|
385 |
isConnectedToSession() && |
|
386 |
isInverseCollection(); |
|
387 |
} |
|
388 |
|
|
389 |
/** |
|
390 |
* Is this collection in a state that would allow us to |
|
391 |
* "queue" puts? This is a special case, because of orphan |
|
392 |
* delete. |
|
393 |
*/ |
|
394 |
@SuppressWarnings({"JavaDoc"}) |
|
395 |
protected boolean isPutQueueEnabled() { |
|
396 |
return !initialized && |
|
397 |
isConnectedToSession() && |
|
398 |
isInverseOneToManyOrNoOrphanDelete(); |
|
399 |
} |
|
400 |
|
|
401 |
/** |
|
402 |
* Is this collection in a state that would allow us to |
|
403 |
* "queue" clear? This is a special case, because of orphan |
|
404 |
* delete. |
|
405 |
*/ |
|
406 |
@SuppressWarnings({"JavaDoc"}) |
|
407 |
protected boolean isClearQueueEnabled() { |
|
408 |
return !initialized && |
|
409 |
isConnectedToSession() && |
|
410 |
isInverseCollectionNoOrphanDelete(); |
|
411 |
} |
|
412 |
|
|
413 |
/** |
|
414 |
* Is this the "inverse" end of a bidirectional association? |
|
415 |
*/ |
|
416 |
@SuppressWarnings({"JavaDoc"}) |
|
417 |
private boolean isInverseCollection() { |
|
418 |
CollectionEntry ce = session.getPersistenceContext().getCollectionEntry( this ); |
|
419 |
return ce != null && ce.getLoadedPersister().isInverse(); |
|
420 |
} |
|
421 |
|
|
422 |
/** |
|
423 |
* Is this the "inverse" end of a bidirectional association with |
|
424 |
* no orphan delete enabled? |
|
425 |
*/ |
|
426 |
@SuppressWarnings({"JavaDoc"}) |
|
427 |
private boolean isInverseCollectionNoOrphanDelete() { |
|
428 |
CollectionEntry ce = session.getPersistenceContext().getCollectionEntry( this ); |
|
429 |
return ce != null && |
|
430 |
ce.getLoadedPersister().isInverse() && |
|
431 |
!ce.getLoadedPersister().hasOrphanDelete(); |
|
432 |
} |
|
433 |
|
|
434 |
/** |
|
435 |
* Is this the "inverse" end of a bidirectional one-to-many, or |
|
436 |
* of a collection with no orphan delete? |
|
437 |
*/ |
|
438 |
@SuppressWarnings({"JavaDoc"}) |
|
439 |
private boolean isInverseOneToManyOrNoOrphanDelete() { |
|
440 |
CollectionEntry ce = session.getPersistenceContext().getCollectionEntry( this ); |
|
441 |
return ce != null && ce.getLoadedPersister().isInverse() && ( |
|
442 |
ce.getLoadedPersister().isOneToMany() || |
|
443 |
!ce.getLoadedPersister().hasOrphanDelete() |
|
444 |
); |
|
445 |
} |
|
446 |
|
|
447 |
/** |
|
448 |
* Queue an addition |
|
449 |
*/ |
|
450 |
@SuppressWarnings({"JavaDoc"}) |
|
451 |
protected final void queueOperation(DelayedOperation operation) { |
|
452 |
if ( operationQueue == null ) { |
|
453 |
operationQueue = new ArrayList<DelayedOperation>( 10 ); |
|
454 |
} |
|
455 |
operationQueue.add( operation ); |
|
456 |
dirty = true; //needed so that we remove this collection from the second-level cache |
|
457 |
} |
|
458 |
|
|
459 |
/** |
|
460 |
* After reading all existing elements from the database, |
|
461 |
* add the queued elements to the underlying collection. |
|
462 |
*/ |
|
463 |
protected final void performQueuedOperations() { |
|
464 |
for ( DelayedOperation operation : operationQueue ) { |
|
465 |
operation.operate(); |
|
466 |
} |
|
467 |
} |
|
468 |
|
|
469 |
/** |
|
470 |
* After flushing, re-init snapshot state. |
|
471 |
*/ |
|
472 |
public void setSnapshot(Serializable key, String role, Serializable snapshot) { |
|
473 |
this.key = key; |
|
474 |
this.role = role; |
|
475 |
this.storedSnapshot = snapshot; |
|
476 |
} |
|
477 |
|
|
478 |
/** |
|
479 |
* After flushing, clear any "queued" additions, since the |
|
480 |
* database state is now synchronized with the memory state. |
|
481 |
*/ |
|
482 |
public void postAction() { |
|
483 |
operationQueue = null; |
|
484 |
cachedSize = -1; |
|
485 |
clearDirty(); |
|
486 |
} |
|
487 |
|
|
488 |
/** |
|
489 |
* Not called by Hibernate, but used by non-JDK serialization, |
|
490 |
* eg. SOAP libraries. |
|
491 |
*/ |
|
492 |
public AbstractPersistentCollection() { |
|
493 |
} |
|
494 |
|
|
495 |
protected AbstractPersistentCollection(SessionImplementor session) { |
|
496 |
this.session = session; |
|
497 |
} |
|
498 |
|
|
499 |
/** |
|
500 |
* return the user-visible collection (or array) instance |
|
501 |
*/ |
|
502 |
public Object getValue() { |
|
503 |
return this; |
|
504 |
} |
|
505 |
|
|
506 |
/** |
|
507 |
* Called just before reading any rows from the JDBC result set |
|
508 |
*/ |
|
509 |
public void beginRead() { |
|
510 |
// override on some subclasses |
|
511 |
initializing = true; |
|
512 |
} |
|
513 |
|
|
514 |
/** |
|
515 |
* Called after reading all rows from the JDBC result set |
|
516 |
*/ |
|
517 |
public boolean endRead() { |
|
518 |
//override on some subclasses |
|
519 |
return afterInitialize(); |
|
520 |
} |
|
521 |
|
|
522 |
public boolean afterInitialize() { |
|
523 |
setInitialized(); |
|
524 |
//do this bit after setting initialized to true or it will recurse |
|
525 |
if ( operationQueue != null ) { |
|
526 |
performQueuedOperations(); |
|
527 |
operationQueue = null; |
|
528 |
cachedSize = -1; |
|
529 |
return false; |
|
530 |
} |
|
531 |
else { |
|
532 |
return true; |
|
533 |
} |
|
534 |
} |
|
535 |
|
|
536 |
/** |
|
537 |
* Initialize the collection, if possible, wrapping any exceptions |
|
538 |
* in a runtime exception |
|
539 |
* |
|
540 |
* @param writing currently obsolete |
|
541 |
* |
|
542 |
* @throws LazyInitializationException if we cannot initialize |
|
543 |
*/ |
|
544 |
protected final void initialize(final boolean writing) { |
|
545 |
if ( initialized ) { |
|
546 |
return; |
|
547 |
} |
|
548 |
|
|
549 |
withTemporarySessionIfNeeded( |
|
550 |
new LazyInitializationWork<Object>() { |
|
551 |
@Override |
|
552 |
public Object doWork() { |
|
553 |
session.initializeCollection( AbstractPersistentCollection.this, writing ); |
|
554 |
return null; |
|
555 |
} |
|
556 |
} |
|
557 |
); |
|
558 |
} |
|
559 |
|
|
560 |
private void throwLazyInitializationExceptionIfNotConnected() { |
|
561 |
if ( !isConnectedToSession() ) { |
|
562 |
throwLazyInitializationException( "no session or session was closed" ); |
|
563 |
} |
|
564 |
if ( !session.isConnected() ) { |
|
565 |
throwLazyInitializationException( "session is disconnected" ); |
|
566 |
} |
|
567 |
} |
|
568 |
|
|
569 |
private void throwLazyInitializationException(String message) { |
|
570 |
throw new LazyInitializationException( |
|
571 |
"failed to lazily initialize a collection" + |
|
572 |
(role == null ? "" : " of role: " + role) + |
|
573 |
", " + message |
|
574 |
); |
|
575 |
} |
|
576 |
|
|
577 |
protected final void setInitialized() { |
|
578 |
this.initializing = false; |
|
579 |
this.initialized = true; |
|
580 |
} |
|
581 |
|
|
582 |
protected final void setDirectlyAccessible(boolean directlyAccessible) { |
|
583 |
this.directlyAccessible = directlyAccessible; |
|
584 |
} |
|
585 |
|
|
586 |
/** |
|
587 |
* Could the application possibly have a direct reference to |
|
588 |
* the underlying collection implementation? |
|
589 |
*/ |
|
590 |
public boolean isDirectlyAccessible() { |
|
591 |
return directlyAccessible; |
|
592 |
} |
|
593 |
|
|
594 |
/** |
|
595 |
* Disassociate this collection from the given session. |
|
596 |
* |
|
597 |
* @return true if this was currently associated with the given session |
|
598 |
*/ |
|
599 |
public final boolean unsetSession(SessionImplementor currentSession) { |
|
600 |
prepareForPossibleSpecialSpecjInitialization(); |
|
601 |
if ( currentSession == this.session ) { |
|
602 |
this.session = null; |
|
603 |
return true; |
|
604 |
} |
|
605 |
else { |
|
606 |
return false; |
|
607 |
} |
|
608 |
} |
|
609 |
|
|
610 |
protected void prepareForPossibleSpecialSpecjInitialization() { |
|
611 |
if ( session != null ) { |
|
612 |
specjLazyLoad = session.getFactory().getSettings().isInitializeLazyStateOutsideTransactionsEnabled(); |
|
613 |
|
|
614 |
if ( specjLazyLoad && sessionFactoryUuid == null ) { |
|
615 |
try { |
|
616 |
sessionFactoryUuid = (String) session.getFactory().getReference().get( "uuid" ).getContent(); |
|
617 |
} |
|
618 |
catch (NamingException e) { |
|
619 |
//not much we can do if this fails... |
|
620 |
} |
|
621 |
} |
|
622 |
} |
|
623 |
} |
|
624 |
|
|
625 |
|
|
626 |
/** |
|
627 |
* Associate the collection with the given session. |
|
628 |
* |
|
629 |
* @return false if the collection was already associated with the session |
|
630 |
* |
|
631 |
* @throws HibernateException if the collection was already associated |
|
632 |
* with another open session |
|
633 |
*/ |
|
634 |
public final boolean setCurrentSession(SessionImplementor session) throws HibernateException { |
|
635 |
if ( session == this.session ) { |
|
636 |
return false; |
|
637 |
} |
|
638 |
else { |
|
639 |
if ( isConnectedToSession() ) { |
|
640 |
CollectionEntry ce = session.getPersistenceContext().getCollectionEntry( this ); |
|
641 |
if ( ce == null ) { |
|
642 |
throw new HibernateException( |
|
643 |
"Illegal attempt to associate a collection with two open sessions" |
|
644 |
); |
|
645 |
} |
|
646 |
else { |
|
647 |
throw new HibernateException( |
|
648 |
"Illegal attempt to associate a collection with two open sessions: " + |
|
649 |
MessageHelper.collectionInfoString( |
|
650 |
ce.getLoadedPersister(), this, |
|
651 |
ce.getLoadedKey(), session |
|
652 |
) |
|
653 |
); |
|
654 |
} |
|
655 |
} |
|
656 |
else { |
|
657 |
this.session = session; |
|
658 |
return true; |
|
659 |
} |
|
660 |
} |
|
661 |
} |
|
662 |
|
|
663 |
/** |
|
664 |
* Do we need to completely recreate this collection when it changes? |
|
665 |
*/ |
|
666 |
public boolean needsRecreate(CollectionPersister persister) { |
|
667 |
return false; |
|
668 |
} |
|
669 |
|
|
670 |
/** |
|
671 |
* To be called internally by the session, forcing |
|
672 |
* immediate initialization. |
|
673 |
*/ |
|
674 |
public final void forceInitialization() throws HibernateException { |
|
675 |
if ( !initialized ) { |
|
676 |
if ( initializing ) { |
|
677 |
throw new AssertionFailure( "force initialize loading collection" ); |
|
678 |
} |
|
679 |
if ( session == null ) { |
|
680 |
throw new HibernateException( "collection is not associated with any session" ); |
|
681 |
} |
|
682 |
if ( !session.isConnected() ) { |
|
683 |
throw new HibernateException( "disconnected session" ); |
|
684 |
} |
|
685 |
session.initializeCollection( this, false ); |
|
686 |
} |
|
687 |
} |
|
688 |
|
|
689 |
|
|
690 |
/** |
|
691 |
* Get the current snapshot from the session |
|
692 |
*/ |
|
693 |
@SuppressWarnings({"JavaDoc"}) |
|
694 |
protected final Serializable getSnapshot() { |
|
695 |
return session.getPersistenceContext().getSnapshot( this ); |
|
696 |
} |
|
697 |
|
|
698 |
/** |
|
699 |
* Is this instance initialized? |
|
700 |
*/ |
|
701 |
public final boolean wasInitialized() { |
|
702 |
return initialized; |
|
703 |
} |
|
704 |
|
|
705 |
public boolean isRowUpdatePossible() { |
|
706 |
return true; |
|
707 |
} |
|
708 |
|
|
709 |
/** |
|
710 |
* Does this instance have any "queued" additions? |
|
711 |
*/ |
Also available in: Unified diff
erging from remoting-1.0 branch