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