test connection and ICdmDatasource getters
[cdmlib.git] / cdmlib-persistence / src / main / java / eu / etaxonomy / cdm / database / CdmDataSourceBase.java
1 /**
2 * Copyright (C) 2007 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.sql.Connection;
13 import java.sql.DriverManager;
14
15 import org.apache.log4j.Logger;
16
17 import eu.etaxonomy.cdm.database.types.IDatabaseType;
18
19 /**
20 * @author a.mueller
21 * @created 18.12.2008
22 * @version 1.0
23 */
24 abstract class CdmDataSourceBase implements ICdmDataSource {
25 private static final Logger logger = Logger.getLogger(CdmDataSourceBase.class);
26
27
28
29 /* (non-Javadoc)
30 * @see eu.etaxonomy.cdm.database.ICdmDataSource#testConnection()
31 */
32 public boolean testConnection() {
33 try {
34 IDatabaseType dbType = getDatabaseType().getDatabaseType();
35 String classString = dbType.getClassString();
36 Class.forName(classString);
37
38 String mUrl = dbType.getConnectionString(this);
39 Connection mConn = DriverManager.getConnection(mUrl, getUserName(), getPassword());
40 if (mConn != null){
41 return true;
42 }else{
43 return false;
44 }
45 } catch (Exception e) {
46 logger.warn(e.getMessage());
47 return false;
48 }
49 }
50 }