Skip to content

Commit

Permalink
Small adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
Willena committed Aug 15, 2024
1 parent 4471595 commit d321f92
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
22 changes: 7 additions & 15 deletions src/main/java/org/sqlite/SQLiteConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,7 @@ protected void applyRemainingPragmas(Connection conn, HashSet<String> pragmaPara
orderedPragmaTable.add(Pragma.PAGE_SIZE.getPragmaName());
orderedPragmaTable.add(Pragma.AUTO_VACUUM.getPragmaName());
orderedPragmaTable.add(Pragma.ENCODING.getPragmaName());
for (Object item : pragmaTable.keySet()) {
if (!orderedPragmaTable.contains(item)) {
orderedPragmaTable.add(item);
}
}
orderedPragmaTable.addAll(pragmaTable.keySet());
try (Statement stat = conn.createStatement()) {
for (Object each : orderedPragmaTable) {
String key = each.toString();
Expand Down Expand Up @@ -411,7 +407,7 @@ public void setExplicitReadOnly(boolean readOnly) {
this.explicitReadOnly = readOnly;
}

public static enum Pragma {
public enum Pragma {

// Parameters requiring SQLite3 API invocation
OPEN_MODE("open_mode", "Database open-mode flag", null),
Expand Down Expand Up @@ -669,23 +665,19 @@ private static String[] toStringArray(PragmaValue[] list) {
return result;
}

static final Set<String> pragmaSet = new TreeSet<>();
static final Set<String> pragmaNameSet = new TreeSet<>();

static {
for (SQLiteConfig.Pragma pragma : SQLiteConfig.Pragma.values()) {
pragmaSet.add(pragma.pragmaName);
pragmaNameSet.add(pragma.pragmaName);
}
}

public final String getPragmaName() {
return pragmaName;
}

public static Set<String> pragmaNameSet() {
return Arrays.stream(Pragma.class.getEnumConstants())
.map(p -> p.pragmaName)
.collect(Collectors.toSet());
}

}

/**
Expand Down Expand Up @@ -835,8 +827,8 @@ public void enableEmptyResultCallBacks(boolean enable) {
*
* @author leo
*/
private static interface PragmaValue {
public String getValue();
private interface PragmaValue {
String getValue();
}

public enum Encoding implements PragmaValue {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/sqlite/SQLiteConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ protected static String extractPragmasFromFilename(String url, String filename,
int nonPragmaCount = 0;
String[] parameters = filename.substring(parameterDelimiter + 1).split("&");

Set<String> pragmaSet = SQLiteConfig.Pragma.pragmaNameSet();
Set<String> pragmaSet = SQLiteConfig.Pragma.pragmaNameSet;

for (int i = 0; i < parameters.length; i++) {
// process parameters in reverse-order, last specified pragma value wins
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/sqlite/SQLiteConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ public void pragmaSet() {
expectedPragmaSet.add(v.pragmaName);
}

assertThat(SQLiteConfig.pragmaSet).isEqualTo(expectedPragmaSet);
assertThat(Pragma.pragmaNameSet).isEqualTo(expectedPragmaSet);
}
}

0 comments on commit d321f92

Please sign in to comment.