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 java.sql.Connection;
21 import java.sql.DatabaseMetaData;
22 import java.sql.SQLException;
23
24 import org.apache.log4j.db.dialect.Util;
25 import org.apache.log4j.spi.ComponentBase;
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
48 public void discoverConnnectionProperties() {
49 Connection connection = null;
50 try {
51 connection = getConnection();
52 if (connection == null) {
53 getLogger().warn("Could not get a conneciton");
54 return;
55 }
56 DatabaseMetaData meta = connection.getMetaData();
57 Util util = new Util();
58 util.setLoggerRepository(repository);
59 if (overriddenSupportsGetGeneratedKeys != null) {
60 supportsGetGeneratedKeys = overriddenSupportsGetGeneratedKeys
61 .booleanValue();
62 } else {
63 supportsGetGeneratedKeys = util.supportsGetGeneratedKeys(meta);
64 }
65 supportsBatchUpdates = util.supportsBatchUpdates(meta);
66 dialectCode = Util.discoverSQLDialect(meta);
67 } catch (SQLException se) {
68 getLogger().warn("Could not discover the dialect to use.", se);
69 } finally {
70 DBHelper.closeConnection(connection);
71 }
72 }
73
74
75
76
77 public final boolean supportsGetGeneratedKeys() {
78 return supportsGetGeneratedKeys;
79 }
80
81 public final int getSQLDialectCode() {
82 return dialectCode;
83 }
84
85
86
87
88 public final String getPassword() {
89 return password;
90 }
91
92
93
94
95
96 public final void setPassword(final String password) {
97 this.password = password;
98 }
99
100
101
102
103 public final String getUser() {
104 return user;
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
138 public void setOverriddenSupportsGetGeneratedKeys(
139 String overriddenSupportsGetGeneratedKeys) {
140 this.overriddenSupportsGetGeneratedKeys = Boolean
141 .valueOf(overriddenSupportsGetGeneratedKeys);
142 }
143
144
145
146
147 public final boolean supportsBatchUpdates() {
148 return supportsBatchUpdates;
149 }
150 }