Class RDBJDBCTools
- java.lang.Object
-
- org.apache.jackrabbit.oak.plugins.document.rdb.RDBJDBCTools
-
public class RDBJDBCTools extends java.lang.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(java.lang.StringBuilder builder, java.lang.String field, int placeholdersCount, int maxListLength)
Appends following SQL condition to the builder:ID in (?,?,?)
.static DocumentStoreException
asDocumentStoreException(@NotNull java.lang.Exception cause, @NotNull java.lang.String message)
protected static java.sql.ResultSet
closeResultSet(@Nullable java.sql.ResultSet rs)
Closes aResultSet
, logging potential problems.protected static <T extends java.sql.Statement>
TcloseStatement(T stmt)
Closes aStatement
, logging potential problems.static RDBJDBCTools.PreparedStatementComponent
createInStatement(java.lang.String fieldName, java.util.Collection<java.lang.String> values, boolean binary)
protected static @NotNull java.lang.String
createTableName(@NotNull java.lang.String prefix, @NotNull java.lang.String basename)
Creates a table name based on an optional prefix and a base name.protected static java.lang.String
driverForDBType(java.lang.String type)
protected static java.lang.String
dumpResultSetMeta(java.sql.ResultSetMetaData met)
Return approximated string representation of table DDL.protected static @NotNull java.lang.String
getAdditionalMessages(java.sql.SQLException ex)
Return a string containing additional messages from chained exceptions.protected static @NotNull java.lang.String
isolationLevelToString(int isolationLevel)
Return string representation of transaction isolation level.protected static java.lang.String
jdbctype(java.lang.String jdbcurl)
protected static boolean
matchesSQLState(java.sql.SQLException ex, java.lang.String... statePrefix)
Check whether the exception matches one of the given states.protected static java.lang.String
versionCheck(java.sql.DatabaseMetaData md, int dbmax, int dbmin, int drmax, int drmin, java.lang.String dbname)
Generate database + driver version diagnostics.protected static java.lang.String
versionCheck(java.sql.DatabaseMetaData md, int dbmax, int dbmin, java.lang.String dbname)
Generate database version diagnostics.
-
-
-
Method Detail
-
jdbctype
protected static java.lang.String jdbctype(java.lang.String jdbcurl)
-
driverForDBType
protected static java.lang.String driverForDBType(java.lang.String type)
-
createTableName
@NotNull protected static @NotNull java.lang.String createTableName(@NotNull @NotNull java.lang.String prefix, @NotNull @NotNull java.lang.String basename) throws java.lang.IllegalArgumentException
Creates a table name based on an optional prefix and a base name.- Throws:
java.lang.IllegalArgumentException
- upon illegal characters in name
-
isolationLevelToString
@NotNull protected static @NotNull java.lang.String isolationLevelToString(int isolationLevel)
Return string representation of transaction isolation level.
-
dumpResultSetMeta
protected static java.lang.String dumpResultSetMeta(java.sql.ResultSetMetaData met)
Return approximated string representation of table DDL.
-
getAdditionalMessages
@NotNull protected static @NotNull java.lang.String getAdditionalMessages(java.sql.SQLException ex)
Return a string containing additional messages from chained exceptions.
-
matchesSQLState
protected static boolean matchesSQLState(java.sql.SQLException ex, java.lang.String... statePrefix)
Check whether the exception matches one of the given states.
-
versionCheck
protected static java.lang.String versionCheck(java.sql.DatabaseMetaData md, int dbmax, int dbmin, int drmax, int drmin, java.lang.String dbname) throws java.sql.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:
java.sql.SQLException
-
versionCheck
protected static java.lang.String versionCheck(java.sql.DatabaseMetaData md, int dbmax, int dbmin, java.lang.String dbname) throws java.sql.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:
java.sql.SQLException
-
closeStatement
protected static <T extends java.sql.Statement> T closeStatement(@Nullable T stmt)
Closes aStatement
, logging potential problems.- Returns:
- null
-
closeResultSet
protected static java.sql.ResultSet closeResultSet(@Nullable @Nullable java.sql.ResultSet rs)
Closes aResultSet
, logging potential problems.- Returns:
- null
-
appendInCondition
protected static void appendInCondition(java.lang.StringBuilder builder, java.lang.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(java.lang.String fieldName, java.util.Collection<java.lang.String> values, boolean binary)
-
asDocumentStoreException
public static DocumentStoreException asDocumentStoreException(@NotNull @NotNull java.lang.Exception cause, @NotNull @NotNull java.lang.String message)
-
-