1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.dbforms.conprovider;
25
26 import java.sql.Connection;
27 import java.sql.SQLException;
28
29
30
31 /***
32 * ConnectionProvider base class. <br>
33 * To create a ConnectionProvider for your preferred ConnectionPooler, extend
34 * this class and implement <code>initialize</code> and
35 * <code>getConnection</code> methods.
36 *
37 * @author Luca Fossato
38 */
39 public abstract class AbstractConnectionProvider {
40 /*** ConnectionProvider preferences */
41 private ConnectionProviderPrefs prefs = null;
42
43 /***
44 * Constructor for the ConnectionProvider object.
45 *
46 * @exception Exception Description of the Exception
47 */
48 public AbstractConnectionProvider() throws Exception {
49 }
50
51 /***
52 * Sets the prefs attribute of the ConnectionProvider object
53 *
54 * @param prefs The new prefs value
55 */
56 public void setPrefs(ConnectionProviderPrefs prefs) {
57 this.prefs = prefs;
58 }
59
60
61 /***
62 * Gets the prefs attribute of the ConnectionProvider object
63 *
64 * @return The prefs value
65 */
66 public ConnectionProviderPrefs getPrefs() {
67 return prefs;
68 }
69
70
71 /***
72 * Get a JDBC Connection.
73 *
74 * @return a JDBC Connection
75 *
76 * @exception SQLException Description of the Exception
77 */
78 protected abstract Connection getConnection() throws SQLException;
79
80
81 /***
82 * Initialize the connection pool provider.
83 *
84 * @exception Exception Description of the Exception
85 */
86 protected abstract void init() throws Exception;
87
88
89 /***
90 * Get a "transactional" JDBC connection.
91 *
92 * @param isolationLevel the isolation level to set the connection to
93 *
94 * @return the new "transactional" connection object
95 *
96 * @throws SQLException if any error occurs
97 */
98 protected Connection getConnection(int isolationLevel)
99 throws SQLException {
100 Connection con = getConnection();
101 con.setTransactionIsolation(isolationLevel);
102 con.setAutoCommit(false);
103
104 return con;
105 }
106
107
108 /***
109 * Get the last token from the input string.
110 *
111 * @param str the string containing the token
112 * @param tokenSeparator the token separator string (i.e.: "'", ":", etc)
113 *
114 * @return the last token from the input string
115 */
116 protected String getLastToken(String str,
117 String tokenSeparator) {
118 str = str.trim();
119
120 return str.substring(str.lastIndexOf(tokenSeparator) + 1, str.length());
121 }
122 }