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