Project

General

Profile

Download (3.8 KB) Statistics
| Branch: | Tag: | Revision:
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.DatabaseMetaData;
13
import java.sql.ResultSet;
14
import java.sql.SQLException;
15

    
16
import javax.sql.DataSource;
17

    
18
import org.hibernate.cache.spi.RegionFactory;
19
import org.springframework.beans.factory.config.BeanDefinition;
20

    
21
import eu.etaxonomy.cdm.config.ICdmSource;
22

    
23
public interface ICdmDataSource  extends DataSource,ICdmSource {
24

    
25
	/**
26
	 * Returns a BeanDefinition object of type  DataSource that contains
27
	 * datsource properties (url, username, password, ...)
28
	 * @return BeanDefinition
29
	 */
30
	public BeanDefinition getDatasourceBean();
31
	
32
	/**
33
	 * @param hbm2dll
34
	 * @return BeanDefinition
35
	 */
36
	public BeanDefinition getHibernatePropertiesBean(DbSchemaValidation hbm2dll);
37
	
38
	/**
39
	 * @param hbm2dll
40
	 * @param showSql
41
	 * @param formatSql
42
	 * @param cacheProviderClass
43
	 * @return BeanDefinition
44
	 */
45
	public BeanDefinition getHibernatePropertiesBean(DbSchemaValidation hbm2dll, Boolean showSql, Boolean formatSql, Boolean registerSearchListener, Class<? extends RegionFactory> cacheProviderClass);
46

    
47

    
48
	
49
	/**
50
	 * @return
51
	 */
52
	public String getFilePath();
53

    
54
	/**
55
	 * @return
56
	 */
57
	public H2Mode getMode();
58
	
59
	public String getUsername();
60
	
61
	public String getPassword();
62
	
63
	public String getDatabase();
64
	
65
	public void setMode(H2Mode h2Mode);
66
	
67
	public void setUsername(String username);
68
	
69
	public void setPassword(String password);
70
	
71
	public void setDatabase(String database);
72
	
73
	
74
	/**
75
	 * Returns the database type of the data source. 
76
	 * @return the database type of the data source. 
77
	 * <code>null</code> if the bean or the driver class property does not exist or the driver class is unknown.
78
	 */
79
	public DatabaseTypeEnum getDatabaseType();
80
	/**
81
	 * Tests, if a database connection can be established.
82
	 * @return true if test was successful, false otherwise
83
	 * @throws ClassNotFoundException 
84
	 * @throws SQLException 
85
	 * @throws Exception 
86
	 */
87
	public boolean testConnection() throws ClassNotFoundException, SQLException;
88
	
89

    
90
	 /**
91
     * Executes a query and returns the ResultSet.
92
     * @return ResultSet for the query.
93
	 * @throws SQLException 
94
     */
95
	public ResultSet executeQuery (String query) throws SQLException;
96
	
97
    /**
98
     * Executes an update
99
     * @return return code
100
     */
101
	public int executeUpdate (String sqlUpdate) throws SQLException;
102
	
103
	/**
104
	 * Starts a transaction for the given datasource.
105
	 */
106
	public void startTransaction();
107
	
108
	/**
109
	 * Commits the transaction for the given datasource.
110
	 * @return
111
	 * @throws SQLException 
112
	 */
113
	public void commitTransaction() throws SQLException;
114
	
115
	/**
116
	 * Rolls the connection back.
117
	 * @throws SQLException 
118
	 */
119
	public void rollback() throws SQLException;
120

    
121

    
122
	/**
123
	 * Returns the first value of the first row of a result set.<BR>
124
	 * If no row exists in the result set
125
	 * <code>null</code> is returned.
126
	 * 
127
	 * <strong>Caution</strong> This method opens a connection on first use. Subsequent calls will use the same connection.
128
	 * Please close the connection when not needed anymore with {@link ICdmDataSource#closeOpenConnections()}
129
	 * 
130
	 * @param query
131
	 * @return
132
	 * @throws SQLException
133
	 */
134
	public Object getSingleValue(String query) throws SQLException;	
135
	
136
	/**
137
	 * Returns {@link DatabaseMetaData} for <code>this</code> datasource.
138
	 * 
139
	 * <br>
140
	 * <br>
141
	 * <strong>Caution</strong> This method opens a connection that should be closed
142
	 * with {@link #closeOpenConnections()}
143
	 * 
144
	 * @return
145
	 */
146
	public DatabaseMetaData getMetaData();
147

    
148
}
(12-12/20)