2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.database
;
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
;
22 public class DataSourceReloader
{
24 static final Logger logger
= Logger
.getLogger(DataSourceReloader
.class);
26 private SessionFactory factory
;
29 public void setSessionFacory(SessionFactory factory
){
30 this.factory
= factory
;
33 public UpdatableRoutingDataSource
getDataSource() {
34 UpdatableRoutingDataSource as
= (UpdatableRoutingDataSource
)SessionFactoryUtils
.getDataSource(factory
);
38 public Map
<String
,DataSourceInfo
> reload() {
39 return getDataSource().updateDataSources();
42 public Map
<String
,DataSourceInfo
> test() {
43 Map
<String
,SimpleDriverDataSource
> dataSources
= getDataSource().loadDataSources();
44 Map
<String
, DataSourceInfo
> dataSourceInfos
= getDataSource().testDataSources(dataSources
);
45 return dataSourceInfos
;