Skip to content

Commit

Permalink
static lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
ptiurin committed Jul 1, 2024
1 parent 855f4c7 commit 79b434d
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/main/java/com/firebolt/jdbc/exception/SQLState.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.firebolt.jdbc.exception;

import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;

// https://en.wikipedia.org/wiki/SQLSTATE
public enum SQLState {
SUCCESS("00000"),
Expand Down Expand Up @@ -107,6 +111,11 @@ public enum SQLState {
STATE_NOT_DEFINED(null);

private final String code;
private static final Map<String, SQLState> codeMap = new HashMap<>();
static {
for (SQLState s : EnumSet.allOf(SQLState.class))
codeMap.put(s.getCode(), s);
}

SQLState(String code) {
this.code = code;
Expand All @@ -117,11 +126,6 @@ public String getCode() {
}

public static SQLState fromCode(String sqlState) {
for (SQLState state : SQLState.values()) {
if (state.code != null && state.code.equals(sqlState)) {
return state;
}
}
return STATE_NOT_DEFINED;
return codeMap.get(sqlState);
}
}

0 comments on commit 79b434d

Please sign in to comment.