term updater 313_314 and implementation for transactions (#2027)
[cdmlib.git] / cdmlib-persistence / src / main / java / eu / etaxonomy / cdm / database / ICdmDataSource.java
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 org.hibernate.cache.CacheProvider;
17 import org.springframework.beans.factory.config.BeanDefinition;
18
19 import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
20
21 public interface ICdmDataSource {
22
23 /**
24 * Returns a BeanDefinition object of type DataSource that contains
25 * datsource properties (url, username, password, ...)
26 * @return BeanDefinition
27 */
28 public BeanDefinition getDatasourceBean();
29
30 /**
31 * @param hbm2dll
32 * @return BeanDefinition
33 */
34 public BeanDefinition getHibernatePropertiesBean(DbSchemaValidation hbm2dll);
35
36 /**
37 * @param hbm2dll
38 * @param showSql
39 * @param formatSql
40 * @param cacheProviderClass
41 * @return BeanDefinition
42 */
43 public BeanDefinition getHibernatePropertiesBean(DbSchemaValidation hbm2dll, Boolean showSql, Boolean formatSql, Boolean registerSearchListener, Class<? extends CacheProvider> cacheProviderClass);
44
45
46 /**
47 * The name representation of thie Datasource.
48 * @return
49 */
50 public String getName();
51
52
53 /**
54 * @return
55 */
56 public String getServer();
57
58 /**
59 * @return
60 */
61 public String getDatabase();
62
63 public DatabaseTypeEnum getDatabaseType();
64
65 /**
66 * @return
67 */
68 public int getPort();
69
70 /**
71 * @return
72 */
73 public String getFilePath();
74
75 /**
76 * @return
77 */
78 public H2Mode getMode();
79
80 /**
81 * Tests, if a database connection can be established.
82 * @return true if test was successful, false otherwise
83 * @throws ClassNotFoundException
84 * @throws SQLException
85 * @throws Exception
86 */
87 public boolean testConnection() throws ClassNotFoundException, SQLException;
88
89 public String getUsername();
90
91 public String getPassword();
92
93 /**
94 * Executes a query and returns the ResultSet.
95 * @return ResultSet for the query.
96 * @throws SQLException
97 */
98 public ResultSet executeQuery (String query) throws SQLException;
99
100 /**
101 * Executes an update
102 * @return return code
103 */
104 public int executeUpdate (String sqlUpdate) throws SQLException;
105
106 /**
107 * Starts a transaction for the given datasource.
108 */
109 public void startTransaction();
110
111 /**
112 * Commits the transaction for the given datasource.
113 * @return
114 * @throws SQLException
115 */
116 public void commitTransaction() throws SQLException;
117
118 /**
119 * Rolls the connection back.
120 * @throws SQLException
121 */
122 public void rollback() throws SQLException;
123
124
125 public NomenclaturalCode getNomenclaturalCode();
126
127 /**
128 * Returns a single the first value of a row of a resultset.
129 *
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()}
132 *
133 * @param query
134 * @return
135 * @throws SQLException
136 */
137 public Object getSingleValue(String query) throws SQLException;
138
139 /**
140 * Returns {@link DatabaseMetaData} for <code>this</code> datasource.
141 *
142 * <br>
143 * <br>
144 * <strong>Caution</strong> This method opens a connection that should be closed
145 * with {@link #closeOpenConnections()}
146 *
147 * @return
148 */
149 public DatabaseMetaData getMetaData();
150
151 /**
152 *
153 */
154 public void closeOpenConnections();
155
156
157 //
158 // public void setFilePath(String filePath);
159 //
160 // public void setMode(H2Mode mode);
161
162 }