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
30
31 public abstract class ConnectionSourceSkeleton extends ComponentBase implements ConnectionSource {
32
33 private Boolean overriddenSupportsGetGeneratedKeys = null;
34
35 private String user = null;
36 private String password = null;
37
38
39 private int dialectCode = UNKNOWN_DIALECT;
40 private boolean supportsGetGeneratedKeys = false;
41 private boolean supportsBatchUpdates = false;
42
43
44
45
46
47 public void discoverConnnectionProperties() {
48 Connection connection = null;
49 try {
50 connection = getConnection();
51 if (connection == null) {
52 getLogger().warn("Could not get a conneciton");
53 return;
54 }
55 DatabaseMetaData meta = connection.getMetaData();
56 Util util = new Util();
57 util.setLoggerRepository(repository);
58 if (overriddenSupportsGetGeneratedKeys != null) {
59 supportsGetGeneratedKeys = overriddenSupportsGetGeneratedKeys;
60 } else {
61 supportsGetGeneratedKeys = util.supportsGetGeneratedKeys(meta);
62 }
63 supportsBatchUpdates = util.supportsBatchUpdates(meta);
64 dialectCode = Util.discoverSQLDialect(meta);
65 } catch (SQLException se) {
66 getLogger().warn("Could not discover the dialect to use.", se);
67 } finally {
68 DBHelper.closeConnection(connection);
69 }
70 }
71
72
73
74
75 public final boolean supportsGetGeneratedKeys() {
76 return supportsGetGeneratedKeys;
77 }
78
79 public final int getSQLDialectCode() {
80 return dialectCode;
81 }
82
83
84
85
86 public final String getPassword() {
87 return password;
88 }
89
90
91
92
93
94
95 public final void setPassword(final String password) {
96 this.password = password;
97 }
98
99
100
101
102 public final String getUser() {
103 return user;
104 }
105
106
107
108
109
110
111 public final void setUser(final String username) {
112 this.user = username;
113 }
114
115
116
117
118
119
120
121
122
123 public String getOverriddenSupportsGetGeneratedKeys() {
124 return overriddenSupportsGetGeneratedKeys != null ? overriddenSupportsGetGeneratedKeys
125 .toString()
126 : null;
127 }
128
129
130
131
132
133
134
135
136
137 public void setOverriddenSupportsGetGeneratedKeys(
138 String overriddenSupportsGetGeneratedKeys) {
139 this.overriddenSupportsGetGeneratedKeys = Boolean
140 .valueOf(overriddenSupportsGetGeneratedKeys);
141 }
142
143
144
145
146 public final boolean supportsBatchUpdates() {
147 return supportsBatchUpdates;
148 }
149 }