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
|
|
10
|
package eu.etaxonomy.cdm.database;
|
11
|
|
12
|
import java.util.Map;
|
13
|
|
14
|
import org.apache.log4j.Logger;
|
15
|
import org.hibernate.SessionFactory;
|
16
|
import org.springframework.beans.factory.annotation.Autowired;
|
17
|
import org.springframework.jdbc.datasource.SimpleDriverDataSource;
|
18
|
import org.springframework.orm.hibernate4.SessionFactoryUtils;
|
19
|
import org.springframework.stereotype.Component;
|
20
|
|
21
|
@Component
|
22
|
public class DataSourceReloader {
|
23
|
|
24
|
static final Logger logger = Logger.getLogger(DataSourceReloader.class);
|
25
|
|
26
|
private SessionFactory factory;
|
27
|
|
28
|
@Autowired
|
29
|
public void setSessionFacory(SessionFactory factory){
|
30
|
this.factory = factory;
|
31
|
}
|
32
|
|
33
|
public UpdatableRoutingDataSource getDataSource() {
|
34
|
UpdatableRoutingDataSource as = (UpdatableRoutingDataSource)SessionFactoryUtils.getDataSource(factory);
|
35
|
return as;
|
36
|
}
|
37
|
|
38
|
public Map<String,DataSourceInfo> reload() {
|
39
|
return getDataSource().updateDataSources();
|
40
|
}
|
41
|
|
42
|
public Map<String,DataSourceInfo> test() {
|
43
|
Map<String,SimpleDriverDataSource> dataSources = getDataSource().loadDataSources();
|
44
|
Map<String, DataSourceInfo> dataSourceInfos = getDataSource().testDataSources(dataSources);
|
45
|
return dataSourceInfos;
|
46
|
}
|
47
|
|
48
|
}
|