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 interface
RDBJDBCTools.PreparedStatementComponent
Provides a component for aPreparedStatement
and a method for setting the parameters within this component
-
Field Summary
Fields Modifier and Type Field Description static int
MAX_IN_CLAUSE
-
Constructor Summary
Constructors Constructor Description RDBJDBCTools()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description protected static void
appendInCondition(StringBuilder builder, String field, int placeholdersCount, int maxListLength)
Appends following SQL condition to the builder:ID in (?,?,?)
.static DocumentStoreException
asDocumentStoreException(@NotNull Exception cause, @NotNull String message)
protected static ResultSet
closeResultSet(@Nullable ResultSet rs)
Closes aResultSet
, logging potential problems.protected static <T extends Statement>
TcloseStatement(T stmt)
Closes aStatement
, logging potential problems.static RDBJDBCTools.PreparedStatementComponent
createInStatement(String fieldName, Collection<String> values, boolean binary)
protected static @NotNull String
createTableName(@NotNull String prefix, @NotNull String basename)
Creates a table name based on an optional prefix and a base name.protected static String
driverForDBType(String type)
protected static String
dumpResultSetMeta(ResultSetMetaData met)
Return approximated string representation of table DDL.protected static @NotNull String
getAdditionalMessages(SQLException ex)
Return a string containing additional messages from chained exceptions.protected static @NotNull String
isolationLevelToString(int isolationLevel)
Return string representation of transaction isolation level.protected static String
jdbctype(String jdbcurl)
protected static boolean
matchesSQLState(SQLException ex, String... statePrefix)
Check whether the exception matches one of the given states.protected static String
versionCheck(DatabaseMetaData md, int dbmax, int dbmin, int drmax, int drmin, String dbname)
Generate database + driver version diagnostics.protected static String
versionCheck(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-1
disables the check)dbmin
- minimal DB minor version numberdrmax
- minimal driver major version number (where-1
disables 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-1
disables 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 nameID
and 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)
-
-