-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProxy.java
More file actions
79 lines (65 loc) · 1.9 KB
/
Proxy.java
File metadata and controls
79 lines (65 loc) · 1.9 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
package structural;
// One of the Practical cases, for database query distribution
interface ORM {
public Object select(String[] args);
public Object update(String[] args);
public Object delete(Integer id);
}
class RealMySQLEngine implements ORM{
@Override
public Object select(String[] args) {
return null;
}
@Override
public Object update(String[] args) {
return null;
}
@Override
public Object delete(Integer id) {
return null;
}
}
class ProxyMySQLEngine implements ORM {
private final String masterJDBCConfig = "172.16.11.12";
private final String slaveJDBCConfig = "172.16.11.14";
@Override
public Object select(String[] args) {
Object connection = connect("select");
// connection.query(); TODO: Do the query here
return null;
}
@Override
public Object update(String[] args) {
Object connection = connect("update");
// connection.query(); TODO: Do the query here
return null;
}
@Override
public Object delete(Integer id) {
Object connection = connect("delete");
// connection.query(); TODO: Do the query here
return null;
}
private Object connect(String type){
String JDBCConfig = DBSelection(type);
// TODO: Return the Connected object
return null;
}
private String DBSelection(String type){
String config;
switch (type){
case "select" -> config = slaveJDBCConfig;
case "update" -> config = masterJDBCConfig;
case "delete" -> config = masterJDBCConfig;
default -> config = masterJDBCConfig;
}
System.out.println(config);
return config;
}
}
public class Proxy {
public static void main(String[] args) {
ORM proxy = new ProxyMySQLEngine();
proxy.update(new String[]{"active", "1"});
}
}