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 org
.hibernate
.cache
.spi
.RegionFactory
;
17 import org
.springframework
.beans
.factory
.config
.BeanDefinition
;
19 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
21 public interface ICdmDataSource
{
24 * Returns a BeanDefinition object of type DataSource that contains
25 * datsource properties (url, username, password, ...)
26 * @return BeanDefinition
28 public BeanDefinition
getDatasourceBean();
32 * @return BeanDefinition
34 public BeanDefinition
getHibernatePropertiesBean(DbSchemaValidation hbm2dll
);
40 * @param cacheProviderClass
41 * @return BeanDefinition
43 public BeanDefinition
getHibernatePropertiesBean(DbSchemaValidation hbm2dll
, Boolean showSql
, Boolean formatSql
, Boolean registerSearchListener
, Class
<?
extends RegionFactory
> cacheProviderClass
);
47 * The name representation of thie Datasource.
50 public String
getName();
56 public String
getServer();
59 * Returns the name of the datasource on the given server.
62 public String
getDatabase();
64 public DatabaseTypeEnum
getDatabaseType();
74 public String
getFilePath();
79 public H2Mode
getMode();
82 * Tests, if a database connection can be established.
83 * @return true if test was successful, false otherwise
84 * @throws ClassNotFoundException
85 * @throws SQLException
88 public boolean testConnection() throws ClassNotFoundException
, SQLException
;
90 public String
getUsername();
92 public String
getPassword();
95 * Executes a query and returns the ResultSet.
96 * @return ResultSet for the query.
97 * @throws SQLException
99 public ResultSet
executeQuery (String query
) throws SQLException
;
103 * @return return code
105 public int executeUpdate (String sqlUpdate
) throws SQLException
;
108 * Starts a transaction for the given datasource.
110 public void startTransaction();
113 * Commits the transaction for the given datasource.
115 * @throws SQLException
117 public void commitTransaction() throws SQLException
;
120 * Rolls the connection back.
121 * @throws SQLException
123 public void rollback() throws SQLException
;
126 public NomenclaturalCode
getNomenclaturalCode();
129 * Returns the first value of the first row of a result set.<BR>
130 * If no row exists in the result set
131 * <code>null</code> is returned.
133 * <strong>Caution</strong> This method opens a connection on first use. Subsequent calls will use the same connection.
134 * Please close the connection when not needed anymore with {@link ICdmDataSource#closeOpenConnections()}
138 * @throws SQLException
140 public Object
getSingleValue(String query
) throws SQLException
;
143 * Returns {@link DatabaseMetaData} for <code>this</code> datasource.
147 * <strong>Caution</strong> This method opens a connection that should be closed
148 * with {@link #closeOpenConnections()}
152 public DatabaseMetaData
getMetaData();
157 public void closeOpenConnections();
161 // public void setFilePath(String filePath);
163 // public void setMode(H2Mode mode);