Project

General

Profile

« Previous | Next » 

Revision 6a73c9ea

Added by Andreas Kohlbecker about 13 years ago

CdmDataSourceBean should implement javax.sql.DataSource: preparing to do so

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/CdmDataSourceBase.java
16 16
import java.sql.SQLException;
17 17
import java.sql.Statement;
18 18

  
19
import javax.sql.DataSource;
20

  
19 21
import org.apache.log4j.Logger;
20 22

  
21 23
import eu.etaxonomy.cdm.database.types.IDatabaseType;
......
31 33
	private static final int TIMEOUT = 10;
32 34
	private Connection connection;
33 35
	
34
	private Connection getConnection() {
35 36

  
37
	public Connection getConnection() throws SQLException {
38

  
39
		return getConnection(getUsername(), getPassword());
40
	}
41
	
42

  
43
	public Connection getConnection(String username, String password) throws SQLException {
36 44
		try {
37 45
			if(connection != null && connection.isValid(TIMEOUT)){
38 46
				return connection;
......
41 49
				String classString = dbType.getClassString();
42 50
				Class.forName(classString);
43 51
				String mUrl = dbType.getConnectionString(this);
44
				return DriverManager.getConnection(mUrl, getUsername(), getPassword());	
52
				return DriverManager.getConnection(mUrl, username, password);	
45 53
			}
46 54
		} catch (ClassNotFoundException e) {
47 55
			logger.error("Database driver class could not be loaded\n" + "Exception: " + e.toString());
......
50 58
		}
51 59
		return null;
52 60
	}
53
	
61

  
62

  
54 63
	/* (non-Javadoc)
55 64
	 * @see eu.etaxonomy.cdm.database.ICdmDataSource#testConnection()
56 65
	 */
......
68 77
		return false;
69 78
	}
70 79

  
80
	/* (non-Javadoc)
81
	 * @see eu.etaxonomy.cdm.database.ICdmDataSource#getSingleValue(java.lang.String)
82
	 */
71 83
	@Override
72 84
	public Object getSingleValue(String query) throws SQLException{
73 85
		String queryString = query == null? "(null)": query;  

Also available in: Unified diff