1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package org.objectledge.database;
29
30 import java.sql.Connection;
31 import java.sql.SQLException;
32
33 /***
34 * A convenience wrapper around database related components.
35 *
36 * <p>Use this component to reduce the number of required constructor parameters in your database
37 * dependant components, and make sure that they'll access the right data source, if you are using
38 * the ThreadDataSource decorator.</p>
39 *
40 * @author <a href="mailto:rafal@caltha.pl">Rafal Krzewski</a>
41 * @version $Id: Database.java,v 1.7 2005/04/04 11:38:08 rafal Exp $
42 */
43 public interface Database
44 {
45 /***
46 * Returns a database Connection produced by the DataSource.
47 *
48 * @return a database Connection.
49 * @throws SQLException if the conneciton could not be obtained.
50 */
51 public abstract Connection getConnection() throws SQLException;
52
53 /***
54 * Returns a database Connection produced by the DataSource.
55 *
56 * @param user the user to connect as.
57 * @param password the user's password.
58 * @return a database Connection.
59 * @throws SQLException if the conneciton could not be obtained.
60 */
61 public abstract Connection getConnection(String user, String password) throws SQLException;
62
63 /***
64 * Get the next row identifier for the table.
65 *
66 * @param table the table name.
67 * @return the identifier.
68 * @throws SQLException if the id could not be generated.
69 */
70 public abstract long getNextId(String table) throws SQLException;
71
72 /***
73 * Sets the transaction timeout for the current transaction.
74 *
75 * @param seconds the requested length of timeout period in seconds.
76 * @throws SQLException if the timeout could not be set.
77 */
78 public abstract void setTransactionTimeout(int seconds) throws SQLException;
79
80 /***
81 * Begin the transaction, if there is none active.
82 *
83 * @return <code>true</code> if the requestor become the controler.
84 * @throws SQLException if the operation fails.
85 */
86 public abstract boolean beginTransaction() throws SQLException;
87
88 /***
89 * Commit the transaction, if the caller is the controller.
90 *
91 * @param controller <code>true</code> if the caller is the controler.
92 * @throws SQLException if the commit fails.
93 */
94 public abstract void commitTransaction(boolean controller) throws SQLException;
95
96 /***
97 * Rollback the transaction, if the caller is the controller.
98 *
99 * @param controller <code>true</code> if the caller is the controler.
100 * @throws SQLException if the rollback fails.
101 */
102 public abstract void rollbackTransaction(boolean controller) throws SQLException;
103 }