|
18 | 18 |
|
19 | 19 | import java.io.File; |
20 | 20 | import java.io.IOException; |
| 21 | +import java.net.URL; |
| 22 | +import java.nio.charset.Charset; |
21 | 23 | import java.nio.file.Paths; |
22 | 24 | import java.sql.SQLException; |
23 | 25 |
|
| 26 | +import org.h2.tools.RunScript; |
24 | 27 | import org.h2.tools.Script; |
25 | 28 | import org.slf4j.Logger; |
26 | 29 | import org.slf4j.LoggerFactory; |
@@ -101,6 +104,9 @@ public class SettingsController { |
101 | 104 | @FXML |
102 | 105 | private Button exportButton; |
103 | 106 |
|
| 107 | + @FXML |
| 108 | + private Button importButton; |
| 109 | + |
104 | 110 | @FXML |
105 | 111 | private Button aboutButton; |
106 | 112 |
|
@@ -150,6 +156,7 @@ private void initialize() { |
150 | 156 | } |
151 | 157 |
|
152 | 158 | initExportButton(); |
| 159 | + initImportButton(); |
153 | 160 |
|
154 | 161 | LOG.debug("saveButton.setOnAction"); |
155 | 162 | saveButton.setOnAction(ae -> { |
@@ -232,6 +239,31 @@ private void initialize() { |
232 | 239 | aboutStage.show(); |
233 | 240 | }); |
234 | 241 | } |
| 242 | + private void initImportButton(){ |
| 243 | + LOG.debug("Initialize importButton."); |
| 244 | + importButton.setOnAction(event ->{ |
| 245 | + |
| 246 | + try { |
| 247 | + final FileChooser fileChooser = new FileChooser(); |
| 248 | + fileChooser.setTitle("Open Exported SQl Script"); |
| 249 | + File file = fileChooser.showOpenDialog(thisStage); |
| 250 | + |
| 251 | + LOG.info(file.toString()); |
| 252 | + |
| 253 | + final String url = applicationProperties.getSpringDataSourceUrl(); |
| 254 | + final String username = applicationProperties.getSpringDataSourceUserName(); |
| 255 | + final String password = applicationProperties.getSpringDataSourcePassword(); |
| 256 | + ; |
| 257 | + RunScript.execute(url, username, password, file.toString(), Charset.defaultCharset(), true); |
| 258 | + |
| 259 | + |
| 260 | + } catch (SQLException e) { |
| 261 | + throw new RuntimeException(e); |
| 262 | + } |
| 263 | + |
| 264 | + }); |
| 265 | + |
| 266 | + } |
235 | 267 |
|
236 | 268 | private void initExportButton() { |
237 | 269 | LOG.debug("Initialize exportButton."); |
@@ -259,6 +291,8 @@ private void initExportButton() { |
259 | 291 | Script.process(url, username, password, fileToSave.getAbsolutePath(), "DROP", ""); |
260 | 292 | LOG.info("Export done."); |
261 | 293 |
|
| 294 | + |
| 295 | + |
262 | 296 | Alert informationDialog = new Alert(AlertType.INFORMATION); |
263 | 297 | informationDialog.setTitle("Export done"); |
264 | 298 | informationDialog.setHeaderText("The current data was exported."); |
|
0 commit comments