2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.database
;
12 import java
.sql
.DatabaseMetaData
;
13 import java
.sql
.ResultSet
;
14 import java
.sql
.SQLException
;
16 import javax
.sql
.DataSource
;
18 import org
.hibernate
.cache
.spi
.RegionFactory
;
19 import org
.springframework
.beans
.factory
.config
.BeanDefinition
;
21 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
23 public interface ICdmDataSource
extends DataSource
{
26 * Returns a BeanDefinition object of type DataSource that contains
27 * datsource properties (url, username, password, ...)
28 * @return BeanDefinition
30 public BeanDefinition
getDatasourceBean();
34 * @return BeanDefinition
36 public BeanDefinition
getHibernatePropertiesBean(DbSchemaValidation hbm2dll
);
42 * @param cacheProviderClass
43 * @return BeanDefinition
45 public BeanDefinition
getHibernatePropertiesBean(DbSchemaValidation hbm2dll
, Boolean showSql
, Boolean formatSql
, Boolean registerSearchListener
, Class
<?
extends RegionFactory
> cacheProviderClass
);
49 * The name representation of thie Datasource.
52 public String
getName();
58 public String
getServer();
61 * Returns the name of the datasource on the given server.
64 public String
getDatabase();
67 * Returns the database type of the data source.
68 * @return the database type of the data source.
69 * <code>null</code> if the bean or the driver class property does not exist or the driver class is unknown.
71 public DatabaseTypeEnum
getDatabaseType();
81 public String
getFilePath();
86 public H2Mode
getMode();
89 * Tests, if a database connection can be established.
90 * @return true if test was successful, false otherwise
91 * @throws ClassNotFoundException
92 * @throws SQLException
95 public boolean testConnection() throws ClassNotFoundException
, SQLException
;
97 public String
getUsername();
99 public String
getPassword();
102 * Executes a query and returns the ResultSet.
103 * @return ResultSet for the query.
104 * @throws SQLException
106 public ResultSet
executeQuery (String query
) throws SQLException
;
110 * @return return code
112 public int executeUpdate (String sqlUpdate
) throws SQLException
;
115 * Starts a transaction for the given datasource.
117 public void startTransaction();
120 * Commits the transaction for the given datasource.
122 * @throws SQLException
124 public void commitTransaction() throws SQLException
;
127 * Rolls the connection back.
128 * @throws SQLException
130 public void rollback() throws SQLException
;
133 public NomenclaturalCode
getNomenclaturalCode();
136 * Returns the first value of the first row of a result set.<BR>
137 * If no row exists in the result set
138 * <code>null</code> is returned.
140 * <strong>Caution</strong> This method opens a connection on first use. Subsequent calls will use the same connection.
141 * Please close the connection when not needed anymore with {@link ICdmDataSource#closeOpenConnections()}
145 * @throws SQLException
147 public Object
getSingleValue(String query
) throws SQLException
;
150 * Returns {@link DatabaseMetaData} for <code>this</code> datasource.
154 * <strong>Caution</strong> This method opens a connection that should be closed
155 * with {@link #closeOpenConnections()}
159 public DatabaseMetaData
getMetaData();
164 public void closeOpenConnections();
168 // public void setFilePath(String filePath);
170 // public void setMode(H2Mode mode);