Revision 892efc69
Added by Andreas Kohlbecker almost 14 years ago
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/UpdatableRoutingDataSource.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
package eu.etaxonomy.cdm.database; |
11 | 11 |
|
12 |
import java.io.File; |
|
13 | 12 |
import java.sql.Connection; |
14 | 13 |
import java.sql.SQLException; |
15 | 14 |
import java.util.HashMap; |
... | ... | |
17 | 16 |
|
18 | 17 |
import javax.sql.DataSource; |
19 | 18 |
|
20 |
import org.springframework.beans.factory.xml.XmlBeanFactory; |
|
21 |
import org.springframework.core.io.FileSystemResource; |
|
22 | 19 |
import org.springframework.jdbc.datasource.SimpleDriverDataSource; |
23 | 20 |
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource; |
24 | 21 |
|
... | ... | |
44 | 41 |
* |
45 | 42 |
* @author a.kohlbecker |
46 | 43 |
*/ |
44 |
@Deprecated |
|
47 | 45 |
public class UpdatableRoutingDataSource extends AbstractRoutingDataSource { |
48 | 46 |
|
49 |
|
|
50 |
private static final String DATASOURCE_BEANDEF_FILE = "datasources.xml"; |
|
51 |
private static final String DATASOURCE_BEANDEF_PATH = System.getProperty("user.home")+File.separator+".cdmLibrary"+File.separator; |
|
52 |
|
|
53 |
private static String userdefinedBeanDefinitionFile = null; |
|
54 |
|
|
47 |
|
|
55 | 48 |
private String defaultDatasourceName = "default"; |
56 | 49 |
|
57 | 50 |
@Override |
... | ... | |
70 | 63 |
} |
71 | 64 |
|
72 | 65 |
|
73 |
public void setBeanDefinitionFile(String filename){ |
|
74 |
userdefinedBeanDefinitionFile = filename; |
|
75 |
} |
|
66 |
|
|
76 | 67 |
|
77 | 68 |
public Map<String, DataSourceInfo> updateDataSources() { |
78 | 69 |
|
... | ... | |
90 | 81 |
|
91 | 82 |
return dataSourceInfos; |
92 | 83 |
} |
93 |
|
|
94 |
/** |
|
95 |
* @return |
|
96 |
*/ |
|
97 |
protected Map<String, SimpleDriverDataSource> loadDataSources() { |
|
98 |
|
|
99 |
Map<String, SimpleDriverDataSource> dataSources = new HashMap<String, SimpleDriverDataSource>(); |
|
100 |
|
|
101 |
String path = DATASOURCE_BEANDEF_PATH + (userdefinedBeanDefinitionFile == null ? DATASOURCE_BEANDEF_FILE : userdefinedBeanDefinitionFile); |
|
102 |
logger.info(" loading bean definition file: " + path); |
|
103 |
FileSystemResource file = new FileSystemResource(path); |
|
104 |
XmlBeanFactory beanFactory = new XmlBeanFactory(file); |
|
105 |
|
|
106 |
for(String beanName : beanFactory.getBeanDefinitionNames()){ |
|
107 |
SimpleDriverDataSource datasource = (SimpleDriverDataSource)beanFactory.getBean(beanName, SimpleDriverDataSource.class); |
|
108 |
dataSources.put(beanName, datasource); |
|
109 |
} |
|
110 |
return dataSources; |
|
111 |
} |
|
112 | 84 |
|
85 |
protected Map<String, SimpleDriverDataSource> loadDataSources(){ |
|
86 |
return DataSourceBeanLoader.loadDataSources(SimpleDriverDataSource.class); |
|
87 |
} |
|
88 |
|
|
113 | 89 |
/** |
114 | 90 |
* @param dataSources |
115 | 91 |
* @return |
Also available in: Unified diff
merging /branches/cdmlib/SPRINT-Chichorieae1/ to trunk