|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eclipse.net4j.db.DBUtil
A utility class with various static factory and convenience methods.
Nested Class Summary | |
---|---|
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
A row handler with a method
that is called once per row serialized within DBUtil.serializeTable() . |
Field Summary | |
---|---|
static int |
MAX_BATCH_SIZE
|
Method Summary | ||
---|---|---|
static int |
asInt(Object value)
|
|
static long |
asLong(Object value)
|
|
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 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
|
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(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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int MAX_BATCH_SIZE
Method Detail |
---|
@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 IDBSchema createSchema(String name)
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 IDBSchema copySchema(IDBSchema source)
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 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 Exception close(ResultSet resultSet)
public static Exception close(Statement statement)
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 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 String trace(String sql)
public static boolean isTracerEnabled()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |