Project

General

Profile

Download (4.36 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
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

    
53
	/**
54
	 * @param hbm2dll schema validation
55
	 * @param hibernateConfig the hibernate configuration
56
	 * @return the computed {@link BeanDefinition bean definition}
57
	 */
58
	public BeanDefinition getHibernatePropertiesBean(DbSchemaValidation hbm2dll,
59
	        HibernateConfiguration hibernateConfig);
60

    
61
	public String getFilePath();
62

    
63
	public H2Mode getMode();
64

    
65
	public String getUsername();
66

    
67
	public String getPassword();
68

    
69
	public String getDatabase();
70

    
71
	public void setMode(H2Mode h2Mode);
72

    
73
	public void setUsername(String username);
74

    
75
	public void setPassword(String password);
76

    
77
	public void setDatabase(String database);
78

    
79

    
80
	/**
81
	 * Returns the database type of the data source.
82
	 * @return the database type of the data source.
83
	 * <code>null</code> if the bean or the driver class property does not exist or the driver class is unknown.
84
	 */
85
	public DatabaseTypeEnum getDatabaseType();
86
	/**
87
	 * Tests, if a database connection can be established.
88
	 * @return true if test was successful, false otherwise
89
	 * @throws ClassNotFoundException
90
	 * @throws SQLException
91
	 * @throws Exception
92
	 */
93
	public boolean testConnection() throws ClassNotFoundException, SQLException;
94

    
95

    
96
	 /**
97
     * Executes a query and returns the ResultSet.
98
     * @see #executeUpdate(String)
99
     * @return ResultSet for the query.
100
	 * @throws SQLException
101
     */
102
	public ResultSet executeQuery (String query) throws SQLException;
103

    
104
    /**
105
     * Executes an update
106
     * @see #executeQuery(String)
107
     * @return return code
108
     */
109
	public int executeUpdate (String sqlUpdate) throws SQLException;
110

    
111
	/**
112
	 * Starts a transaction for the given datasource.
113
	 */
114
	public void startTransaction();
115

    
116
	/**
117
	 * Commits the transaction for the given datasource.
118
	 * @return
119
	 * @throws SQLException
120
	 */
121
	public void commitTransaction() throws SQLException;
122

    
123
	/**
124
	 * Rolls the connection back.
125
	 * @throws SQLException
126
	 */
127
	public void rollback() throws SQLException;
128

    
129

    
130
	/**
131
	 * Returns the first value of the first row of a result set.<BR>
132
	 * If no row exists in the result set
133
	 * <code>null</code> is returned.
134
	 *
135
	 * <strong>Caution</strong> This method opens a connection on first use. Subsequent calls will use the same connection.
136
	 * Please close the connection when not needed anymore with {@link ICdmDataSource#closeOpenConnections()}
137
	 *
138
	 * @param query
139
	 * @return
140
	 * @throws SQLException
141
	 */
142
	public Object getSingleValue(String query) throws SQLException;
143

    
144
	/**
145
	 * Returns {@link DatabaseMetaData} for <code>this</code> datasource.
146
	 *
147
	 * <br>
148
	 * <br>
149
	 * <strong>Caution</strong> This method opens a connection that should be closed
150
	 * with {@link #closeOpenConnections()}
151
	 *
152
	 * @return
153
	 */
154
	public DatabaseMetaData getMetaData();
155

    
156
}
(14-14/22)