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
.CacheProvider
;
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 CacheProvider
> cacheProviderClass
);
47 * The name representation of thie Datasource.
50 public String
getName();
56 public String
getServer();
61 public String
getDatabase();
63 public DatabaseTypeEnum
getDatabaseType();
73 public String
getFilePath();
78 public H2Mode
getMode();
81 * Tests, if a database connection can be established.
82 * @return true if test was successful, false otherwise
83 * @throws ClassNotFoundException
84 * @throws SQLException
87 public boolean testConnection() throws ClassNotFoundException
, SQLException
;
89 public String
getUsername();
91 public String
getPassword();
94 * Executes a query and returns the ResultSet.
95 * @return ResultSet for the query.
96 * @throws SQLException
98 public ResultSet
executeQuery (String query
) throws SQLException
;
102 * @return return code
104 public int executeUpdate (String sqlUpdate
) throws SQLException
;
107 * Starts a transaction for the given datasource.
109 public void startTransaction();
112 * Commits the transaction for the given datasource.
114 * @throws SQLException
116 public void commitTransaction() throws SQLException
;
119 * Rolls the connection back.
120 * @throws SQLException
122 public void rollback() throws SQLException
;
125 public NomenclaturalCode
getNomenclaturalCode();
128 * Returns a single the first value of a row of a resultset.
130 * <strong>Caution</strong> This method opens a connection on first use. Subsequent calls will use the same connection.
131 * Please close the connection when not needed anymore with {@link ICdmDataSource#closeOpenConnections()}
135 * @throws SQLException
137 public Object
getSingleValue(String query
) throws SQLException
;
140 * Returns {@link DatabaseMetaData} for <code>this</code> datasource.
144 * <strong>Caution</strong> This method opens a connection that should be closed
145 * with {@link #closeOpenConnections()}
149 public DatabaseMetaData
getMetaData();
154 public void closeOpenConnections();
158 // public void setFilePath(String filePath);
160 // public void setMode(H2Mode mode);