|
15 | 15 | import javafx.fxml.FXML; |
16 | 16 | import javafx.fxml.FXMLLoader; |
17 | 17 | import javafx.scene.Node; |
| 18 | +import javafx.scene.control.Alert.AlertType; |
18 | 19 | import javafx.scene.control.Label; |
19 | 20 | import javafx.scene.layout.AnchorPane; |
20 | 21 | import javafx.scene.layout.StackPane; |
|
25 | 26 | import lombok.Data; |
26 | 27 | import root.core.repository.constracts.PropertyRepository; |
27 | 28 | import root.core.repository.implement.PropertyRepositoryImpl; |
| 29 | +import root.javafx.Service.ConnectionTestService; |
| 30 | +import root.utils.AlertUtils; |
28 | 31 |
|
29 | 32 | public class ConnectionInfoVBox extends VBox { |
30 | 33 |
|
@@ -101,69 +104,40 @@ public void addConnectionInfoAP(int type, Node connInfoAP) { |
101 | 104 | } |
102 | 105 | } |
103 | 106 |
|
104 | | - // TODO 다형성을 이용해 클래스 타입체크 제거하기 |
105 | 107 | public void saveConnInfoSettings(String configFilePath) { |
106 | 108 | connInfoControl.save(configFilePath, this.connInfoAPMap.getActiveAPs().values()); |
107 | | - /* |
108 | | - if (childAPClazz == DBConnectionInfoAnchorPane.class) { |
109 | | - Map<String, JdbcConnectionInfo> config = new HashMap<>(); |
110 | | -
|
111 | | - for (StatefulAP childAP : this.connInfoAPMap.getActiveAPs().values()) { |
112 | | - DBConnectionInfoAnchorPane dbConnAP = (DBConnectionInfoAnchorPane) childAP.getAp(); |
113 | | - JdbcConnectionInfo jdbc = dbConnAP.getInputValues(); |
114 | | - config.put(jdbc.getJdbcDBName().toUpperCase(), jdbc); |
115 | | - } |
116 | | - propertyRepository.saveDBConnectionInfo(configFilePath, config); |
117 | | - } else { |
118 | | - Map<String, JschConnectionInfo> config = new HashMap<>(); |
119 | | -
|
120 | | - for (StatefulAP childAP : this.connInfoAPMap.getActiveAPs().values()) { |
121 | | - ServerConnectionInfoAnchorPane serverConnAP = (ServerConnectionInfoAnchorPane) childAP.getAp(); |
122 | | - JschConnectionInfo jsch = serverConnAP.getInputValues(); |
123 | | - config.put(jsch.getServerName().toUpperCase(), jsch); |
124 | | - } |
125 | | - propertyRepository.saveServerConnectionInfo(configFilePath, config); |
126 | | - } |
127 | | - */ |
128 | 109 | } |
129 | 110 |
|
130 | 111 | /* Button Click Listener */ |
131 | 112 |
|
132 | 113 | public void testConnection(ActionEvent e) { |
133 | | - connInfoControl.test(); |
134 | | - /* |
135 | | - if (childAPClazz == DBConnectionInfoAnchorPane.class) { |
| 114 | + |
| 115 | + // 현재 AP에 작성된 접속정보를 이용해 연결 테스트 |
| 116 | + ConnectionInfoAP curAP = connInfoAPMap.get(connInfoIdx).getAp(); |
| 117 | + |
| 118 | + ConnectionTestService testService = connInfoControl.getConnectionTestService(curAP); |
| 119 | + |
| 120 | + if (testService != null) { |
136 | 121 | // 아이콘 변경 |
137 | 122 | setConnectionBtnIcon(4); |
138 | 123 |
|
139 | | - AnchorPane curAP = connInfoAPMap.get(connInfoIdx).getAp(); |
140 | | -
|
141 | | - String jdbcUrl = ((TextField) curAP.lookup("#urlTF")).getText(); |
142 | | - String jdbcId = ((TextField) curAP.lookup("#userTF")).getText(); |
143 | | - String jdbcPw = ((PasswordField) curAP.lookup("#passwordPF")).getText(); |
144 | | -
|
145 | | - // TODO JdbcDriver, Validation Query 하드코딩 변경 - DBMS에 따라 다르게 해야 함 |
146 | | - JdbcConnectionInfo jdbc = new JdbcConnectionInfo("oracle.jdbc.driver.OracleDriver", jdbcUrl, jdbcId, jdbcPw, |
147 | | - "SELECT 1 FROM DUAL", 1); |
148 | | -
|
149 | | - DatabaseConnectService dbConnService = new DatabaseConnectService(jdbc); |
150 | | - dbConnService.setOnSucceeded(s -> { |
151 | | - AlertUtils.showAlert(AlertType.INFORMATION, "DB 연동테스트", |
152 | | - String.format(DatabaseConnectService.SUCCESS_MSG, jdbc.getJdbcUrl(), jdbc.getJdbcDriver())); |
| 124 | + // 성공시 콜백 이벤트 설정 |
| 125 | + testService.setOnSucceeded(s -> { |
| 126 | + testService.alertSucceed(); |
153 | 127 | setConnectionBtnIcon(2); |
154 | 128 | }); |
155 | | -
|
156 | | - dbConnService.setOnFailed(f -> { |
157 | | - AlertUtils.showAlert(AlertType.ERROR, "DB 연동테스트", |
158 | | - String.format(DatabaseConnectService.FAIL_MSG, jdbc.getJdbcUrl(), jdbc.getJdbcDriver())); |
| 129 | + |
| 130 | + // 실패시 콜백 이벤트 설정 |
| 131 | + testService.setOnFailed(f -> { |
| 132 | + testService.alertFailed(); |
159 | 133 | setConnectionBtnIcon(3); |
160 | 134 | }); |
161 | 135 |
|
162 | | - dbConnService.start(); |
163 | | - } else if (childAPClazz == ServerConnectionInfoAnchorPane.class) { |
164 | | -
|
| 136 | + // 연결테스트 시작 |
| 137 | + testService.start(); |
| 138 | + } else { |
| 139 | + AlertUtils.showAlert(AlertType.ERROR, "연결 테스트", "연결 테스트를 수행하기 위한 정보가 부족합니다.\n접속정보를 입력해주세요."); |
165 | 140 | } |
166 | | - */ |
167 | 141 | } |
168 | 142 |
|
169 | 143 | public void addNewConnInfo(ActionEvent e) { |
|
0 commit comments