public final class Databases
extends java.lang.Object
Database
implementations and misc. database related things.Database.DATABASE_TYPE
Modifier and Type | Class and Description |
---|---|
static class |
Databases.QueryCounter
A class for counting query types, providing averages over time
|
Modifier and Type | Field and Description |
---|---|
static ResultPacker<java.lang.Integer> |
INTEGER_RESULT_PACKER
A result packer for fetching integers from a result set containing a single integer column
|
static ResultPacker<java.lang.Long> |
LONG_RESULT_PACKER
A result packer for fetching longs from a result set containing a single long column
|
static Databases.QueryCounter |
QUERY_COUNTER
A synchronized query counter.
|
Modifier and Type | Method and Description |
---|---|
static void |
closeSilently(java.sql.Connection connection)
Closes the given Connection instance, swallowing any SQLExceptions that occur
|
static void |
closeSilently(java.sql.ResultSet resultSet)
Closes the given ResultSet instance, swallowing any SQLExceptions that occur
|
static void |
closeSilently(java.sql.Statement statement)
Closes the given Statement instance, swallowing any SQLExceptions that occur
|
static java.lang.String |
createLogMessage(User user,
java.lang.String sqlStatement,
java.util.List values,
java.lang.Exception exception,
MethodLogger.Entry entry)
Creates a log message from the given information
|
static Database.Statistics |
getDatabaseStatistics()
Returns the statistics gathered via
QUERY_COUNTER . |
static Database |
getInstance() |
static boolean |
isValid(java.sql.Connection connection,
Database database,
int timeoutInSeconds)
Returns true if the given connection is valid, if the underlying driver supports
isValid()
it is used, otherwise a simple query is run |
public static final Databases.QueryCounter QUERY_COUNTER
getDatabaseStatistics()
public static final ResultPacker<java.lang.Integer> INTEGER_RESULT_PACKER
public static final ResultPacker<java.lang.Long> LONG_RESULT_PACKER
public static Database getInstance()
java.lang.IllegalArgumentException
- in case an unsupported database type is specifiedjava.lang.RuntimeException
- in case of an exception occurring while instantiating the database implementation instanceDatabase.DATABASE_TYPE
,
Database.getDatabaseType()
public static void closeSilently(java.sql.ResultSet resultSet)
resultSet
- the result set to closepublic static void closeSilently(java.sql.Statement statement)
statement
- the statement to closepublic static void closeSilently(java.sql.Connection connection)
connection
- the connection to closepublic static boolean isValid(java.sql.Connection connection, Database database, int timeoutInSeconds)
isValid()
it is used, otherwise a simple query is runconnection
- the connection to validatedatabase
- the underlying database implementationtimeoutInSeconds
- the timeoutpublic static Database.Statistics getDatabaseStatistics()
QUERY_COUNTER
.Database.Statistics
object containing query statistics collected since
the last time this function was called.public static java.lang.String createLogMessage(User user, java.lang.String sqlStatement, java.util.List values, java.lang.Exception exception, MethodLogger.Entry entry)
user
- the usersqlStatement
- the sql statementvalues
- the valuesexception
- the exception, if anyentry
- the log entry