Project

General

Profile

Download (2.11 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2018 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.config;
10

    
11
import org.hibernate.SessionFactory;
12
import org.hibernate.event.service.spi.EventListenerRegistry;
13
import org.hibernate.event.spi.EventType;
14
import org.hibernate.internal.SessionFactoryImpl;
15
import org.springframework.beans.factory.annotation.Autowired;
16
import org.springframework.context.annotation.Bean;
17
import org.springframework.context.annotation.Configuration;
18

    
19
import eu.etaxonomy.cdm.persistence.hibernate.TaxonGraphHibernateListener;
20

    
21
/**
22
 * Spring configuration to provide the {@link TaxonGraphHibernateListener} bean.
23
 * This configuration can be activated by adding {@code @CdmHibernateListener}
24
 * to a java spring configuration see
25
 * <code>eu.etaxonomy.cdm.addon.config.CdmVaadinConfiguration</code> in <a href=
26
 * "https://github.com/cybertaxonomy/cdm-vaadin">https://github.com/cybertaxonomy/cdm-vaadin</a>
27
 * for an example.
28
 *
29
 * @see {@link CdmHibernateListener}
30
 * @see <a href=
31
 *      "https://dev.e-taxonomy.eu/redmine/issues/7648">https://dev.e-taxonomy.eu/redmine/issues/7648</a>
32
 *
33
 * @author a.kohlbecker
34
 * @since Oct 10, 2018
35
 *
36
 */
37
@Configuration
38
public class CdmHibernateListenerConfiguration {
39

    
40
    @Autowired
41
    SessionFactory sessionFactory;
42

    
43
    @Bean
44
    public TaxonGraphHibernateListener taxonGraphHibernateListener(){
45

    
46
        TaxonGraphHibernateListener taxonGraphHibernateListener = new TaxonGraphHibernateListener();
47
        EventListenerRegistry listenerRegistry = ((SessionFactoryImpl) sessionFactory).getServiceRegistry().getService(
48
                EventListenerRegistry.class);
49

    
50
        listenerRegistry.appendListeners(EventType.POST_UPDATE, taxonGraphHibernateListener);
51
        listenerRegistry.appendListeners(EventType.POST_INSERT, taxonGraphHibernateListener);
52
        listenerRegistry.appendListeners(EventType.PRE_DELETE, taxonGraphHibernateListener);
53

    
54
        return taxonGraphHibernateListener;
55
    }
56

    
57
}
(3-3/11)