public final class DB extends Object
An object of this kind is used to encapsulate access to a database connection.
JDBDT.database(Connection)
Modifier and Type | Class and Description |
---|---|
static class |
DB.Option
Database options.
|
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_MAX_BATCH_UPDATE_SIZE
Default value for maximum batch update size (if batch updates enabled).
|
Constructor and Description |
---|
DB(Connection connection)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
disable(DB.Option... options)
Disable options.
|
void |
enable(DB.Option... options)
Enable options.
|
void |
enableFullLogging()
Enable all logging options.
|
boolean |
getAutoCommit()
Get auto-commit mode for the underlying database connection.
|
Connection |
getConnection()
Get connection.
|
int |
getMaximumBatchUpdateSize()
Get current setting for maximum batch update size.
|
boolean |
isEnabled(DB.Option o)
Check if option is enabled.
|
void |
setAutoCommit(boolean enable)
Set auto-commit mode for the underlying database connection.
|
void |
setLog(File outputFile)
Set output file for log output.
|
void |
setLog(PrintStream out)
Redirect log output to a stream.
|
void |
setMaximumBatchUpdateSize(int size)
Set maximum size for batch updates.
|
public static final int DEFAULT_MAX_BATCH_UPDATE_SIZE
public DB(Connection connection)
connection
- Database connection.@SafeVarargs public final void enable(DB.Option... options)
options
- Options to enable.public void setMaximumBatchUpdateSize(int size)
size
- The size to set.getMaximumBatchUpdateSize()
,
DEFAULT_MAX_BATCH_UPDATE_SIZE
,
DB.Option.BATCH_UPDATES
public int getMaximumBatchUpdateSize()
setMaximumBatchUpdateSize(int)
,
DEFAULT_MAX_BATCH_UPDATE_SIZE
,
DB.Option.BATCH_UPDATES
public void enableFullLogging()
@SafeVarargs public final void disable(DB.Option... options)
options
- Options to enable.enable(Option...)
,
isEnabled(Option)
public boolean isEnabled(DB.Option o)
o
- Option.true
if o
is enabled.enable(Option...)
,
disable(Option...)
public Connection getConnection()
public void setLog(PrintStream out)
System.err
.out
- Output stream.public void setLog(File outputFile)
The output file will be GZIP-compressed if it has a .gz
extension.
Note that the log output set at creation time
is System.err
.
outputFile
- Logging instance.public void setAutoCommit(boolean enable) throws DBExecutionException
A call to this method is equivalent to getConnection().setAutoCommit(enable)
.
with the sole difference than any thrown SQLException
(a checked exception) is "wrapped" a
DBExecutionException
(an unchecked exception).
enable
- Enable/disable auto-commit setting.DBExecutionException
- if a database exception occurs.getAutoCommit()
,
Connection.getAutoCommit()
,
Connection.setAutoCommit(boolean)
public boolean getAutoCommit() throws DBExecutionException
A call to this method is equivalent to getConnection().getAutoCommit()
.
with the sole difference than any thrown SQLException
(a checked exception) is "wrapped" a
DBExecutionException
(an unchecked exception).
DBExecutionException
- if a database exception occurs.setAutoCommit(boolean)
,
Connection.getAutoCommit()
,
Connection.setAutoCommit(boolean)
Copyright © 2016–2021 JDBDT. All rights reserved.