forked from utPLSQL/utPLSQL-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnectionConfig.java
More file actions
54 lines (44 loc) · 1.43 KB
/
ConnectionConfig.java
File metadata and controls
54 lines (44 loc) · 1.43 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
package org.utplsql.cli;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ConnectionConfig {
private final String user;
private final String password;
private final String connect;
public ConnectionConfig(String connectString) {
Matcher m = Pattern.compile("^(\".+\"|[^/]+)/(\".+\"|[^@]+)@(.*)$").matcher(connectString);
if (m.find()) {
user = stripEnclosingQuotes(m.group(1));
password = stripEnclosingQuotes(m.group(2));
connect = m.group(3);
} else {
throw new IllegalArgumentException("Not a valid connectString: '" + connectString + "'");
}
}
private String stripEnclosingQuotes(String value) {
if (value.length() > 1
&& value.startsWith("\"")
&& value.endsWith("\"")) {
return value.substring(1, value.length() - 1);
} else {
return value;
}
}
public String getConnect() {
return connect;
}
public String getUser() {
return user;
}
public String getPassword() {
return password;
}
public String getConnectString() {
return user + "/" + password + "@" + connect;
}
public boolean isSysDba() {
return user != null &&
(user.toLowerCase().endsWith(" as sysdba")
|| user.toLowerCase().endsWith(" as sysoper"));
}
}