public final class DbUtils extends Object
Modifier and Type | Field and Description |
---|---|
static com.google.common.collect.ImmutableList<DatabaseType> |
DATABASES_WITH_EMPTY_STRING_TO_NULL_CONVERSION
Constants that defines the databases for which replace '' string with null.
|
static com.google.common.collect.ImmutableList<DatabaseType> |
DATABASES_WITH_LIMITED_IN_PREDICATE_QUERY_SUPPORT
Constants that defines the databases for which only limited support for `in` predicates .
|
static com.google.common.collect.ImmutableList<DatabaseType> |
DATABASES_WITH_LIMITED_LARGE_STRING_QUERY_SUPPORT
Constants that defines the databases for which only limited support exists to query large strings.
|
static String[] |
JDBC_TABLE_TYPES_WHITE_LIST
Constant that defines what JDBC table types to include by default when querying for table metadata.
|
static int |
MAX_BYTES_IN_VARCHAR_COLUMN
Constant the defines the cross-database maximum number of bytes that are stored in a VARCHAR table column.
|
Modifier and Type | Method and Description |
---|---|
static com.google.common.collect.ImmutableList<String> |
adjustCasing(List<String> tableNames,
DatabaseType databaseType)
Some databases like PostgreSQL by default convert all table names to lower-case, hence we need to adjust the casing before we compare table names in Java code.
|
static String |
adjustCasing(String tableName,
DatabaseType databaseType)
Some databases like PostgreSQL by default convert all table names to lower-case, hence we need to adjust the casing before we compare a table name in Java code.
|
static boolean |
containsAllTables(List<String> tableNames,
DataSource dataSource,
String catalog,
String schema)
Checks if all tables (not views) with the given names exist in the database.
|
static boolean |
containsForeignKey(String referencedTableName,
String foreignKeyConstraintName,
DataSource dataSource,
String catalog,
String schema)
Checks if an foreign key constraint with the given name exists for the given primary key table in the database.
|
static boolean |
containsIndex(String tableName,
String indexName,
DataSource dataSource,
String catalog,
String schema)
Checks if an index with the given name exists for a given table in the database.
|
static boolean |
containsTable(String tableName,
DataSource dataSource,
String catalog,
String schema)
Checks if a table (not a view) with the given name exists in the database.
|
static byte[] |
getBlobBytes(ResultSet resultSet,
String columnLabel)
Retrieves the value of the given column as a
byte[] value of a Blob. |
static com.google.common.base.Optional<DatabaseMetaData> |
getDatabaseMetaData(DataSource dataSource)
Gets the database driver name from the given data source.
|
static Double |
getDouble(ResultSet resultSet,
String columnLabel)
Retrieves the value of the given column as a
Double value. |
static Integer |
getInteger(ResultSet resultSet,
String columnLabel)
Retrieves the value of the given column as an
Integer value. |
static Long |
getLong(ResultSet resultSet,
String columnLabel)
Retrieves the value of the given column as a
Long value. |
static DatabaseType |
inferDatabaseType(DataSource dataSource)
Infers the database type from the given data source.
|
public static final String[] JDBC_TABLE_TYPES_WHITE_LIST
public static final int MAX_BYTES_IN_VARCHAR_COLUMN
public static final com.google.common.collect.ImmutableList<DatabaseType> DATABASES_WITH_LIMITED_LARGE_STRING_QUERY_SUPPORT
public static final com.google.common.collect.ImmutableList<DatabaseType> DATABASES_WITH_LIMITED_IN_PREDICATE_QUERY_SUPPORT
public static final com.google.common.collect.ImmutableList<DatabaseType> DATABASES_WITH_EMPTY_STRING_TO_NULL_CONVERSION
public static boolean containsTable(String tableName, DataSource dataSource, String catalog, String schema)
tableName
- the name of the table to finddataSource
- the data sourcecatalog
- the catalog nameschema
- the schema namepublic static boolean containsAllTables(List<String> tableNames, DataSource dataSource, String catalog, String schema)
tableNames
- the names of the tables to finddataSource
- the data sourcecatalog
- the catalog nameschema
- the schema namepublic static boolean containsIndex(String tableName, String indexName, DataSource dataSource, String catalog, String schema)
tableName
- the name of the table for which to find the indexindexName
- the name of the indexdataSource
- the data sourcecatalog
- the catalog nameschema
- the schema namepublic static boolean containsForeignKey(String referencedTableName, String foreignKeyConstraintName, DataSource dataSource, String catalog, String schema)
referencedTableName
- the name of the table that is referencedforeignKeyConstraintName
- the name of the foreign key to finddataSource
- the data sourcecatalog
- the catalog nameschema
- the schema namepublic static String adjustCasing(String tableName, DatabaseType databaseType)
tableName
- the table namedatabaseType
- the database typepublic static com.google.common.collect.ImmutableList<String> adjustCasing(List<String> tableNames, DatabaseType databaseType)
tableNames
- the table namesdatabaseType
- the database typepublic static Integer getInteger(ResultSet resultSet, String columnLabel) throws SQLException
Integer
value.resultSet
- the record from which to retrieve a column valuecolumnLabel
- the column's labelSQLException
- thrown if accessing the result set failspublic static Long getLong(ResultSet resultSet, String columnLabel) throws SQLException
Long
value.resultSet
- the record from which to retrieve a column valuecolumnLabel
- the column's labelSQLException
- thrown if accessing the result set failspublic static Double getDouble(ResultSet resultSet, String columnLabel) throws SQLException
Double
value.resultSet
- the record from which to retrieve a column valuecolumnLabel
- the column's labelSQLException
- thrown if accessing the result set failspublic static byte[] getBlobBytes(ResultSet resultSet, String columnLabel) throws SQLException, IOException
byte[]
value of a Blob.resultSet
- the record from which to retrieve a column valuecolumnLabel
- the column's labelSQLException
- thrown if accessing the result set failsIOException
- thrown if accessing the binary stream failspublic static DatabaseType inferDatabaseType(DataSource dataSource)
dataSource
- the data sourcepublic static com.google.common.base.Optional<DatabaseMetaData> getDatabaseMetaData(DataSource dataSource)
dataSource
- the data sourceCopyright © 2010 - 2018 edorasware ag. All Rights Reserved.