public class DbUtils extends Object
Provides utility methods related to database operations.
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 Map<String,Object> |
calculatePagingParameters(int offset,
int limit) |
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 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. |
public static final String[] JDBC_TABLE_TYPES_WHITE_LIST
Constant that defines what JDBC table types to include by default when querying for table metadata.
public static final int MAX_BYTES_IN_VARCHAR_COLUMN
Constant the defines the cross-database maximum number of bytes that are stored in a VARCHAR table column.
public static final 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.
public static final 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 .
public static final com.google.common.collect.ImmutableList<DatabaseType> DATABASES_WITH_EMPTY_STRING_TO_NULL_CONVERSION
Constants that defines the databases for which replace '' string with null.
public 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. The table name comparison is done case-insensitive.
tableName
- the name of the table to finddataSource
- the data sourcecatalog
- the catalog nameschema
- the schema namepublic 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. The table name and index name comparisons are done case-insensitive.
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)
Checks if an foreign key constraint with the given name exists for the given primary key table in the database. The table name and index name comparisons are done case-insensitive.
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 Integer getInteger(ResultSet resultSet, String columnLabel) throws SQLException
Retrieves the value of the given column as an 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
Retrieves the value of the given column as a 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
Retrieves the value of the given column as a Double
value.
resultSet
- the record from which to retrieve a column valuecolumnLabel
- the column’s labelSQLException
- thrown if accessing the result set failsCopyright © 2010 - 2019 edorasware ag. All Rights Reserved.