public final class DBUtil extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
DBUtil.DeserializeRowHandler
A
row handler with a method
that is called once per row deserialized within DBUtil.deserializeTable() . |
static interface |
DBUtil.RowHandler
Call-back interface with a
method that is called after
a number of table rows have been handled by one of the subtypes of this interface. |
static interface |
DBUtil.RunnableWithConnection<T> |
static interface |
DBUtil.SerializeRowHandler
|
Modifier and Type | Field and Description |
---|---|
static int |
MAX_BATCH_SIZE |
static String |
PROP_ENABLE_NOISY_CLOSE
A system property to enable noisy close, i.e.
|
Modifier and Type | Method and Description |
---|---|
static int |
asInt(Object value) |
static long |
asLong(Object value) |
static BatchedStatement |
batched(PreparedStatement delegate,
int batchSize) |
static int |
clearTable(Connection connection,
IDBTable table) |
static int |
clearTable(Connection connection,
String tableName) |
static Exception |
close(Connection connection) |
static Exception |
close(ResultSet resultSet) |
static Exception |
close(Statement statement) |
static IDBSchema |
copySchema(IDBSchema source) |
static IDBConnectionProvider |
createConnectionProvider(DataSource dataSource) |
static IDBConnectionProvider2 |
createConnectionProvider(DataSource dataSource,
String user) |
static DataSource |
createDataSource(Map<Object,Object> properties) |
static DataSource |
createDataSource(Map<Object,Object> properties,
String namespace) |
static DataSource |
createDataSource(Map<Object,Object> properties,
String namespace,
String driverClassKey) |
static IDBSchema |
createSchema(String name) |
static void |
deserializeTable(ExtendedDataInput in,
Connection connection,
IDBTable table,
OMMonitor monitor) |
static void |
deserializeTable(ExtendedDataInput in,
Connection connection,
IDBTable table,
OMMonitor monitor,
DBUtil.DeserializeRowHandler handler) |
static List<Exception> |
dropAllTables(Connection connection,
String dbName) |
static void |
dump(IDBNamedElement namedElement) |
static void |
dump(IDBNamedElement namedElement,
Writer writer) |
static String |
dumpToString(IDBNamedElement namedElement) |
static void |
execute(Connection connection,
CharSequence sql) |
static <T> T |
execute(IDBConnectionProvider connectionProvider,
DBUtil.RunnableWithConnection<T> runnable) |
static void |
executeBatch(PreparedStatement stmt,
int counter) |
static void |
executeBatch(PreparedStatement stmt,
int counter,
boolean checkExactlyOne) |
static List<String> |
getAllSchemaNames(Connection connection) |
static Set<String> |
getAllSchemaNames(DatabaseMetaData metaData) |
static List<String> |
getAllSchemaTableNames(Connection connection)
Deprecated.
As of 4.2 use
getAllSchemaNames(Connection) . |
static List<String> |
getAllSchemaTableNames(DatabaseMetaData metaData)
Deprecated.
As of 4.2 use
getAllSchemaNames(DatabaseMetaData) . |
static List<String> |
getAllTableNames(Connection connection,
String dbName) |
static IDBAdapter |
getDBAdapter(String adapterName)
Retrieves an
adapter from the adapter registry . |
static int |
getRowCount(Connection connection,
String tableName)
Returns the number of rows contained in the given table.
|
static int |
getRowCount(ResultSet resultSet)
Returns the number of rows contained in the given result set.
|
static boolean |
isTracerEnabled() |
static IDBDatabase |
openDatabase(IDBAdapter adapter,
IDBConnectionProvider connectionProvider,
String schemaName) |
static IDBDatabase |
openDatabase(IDBAdapter adapter,
IDBConnectionProvider connectionProvider,
String schemaName,
boolean fixNullableIndexColumns) |
static void |
readSchema(IDBAdapter adapter,
Connection connection,
IDBSchema schema) |
static IDBSchema |
readSchema(IDBAdapter adapter,
Connection connection,
String name) |
static IDBSchema |
readSchema(IDBAdapter adapter,
Connection connection,
String name,
boolean fixNullableIndexColumns) |
static Exception |
rollbackSilently(Connection connection) |
static int |
select(Connection connection,
IDBRowHandler rowHandler,
IDBField... fields) |
static int |
select(Connection connection,
IDBRowHandler rowHandler,
String where,
IDBField... fields) |
static Object[] |
select(Connection connection,
String where,
IDBField... fields) |
static int |
selectMaximumInt(Connection connection,
IDBField field,
String... where) |
static long |
selectMaximumLong(Connection connection,
IDBField field,
String... where) |
static int |
selectMinimumInt(Connection connection,
IDBField field,
String... where) |
static long |
selectMinimumLong(Connection connection,
IDBField field,
String... where) |
static void |
serializeTable(ExtendedDataOutput out,
Connection connection,
IDBTable table,
String tableAlias,
String sqlSuffix) |
static void |
serializeTable(ExtendedDataOutput out,
Connection connection,
IDBTable table,
String tableAlias,
String sqlSuffix,
DBUtil.SerializeRowHandler handler) |
static boolean |
setAutoCommit(Connection connection,
boolean autoCommit) |
static void |
sqlDump(Connection conn,
String sql)
Deprecated.
Should only be used when debugging.
|
static void |
sqlDump(IDBConnectionProvider connectionProvider,
String sql)
Deprecated.
Should only be used when debugging.
|
static String |
trace(String sql) |
static int |
update(Connection connection,
String sql) |
static int |
update(PreparedStatement stmt,
boolean exactlyOne)
Execute update on the given prepared statement and handle common cases of return values.
|
public static final int MAX_BATCH_SIZE
public static final String PROP_ENABLE_NOISY_CLOSE
DBException
exception.@Deprecated public static void sqlDump(Connection conn, String sql)
@Deprecated public static void sqlDump(IDBConnectionProvider connectionProvider, String sql)
public static String dumpToString(IDBNamedElement namedElement)
public static void dump(IDBNamedElement namedElement)
public static void dump(IDBNamedElement namedElement, Writer writer) throws IOException
IOException
public static IDBDatabase openDatabase(IDBAdapter adapter, IDBConnectionProvider connectionProvider, String schemaName)
public static IDBDatabase openDatabase(IDBAdapter adapter, IDBConnectionProvider connectionProvider, String schemaName, boolean fixNullableIndexColumns)
public static void readSchema(IDBAdapter adapter, Connection connection, IDBSchema schema)
public static IDBSchema readSchema(IDBAdapter adapter, Connection connection, String name)
public static IDBSchema readSchema(IDBAdapter adapter, Connection connection, String name, boolean fixNullableIndexColumns)
public static DataSource createDataSource(Map<Object,Object> properties)
public static DataSource createDataSource(Map<Object,Object> properties, String namespace)
public static DataSource createDataSource(Map<Object,Object> properties, String namespace, String driverClassKey)
public static IDBConnectionProvider createConnectionProvider(DataSource dataSource)
public static IDBConnectionProvider2 createConnectionProvider(DataSource dataSource, String user)
public static IDBAdapter getDBAdapter(String adapterName)
adapter
from the adapter registry
.
If Eclipse is running adapters are automatically created from descriptors that are contributed to the extension point org.eclipse.net4j.db.dbAdapters
.
In standalone scenarios the needed adapter instances must be registered with the adapter registry
manually.
public static BatchedStatement batched(PreparedStatement delegate, int batchSize) throws DBException
DBException
public static Exception close(Connection connection)
public static boolean setAutoCommit(Connection connection, boolean autoCommit)
public static Exception rollbackSilently(Connection connection)
@Deprecated public static List<String> getAllSchemaTableNames(Connection connection)
getAllSchemaNames(Connection)
.@Deprecated public static List<String> getAllSchemaTableNames(DatabaseMetaData metaData)
getAllSchemaNames(DatabaseMetaData)
.public static List<String> getAllSchemaNames(Connection connection)
public static Set<String> getAllSchemaNames(DatabaseMetaData metaData)
public static List<String> getAllTableNames(Connection connection, String dbName)
public static List<Exception> dropAllTables(Connection connection, String dbName)
public static int asInt(Object value)
public static long asLong(Object value)
public static int selectMinimumInt(Connection connection, IDBField field, String... where) throws DBException
DBException
public static long selectMinimumLong(Connection connection, IDBField field, String... where) throws DBException
DBException
public static int selectMaximumInt(Connection connection, IDBField field, String... where) throws DBException
DBException
public static long selectMaximumLong(Connection connection, IDBField field, String... where) throws DBException
DBException
public static <T> T execute(IDBConnectionProvider connectionProvider, DBUtil.RunnableWithConnection<T> runnable)
public static void execute(Connection connection, CharSequence sql)
public static void executeBatch(PreparedStatement stmt, int counter)
public static void executeBatch(PreparedStatement stmt, int counter, boolean checkExactlyOne)
public static int update(Connection connection, String sql)
public static int update(PreparedStatement stmt, boolean exactlyOne) throws SQLException
stmt
- the prepared statementexactlyOne
- if true
, the update count is checked to be 1
. Else the update result is only
checked so that the update was successful (i.e. result code != Statement.EXECUTE_FAILED).PreparedStatement.executeUpdate()
. Can be used
by the caller to perform more advanced checks.SQLException
- if PreparedStatement.executeUpdate()
throws it.IllegalStateException
- if the check indicated by excatlyOne
indicates an error.public static int clearTable(Connection connection, IDBTable table)
public static int clearTable(Connection connection, String tableName)
public static int select(Connection connection, IDBRowHandler rowHandler, String where, IDBField... fields) throws DBException
DBException
public static int select(Connection connection, IDBRowHandler rowHandler, IDBField... fields) throws DBException
DBException
public static Object[] select(Connection connection, String where, IDBField... fields) throws DBException
DBException
public static int getRowCount(ResultSet resultSet) throws DBException
The statement
of the result set must have been created with
TYPE_SCROLL_INSENSITIVE
.
DBException
public static int getRowCount(Connection connection, String tableName) throws DBException
DBException
public static void serializeTable(ExtendedDataOutput out, Connection connection, IDBTable table, String tableAlias, String sqlSuffix) throws DBException, IOException
DBException
IOException
public static void serializeTable(ExtendedDataOutput out, Connection connection, IDBTable table, String tableAlias, String sqlSuffix, DBUtil.SerializeRowHandler handler) throws DBException, IOException
DBException
IOException
public static void deserializeTable(ExtendedDataInput in, Connection connection, IDBTable table, OMMonitor monitor) throws IOException
IOException
public static void deserializeTable(ExtendedDataInput in, Connection connection, IDBTable table, OMMonitor monitor, DBUtil.DeserializeRowHandler handler) throws IOException
IOException
public static boolean isTracerEnabled()
Copyright (c) 2014 Eike Stepper (Berlin, Germany) and others.
All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html