Skip to content

Commit 68b0269

Browse files
ddamkeddamke
authored andcommitted
exported sql files now can be imported again
1 parent cef9fe4 commit 68b0269

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/main/java/de/doubleslash/keeptime/view/SettingsController.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@
1818

1919
import java.io.File;
2020
import java.io.IOException;
21+
import java.net.URL;
22+
import java.nio.charset.Charset;
2123
import java.nio.file.Paths;
2224
import java.sql.SQLException;
2325

26+
import org.h2.tools.RunScript;
2427
import org.h2.tools.Script;
2528
import org.slf4j.Logger;
2629
import org.slf4j.LoggerFactory;
@@ -101,6 +104,9 @@ public class SettingsController {
101104
@FXML
102105
private Button exportButton;
103106

107+
@FXML
108+
private Button importButton;
109+
104110
@FXML
105111
private Button aboutButton;
106112

@@ -150,6 +156,7 @@ private void initialize() {
150156
}
151157

152158
initExportButton();
159+
initImportButton();
153160

154161
LOG.debug("saveButton.setOnAction");
155162
saveButton.setOnAction(ae -> {
@@ -232,6 +239,31 @@ private void initialize() {
232239
aboutStage.show();
233240
});
234241
}
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+
}
235267

236268
private void initExportButton() {
237269
LOG.debug("Initialize exportButton.");
@@ -259,6 +291,8 @@ private void initExportButton() {
259291
Script.process(url, username, password, fileToSave.getAbsolutePath(), "DROP", "");
260292
LOG.info("Export done.");
261293

294+
295+
262296
Alert informationDialog = new Alert(AlertType.INFORMATION);
263297
informationDialog.setTitle("Export done");
264298
informationDialog.setHeaderText("The current data was exported.");

src/main/resources/layouts/settings.fxml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,11 @@
302302
<Font name="Open Sans Regular" size="12.0" />
303303
</font>
304304
</Button>
305+
<Button fx:id="importButton" mnemonicParsing="false" text="Import">
306+
<font>
307+
<Font name="Open Sans Regular" size="12.0" />
308+
</font>
309+
</Button>
305310
<Button fx:id="aboutButton" mnemonicParsing="false" text="About">
306311
<font>
307312
<Font name="Open Sans Regular" size="12.0" />

0 commit comments

Comments
 (0)