-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMySQLDriverManagerDataSource.java
More file actions
80 lines (66 loc) · 1.82 KB
/
MySQLDriverManagerDataSource.java
File metadata and controls
80 lines (66 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package com.github.collinalpert.java2db.database;
import javax.sql.DataSource;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Logger;
/**
* {@link DataSource} implementation hard-coded to support only MySQL databases.
* Obtains connections directly from {@link java.sql.DriverManager}
*
* @author Tyler Sharpe
*/
public class MySQLDriverManagerDataSource implements DataSource {
static {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
} catch (ClassNotFoundException e) {
throw new ExceptionInInitializerError(e);
}
}
private final ConnectionConfiguration configuration;
public MySQLDriverManagerDataSource(ConnectionConfiguration configuration) {
this.configuration = configuration;
}
@Override
public Connection getConnection() throws SQLException {
return DriverManager.getConnection(
String.format("jdbc:mysql://%s:%d/%s?rewriteBatchedStatements=true", configuration.getHost(), configuration.getPort(), configuration.getDatabase()),
configuration.getUsername(),
configuration.getPassword()
);
}
@Override
public Connection getConnection(String username, String password) {
throw new UnsupportedOperationException();
}
@Override
public PrintWriter getLogWriter() {
return null;
}
@Override
public void setLogWriter(PrintWriter out) {
throw new UnsupportedOperationException();
}
@Override
public void setLoginTimeout(int seconds) {
throw new UnsupportedOperationException();
}
@Override
public int getLoginTimeout() {
return configuration.getTimeout();
}
@Override
public Logger getParentLogger() {
return null;
}
@Override
public <T> T unwrap(Class<T> interfaceType) {
return null;
}
@Override
public boolean isWrapperFor(Class<?> interfaceType) {
return false;
}
}