Class SQLUtilities
java.lang.Object
org.apache.sis.util.Static
org.apache.sis.internal.metadata.sql.SQLUtilities
Utilities relative to the SQL language.
DO NOT USE
This class is for Apache SIS internal usage and may change in any future version.
- Since:
- 0.7
- Version:
- 1.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
appendIfNotRedundant
(StringBuilder buffer, char wildcard) Appends the given wildcard character to the given buffer if the buffer does not ends with'%'
.static String
Returns the given pattern with'_'
and'%'
characters escaped by the database-specific escape characters.static boolean
filterFalsePositive
(String expected, String actual) Workaround for what seems to be a Derby 10.11 bug, which seems to behave as if the LIKE pattern had a trailing % wildcard.static String
getSimplifiedURL
(DatabaseMetaData metadata) Returns a simplified form of the URL (truncated before the first?
or;
character), for logging or informative purpose only.static Boolean
parseBoolean
(String text) Converts the given string to a boolean value, or returnsnull
if the value is unrecognized.static void
toLikePattern
(String identifier, int i, int end, boolean allowSuffix, boolean toLower, StringBuilder buffer) Returns a SQL LIKE pattern for the given identifier.
-
Constructor Details
-
SQLUtilities
private SQLUtilities()Do not allow instantiation of this class.
-
-
Method Details
-
getSimplifiedURL
Returns a simplified form of the URL (truncated before the first?
or;
character), for logging or informative purpose only.- Parameters:
metadata
- the metadata of the database.- Returns:
- a simplified version of database URL.
- Throws:
SQLException
- if an error occurred while fetching the URL.
-
parseBoolean
Converts the given string to a boolean value, or returnsnull
if the value is unrecognized. This method recognizes "true", "false", "yes", "no", "t", "f", 0 and 1 (case insensitive). An empty string is interpreted asnull
.- Parameters:
text
- the characters to convert to a boolean value, ornull
.- Returns:
- the given characters as a boolean value, or
null
if the given text was null or empty. - Throws:
SQLDataException
- if the given text is non-null and non-empty but not recognized.SQLException
- Since:
- 0.8
- See Also:
-
escape
Returns the given pattern with'_'
and'%'
characters escaped by the database-specific escape characters. This method should be invoked for escaping the values of allDatabaseMetaData
method arguments with a name ending by"Pattern"
. Note that not all arguments are pattern; please checks carefullyDatabaseMetaData
javadoc for each method.Example: if a method expects an argument namedtableNamePattern
, then that argument value should be escaped. But if the argument name is onlytableName
, then the value should not be escaped.- Parameters:
pattern
- the pattern to escape, ornull
if none.escape
- value ofDatabaseMetaData.getSearchStringEscape()
.- Returns:
- escaped strings, or the same instance than
pattern
if there are no characters to escape.
-
toLikePattern
public static void toLikePattern(String identifier, int i, int end, boolean allowSuffix, boolean toLower, StringBuilder buffer) Returns a SQL LIKE pattern for the given identifier. The identifier is optionally returned in all lower cases for allowing case-insensitive searches. Punctuations are replaced by any sequence of characters ('%'
) and non-ASCII letters or digits are replaced by any single character ('_'
). This method avoid to put a'%'
symbol as the first character since it prevents some databases to use their index.- Parameters:
identifier
- the identifier to get as a SQL LIKE pattern.i
- index of the first character to use in the givenidentifier
.end
- index after the last character to use in the givenidentifier
.allowSuffix
- whether to append a final'%'
wildcard at the end of the pattern.toLower
- whether to convert characters to lower case.buffer
- buffer where to append the SQL LIKE pattern.
-
appendIfNotRedundant
Appends the given wildcard character to the given buffer if the buffer does not ends with'%'
. -
filterFalsePositive
@Workaround(library="Derby", version="10.11") public static boolean filterFalsePositive(String expected, String actual) Workaround for what seems to be a Derby 10.11 bug, which seems to behave as if the LIKE pattern had a trailing % wildcard. This can be verified with the following query on the EPSG database: which returns "NTF (Paris) / Lambert zone I" as expected but also zones II and III.- Parameters:
expected
- the string to search.actual
- the string found in the database.- Returns:
true
if the given string can be accepted.
-