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
|
import eu.etaxonomy.cdm.persistence.hibernate.HibernateConfiguration;
|
23
|
|
24
|
public interface ICdmDataSource extends DataSource,ICdmSource {
|
25
|
|
26
|
/**
|
27
|
* Returns a BeanDefinition object of type DataSource that contains
|
28
|
* datsource properties (url, username, password, ...)
|
29
|
* @return BeanDefinition
|
30
|
*/
|
31
|
public BeanDefinition getDatasourceBean();
|
32
|
|
33
|
/**
|
34
|
* @param hbm2dll
|
35
|
* @return BeanDefinition
|
36
|
*/
|
37
|
public BeanDefinition getHibernatePropertiesBean(DbSchemaValidation hbm2dll);
|
38
|
|
39
|
/**
|
40
|
* @param hbm2dll
|
41
|
* @param showSql
|
42
|
* @param formatSql
|
43
|
* @param registerSearchListener
|
44
|
* @param cacheProviderClass
|
45
|
* @return
|
46
|
* @deprecated use {@link #getHibernatePropertiesBean(DbSchemaValidation, Boolean, Boolean, Boolean, Boolean, Class)} instead
|
47
|
*/
|
48
|
@Deprecated
|
49
|
public BeanDefinition getHibernatePropertiesBean(DbSchemaValidation hbm2dll, Boolean showSql,
|
50
|
Boolean formatSql, Boolean registerSearchListener, Class<? extends RegionFactory> cacheProviderClass);
|
51
|
|
52
|
/**
|
53
|
* @param hbm2dll schema validation
|
54
|
* @param hibernateConfig the hibernate configuration
|
55
|
* @return the computed {@link BeanDefinition bean definition}
|
56
|
*/
|
57
|
public BeanDefinition getHibernatePropertiesBean(DbSchemaValidation hbm2dll,
|
58
|
HibernateConfiguration hibernateConfig);
|
59
|
|
60
|
/**
|
61
|
* @return
|
62
|
*/
|
63
|
public String getFilePath();
|
64
|
|
65
|
/**
|
66
|
* @return
|
67
|
*/
|
68
|
public H2Mode getMode();
|
69
|
|
70
|
public String getUsername();
|
71
|
|
72
|
public String getPassword();
|
73
|
|
74
|
public String getDatabase();
|
75
|
|
76
|
public void setMode(H2Mode h2Mode);
|
77
|
|
78
|
public void setUsername(String username);
|
79
|
|
80
|
public void setPassword(String password);
|
81
|
|
82
|
public void setDatabase(String database);
|
83
|
|
84
|
|
85
|
/**
|
86
|
* Returns the database type of the data source.
|
87
|
* @return the database type of the data source.
|
88
|
* <code>null</code> if the bean or the driver class property does not exist or the driver class is unknown.
|
89
|
*/
|
90
|
public DatabaseTypeEnum getDatabaseType();
|
91
|
/**
|
92
|
* Tests, if a database connection can be established.
|
93
|
* @return true if test was successful, false otherwise
|
94
|
* @throws ClassNotFoundException
|
95
|
* @throws SQLException
|
96
|
* @throws Exception
|
97
|
*/
|
98
|
public boolean testConnection() throws ClassNotFoundException, SQLException;
|
99
|
|
100
|
|
101
|
/**
|
102
|
* Executes a query and returns the ResultSet.
|
103
|
* @return ResultSet for the query.
|
104
|
* @throws SQLException
|
105
|
*/
|
106
|
public ResultSet executeQuery (String query) throws SQLException;
|
107
|
|
108
|
/**
|
109
|
* Executes an update
|
110
|
* @return return code
|
111
|
*/
|
112
|
public int executeUpdate (String sqlUpdate) throws SQLException;
|
113
|
|
114
|
/**
|
115
|
* Starts a transaction for the given datasource.
|
116
|
*/
|
117
|
public void startTransaction();
|
118
|
|
119
|
/**
|
120
|
* Commits the transaction for the given datasource.
|
121
|
* @return
|
122
|
* @throws SQLException
|
123
|
*/
|
124
|
public void commitTransaction() throws SQLException;
|
125
|
|
126
|
/**
|
127
|
* Rolls the connection back.
|
128
|
* @throws SQLException
|
129
|
*/
|
130
|
public void rollback() throws SQLException;
|
131
|
|
132
|
|
133
|
/**
|
134
|
* Returns the first value of the first row of a result set.<BR>
|
135
|
* If no row exists in the result set
|
136
|
* <code>null</code> is returned.
|
137
|
*
|
138
|
* <strong>Caution</strong> This method opens a connection on first use. Subsequent calls will use the same connection.
|
139
|
* Please close the connection when not needed anymore with {@link ICdmDataSource#closeOpenConnections()}
|
140
|
*
|
141
|
* @param query
|
142
|
* @return
|
143
|
* @throws SQLException
|
144
|
*/
|
145
|
public Object getSingleValue(String query) throws SQLException;
|
146
|
|
147
|
/**
|
148
|
* Returns {@link DatabaseMetaData} for <code>this</code> datasource.
|
149
|
*
|
150
|
* <br>
|
151
|
* <br>
|
152
|
* <strong>Caution</strong> This method opens a connection that should be closed
|
153
|
* with {@link #closeOpenConnections()}
|
154
|
*
|
155
|
* @return
|
156
|
*/
|
157
|
public DatabaseMetaData getMetaData();
|
158
|
|
159
|
}
|