1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.core.db;
15
16 import java.sql.Connection;
17 import java.sql.DatabaseMetaData;
18 import java.sql.SQLException;
19
20 import ch.qos.logback.core.db.dialect.DBUtil;
21 import ch.qos.logback.core.db.dialect.SQLDialectCode;
22 import ch.qos.logback.core.spi.ContextAwareBase;
23
24
25
26
27
28 public abstract class ConnectionSourceBase extends ContextAwareBase implements ConnectionSource {
29
30 private boolean started;
31
32 private String user = null;
33 private String password = null;
34
35
36 private SQLDialectCode dialectCode = SQLDialectCode.UNKNOWN_DIALECT;
37 private boolean supportsGetGeneratedKeys = false;
38 private boolean supportsBatchUpdates = false;
39
40
41
42
43
44
45 public void discoverConnnectionProperties() {
46 try {
47 Connection connection = getConnection();
48 if (connection == null) {
49 addWarn("Could not get a connection");
50 return;
51 }
52 DatabaseMetaData meta = connection.getMetaData();
53 DBUtil util = new DBUtil();
54 util.setContext(getContext());
55 supportsGetGeneratedKeys = util.supportsGetGeneratedKeys(meta);
56 supportsBatchUpdates = util.supportsBatchUpdates(meta);
57 dialectCode = DBUtil.discoverSQLDialect(meta);
58 addInfo("Driver name="+meta.getDriverName());
59 addInfo("Driver version="+meta.getDriverVersion());
60 addInfo("supportsGetGeneratedKeys="+supportsGetGeneratedKeys);
61
62 } catch (SQLException se) {
63 addWarn("Could not discover the dialect to use.", se);
64 }
65 }
66
67
68
69
70 public final boolean supportsGetGeneratedKeys() {
71 return supportsGetGeneratedKeys;
72 }
73
74 public final SQLDialectCode getSQLDialectCode() {
75 return dialectCode;
76 }
77
78
79
80
81 public final String getPassword() {
82 return password;
83 }
84
85
86
87
88
89 public final void setPassword(final String password) {
90 this.password = password;
91 }
92
93
94
95
96 public final String getUser() {
97 return user;
98 }
99
100
101
102
103
104 public final void setUser(final String username) {
105 this.user = username;
106 }
107
108
109
110
111 public final boolean supportsBatchUpdates() {
112 return supportsBatchUpdates;
113 }
114
115 public boolean isStarted() {
116 return started;
117 }
118
119 public void start() {
120 started = true;
121 }
122
123 public void stop() {
124 started = false;
125 }
126
127
128 }