1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.log4j.db;
19
20 import org.apache.log4j.db.dialect.Util;
21 import org.apache.log4j.spi.ComponentBase;
22
23 import java.sql.Connection;
24 import java.sql.DatabaseMetaData;
25 import java.sql.SQLException;
26
27
28 /***
29 * @author Ceki Gülcü
30 */
31 public abstract class ConnectionSourceSkeleton extends ComponentBase implements ConnectionSource {
32 private String user = null;
33 private String password = null;
34
35
36 private int dialectCode = UNKNOWN_DIALECT;
37 private boolean supportsGetGeneratedKeys = false;
38 private boolean supportsBatchUpdates = false;
39
40
41 /***
42 * Learn relevant information about this connection source.
43 *
44 */
45 public void discoverConnnectionProperties() {
46 try {
47 Connection connection = getConnection();
48 if (connection == null) {
49 getLogger().warn("Could not get a conneciton");
50 return;
51 }
52 DatabaseMetaData meta = connection.getMetaData();
53 Util util = new Util();
54 util.setLoggerRepository(repository);
55 supportsGetGeneratedKeys = util.supportsGetGeneratedKeys(meta);
56 supportsBatchUpdates = util.supportsBatchUpdates(meta);
57 dialectCode = Util.discoverSQLDialect(meta);
58 } catch (SQLException se) {
59 getLogger().warn("Could not discover the dialect to use.", se);
60 }
61 }
62
63 /***
64 * Does this connection support the JDBC Connection.getGeneratedKeys method?
65 */
66 public final boolean supportsGetGeneratedKeys() {
67 return supportsGetGeneratedKeys;
68 }
69
70 public final int getSQLDialectCode() {
71 return dialectCode;
72 }
73
74 /***
75 * Get the password for this connection source.
76 */
77 public final String getPassword() {
78 return password;
79 }
80
81 /***
82 * Sets the password.
83 * @param password The password to set
84 */
85 public final void setPassword(final String password) {
86 this.password = password;
87 }
88
89 /***
90 * Get the user for this connection source.
91 */
92 public final String getUser() {
93 return user;
94 }
95
96 /***
97 * Sets the username.
98 * @param username The username to set
99 */
100 public final void setUser(final String username) {
101 this.user = username;
102 }
103
104 /***
105 * Does this connection support batch updates?
106 */
107 public final boolean supportsBatchUpdates() {
108 return supportsBatchUpdates;
109 }
110 }