Skip to content

Commit 19b9f27

Browse files
committed
Abstract connection test service
1 parent 7674742 commit 19b9f27

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package root.javafx.Service;
2+
3+
import javafx.concurrent.Service;
4+
5+
public abstract class ConnectionTestService extends Service<Boolean> {
6+
7+
public abstract void alertSucceed();
8+
9+
public abstract void alertFailed();
10+
}

src/main/java/root/javafx/Service/DatabaseConnectService.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package root.javafx.Service;
22

3-
import javafx.concurrent.Service;
43
import javafx.concurrent.Task;
4+
import javafx.scene.control.Alert.AlertType;
55
import root.common.database.implement.JdbcDatabase;
66
import root.core.domain.JdbcConnectionInfo;
7+
import root.utils.AlertUtils;
78

8-
public class DatabaseConnectService extends Service<Boolean> {
9+
public class DatabaseConnectService extends ConnectionTestService {
910

1011
public static final String SUCCESS_MSG = "데이터베이스가 성공적으로 연동되었습니다.\n URL: %s \n Driver: %s";
1112
public static final String FAIL_MSG = "데이터베이스 연동에 실패했습니다.\n URL: %s \n Driver: %s";
@@ -32,4 +33,16 @@ protected Boolean call() throws Exception {
3233
}
3334
};
3435
}
36+
37+
@Override
38+
public void alertSucceed() {
39+
AlertUtils.showAlert(AlertType.INFORMATION, "DB 연동테스트",
40+
String.format(DatabaseConnectService.SUCCESS_MSG, jdbc.getJdbcUrl(), jdbc.getJdbcDriver()));
41+
}
42+
43+
@Override
44+
public void alertFailed() {
45+
AlertUtils.showAlert(AlertType.ERROR, "DB 연동테스트",
46+
String.format(DatabaseConnectService.FAIL_MSG, jdbc.getJdbcUrl(), jdbc.getJdbcDriver()));
47+
}
3548
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package root.javafx.Service;
2+
3+
import javafx.concurrent.Task;
4+
import root.core.domain.JschConnectionInfo;
5+
6+
public class ServerConnectService extends ConnectionTestService {
7+
8+
public static final String SUCCESS_MSG = "원격서버가 성공적으로 연동되었습니다.";
9+
public static final String FAIL_MSG = "원격서버 연동에 실패했습니다.";
10+
11+
private JschConnectionInfo jsch;
12+
13+
public ServerConnectService(JschConnectionInfo jsch) {
14+
this.jsch = jsch;
15+
}
16+
17+
@Override
18+
protected Task<Boolean> createTask() {
19+
return new Task<Boolean>() {
20+
@Override
21+
protected Boolean call() throws Exception {
22+
return true;
23+
}
24+
};
25+
}
26+
27+
@Override
28+
public void alertSucceed() {
29+
// TODO Auto-generated method stub
30+
31+
}
32+
33+
@Override
34+
public void alertFailed() {
35+
// TODO Auto-generated method stub
36+
37+
}
38+
}

0 commit comments

Comments
 (0)