changed from file to resource input stream to read the update scripts from the jar and not from file system
This commit is contained in:
@@ -30,12 +30,10 @@ import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
@@ -70,7 +68,7 @@ public class DatabaseUpdater {
|
||||
try {
|
||||
URL url = getUpdateFileUrl(version);
|
||||
while(url != null) {
|
||||
executeSQL(url);
|
||||
executeSQL(version);
|
||||
version++;
|
||||
url = getUpdateFileUrl(version);
|
||||
}
|
||||
@@ -87,13 +85,25 @@ public class DatabaseUpdater {
|
||||
return DatabaseUpdater.class.getResource(UPDATE_FOLDER+version+SQL_EXTENSION);
|
||||
}
|
||||
|
||||
private void executeSQL(URL url) throws URISyntaxException, IOException {
|
||||
List<String> lines = Files.readAllLines(Paths.get(url.toURI()), Charset.defaultCharset());
|
||||
private void executeSQL(Integer version) throws URISyntaxException, IOException {
|
||||
|
||||
List<String> lines = new ArrayList<>();
|
||||
|
||||
try(InputStream in = DatabaseUpdater.class.getResourceAsStream(UPDATE_FOLDER + version + SQL_EXTENSION);
|
||||
Reader reader = new InputStreamReader(in, Charset.defaultCharset());
|
||||
BufferedReader bufferedReader = new BufferedReader(reader)) {
|
||||
|
||||
String line;
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
lines.add(line);
|
||||
}
|
||||
|
||||
List<String> statements = extractStatements(lines);
|
||||
for (String statement: statements) {
|
||||
jdbcTemplate.execute(statement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> extractStatements(List<String> lines) {
|
||||
List<String> statements = new ArrayList<>();
|
||||
|
||||
Reference in New Issue
Block a user