Skip to content

Commit d7c3f29

Browse files
author
chengyitian
committed
AJ-825: optimize internal logic of connected();
1 parent 3af0980 commit d7c3f29

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/com/xxdb/DBConnection.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ private enum ExceptionType{
6666
ET_NOINITIALIZED(4),
6767
ET_NOTLEADER(5),
6868
ET_READTIMEDOUT(6),
69-
ET_NORESPONSEHEADER(7);
69+
ET_NORESPONSEHEADER(7),
70+
ET_LOGINREQUIRED(8);
7071

7172
public int value;
7273
ExceptionType(int value){
@@ -1113,6 +1114,9 @@ public ExceptionType parseException(String msg, Node node) {
11131114
} else if (msg.contains("Failed to read response header from the socket with IO error null")) {
11141115
conn_.getNode(node);
11151116
return ExceptionType.ET_NORESPONSEHEADER;
1117+
} else if (msg.contains("Login is required for script execution with client authentication enabled")) {
1118+
conn_.getNode(node);
1119+
return ExceptionType.ET_LOGINREQUIRED;
11161120
} else {
11171121
node.hostName = "";
11181122
node.port = 0;
@@ -1131,8 +1135,8 @@ public void parseIpPort(String ipport, Node node){
11311135

11321136
public boolean connected(){
11331137
try {
1134-
BasicInt ret= (BasicInt) conn_.run("1+1",0);
1135-
return !ret.isNull() && (ret.getInt() == 2);
1138+
conn_.run("version", new ArrayList<>(), 0);
1139+
return true;
11361140
}catch (Exception e){
11371141
return false;
11381142
}
@@ -1253,7 +1257,7 @@ public Entity run(String script, ProgressListener listener, int priority, int pa
12531257
ExceptionType type = parseException(e.getMessage(), node);
12541258
if (type == ExceptionType.ET_IGNORE)
12551259
return new Void();
1256-
else if (type == ExceptionType.ET_UNKNOW)
1260+
else if (type == ExceptionType.ET_UNKNOW || type == ExceptionType.ET_LOGINREQUIRED)
12571261
throw e;
12581262
else if (type == ExceptionType.ET_READTIMEDOUT)
12591263
cancelConsoleJob(enableSeqNo, currentSeqNo, e);

0 commit comments

Comments
 (0)