Project

General

Profile

Download (2 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2009 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.persistence.dao.hibernate;
10

    
11
import org.apache.log4j.Logger;
12
import org.hibernate.HibernateException;
13
import org.hibernate.collection.spi.PersistentCollection;
14
import org.hibernate.envers.internal.entities.mapper.relation.lazy.proxy.CollectionProxy;
15
import org.hibernate.envers.internal.entities.mapper.relation.lazy.proxy.MapProxy;
16
import org.hibernate.proxy.HibernateProxy;
17

    
18
import eu.etaxonomy.cdm.model.common.CdmBase;
19
import eu.etaxonomy.cdm.persistence.dao.initializer.AbstractBeanInitializer;
20

    
21
/**
22
 * @author a.kohlbecker
23
 * @since 25.03.2009
24
 *
25
 */
26
//@Component("defaultBeanInitializer")
27
public class HibernateBeanInitializer<CDM extends CdmBase> extends AbstractBeanInitializer<CDM>{
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)