Skip to content

Commit

Permalink
net-sf-ucanaccess-fork: Code hygiene
Browse files Browse the repository at this point in the history
  • Loading branch information
spannm committed Sep 16, 2023
1 parent 5783840 commit ab6b335
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
9 changes: 4 additions & 5 deletions src/main/java/net/ucanaccess/converters/FormatCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ private FormatCache() {
}

public static synchronized DecimalFormat getDecimalFormat(String _pattern) {
if (!CACHE.containsKey(_pattern)) {
DecimalFormat dc = new DecimalFormat(_pattern);
return CACHE.computeIfAbsent(_pattern, p -> {
DecimalFormat dc = new DecimalFormat(p);
dc.setRoundingMode(RoundingMode.HALF_UP);
CACHE.put(_pattern, dc);
}
return CACHE.get(_pattern);
return dc;
});
}

public static DecimalFormat getNoArgs() {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/net/ucanaccess/converters/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -794,14 +794,15 @@ public static boolean isNumeric(String s) {
if (".".equals(sep)) {
s = s.replaceAll(gs, "");
} else {
s = s.replaceAll("\\.", "").replace(sep, ".");
s = s.replaceAll("\\.", "")
.replace(sep, ".");
}

new BigDecimal(s);
return true;
} catch (Exception ignored) {
return false;
}
return false;
}

@FunctionType(functionName = "LEFT", namingConflict = true, argumentTypes = { AccessType.MEMO,
Expand Down
17 changes: 5 additions & 12 deletions src/main/java/net/ucanaccess/jdbc/DBReference.java
Original file line number Diff line number Diff line change
Expand Up @@ -338,23 +338,16 @@ String getId() {
}

private String key(String _pwd) throws SQLException {
Connection conn = null;
try {
if (encryptionKey == null) {
String url = "jdbc:hsqldb:mem:" + id + "_tmp";
conn = DriverManager.getConnection(url);
if (encryptionKey == null) {
String url = "jdbc:hsqldb:mem:" + id + "_tmp";
try (Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("CALL CRYPT_KEY('" + CIPHER_SPEC + "', null) ");
ResultSet rs = stmt.executeQuery("CALL CRYPT_KEY('" + CIPHER_SPEC + "', null) ")) {
rs.next();
encryptionKey = rs.getString(1);
}
return encryptionKey;
} finally {
if (conn != null) {
conn.close();
}

}
return encryptionKey;
}

private String getHsqlUrl(final Session session) throws SQLException {
Expand Down

0 comments on commit ab6b335

Please sign in to comment.