1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2009 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
|
package eu.etaxonomy.cdm.persistence.dao.hibernate;
|
11
|
|
12
|
import org.apache.log4j.Logger;
|
13
|
import org.hibernate.HibernateException;
|
14
|
import org.hibernate.collection.PersistentCollection;
|
15
|
import org.hibernate.envers.entities.mapper.relation.lazy.proxy.CollectionProxy;
|
16
|
import org.hibernate.envers.entities.mapper.relation.lazy.proxy.MapProxy;
|
17
|
import org.hibernate.proxy.HibernateProxy;
|
18
|
import org.springframework.stereotype.Component;
|
19
|
|
20
|
import eu.etaxonomy.cdm.persistence.dao.AbstractBeanInitializer;
|
21
|
|
22
|
/**
|
23
|
* @author a.kohlbecker
|
24
|
* @date 25.03.2009
|
25
|
*
|
26
|
*/
|
27
|
//@Component("defaultBeanInitializer")
|
28
|
public class HibernateBeanInitializer extends AbstractBeanInitializer{
|
29
|
|
30
|
public static final Logger logger = Logger.getLogger(HibernateBeanInitializer.class);
|
31
|
|
32
|
/* (non-Javadoc)
|
33
|
* @see eu.etaxonomy.cdm.persistence.dao.AbstractBeanInitializer#initializeInstance(java.lang.Object)
|
34
|
*/
|
35
|
@Override
|
36
|
protected Object initializeInstance(Object bean) {
|
37
|
initialize(bean);
|
38
|
return HibernateProxyHelperExtended.getProxyTarget(bean);
|
39
|
}
|
40
|
|
41
|
public static void initialize(Object proxy) throws HibernateException {
|
42
|
if ( proxy == null ) {
|
43
|
return;
|
44
|
}
|
45
|
else if ( proxy instanceof HibernateProxy ) {
|
46
|
( ( HibernateProxy ) proxy ).getHibernateLazyInitializer().initialize();
|
47
|
} else if ( proxy instanceof PersistentCollection ) {
|
48
|
( ( PersistentCollection ) proxy ).forceInitialization();
|
49
|
} else if(proxy instanceof CollectionProxy) {
|
50
|
( ( CollectionProxy ) proxy ).isEmpty(); // checkInit is protected, unfortunately;
|
51
|
} else if(proxy instanceof MapProxy) {
|
52
|
( ( MapProxy ) proxy ).isEmpty(); // checkInit is protected, unfortunately;
|
53
|
}
|
54
|
}
|
55
|
|
56
|
}
|