Se limpio minimamente el modelo de version

This commit is contained in:
Daniel Cortes
2019-03-07 19:30:10 -03:00
parent cd6dbc0709
commit 2dbf62f9b9
2 changed files with 19 additions and 26 deletions

BIN
dist/Programa Caja.jar vendored

Binary file not shown.

View File

@@ -28,11 +28,9 @@ public class SQLiteVersionDAO extends VersionDAO {
private boolean tableVersionsExists() { private boolean tableVersionsExists() {
try { try {
DatabaseMetaData md = this.connectionHolder.getConnection().getMetaData(); DatabaseMetaData md = this.connectionHolder.getConnection().getMetaData();
ResultSet rs = md.getTables(null, null, "version", null); try(ResultSet rs = md.getTables(null, null, "version", null)) {
boolean exists = rs.next(); return rs.next();
rs.close(); }
return exists;
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
return false; return false;
@@ -41,17 +39,14 @@ public class SQLiteVersionDAO extends VersionDAO {
private int getCurrentVersion() { private int getCurrentVersion() {
if (tableVersionsExists()) { if (tableVersionsExists()) {
try (Connection conn = this.connectionHolder.getConnection()) {
String query = "SELECT version FROM version LIMIT 1"; String query = "SELECT version FROM version LIMIT 1";
PreparedStatement ps = conn.prepareStatement(query); try (Connection conn = this.connectionHolder.getConnection()) {
ResultSet rs = ps.executeQuery(); try (PreparedStatement ps = conn.prepareStatement(query)) {
try (ResultSet rs = ps.executeQuery()) {
rs.next(); rs.next();
int version = rs.getInt(1); return rs.getInt(1);
}
rs.close(); }
ps.close();
return version;
} catch (SQLException e) { } catch (SQLException e) {
LOGGER.log(Level.SEVERE, e.toString(), e); LOGGER.log(Level.SEVERE, e.toString(), e);
} }
@@ -77,17 +72,16 @@ public class SQLiteVersionDAO extends VersionDAO {
private void executeVersionScript(int version) { private void executeVersionScript(int version) {
try (Connection conn = this.connectionHolder.getConnection()) { try (Connection conn = this.connectionHolder.getConnection()) {
Statement statement = conn.createStatement(); try(Statement statement = conn.createStatement()) {
InputStream inputStream = getVersionScript(version); InputStream inputStream = getVersionScript(version);
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); try(BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
String line; String line;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
statement.addBatch(line); statement.addBatch(line);
} }
reader.close(); }
statement.executeBatch(); statement.executeBatch();
statement.close(); }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
LOGGER.log(Level.SEVERE, e.toString(), e); LOGGER.log(Level.SEVERE, e.toString(), e);
@@ -104,5 +98,4 @@ public class SQLiteVersionDAO extends VersionDAO {
executeVersionScript(currentVersion); executeVersionScript(currentVersion);
} }
} }
} }