Project

General

Profile

« Previous | Next » 

Revision 5cf75203

Added by Cherian Mathew about 9 years ago

NewTaxonBaseComposite, INewTaxonBaseComposite, INewTaxonBaseComponentListener, NewTaxonBasePresenter : added new component for creating new taxon / synonym
CdmVaadinSessionUtilities : utility class for vaddin session
CdmVaadinUtilities : utility class for general vaadin ui
SQLUtils : utility class for cdm sql containers
CdmQueryFactory : added freeform query to mimic table query and using default id
CdmDataChangeService, CdmChangeEvent, ICdmChangeListener : service which calls registers listeners when events are fired
CdmBaseUI : base cdm ui class, currently manages the cdm data change service
AbstractAuthenticatedUI, AuthenticationView, CdmVaadinConversationalServlet : using CdmVaadinSessionUtilities to set session attributes
CdmSpringContextHelper : using vaadin connection pool and cleanup code
DistributionSelectionPresenter, DistributionTablePresenter : changes coming from update in CdmQueryFactory

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/util/CdmSpringContextHelper.java
1 1
package eu.etaxonomy.cdm.vaadin.util;
2 2

  
3
import java.sql.Connection;
3 4
import java.sql.SQLException;
4 5

  
5 6
import javax.servlet.ServletContext;
......
8 9
import org.springframework.context.ApplicationContext;
9 10
import org.springframework.web.context.support.WebApplicationContextUtils;
10 11

  
12
import com.vaadin.data.util.sqlcontainer.connection.J2EEConnectionPool;
11 13
import com.vaadin.data.util.sqlcontainer.connection.JDBCConnectionPool;
12 14
import com.vaadin.server.VaadinServlet;
13 15

  
16
import eu.etaxonomy.cdm.api.service.IClassificationService;
17
import eu.etaxonomy.cdm.api.service.ICommonService;
18
import eu.etaxonomy.cdm.api.service.IDescriptionService;
19
import eu.etaxonomy.cdm.api.service.INameService;
20
import eu.etaxonomy.cdm.api.service.IReferenceService;
21
import eu.etaxonomy.cdm.api.service.IService;
22
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
14 23
import eu.etaxonomy.cdm.api.service.ITaxonService;
15
import eu.etaxonomy.cdm.vaadin.container.CdmSpringConnectionPool;
24
import eu.etaxonomy.cdm.api.service.ITermService;
25
import eu.etaxonomy.cdm.api.service.IVocabularyService;
16 26

  
17 27
public class CdmSpringContextHelper {
18 28

  
19 29
    private final ApplicationContext context;
30
    private final DataSource dataSource;
20 31

  
32
    private final JDBCConnectionPool connPool;
21 33
    private static CdmSpringContextHelper contextHelper;
22 34

  
23
    private CdmSpringContextHelper(ServletContext servletContext) {
35
    private CdmSpringContextHelper(ServletContext servletContext) throws SQLException {
24 36
        context = WebApplicationContextUtils.
25 37
                getRequiredWebApplicationContext(servletContext);
38
        dataSource = (DataSource)getBean("dataSource");
39
        connPool = new J2EEConnectionPool(dataSource);
26 40

  
27 41
    }
28 42

  
29 43

  
30
    public static CdmSpringContextHelper newInstance() {
31
    	if(VaadinServlet.getCurrent() == null || VaadinServlet.getCurrent().getServletContext() == null) {
32
    		throw new RuntimeException("Vaadin Servlet or Vaadin Servlet Context not initialized");
33
    	}
44
    public static CdmSpringContextHelper getCurrent() {
45
        if(VaadinServlet.getCurrent() == null || VaadinServlet.getCurrent().getServletContext() == null) {
46
            throw new RuntimeException("Vaadin Servlet or Vaadin Servlet Context not initialized");
47
        }
48

  
49
        if(contextHelper == null) {
50
            ServletContext sc = VaadinServlet.getCurrent().getServletContext();
51
            try {
52
                contextHelper = new CdmSpringContextHelper(sc);
53
            } catch (SQLException e) {
54
                // TODO Auto-generated catch block
55
                e.printStackTrace();
56
            }
57
        }
58
        return contextHelper;
34 59

  
35
    	if(contextHelper == null) {
36
    		ServletContext sc = VaadinServlet.getCurrent().getServletContext();
37
    		contextHelper = new CdmSpringContextHelper(sc);
38
    		return contextHelper;
39
    	} else {
40
    		return contextHelper;
41
    	}
42 60
    }
43 61

  
44 62
    public Object getBean(final String beanRef) {
45 63
        return context.getBean(beanRef);
46 64
    }
47 65

  
48
    public static JDBCConnectionPool getConnectionPool() throws SQLException {
49
        DataSource bean = (DataSource) newInstance().getBean("dataSource");
50
        JDBCConnectionPool connectionPool = new CdmSpringConnectionPool(bean.getConnection());
51
        return connectionPool;
66
    public Object getBean(Class clazz) {
67
        return context.getBean(clazz);
68
    }
69

  
70
    public <T extends IService> T getService(Class<T> clazz) {
71
        return context.getBean(clazz);
72
    }
73

  
74
    public DataSource getDataSource() {
75
        return dataSource;
76
    }
77

  
78
    public JDBCConnectionPool getConnectionPool() {
79
        return connPool;
80
    }
81

  
82
//    public static JDBCConnectionPool createConnectionPool() {
83
//        return new J2EEConnectionPool(getCurrent().getDataSource());
84
//    }
85

  
86
//    public static JDBCConnectionPool getConnectionPool() {
87
//        return new J2EEConnectionPool(getCurrent().getDataSource());
88
//    }
89

  
90

  
91

  
92
    public static Connection getConnection() throws SQLException {
93
        return getCurrent().getDataSource().getConnection();
52 94
    }
53 95

  
54 96
    public static ITaxonService getTaxonService() {
55
        return (ITaxonService)CdmSpringContextHelper.newInstance().getBean("taxonServiceImpl");
97
        return (ITaxonService)getCurrent().getBean(ITaxonService.class);
98
    }
99

  
100
    public static ITaxonNodeService getTaxonNodeService() {
101
        return (ITaxonNodeService)getCurrent().getBean(ITaxonNodeService.class);
102
    }
103

  
104
    public static IReferenceService getReferenceService() {
105
        return (IReferenceService)getCurrent().getBean(IReferenceService.class);
106
    }
107

  
108
    public static INameService getNameService() {
109
        return (INameService)getCurrent().getBean(INameService.class);
110
    }
111

  
112
    public static ICommonService getCommonService() {
113
        return (ICommonService)getCurrent().getBean(ICommonService.class);
114
    }
115

  
116
    public static IClassificationService getClassificationService() {
117
        return (IClassificationService)getCurrent().getBean(IClassificationService.class);
118
    }
119

  
120
    public static IVocabularyService getVocabularyService() {
121
        return (IVocabularyService)getCurrent().getBean(IVocabularyService.class);
122
    }
123

  
124
    public static ITermService getTermService() {
125
        return (ITermService)getCurrent().getBean(ITermService.class);
126
    }
127

  
128
    public static IDescriptionService getDescriptionService() {
129
        return (IDescriptionService)getCurrent().getBean(IDescriptionService.class);
56 130
    }
57 131
}

Also available in: Unified diff