Class RDBJDBCTools
- java.lang.Object
-
- org.apache.jackrabbit.oak.plugins.document.rdb.RDBJDBCTools
-
public class RDBJDBCTools extends Object
Convenience methods dealing with JDBC specifics.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceRDBJDBCTools.PreparedStatementComponentProvides a component for aPreparedStatementand a method for setting the parameters within this component
-
Field Summary
Fields Modifier and Type Field Description static intMAX_IN_CLAUSE
-
Constructor Summary
Constructors Constructor Description RDBJDBCTools()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description protected static voidappendInCondition(StringBuilder builder, String field, int placeholdersCount, int maxListLength)Appends following SQL condition to the builder:ID in (?,?,?).static DocumentStoreExceptionasDocumentStoreException(@NotNull Exception cause, @NotNull String message)protected static ResultSetcloseResultSet(@Nullable ResultSet rs)Closes aResultSet, logging potential problems.protected static <T extends Statement>
TcloseStatement(T stmt)Closes aStatement, logging potential problems.static RDBJDBCTools.PreparedStatementComponentcreateInStatement(String fieldName, Collection<String> values, boolean binary)protected static @NotNull StringcreateTableName(@NotNull String prefix, @NotNull String basename)Creates a table name based on an optional prefix and a base name.protected static StringdriverForDBType(String type)protected static StringdumpResultSetMeta(ResultSetMetaData met)Return approximated string representation of table DDL.protected static @NotNull StringgetAdditionalMessages(SQLException ex)Return a string containing additional messages from chained exceptions.protected static @NotNull StringisolationLevelToString(int isolationLevel)Return string representation of transaction isolation level.protected static Stringjdbctype(String jdbcurl)protected static booleanmatchesSQLState(SQLException ex, String... statePrefix)Check whether the exception matches one of the given states.protected static StringversionCheck(DatabaseMetaData md, int dbmax, int dbmin, int drmax, int drmin, String dbname)Generate database + driver version diagnostics.protected static StringversionCheck(DatabaseMetaData md, int dbmax, int dbmin, String dbname)Generate database version diagnostics.
-
-
-
Method Detail
-
createTableName
@NotNull protected static @NotNull String createTableName(@NotNull @NotNull String prefix, @NotNull @NotNull String basename) throws IllegalArgumentException
Creates a table name based on an optional prefix and a base name.- Throws:
IllegalArgumentException- upon illegal characters in name
-
isolationLevelToString
@NotNull protected static @NotNull String isolationLevelToString(int isolationLevel)
Return string representation of transaction isolation level.
-
dumpResultSetMeta
protected static String dumpResultSetMeta(ResultSetMetaData met)
Return approximated string representation of table DDL.
-
getAdditionalMessages
@NotNull protected static @NotNull String getAdditionalMessages(SQLException ex)
Return a string containing additional messages from chained exceptions.
-
matchesSQLState
protected static boolean matchesSQLState(SQLException ex, String... statePrefix)
Check whether the exception matches one of the given states.
-
versionCheck
protected static String versionCheck(DatabaseMetaData md, int dbmax, int dbmin, int drmax, int drmin, String dbname) throws SQLException
Generate database + driver version diagnostics.- Parameters:
md- metadata objectdbmax- minimal DB major version number (where-1disables the check)dbmin- minimal DB minor version numberdrmax- minimal driver major version number (where-1disables the check)drmin- minimal driver minor version numberdbname- database type- Returns:
- diagnostics (empty when there's nothing to complain about)
- Throws:
SQLException
-
versionCheck
protected static String versionCheck(DatabaseMetaData md, int dbmax, int dbmin, String dbname) throws SQLException
Generate database version diagnostics.- Parameters:
md- metadata objectdbmax- minimal DB major version number (where-1disables the check)dbmin- minimal DB minor version numberdbname- database type- Returns:
- diagnostics (empty when there's nothing to complain about)
- Throws:
SQLException
-
closeStatement
protected static <T extends Statement> T closeStatement(@Nullable T stmt)
Closes aStatement, logging potential problems.- Returns:
- null
-
closeResultSet
protected static ResultSet closeResultSet(@Nullable @Nullable ResultSet rs)
Closes aResultSet, logging potential problems.- Returns:
- null
-
appendInCondition
protected static void appendInCondition(StringBuilder builder, String field, int placeholdersCount, int maxListLength)
Appends following SQL condition to the builder:ID in (?,?,?). The field nameIDand the number of place holders is configurable. If the number of place holders is greater thanmaxListLength, then the condition will have following form:(ID in (?,?,?) or ID in (?,?,?) or ID in (?,?))- Parameters:
builder- the condition will be appended herefield- name of the fieldplaceholdersCount- how many ? should be includedmaxListLength- what's the max number of ? in one list
-
createInStatement
public static RDBJDBCTools.PreparedStatementComponent createInStatement(String fieldName, Collection<String> values, boolean binary)
-
asDocumentStoreException
public static DocumentStoreException asDocumentStoreException(@NotNull @NotNull Exception cause, @NotNull @NotNull String message)
-
-