public final class DataSourceUtils extends Object
DataSource
s and its related objects.Modifier and Type | Method and Description |
---|---|
static void |
closeConnection(@Nullable Connection connection)
Simply closes a connection.
|
static void |
closePool(@Nullable AsyncDatabase asyncDatabase) |
static void |
closePool(@Nullable DatabaseAccessor accessor) |
static void |
closePool(@Nullable DataSource dataSource)
Closes a connection pool managed by a DataSource.
|
static void |
closePool(@Nullable Object o) |
static void |
closeResultSet(@Nullable ResultSet resultSet) |
static void |
closeStatement(@Nullable Statement statement) |
static String |
getColumnName(@NotNull ResultSetMetaData metaData,
int i) |
static @Nullable Connection |
getConnection(@NotNull DataSource dataSource)
Simply gets a connection from a given valid DataSource.
|
static @Nullable Object |
getResultSetValue(ResultSet rs,
int index)
Retrieve a JDBC column value from a ResultSet, using the most appropriate
value type.
|
static Object |
getResultSetValue(ResultSet rs,
int index,
@Nullable Class<?> requiredType)
Retrieve a JDBC column value from a ResultSet, using the specified value type.
|
static @NotNull DataSource |
newDataSource(@NotNull Credentials credentials)
Creates a new DataSource with the given Credentials.
|
@NotNull public static @NotNull DataSource newDataSource(@NotNull @NotNull Credentials credentials) throws DataSourceInitException
DataSourceFactory
: HikariFactory
credentials
- the credentialsDataSourceInitException
- if something went wrong during the creation of the DataSourceDataSourceFactory
,
HikariFactory
@Nullable public static @Nullable Connection getConnection(@NotNull @NotNull DataSource dataSource)
dataSource
- the datasourcepublic static void closeConnection(@Nullable @Nullable Connection connection)
connection
- the connectionpublic static void closeResultSet(@Nullable @Nullable ResultSet resultSet)
public static void closeStatement(@Nullable @Nullable Statement statement)
public static void closePool(@Nullable @Nullable DataSource dataSource)
NOTE: the provided DataSource must implement the interface Closeable
dataSource
- the DataSourceCloseable
public static void closePool(@Nullable @Nullable DatabaseAccessor accessor)
public static void closePool(@Nullable @Nullable AsyncDatabase asyncDatabase)
public static void closePool(@Nullable @Nullable Object o)
public static Object getResultSetValue(ResultSet rs, int index, @Nullable @Nullable Class<?> requiredType) throws SQLException
Uses the specifically typed ResultSet accessor methods, falling back to
getResultSetValue(java.sql.ResultSet, int)
for unknown types.
Note that the returned value may not be assignable to the specified required type, in case of an unknown type. Calling code needs to deal with this case appropriately, e.g. throwing a corresponding exception.
rs
- is the ResultSet holding the dataindex
- is the column indexrequiredType
- the required value type (may be null
)SQLException
- if thrown by the JDBC APIgetResultSetValue(ResultSet, int)
@Nullable public static @Nullable Object getResultSetValue(ResultSet rs, int index) throws SQLException
Uses the getObject(index)
method, but includes additional "hacks"
to get around Oracle 10g returning a non-standard object for its TIMESTAMP
datatype and a java.sql.Date
for DATE columns leaving out the
time portion: These columns will explicitly be extracted as standard
java.sql.Timestamp
object.
rs
- is the ResultSet holding the dataindex
- is the column indexSQLException
- if thrown by the JDBC APIBlob
,
Clob
,
Timestamp
public static String getColumnName(@NotNull @NotNull ResultSetMetaData metaData, int i) throws SQLException
SQLException
Copyright © 2021. All rights reserved.