+/**\r
+* Copyright (C) 2009 EDIT\r
+* European Distributed Institute of Taxonomy\r
+* http://www.e-taxonomy.eu\r
+*\r
+* The contents of this file are subject to the Mozilla Public License Version 1.1\r
+* See LICENSE.TXT at the top of this package for the full license terms.\r
+*/ \r
+\r
package eu.etaxonomy.cdm.database;\r
\r
-import java.io.File;\r
import java.sql.Connection;\r
import java.sql.SQLException;\r
import java.util.HashMap;\r
\r
import javax.sql.DataSource;\r
\r
-import org.springframework.beans.factory.annotation.Autowired;\r
-import org.springframework.beans.factory.xml.XmlBeanFactory;\r
-import org.springframework.core.io.FileSystemResource;\r
-import org.springframework.jdbc.datasource.AbstractDataSource;\r
import org.springframework.jdbc.datasource.SimpleDriverDataSource;\r
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;\r
\r
</pre>\r
* \r
* @author a.kohlbecker\r
+ * @deprecated<b>NOTICE:</b> \r
+ * <em>This class is related to the switchable database infrastructure which allows to serve \r
+ * multiple databases with only a single instance of the cdm-remote-webapp. \r
+ * This concept however is deprecated due to several problems of which the most severe is the term loading issue.\r
+ * This class should however not deleted since we once might wish to switch back to this concept when we are \r
+ * able to deal with the implicated issues. \r
+ * \r
+ * See http://dev.e-taxonomy.eu/trac/wiki/CdmServerSwitchableDataSources for more information.</em>\r
*/\r
+@Deprecated\r
public class UpdatableRoutingDataSource extends AbstractRoutingDataSource {\r
\r
- \r
- private static final String DATASOURCE_BEANDEF_FILE = "datasources.xml";\r
- private static final String DATASOURCE_BEANDEF_PATH = System.getProperty("user.home")+File.separator+".cdmLibrary"+File.separator;\r
- \r
- private static String userdefinedBeanDefinitionFile = null;\r
- \r
+\r
private String defaultDatasourceName = "default";\r
\r
@Override\r
}\r
\r
\r
- public void setBeanDefinitionFile(String filename){\r
- userdefinedBeanDefinitionFile = filename;\r
- }\r
+\r
\r
- public Map<String,SimpleDriverDataSource> updateDataSources() {\r
+ public Map<String, DataSourceInfo> updateDataSources() {\r
+ \r
logger.info("loading & testing datasources .. ");\r
- Map<String,SimpleDriverDataSource> datasources = loadDataSources();\r
- setTargetDataSources(datasources);\r
- DataSource defaultDatasource = datasources.get(defaultDatasourceName);\r
+ Map<String,SimpleDriverDataSource> dataSources = loadDataSources();\r
+ Map<String, DataSourceInfo> dataSourceInfos = testDataSources(dataSources);\r
+ \r
+ setTargetDataSources((Map)dataSources);\r
+ DataSource defaultDatasource = dataSources.get(defaultDatasourceName);\r
if(defaultDatasource == null) {\r
logger.error("Defaultdatasource '" +defaultDatasourceName + "' not found.");\r
}\r
setDefaultTargetDataSource(defaultDatasource);\r
super.afterPropertiesSet();\r
- return datasources;\r
+ \r
+ return dataSourceInfos;\r
+ }\r
+ \r
+ protected Map<String, SimpleDriverDataSource> loadDataSources(){\r
+ return DataSourceBeanLoader.loadDataSources(SimpleDriverDataSource.class);\r
}\r
\r
- protected Map<String, SimpleDriverDataSource> loadDataSources() {\r
-\r
- Map<String, SimpleDriverDataSource> dataSources = new HashMap<String, SimpleDriverDataSource>();\r
-\r
- String path = DATASOURCE_BEANDEF_PATH + (userdefinedBeanDefinitionFile == null ? DATASOURCE_BEANDEF_FILE : userdefinedBeanDefinitionFile);\r
- logger.info(" loading bean definition file: " + path);\r
- FileSystemResource file = new FileSystemResource(path);\r
- XmlBeanFactory beanFactory = new XmlBeanFactory(file);\r
+ /**\r
+ * @param dataSources\r
+ * @return\r
+ */\r
+ protected Map<String, DataSourceInfo> testDataSources(Map<String, SimpleDriverDataSource> dataSources) {\r
\r
- for(String beanName : beanFactory.getBeanDefinitionNames()){\r
- SimpleDriverDataSource datasource = (SimpleDriverDataSource)beanFactory.getBean(beanName, SimpleDriverDataSource.class);\r
+ Map<String, DataSourceInfo> dataSourceInfos = new HashMap<String, DataSourceInfo>();\r
+\r
+ for(String key : dataSources.keySet()){\r
+ SimpleDriverDataSource datasource = dataSources.get(key);\r
+ DataSourceInfo dsi = new DataSourceInfo(datasource);\r
Connection connection = null;\r
String sqlerror = null;\r
try {\r
connection.close();\r
} catch (SQLException e) {\r
sqlerror = e.getMessage() + "["+ e.getSQLState() + "]";\r
+ dsi.getProblems().add(sqlerror);\r
if(connection != null){\r
try {connection.close();} catch (SQLException e1) { /* IGNORE */ }\r
}\r
}\r
- logger.info(" /" + beanName + " => "+ datasource.getUrl() + "[ "+(sqlerror == null ? "OK" : "ERROR: " + sqlerror) + " ]");\r
- dataSources.put(beanName, datasource);\r
+ logger.info(" /" + key + " => "+ datasource.getUrl() + "[ "+(sqlerror == null ? "OK" : "ERROR: " + sqlerror) + " ]");\r
+ dataSourceInfos.put(key, dsi);\r
}\r
\r
- return dataSources;\r
+ return dataSourceInfos;\r
}\r
\r
}\r