Project

General

Profile

Download (1.93 KB) Statistics
| Branch: | Tag: | Revision:
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.spi.PersistentCollection;
15
import org.hibernate.envers.internal.entities.mapper.relation.lazy.proxy.CollectionProxy;
16
import org.hibernate.envers.internal.entities.mapper.relation.lazy.proxy.MapProxy;
17
import org.hibernate.proxy.HibernateProxy;
18

    
19
import eu.etaxonomy.cdm.persistence.dao.initializer.AbstractBeanInitializer;
20

    
21
/**
22
 * @author a.kohlbecker
23
 * @date 25.03.2009
24
 *
25
 */
26
//@Component("defaultBeanInitializer")
27
public class HibernateBeanInitializer extends AbstractBeanInitializer{
28

    
29
    @SuppressWarnings("unused")
30
	private static final Logger logger = Logger.getLogger(HibernateBeanInitializer.class);
31

    
32
    @Override
33
    public Object initializeInstance(Object bean) {
34
        initialize(bean);
35
        return HibernateProxyHelperExtended.getProxyTarget(bean);
36
    }
37

    
38
    public static void initialize(Object proxy) throws HibernateException {
39
        if ( proxy == null ) {
40
            return;
41
        }
42
        else if ( proxy instanceof HibernateProxy ) {
43
            ( ( HibernateProxy ) proxy ).getHibernateLazyInitializer().initialize();
44
        } else if ( proxy instanceof PersistentCollection ) {
45
            ( ( PersistentCollection ) proxy ).forceInitialization();
46
        } else if(proxy instanceof CollectionProxy) {
47
            ( ( CollectionProxy<?,?> ) proxy ).isEmpty(); // checkInit is protected, unfortunately;
48
        } else if(proxy instanceof MapProxy) {
49
            ( ( MapProxy<?,?> ) proxy ).isEmpty(); // checkInit is protected, unfortunately;
50
        }
51
    }
52

    
53

    
54

    
55
}
(2-2/3)