Skip to content

Commit

Permalink
Mark nullability of entire package org.firebirdsql.jdbc.escape
Browse files Browse the repository at this point in the history
And some other improvements
  • Loading branch information
mrotteveel committed Sep 27, 2024
1 parent 34bb2d4 commit f12ebd9
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 40 deletions.
2 changes: 0 additions & 2 deletions src/main/org/firebirdsql/jdbc/escape/FBEscapedCallParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.firebirdsql.jdbc.FBProcedureCall;
import org.firebirdsql.jdbc.FBProcedureParam;
import org.firebirdsql.util.InternalApi;
import org.jspecify.annotations.NullMarked;

import java.sql.SQLException;

Expand All @@ -34,7 +33,6 @@
* </p>
*/
@InternalApi
@NullMarked
public final class FBEscapedCallParser {

private static final int INITIAL_CAPACITY = 32;
Expand Down
31 changes: 16 additions & 15 deletions src/main/org/firebirdsql/jdbc/escape/FBEscapedFunctionHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.firebirdsql.jdbc.escape;

import org.firebirdsql.util.InternalApi;
import org.jspecify.annotations.Nullable;

import java.util.*;

Expand All @@ -35,7 +36,7 @@ public final class FBEscapedFunctionHelper {
* This map contains mapping between JDBC function names and Firebird ones.
* Mapping to null means: execute as is (might fail if there is no built-in or UDF)
*/
private static final Map<String, SQLFunction> FUNCTION_MAP;
private static final Map<String, @Nullable SQLFunction> FUNCTION_MAP;

/**
* Supported numeric functions
Expand All @@ -58,24 +59,24 @@ public final class FBEscapedFunctionHelper {
private static final Set<String> SUPPORTED_SYSTEM_FUNCTIONS;

static {
final Map<String, SQLFunction> functionMap = new HashMap<>(71);
final Map<String, @Nullable SQLFunction> functionMap = new HashMap<>(71);
/* Numeric Functions */
Map<String, SQLFunction> numericFunctionMap = getNumericFunctions();
Map<String, @Nullable SQLFunction> numericFunctionMap = getNumericFunctions();
SUPPORTED_NUMERIC_FUNCTIONS = Set.copyOf(numericFunctionMap.keySet());
functionMap.putAll(numericFunctionMap);

/* String Functions */
Map<String, SQLFunction> stringFunctionMap = getStringFunctions();
Map<String, @Nullable SQLFunction> stringFunctionMap = getStringFunctions();
SUPPORTED_STRING_FUNCTIONS = Set.copyOf(stringFunctionMap.keySet());
functionMap.putAll(stringFunctionMap);

/* Time and Date Functions */
Map<String, SQLFunction> timeDateFunctionMap = getTimeDateFunctions();
Map<String, @Nullable SQLFunction> timeDateFunctionMap = getTimeDateFunctions();
SUPPORTED_TIME_DATE_FUNCTIONS = Set.copyOf(timeDateFunctionMap.keySet());
functionMap.putAll(timeDateFunctionMap);

/* System Functions */
Map<String, SQLFunction> systemFunctionMap = getSystemFunctions();
Map<String, @Nullable SQLFunction> systemFunctionMap = getSystemFunctions();
SUPPORTED_SYSTEM_FUNCTIONS = Set.copyOf(systemFunctionMap.keySet());
functionMap.putAll(systemFunctionMap);

Expand Down Expand Up @@ -103,8 +104,8 @@ private FBEscapedFunctionHelper() {
// no instances
}

private static Map<String, SQLFunction> getNumericFunctions() {
Map<String, SQLFunction> functionMap = new HashMap<>(32);
private static Map<String, @Nullable SQLFunction> getNumericFunctions() {
Map<String, @Nullable SQLFunction> functionMap = new HashMap<>(32);
functionMap.put("ABS", null);
functionMap.put("ACOS", null);
functionMap.put("ASIN", null);
Expand Down Expand Up @@ -132,8 +133,8 @@ private static Map<String, SQLFunction> getNumericFunctions() {
return functionMap;
}

private static Map<String, SQLFunction> getStringFunctions() {
Map<String, SQLFunction> functionMap = new HashMap<>(32);
private static Map<String, @Nullable SQLFunction> getStringFunctions() {
Map<String, @Nullable SQLFunction> functionMap = new HashMap<>(32);
functionMap.put("ASCII", new PatternSQLFunction("ASCII_VAL({0})"));
functionMap.put("CHAR", new PatternSQLFunction("ASCII_CHAR({0})"));
CharacterLengthFunction characterLengthFunction = new CharacterLengthFunction();
Expand Down Expand Up @@ -163,8 +164,8 @@ private static Map<String, SQLFunction> getStringFunctions() {
return functionMap;
}

private static Map<String, SQLFunction> getTimeDateFunctions() {
Map<String, SQLFunction> functionMap = new HashMap<>(32);
private static Map<String, @Nullable SQLFunction> getTimeDateFunctions() {
Map<String, @Nullable SQLFunction> functionMap = new HashMap<>(32);
ConstantSQLFunction currentDate = new ConstantSQLFunction("CURRENT_DATE");
functionMap.put("CURRENT_DATE", currentDate);
ConstantSQLFunction currentTime = new ConstantSQLFunction("CURRENT_TIME");
Expand Down Expand Up @@ -212,8 +213,8 @@ private static Map<String, SQLFunction> getTimeDateFunctions() {
return functionMap;
}

private static Map<String, SQLFunction> getSystemFunctions() {
Map<String, SQLFunction> functionMap = new HashMap<>(4, 1.0f);
private static Map<String, @Nullable SQLFunction> getSystemFunctions() {
Map<String, @Nullable SQLFunction> functionMap = new HashMap<>(4, 1.0f);
functionMap.put("DATABASE", new ConstantSQLFunction("RDB$GET_CONTEXT('SYSTEM', 'DB_NAME')"));
functionMap.put("IFNULL", new PatternSQLFunction("COALESCE({0}, {1})"));
functionMap.put("USER", new ConstantSQLFunction("USER"));
Expand Down Expand Up @@ -368,7 +369,7 @@ public static List<String> parseArguments(String functionCall) throws FBSQLParse
* @throws FBSQLParseException
* if escaped function call has incorrect syntax.
*/
public static String convertTemplate(final String functionCall) throws FBSQLParseException {
public static @Nullable String convertTemplate(final String functionCall) throws FBSQLParseException {
final String functionName = parseFunction(functionCall).toUpperCase(Locale.ROOT);
final String[] params = parseArguments(functionCall).toArray(new String[0]);

Expand Down
1 change: 0 additions & 1 deletion src/main/org/firebirdsql/jdbc/escape/FBEscapedParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.sql.SQLException;
import java.text.BreakIterator;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Locale;
import java.util.regex.Pattern;

Expand Down
2 changes: 2 additions & 0 deletions src/main/org/firebirdsql/jdbc/escape/FBSQLParseException.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.firebirdsql.jdbc.SQLStateConstants;

import java.io.Serial;
import java.sql.SQLSyntaxErrorException;

/**
Expand All @@ -30,6 +31,7 @@
*/
public class FBSQLParseException extends SQLSyntaxErrorException {

@Serial
private static final long serialVersionUID = 4217078230221445003L;

public FBSQLParseException(String msg) {
Expand Down
32 changes: 11 additions & 21 deletions src/main/org/firebirdsql/jdbc/escape/IntervalMapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,18 @@ private IntervalMapping() {
* @return Firebird interval name, or original value if unsupported or unknown
*/
static String getFirebirdInterval(String jdbcIntervalName) {
switch (jdbcIntervalName) {
case "SQL_TSI_SECOND":
return "SECOND";
case "SQL_TSI_MINUTE":
return "MINUTE";
case "SQL_TSI_HOUR":
return "HOUR";
case "SQL_TSI_DAY":
return "DAY";
case "SQL_TSI_WEEK":
return "WEEK";
case "SQL_TSI_MONTH":
return "MONTH";
case "SQL_TSI_QUARTER":
return switch (jdbcIntervalName) {
case "SQL_TSI_SECOND" -> "SECOND";
case "SQL_TSI_MINUTE" -> "MINUTE";
case "SQL_TSI_HOUR" -> "HOUR";
case "SQL_TSI_DAY" -> "DAY";
case "SQL_TSI_WEEK" -> "WEEK";
case "SQL_TSI_MONTH" -> "MONTH";
// NOTE QUARTER not supported by Firebird
return "QUARTER";
case "SQL_TSI_YEAR":
return "YEAR";
case "SQL_TSI_FRAC_SECOND":
case "SQL_TSI_QUARTER" -> "QUARTER";
case "SQL_TSI_YEAR" -> "YEAR";
// explicitly not supported, passing as-is
default:
return jdbcIntervalName;
}
default -> jdbcIntervalName;
};
}
}
4 changes: 3 additions & 1 deletion src/main/org/firebirdsql/jdbc/escape/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* Implementation of JDBC escapes for the Jaybird Firebird JDBC driver.
*/
@InternalApi
@NullMarked
package org.firebirdsql.jdbc.escape;

import org.firebirdsql.util.InternalApi;
import org.firebirdsql.util.InternalApi;
import org.jspecify.annotations.NullMarked;

0 comments on commit f12ebd9

Please sign in to comment.