Class JdbcUtil
- Since:
- 0.8
- Author:
- Haiyang Li
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
static final int
static final int
static final long
static final long
-
Method Summary
Modifier and TypeMethodDescriptionstatic <A,
B, C, R> com.landawn.abacus.util.ContinuableFuture<R> asyncCall
(A a, B b, C c, com.landawn.abacus.util.Throwables.TriFunction<? super A, ? super B, ? super C, ? extends R, Exception> sqlAction) Any transaction started in current thread won't be automatically applied to specifiedsqlAction
which will be executed in another thread.static <R> com.landawn.abacus.util.ContinuableFuture<R>
Any transaction started in current thread won't be automatically applied to specifiedsqlAction
which will be executed in another thread.static <R1,
R2> com.landawn.abacus.util.Tuple.Tuple2<com.landawn.abacus.util.ContinuableFuture<R1>, com.landawn.abacus.util.ContinuableFuture<R2>> Any transaction started in current thread won't be automatically applied to specifiedsqlAction
which will be executed in another thread.static <R1,
R2, R3> com.landawn.abacus.util.Tuple.Tuple3<com.landawn.abacus.util.ContinuableFuture<R1>, com.landawn.abacus.util.ContinuableFuture<R2>, com.landawn.abacus.util.ContinuableFuture<R3>> Any transaction started in current thread won't be automatically applied to specifiedsqlAction
which will be executed in another thread.static <T,
R> com.landawn.abacus.util.ContinuableFuture<R> asyncCall
(T t, com.landawn.abacus.util.Throwables.Function<? super T, ? extends R, Exception> sqlAction) Any transaction started in current thread won't be automatically applied to specifiedsqlAction
which will be executed in another thread.static <T,
U, R> com.landawn.abacus.util.ContinuableFuture<R> asyncCall
(T t, U u, com.landawn.abacus.util.Throwables.BiFunction<? super T, ? super U, ? extends R, Exception> sqlAction) Any transaction started in current thread won't be automatically applied to specifiedsqlAction
which will be executed in another thread.static <A,
B, C> com.landawn.abacus.util.ContinuableFuture<Void> asyncRun
(A a, B b, C c, com.landawn.abacus.util.Throwables.TriConsumer<? super A, ? super B, ? super C, Exception> sqlAction) Any transaction started in current thread won't be automatically applied to specifiedsqlAction
which will be executed in another thread.static com.landawn.abacus.util.ContinuableFuture<Void>
Any transaction started in current thread won't be automatically applied to specifiedsqlAction
which will be executed in another thread.static com.landawn.abacus.util.Tuple.Tuple2<com.landawn.abacus.util.ContinuableFuture<Void>,
com.landawn.abacus.util.ContinuableFuture<Void>> asyncRun
(com.landawn.abacus.util.Throwables.Runnable<Exception> sqlAction1, com.landawn.abacus.util.Throwables.Runnable<Exception> sqlAction2) Any transaction started in current thread won't be automatically applied to specifiedsqlAction
which will be executed in another thread.static com.landawn.abacus.util.Tuple.Tuple3<com.landawn.abacus.util.ContinuableFuture<Void>,
com.landawn.abacus.util.ContinuableFuture<Void>, com.landawn.abacus.util.ContinuableFuture<Void>> asyncRun
(com.landawn.abacus.util.Throwables.Runnable<Exception> sqlAction1, com.landawn.abacus.util.Throwables.Runnable<Exception> sqlAction2, com.landawn.abacus.util.Throwables.Runnable<Exception> sqlAction3) Any transaction started in current thread won't be automatically applied to specifiedsqlAction
which will be executed in another thread.static <T> com.landawn.abacus.util.ContinuableFuture<Void>
Any transaction started in current thread won't be automatically applied to specifiedsqlAction
which will be executed in another thread.static <T,
U> com.landawn.abacus.util.ContinuableFuture<Void> asyncRun
(T t, U u, com.landawn.abacus.util.Throwables.BiConsumer<? super T, ? super U, Exception> sqlAction) Any transaction started in current thread won't be automatically applied to specifiedsqlAction
which will be executed in another thread.static SQLTransaction
beginTransaction
(DataSource dataSource) Refer to:beginTransaction(javax.sql.DataSource, IsolationLevel, boolean)
.static SQLTransaction
beginTransaction
(DataSource dataSource, IsolationLevel isolationLevel) Refer to:beginTransaction(javax.sql.DataSource, IsolationLevel, boolean)
.static SQLTransaction
beginTransaction
(DataSource dataSource, IsolationLevel isolationLevel, boolean isForUpdateOnly) Starts a global transaction which will be shared by all in-line database query with the sameDataSource
in the same thread, including methods:JdbcUtil.beginTransaction/prepareQuery/prepareNamedQuery/prepareCallableQuery, SQLExecutor(Mapper).beginTransaction/get/insert/batchInsert/update/batchUpdate/query/list/findFirst/...
Spring Transaction is supported and Integrated.static <A,
B, C, R> R call
(A a, B b, C c, com.landawn.abacus.util.Throwables.TriFunction<? super A, ? super B, ? super C, ? extends R, Exception> sqlAction) static <R> R
static <T,
R> R static <T,
U, R> R call
(T t, U u, com.landawn.abacus.util.Throwables.BiFunction<? super T, ? super U, ? extends R, Exception> sqlAction) static <T,
E extends Throwable>
TcallInTransaction
(DataSource dataSource, com.landawn.abacus.util.Throwables.Callable<T, E> cmd) static <T,
E extends Throwable>
TcallInTransaction
(DataSource dataSource, com.landawn.abacus.util.Throwables.Function<DataSource, T, E> cmd) static <T,
E extends Throwable>
TcallNotInStartedTransaction
(DataSource dataSource, com.landawn.abacus.util.Throwables.Callable<T, E> cmd) static <T,
E extends Throwable>
TcallNotInStartedTransaction
(DataSource dataSource, com.landawn.abacus.util.Throwables.Function<DataSource, T, E> cmd) static <R,
E extends Exception>
RcallWithoutUsingSpringTransaction
(com.landawn.abacus.util.Throwables.Callable<R, E> sqlAction) Since using or not using Spring transaction flag is attached with current thread, so don't execute the specifiedsqlAction
in another thread.static <R,
E extends Exception>
RcallWithSqlLogDisabled
(com.landawn.abacus.util.Throwables.Callable<R, E> sqlAction) Since enable/disable sql log flag is attached with current thread, so don't execute the specifiedsqlAction
in another thread.static void
close
(Connection conn) Deprecated.static void
static void
static void
static void
static void
close
(ResultSet rs, Statement stmt, Connection conn) static void
static void
close
(Statement stmt, Connection conn) static void
closeQuietly
(Connection conn) Deprecated.consider usingreleaseConnection(Connection, javax.sql.DataSource)
static void
Unconditionally close anResultSet
.static void
closeQuietly
(ResultSet rs, boolean closeStatement) static void
closeQuietly
(ResultSet rs, boolean closeStatement, boolean closeConnection) static void
closeQuietly
(ResultSet rs, Statement stmt) Unconditionally close theResultSet, Statement
.static void
closeQuietly
(ResultSet rs, Statement stmt, Connection conn) Unconditionally close theResultSet, Statement, Connection
.static void
closeQuietly
(Statement stmt) Unconditionally close anStatement
.static void
closeQuietly
(Statement stmt, Connection conn) Unconditionally close theStatement, Connection
.static DataSource
createC3p0DataSource
(String url, String user, String password) Creates the DataSource.static Connection
Creates the connection.static Connection
createConnection
(String url, String user, String password) Creates the connection.static Connection
createConnection
(String driverClass, String url, String user, String password) Creates the connection.static <TD extends Dao>
TDcreateDao
(Class<TD> daoInterface, DataSource ds) static <TD extends Dao>
TDcreateDao
(Class<TD> daoInterface, DataSource ds, com.landawn.abacus.util.SQLMapper sqlMapper) static <TD extends Dao>
TDcreateDao
(Class<TD> daoInterface, DataSource ds, com.landawn.abacus.util.SQLMapper sqlMapper, com.landawn.abacus.cache.Cache<String, Object> cache) Deprecated.static <TD extends Dao>
TDcreateDao
(Class<TD> daoInterface, DataSource ds, com.landawn.abacus.util.SQLMapper sqlMapper, com.landawn.abacus.cache.Cache<String, Object> cache, Executor executor) Deprecated.static <TD extends Dao>
TDcreateDao
(Class<TD> daoInterface, DataSource ds, com.landawn.abacus.util.SQLMapper sqlMapper, Executor executor) static <TD extends Dao>
TDcreateDao
(Class<TD> daoInterface, DataSource ds, Executor executor) static DataSource
createHikariDataSource
(String url, String user, String password) Creates the DataSource.static boolean
createTableIfNotExists
(Connection conn, String tableName, String schema) Returnstrue
if succeed to create table, otherwisefalse
is returned.static void
disableSpringTransactional
(boolean b) Deprecated.replaced bydoNotUseSpringTransactional(boolean)
static void
Disable sql log in current thread.static boolean
doesTableExist
(Connection conn, String tableName) Does table exist.static void
doNotUseSpringTransactional
(boolean b) Don't share or shareSpring Transactional
in current thread.static boolean
dropTableIfExists
(Connection conn, String tableName) Returnstrue
if succeed to drop table, otherwisefalse
is returned.static void
Enable sql log in current thread.static void
enableSqlLog
(boolean b) Deprecated.replaced byenableSqlLog/disableSqlLog
.static void
enableSqlLog
(boolean b, int maxSqlLogLength) Deprecated.replaced byenableSqlLog/disableSqlLog
.static void
enableSqlLog
(int maxSqlLogLength) Enable sql log in current thread.static boolean
execute
(Connection conn, String sql, Object... parameters) static boolean
execute
(DataSource ds, String sql, Object... parameters) static int
executeBatchUpdate
(Connection conn, String sql, List<?> listOfParameters) Execute batch update.static int
executeBatchUpdate
(Connection conn, String sql, List<?> listOfParameters, int batchSize) Execute batch update.static int
executeBatchUpdate
(DataSource ds, String sql, List<?> listOfParameters) static int
executeBatchUpdate
(DataSource ds, String sql, List<?> listOfParameters, int batchSize) static long
executeLargeBatchUpdate
(Connection conn, String sql, List<?> listOfParameters) Execute batch update.static long
executeLargeBatchUpdate
(Connection conn, String sql, List<?> listOfParameters, int batchSize) Execute batch update.static long
executeLargeBatchUpdate
(DataSource ds, String sql, List<?> listOfParameters) static long
executeLargeBatchUpdate
(DataSource ds, String sql, List<?> listOfParameters, int batchSize) static com.landawn.abacus.util.DataSet
executeQuery
(Connection conn, String sql, Object... parameters) static com.landawn.abacus.util.DataSet
executeQuery
(DataSource ds, String sql, Object... parameters) static int
executeUpdate
(Connection conn, String sql, Object... parameters) static int
executeUpdate
(DataSource ds, String sql, Object... parameters) static com.landawn.abacus.util.ExceptionalStream<com.landawn.abacus.util.DataSet,
SQLException> It's user's responsibility to close the inputstmt
after the stream is finished, or call:
JdbcUtil.extractAllResultSets(stmt).onClose(Fn.closeQuietly(stmt))...
static <T> com.landawn.abacus.util.ExceptionalStream<T,
SQLException> extractAllResultSets
(Statement stmt, Jdbc.BiResultExtractor<T> resultExtractor) It's user's responsibility to close the inputstmt
after the stream is finished, or call:
JdbcUtil.extractAllResultSets(stmt, resultExtractor).onClose(Fn.closeQuietly(stmt))...
static <T> com.landawn.abacus.util.ExceptionalStream<T,
SQLException> extractAllResultSets
(Statement stmt, Jdbc.ResultExtractor<T> resultExtractor) It's user's responsibility to close the inputstmt
after the stream is finished, or call:
JdbcUtil.extractAllResultSets(stmt, resultExtractor).onClose(Fn.closeQuietly(stmt))...
static com.landawn.abacus.util.DataSet
extractData
(ResultSet rs) static com.landawn.abacus.util.DataSet
extractData
(ResultSet rs, boolean closeResultSet) static com.landawn.abacus.util.DataSet
extractData
(ResultSet rs, int offset, int count) static com.landawn.abacus.util.DataSet
extractData
(ResultSet rs, int offset, int count, boolean closeResultSet) static com.landawn.abacus.util.DataSet
extractData
(ResultSet rs, int offset, int count, Jdbc.RowExtractor rowExtractor, boolean closeResultSet) static com.landawn.abacus.util.DataSet
extractData
(ResultSet rs, int offset, int count, Jdbc.RowFilter filter, boolean closeResultSet) static com.landawn.abacus.util.DataSet
extractData
(ResultSet rs, int offset, int count, Jdbc.RowFilter filter, Jdbc.RowExtractor rowExtractor, boolean closeResultSet) static String
generateEntityClass
(Connection conn, String tableName) static String
generateEntityClass
(Connection conn, String tableName, EntityCodeConfig config) static String
generateEntityClass
(Connection conn, String entityName, String query) static String
generateEntityClass
(Connection conn, String entityName, String query, EntityCodeConfig config) static String
generateEntityClass
(DataSource ds, String tableName) static String
generateEntityClass
(DataSource ds, String tableName, EntityCodeConfig config) static String
generateEntityClass
(DataSource ds, String entityName, String query) static String
generateEntityClass
(DataSource ds, String entityName, String query, EntityCodeConfig config) getColumn2FieldNameMap
(Class<?> entityClass) static int
Gets the column count.static int
getColumnIndex
(ResultSetMetaData rsmd, String columnName) Returns the column index starts with from 1, not 0.static int
getColumnIndex
(ResultSet resultSet, String columnName) Returns the column index starts with from 1, not 0.static String
getColumnLabel
(ResultSetMetaData rsmd, int columnIndex) Gets the column label.getColumnNameList
(Connection conn, String tableName) Gets the column name list.static <T> T
getColumnValue
(Class<? extends T> targetClass, ResultSet rs, int columnIndex) Gets the column value.static <T> T
getColumnValue
(Class<? extends T> targetClass, ResultSet rs, String columnLabel) Deprecated.please consider usinggetColumnValue(Class, ResultSet, int)
static Object
getColumnValue
(ResultSet rs, int columnIndex) Gets the column value.static Object
getColumnValue
(ResultSet rs, String columnLabel) Deprecated.please consider usinggetColumnValue(ResultSet, int)
static Connection
Spring Transaction is supported and Integrated.static DBLock
getDBLock
(DataSource ds, String tableName) Supports global lock by db table.static DBProductInfo
getDBProductInfo
(Connection conn) static DBProductInfo
static DBSequence
getDBSequence
(DataSource ds, String tableName, String seqName) Gets the DB sequence.static DBSequence
getDBSequence
(DataSource ds, String tableName, String seqName, long startVal, int seqBufferSize) Supports global sequence by db table.static Collection<String>
getInsertPropNames
(Class<?> entityClass) static Collection<String>
getInsertPropNames
(Class<?> entityClass, Set<String> excludedPropNames) static Collection<String>
getInsertPropNames
(Object entity) static Collection<String>
getInsertPropNames
(Object entity, Set<String> excludedPropNames) static long
Return the minimum execution time in milliseconds to log SQL performance in current thread.getNamedParameters
(String sql) Gets the named parameters.static Jdbc.OutParamResult
getOutParameters
(CallableStatement stmt, List<Jdbc.OutParam> outParams) static Collection<String>
getSelectPropNames
(Class<?> entityClass) static Collection<String>
getSelectPropNames
(Class<?> entityClass, boolean includeSubEntityProperties, Set<String> excludedPropNames) static Collection<String>
getSelectPropNames
(Class<?> entityClass, Set<String> excludedPropNames) static Collection<String>
getUpdatePropNames
(Class<?> entityClass) static Collection<String>
getUpdatePropNames
(Class<?> entityClass, Set<String> excludedPropNames) static boolean
static boolean
isNullOrDefault
(Object value) static boolean
Deprecated.replaced byisSpringTransactionalNotUsed()
static boolean
Check ifSpring Transactional
is shared or not in current thread.static boolean
Checks if sql log is enabled or not in current thread.static PreparedCallableQuery
prepareCallableQuery
(Connection conn, String sql) Never write below code because it will definitely causeConnection
leak:static PreparedCallableQuery
prepareCallableQuery
(Connection conn, String sql, com.landawn.abacus.util.Throwables.BiFunction<Connection, String, CallableStatement, SQLException> stmtCreator) Never write below code because it will definitely causeConnection
leak:static PreparedCallableQuery
prepareCallableQuery
(DataSource ds, String sql) If this method is called where a transaction is started byJdbcUtil.beginTransaction
or inSpring
with the sameDataSource
in the same thread, theConnection
started the Transaction will be used here.static PreparedCallableQuery
prepareCallableQuery
(DataSource ds, String sql, com.landawn.abacus.util.Throwables.BiFunction<Connection, String, CallableStatement, SQLException> stmtCreator) If this method is called where a transaction is started byJdbcUtil.beginTransaction
or inSpring
with the sameDataSource
in the same thread, theConnection
started the Transaction will be used here.static NamedQuery
prepareNamedQuery
(Connection conn, com.landawn.abacus.util.ParsedSql namedSql) Never write below code because it will definitely causeConnection
leak:static NamedQuery
prepareNamedQuery
(Connection conn, com.landawn.abacus.util.ParsedSql namedSql, boolean autoGeneratedKeys) Never write below code because it will definitely causeConnection
leak:static NamedQuery
prepareNamedQuery
(Connection conn, com.landawn.abacus.util.ParsedSql namedSql, int[] returnColumnIndexes) Never write below code because it will definitely causeConnection
leak:static NamedQuery
prepareNamedQuery
(Connection conn, com.landawn.abacus.util.ParsedSql namedSql, com.landawn.abacus.util.Throwables.BiFunction<Connection, String, PreparedStatement, SQLException> stmtCreator) Never write below code because it will definitely causeConnection
leak:static NamedQuery
prepareNamedQuery
(Connection conn, com.landawn.abacus.util.ParsedSql namedSql, String[] returnColumnNames) Never write below code because it will definitely causeConnection
leak:static NamedQuery
prepareNamedQuery
(Connection conn, String namedSql) Never write below code because it will definitely causeConnection
leak:static NamedQuery
prepareNamedQuery
(Connection conn, String namedSql, boolean autoGeneratedKeys) Never write below code because it will definitely causeConnection
leak:static NamedQuery
prepareNamedQuery
(Connection conn, String namedSql, int[] returnColumnIndexes) Never write below code because it will definitely causeConnection
leak:static NamedQuery
prepareNamedQuery
(Connection conn, String namedSql, com.landawn.abacus.util.Throwables.BiFunction<Connection, String, PreparedStatement, SQLException> stmtCreator) Never write below code because it will definitely causeConnection
leak:static NamedQuery
prepareNamedQuery
(Connection conn, String namedSql, String[] returnColumnNames) Never write below code because it will definitely causeConnection
leak:static NamedQuery
prepareNamedQuery
(DataSource ds, com.landawn.abacus.util.ParsedSql namedSql) If this method is called where a transaction is started byJdbcUtil.beginTransaction
or inSpring
with the sameDataSource
in the same thread, theConnection
started the Transaction will be used here.static NamedQuery
prepareNamedQuery
(DataSource ds, com.landawn.abacus.util.ParsedSql namedSql, boolean autoGeneratedKeys) If this method is called where a transaction is started byJdbcUtil.beginTransaction
or inSpring
with the sameDataSource
in the same thread, theConnection
started the Transaction will be used here.static NamedQuery
prepareNamedQuery
(DataSource ds, com.landawn.abacus.util.ParsedSql namedSql, int[] returnColumnIndexes) If this method is called where a transaction is started byJdbcUtil.beginTransaction
or inSpring
with the sameDataSource
in the same thread, theConnection
started the Transaction will be used here.static NamedQuery
prepareNamedQuery
(DataSource ds, com.landawn.abacus.util.ParsedSql namedSql, com.landawn.abacus.util.Throwables.BiFunction<Connection, String, PreparedStatement, SQLException> stmtCreator) If this method is called where a transaction is started byJdbcUtil.beginTransaction
or inSpring
with the sameDataSource
in the same thread, theConnection
started the Transaction will be used here.static NamedQuery
prepareNamedQuery
(DataSource ds, com.landawn.abacus.util.ParsedSql namedSql, String[] returnColumnNames) If this method is called where a transaction is started byJdbcUtil.beginTransaction
or inSpring
with the sameDataSource
in the same thread, theConnection
started the Transaction will be used here.static NamedQuery
prepareNamedQuery
(DataSource ds, String namedSql) If this method is called where a transaction is started byJdbcUtil.beginTransaction
or inSpring
with the sameDataSource
in the same thread, theConnection
started the Transaction will be used here.static NamedQuery
prepareNamedQuery
(DataSource ds, String namedSql, boolean autoGeneratedKeys) If this method is called where a transaction is started byJdbcUtil.beginTransaction
or inSpring
with the sameDataSource
in the same thread, theConnection
started the Transaction will be used here.static NamedQuery
prepareNamedQuery
(DataSource ds, String namedSql, int[] returnColumnIndexes) If this method is called where a transaction is started byJdbcUtil.beginTransaction
or inSpring
with the sameDataSource
in the same thread, theConnection
started the Transaction will be used here.static NamedQuery
prepareNamedQuery
(DataSource ds, String namedSql, com.landawn.abacus.util.Throwables.BiFunction<Connection, String, PreparedStatement, SQLException> stmtCreator) If this method is called where a transaction is started byJdbcUtil.beginTransaction
or inSpring
with the sameDataSource
in the same thread, theConnection
started the Transaction will be used here.static NamedQuery
prepareNamedQuery
(DataSource ds, String namedSql, String[] returnColumnNames) If this method is called where a transaction is started byJdbcUtil.beginTransaction
or inSpring
with the sameDataSource
in the same thread, theConnection
started the Transaction will be used here.static NamedQuery
prepareNamedQueryForBigResult
(Connection conn, String sql) Prepareselect
query for big result set.static NamedQuery
Prepareselect
query for big result set.static PreparedQuery
prepareQuery
(Connection conn, String sql) Never write below code because it will definitely causeConnection
leak:static PreparedQuery
prepareQuery
(Connection conn, String sql, boolean autoGeneratedKeys) Never write below code because it will definitely causeConnection
leak:static PreparedQuery
prepareQuery
(Connection conn, String sql, int[] returnColumnIndexes) Never write below code because it will definitely causeConnection
leak:static PreparedQuery
prepareQuery
(Connection conn, String sql, com.landawn.abacus.util.Throwables.BiFunction<Connection, String, PreparedStatement, SQLException> stmtCreator) Never write below code because it will definitely causeConnection
leak:static PreparedQuery
prepareQuery
(Connection conn, String sql, String[] returnColumnNames) Never write below code because it will definitely causeConnection
leak:static PreparedQuery
prepareQuery
(DataSource ds, String sql) If this method is called where a transaction is started byJdbcUtil.beginTransaction
or inSpring
with the sameDataSource
in the same thread, theConnection
started the Transaction will be used here.static PreparedQuery
prepareQuery
(DataSource ds, String sql, boolean autoGeneratedKeys) If this method is called where a transaction is started byJdbcUtil.beginTransaction
or inSpring
with the sameDataSource
in the same thread, theConnection
started the Transaction will be used here.static PreparedQuery
prepareQuery
(DataSource ds, String sql, int[] returnColumnIndexes) static PreparedQuery
prepareQuery
(DataSource ds, String sql, com.landawn.abacus.util.Throwables.BiFunction<Connection, String, PreparedStatement, SQLException> stmtCreator) If this method is called where a transaction is started byJdbcUtil.beginTransaction
or inSpring
with the sameDataSource
in the same thread, theConnection
started the Transaction will be used here.static PreparedQuery
prepareQuery
(DataSource ds, String sql, String[] returnColumnNames) static PreparedQuery
prepareQueryForBigResult
(Connection conn, String sql) Prepareselect
query for big result set.static PreparedQuery
prepareQueryForBigResult
(DataSource ds, String sql) Prepareselect
query for big result set.static void
releaseConnection
(Connection conn, DataSource ds) Spring Transaction is supported and Integrated.static <A,
B, C> void run
(A a, B b, C c, com.landawn.abacus.util.Throwables.TriConsumer<? super A, ? super B, ? super C, Exception> sqlAction) static void
static <T> void
static <T,
U> void run
(T t, U u, com.landawn.abacus.util.Throwables.BiConsumer<? super T, ? super U, Exception> sqlAction) static <E extends Throwable>
voidrunInTransaction
(DataSource dataSource, com.landawn.abacus.util.Throwables.Consumer<DataSource, E> cmd) static <E extends Throwable>
voidrunInTransaction
(DataSource dataSource, com.landawn.abacus.util.Throwables.Runnable<E> cmd) static <E extends Throwable>
voidrunNotInStartedTransaction
(DataSource dataSource, com.landawn.abacus.util.Throwables.Consumer<DataSource, E> cmd) static <E extends Throwable>
voidrunNotInStartedTransaction
(DataSource dataSource, com.landawn.abacus.util.Throwables.Runnable<E> cmd) static <E extends Exception>
voidrunWithoutUsingSpringTransaction
(com.landawn.abacus.util.Throwables.Runnable<E> sqlAction) Since using or not using Spring transaction flag is attached with current thread, so don't execute the specifiedsqlAction
in another thread.static <E extends Exception>
voidrunWithSqlLogDisabled
(com.landawn.abacus.util.Throwables.Runnable<E> sqlAction) Since enable/disable sql log flag is attached with current thread, so don't execute the specifiedsqlAction
in another thread.static <T,
ID, SB extends com.landawn.abacus.util.SQLBuilder, TD extends CrudDao<T, ID, SB, TD>>
voidsetIdExtractorForDao
(Class<? extends CrudDao<T, ID, SB, TD>> daoInterface, Jdbc.BiRowMapper<? extends ID> idExtractor) static <T,
ID, SB extends com.landawn.abacus.util.SQLBuilder, TD extends CrudDao<T, ID, SB, TD>>
voidsetIdExtractorForDao
(Class<? extends CrudDao<T, ID, SB, TD>> daoInterface, Jdbc.RowMapper<? extends ID> idExtractor) static void
setMinExecutionTimeForSqlPerfLog
(long minExecutionTimeForSqlPerfLog) Set minimum execution time to log sql performance in current thread.static void
setMinExecutionTimeForSqlPerfLog
(long minExecutionTimeForSqlPerfLog, int maxSqlLogLength) Set minimum execution time to log sql performance in current thread.static void
setSqlExtractor
(Function<Statement, String> sqlExtractor) static int
static int
static <T> com.landawn.abacus.util.ExceptionalStream<T,
SQLException> It's user's responsibility to close the inputresultSet
after the stream is finished, or call:
JdbcUtil.stream(resultset).onClose(Fn.closeQuietly(resultSet))...
static com.landawn.abacus.util.ExceptionalStream<Object[],
SQLException> It's user's responsibility to close the inputresultSet
after the stream is finished, or call:
JdbcUtil.stream(resultset).onClose(Fn.closeQuietly(resultSet))...
static <T> com.landawn.abacus.util.ExceptionalStream<T,
SQLException> It's user's responsibility to close the inputresultSet
after the stream is finished, or call:
JdbcUtil.stream(resultset).onClose(Fn.closeQuietly(resultSet))...
static <T> com.landawn.abacus.util.ExceptionalStream<T,
SQLException> stream
(ResultSet resultSet, Jdbc.BiRowFilter rowFilter, Jdbc.BiRowMapper<? extends T> rowMapper) It's user's responsibility to close the inputresultSet
after the stream is finished, or call:
JdbcUtil.stream(resultset).onClose(Fn.closeQuietly(resultSet))...
static <T> com.landawn.abacus.util.ExceptionalStream<T,
SQLException> stream
(ResultSet resultSet, Jdbc.BiRowMapper<? extends T> rowMapper) It's user's responsibility to close the inputresultSet
after the stream is finished, or call:
JdbcUtil.stream(resultset).onClose(Fn.closeQuietly(resultSet))...
static <T> com.landawn.abacus.util.ExceptionalStream<T,
SQLException> stream
(ResultSet resultSet, Jdbc.RowFilter rowFilter, Jdbc.RowMapper<? extends T> rowMapper) It's user's responsibility to close the inputresultSet
after the stream is finished, or call:
JdbcUtil.stream(resultset).onClose(Fn.closeQuietly(resultSet))...
static <T> com.landawn.abacus.util.ExceptionalStream<T,
SQLException> stream
(ResultSet resultSet, Jdbc.RowMapper<? extends T> rowMapper) It's user's responsibility to close the inputresultSet
after the stream is finished, or call:
JdbcUtil.stream(resultset).onClose(Fn.closeQuietly(resultSet))...
static <T> com.landawn.abacus.util.ExceptionalStream<T,
SQLException> It's user's responsibility to close the inputresultSet
after the stream is finished, or call:
JdbcUtil.stream(resultset).onClose(Fn.closeQuietly(resultSet))...
static <T> com.landawn.abacus.util.ExceptionalStream<T,
SQLException> streamAllResultSets
(Statement stmt, Jdbc.BiRowFilter rowFilter, Jdbc.BiRowMapper<? extends T> rowMapper) It's user's responsibility to close the inputstmt
after the stream is finished, or call:
JdbcUtil.streamAllResultSets(stmt, rowFilter, rowMapper).onClose(Fn.closeQuietly(stmt))...
static <T> com.landawn.abacus.util.ExceptionalStream<T,
SQLException> streamAllResultSets
(Statement stmt, Jdbc.BiRowMapper<? extends T> rowMapper) It's user's responsibility to close the inputstmt
after the stream is finished, or call:
JdbcUtil.streamAllResultSets(stmt, rowMapper).onClose(Fn.closeQuietly(stmt))...
static <T> com.landawn.abacus.util.ExceptionalStream<T,
SQLException> streamAllResultSets
(Statement stmt, Jdbc.RowFilter rowFilter, Jdbc.RowMapper<? extends T> rowMapper) It's user's responsibility to close the inputstmt
after the stream is finished, or call:
JdbcUtil.streamAllResultSets(stmt, rowFilter, rowMapper).onClose(Fn.closeQuietly(stmt))...
static <T> com.landawn.abacus.util.ExceptionalStream<T,
SQLException> streamAllResultSets
(Statement stmt, Jdbc.RowMapper<? extends T> rowMapper) It's user's responsibility to close the inputstmt
after the stream is finished, or call:
JdbcUtil.streamAllResultSets(stmt, rowMapper).onClose(Fn.closeQuietly(stmt))...
static void
static void
static void
-
Field Details
-
DEFAULT_BATCH_SIZE
public static final int DEFAULT_BATCH_SIZE- See Also:
-
DEFAULT_FETCH_SIZE_FOR_BIG_RESULT
public static final int DEFAULT_FETCH_SIZE_FOR_BIG_RESULT- See Also:
-
DEFAULT_SQL_EXTRACTOR
-
DEFAULT_MAX_SQL_LOG_LENGTH
public static final int DEFAULT_MAX_SQL_LOG_LENGTH- See Also:
-
DEFAULT_MIN_EXECUTION_TIME_FOR_DAO_METHOD_PERF_LOG
public static final long DEFAULT_MIN_EXECUTION_TIME_FOR_DAO_METHOD_PERF_LOG- See Also:
-
DEFAULT_MIN_EXECUTION_TIME_FOR_SQL_PERF_LOG
public static final long DEFAULT_MIN_EXECUTION_TIME_FOR_SQL_PERF_LOG- See Also:
-
-
Method Details
-
getDBProductInfo
public static DBProductInfo getDBProductInfo(DataSource ds) throws com.landawn.abacus.exception.UncheckedSQLException - Throws:
com.landawn.abacus.exception.UncheckedSQLException
-
getDBProductInfo
public static DBProductInfo getDBProductInfo(Connection conn) throws com.landawn.abacus.exception.UncheckedSQLException - Throws:
com.landawn.abacus.exception.UncheckedSQLException
-
createHikariDataSource
Creates the DataSource.- Parameters:
url
-user
-password
-- Returns:
-
createC3p0DataSource
Creates the DataSource.- Parameters:
url
-user
-password
-- Returns:
-
createConnection
public static Connection createConnection(String url, String user, String password) throws com.landawn.abacus.exception.UncheckedSQLException Creates the connection.- Parameters:
url
-user
-password
-- Returns:
- Throws:
com.landawn.abacus.exception.UncheckedSQLException
- the unchecked SQL exception
-
createConnection
public static Connection createConnection(String driverClass, String url, String user, String password) throws com.landawn.abacus.exception.UncheckedSQLException Creates the connection.- Parameters:
driverClass
-url
-user
-password
-- Returns:
- Throws:
com.landawn.abacus.exception.UncheckedSQLException
- the unchecked SQL exception
-
createConnection
public static Connection createConnection(Class<? extends Driver> driverClass, String url, String user, String password) throws com.landawn.abacus.exception.UncheckedSQLException Creates the connection.- Parameters:
driverClass
-url
-user
-password
-- Returns:
- Throws:
com.landawn.abacus.exception.UncheckedSQLException
- the unchecked SQL exception
-
getConnection
public static Connection getConnection(DataSource ds) throws com.landawn.abacus.exception.UncheckedSQLException Spring Transaction is supported and Integrated. If this method is called where a Spring transaction is started with the specifiedDataSource
, theConnection
started the Spring Transaction will be returned. Otherwise aConnection
directly from the specifiedDataSource
(Connection pool) will be returned.- Parameters:
ds
-- Returns:
- Throws:
com.landawn.abacus.exception.UncheckedSQLException
- the unchecked SQL exception
-
releaseConnection
Spring Transaction is supported and Integrated. If this method is called where a Spring transaction is started with the specifiedDataSource
, the specifiedConnection
won't be returned toDataSource
(Connection pool) until the transaction is committed or rolled back. Otherwise the specifiedConnection
will be directly returned back toDataSource
(Connection pool).- Parameters:
conn
-ds
-
-
close
- Parameters:
rs
-- Throws:
com.landawn.abacus.exception.UncheckedSQLException
- the unchecked SQL exception
-
close
public static void close(ResultSet rs, boolean closeStatement) throws com.landawn.abacus.exception.UncheckedSQLException - Parameters:
rs
-closeStatement
-- Throws:
com.landawn.abacus.exception.UncheckedSQLException
- the unchecked SQL exception
-
close
public static void close(ResultSet rs, boolean closeStatement, boolean closeConnection) throws IllegalArgumentException, com.landawn.abacus.exception.UncheckedSQLException - Parameters:
rs
-closeStatement
-closeConnection
-- Throws:
IllegalArgumentException
- ifcloseStatement = false
whilecloseConnection = true
.com.landawn.abacus.exception.UncheckedSQLException
- the unchecked SQL exception
-
close
- Parameters:
stmt
-- Throws:
com.landawn.abacus.exception.UncheckedSQLException
- the unchecked SQL exception
-
close
@Deprecated public static void close(Connection conn) throws com.landawn.abacus.exception.UncheckedSQLException Deprecated.consider usingreleaseConnection(Connection, javax.sql.DataSource)
- Parameters:
conn
-- Throws:
com.landawn.abacus.exception.UncheckedSQLException
- the unchecked SQL exception
-
close
public static void close(ResultSet rs, Statement stmt) throws com.landawn.abacus.exception.UncheckedSQLException - Parameters:
rs
-stmt
-- Throws:
com.landawn.abacus.exception.UncheckedSQLException
- the unchecked SQL exception
-
close
public static void close(Statement stmt, Connection conn) throws com.landawn.abacus.exception.UncheckedSQLException - Parameters:
stmt
-conn
-- Throws:
com.landawn.abacus.exception.UncheckedSQLException
- the unchecked SQL exception
-
close
public static void close(ResultSet rs, Statement stmt, Connection conn) throws com.landawn.abacus.exception.UncheckedSQLException - Parameters:
rs
-stmt
-conn
-- Throws:
com.landawn.abacus.exception.UncheckedSQLException
- the unchecked SQL exception
-
closeQuietly
Unconditionally close anResultSet
.Equivalent to
ResultSet.close()
, except any exceptions will be ignored. This is typically used in finally blocks.- Parameters:
rs
-
-
closeQuietly
public static void closeQuietly(ResultSet rs, boolean closeStatement) throws com.landawn.abacus.exception.UncheckedSQLException - Parameters:
rs
-closeStatement
-- Throws:
com.landawn.abacus.exception.UncheckedSQLException
- the unchecked SQL exception
-
closeQuietly
public static void closeQuietly(ResultSet rs, boolean closeStatement, boolean closeConnection) throws IllegalArgumentException - Parameters:
rs
-closeStatement
-closeConnection
-- Throws:
IllegalArgumentException
- ifcloseStatement = false
whilecloseConnection = true
.
-
closeQuietly
Unconditionally close anStatement
.Equivalent to
Statement.close()
, except any exceptions will be ignored. This is typically used in finally blocks.- Parameters:
stmt
-
-
closeQuietly
Deprecated.consider usingreleaseConnection(Connection, javax.sql.DataSource)
Unconditionally close anConnection
.Equivalent to
Connection.close()
, except any exceptions will be ignored. This is typically used in finally blocks.- Parameters:
conn
-
-
closeQuietly
Unconditionally close theResultSet, Statement
.Equivalent to
ResultSet.close()
,Statement.close()
, except any exceptions will be ignored. This is typically used in finally blocks.- Parameters:
rs
-stmt
-
-
closeQuietly
Unconditionally close theStatement, Connection
.Equivalent to
Statement.close()
,Connection.close()
, except any exceptions will be ignored. This is typically used in finally blocks.- Parameters:
stmt
-conn
-
-
closeQuietly
Unconditionally close theResultSet, Statement, Connection
.Equivalent to
ResultSet.close()
,Statement.close()
,Connection.close()
, except any exceptions will be ignored. This is typically used in finally blocks.- Parameters:
rs
-stmt
-conn
-
-
skip
- Parameters:
rs
-n
- the count of row to move ahead.- Returns:
- Throws:
SQLException
-
skip
- Parameters:
rs
-n
- the count of row to move ahead.- Returns:
- Throws:
SQLException
-
getColumnCount
Gets the column count.- Parameters:
rs
-- Returns:
- Throws:
SQLException
-
getColumnNameList
Gets the column name list.- Parameters:
conn
-tableName
-- Returns:
- Throws:
SQLException
-
getColumnLabelList
- Throws:
SQLException
-
getColumnLabel
Gets the column label.- Parameters:
rsmd
-columnIndex
-- Returns:
- Throws:
SQLException
-
getColumnIndex
public static int getColumnIndex(ResultSet resultSet, String columnName) throws com.landawn.abacus.exception.UncheckedSQLException Returns the column index starts with from 1, not 0.- Parameters:
resultSet
-columnName
-- Returns:
- Throws:
com.landawn.abacus.exception.UncheckedSQLException
- the unchecked SQL exception
-
getColumnIndex
Returns the column index starts with from 1, not 0.- Parameters:
rsmd
-columnName
-- Returns:
- Throws:
SQLException
-
getColumnValue
Gets the column value.- Parameters:
rs
-columnIndex
- starts with 1, not 0.- Returns:
- Throws:
SQLException
-
getColumnValue
@Deprecated public static Object getColumnValue(ResultSet rs, String columnLabel) throws SQLException Deprecated.please consider usinggetColumnValue(ResultSet, int)
Gets the column value.- Parameters:
rs
-columnLabel
-- Returns:
- Throws:
SQLException
-
getColumnValue
public static <T> T getColumnValue(Class<? extends T> targetClass, ResultSet rs, int columnIndex) throws SQLException Gets the column value.- Type Parameters:
T
-- Parameters:
targetClass
-rs
-columnIndex
-- Returns:
- Throws:
SQLException
-
getColumnValue
@Deprecated public static <T> T getColumnValue(Class<? extends T> targetClass, ResultSet rs, String columnLabel) throws SQLException Deprecated.please consider usinggetColumnValue(Class, ResultSet, int)
Gets the column value.- Type Parameters:
T
-- Parameters:
targetClass
-rs
-columnLabel
-- Returns:
- Throws:
SQLException
-
getColumn2FieldNameMap
-
isInTransaction
- Parameters:
ds
-- Returns:
-
beginTransaction
public static SQLTransaction beginTransaction(DataSource dataSource) throws com.landawn.abacus.exception.UncheckedSQLException Refer to:beginTransaction(javax.sql.DataSource, IsolationLevel, boolean)
.- Parameters:
dataSource
-- Returns:
- Throws:
com.landawn.abacus.exception.UncheckedSQLException
- the unchecked SQL exception
-
beginTransaction
public static SQLTransaction beginTransaction(DataSource dataSource, IsolationLevel isolationLevel) throws com.landawn.abacus.exception.UncheckedSQLException Refer to:beginTransaction(javax.sql.DataSource, IsolationLevel, boolean)
.- Parameters:
dataSource
-isolationLevel
-- Returns:
- Throws:
com.landawn.abacus.exception.UncheckedSQLException
- the unchecked SQL exception
-
beginTransaction
public static SQLTransaction beginTransaction(DataSource dataSource, IsolationLevel isolationLevel, boolean isForUpdateOnly) throws com.landawn.abacus.exception.UncheckedSQLException Starts a global transaction which will be shared by all in-line database query with the sameDataSource
in the same thread, including methods:JdbcUtil.beginTransaction/prepareQuery/prepareNamedQuery/prepareCallableQuery, SQLExecutor(Mapper).beginTransaction/get/insert/batchInsert/update/batchUpdate/query/list/findFirst/...
Spring Transaction is supported and Integrated. If this method is called at where a Spring transaction is started with the specifiedDataSource
, theConnection
started the Spring Transaction will be used here. That's to say the Spring transaction will have the final control on commit/roll back over theConnection
.
Here is the general code pattern to work withSQLTransaction
.public void doSomethingA() { ... final SQLTransaction tranA = JdbcUtil.beginTransaction(dataSource1, isolation); try { ... doSomethingB(); // Share the same transaction 'tranA' because they're in the same thread and start transaction with same DataSource 'dataSource1'. ... doSomethingC(); // won't share the same transaction 'tranA' although they're in the same thread but start transaction with different DataSource 'dataSource2'. ... tranA.commit(); } finally { tranA.rollbackIfNotCommitted(); } } public void doSomethingB() { ... final SQLTransaction tranB = JdbcUtil.beginTransaction(dataSource1, isolation); try { // do your work with the conn... ... tranB.commit(); } finally { tranB.rollbackIfNotCommitted(); } } public void doSomethingC() { ... final SQLTransaction tranC = JdbcUtil.beginTransaction(dataSource2, isolation); try { // do your work with the conn... ... tranC.commit(); } finally { tranC.rollbackIfNotCommitted(); } }
public void doSomethingA() { ... final SQLTransaction tranA = JdbcUtil.beginTransaction(dataSource1, isolation); boolean flagToCommit = false; try { // do your work with the conn... ... flagToCommit = true; } finally { if (flagToCommit) { tranA.commit(); } else { tranA.rollbackIfNotCommitted(); } } }
- Parameters:
dataSource
-isolationLevel
-isForUpdateOnly
-- Returns:
- Throws:
com.landawn.abacus.exception.UncheckedSQLException
- the unchecked SQL exception- See Also:
-
SQLExecutor#beginTransaction(IsolationLevel, boolean, JdbcSettings)
-
callInTransaction
@Beta public static <T,E extends Throwable> T callInTransaction(DataSource dataSource, com.landawn.abacus.util.Throwables.Callable<T, E> cmd) throws E- Type Parameters:
T
-E
-- Parameters:
dataSource
-cmd
-- Returns:
- Throws:
E
-
callInTransaction
@Beta public static <T,E extends Throwable> T callInTransaction(DataSource dataSource, com.landawn.abacus.util.Throwables.Function<DataSource, T, throws EE> cmd) - Type Parameters:
T
-E
-- Parameters:
dataSource
-cmd
-- Returns:
- Throws:
E
-
runInTransaction
@Beta public static <E extends Throwable> void runInTransaction(DataSource dataSource, com.landawn.abacus.util.Throwables.Runnable<E> cmd) throws E - Type Parameters:
E
-- Parameters:
dataSource
-cmd
-- Throws:
E
-
runInTransaction
@Beta public static <E extends Throwable> void runInTransaction(DataSource dataSource, com.landawn.abacus.util.Throwables.Consumer<DataSource, E> cmd) throws E- Type Parameters:
E
-- Parameters:
dataSource
-cmd
-- Throws:
E
-
callNotInStartedTransaction
@Beta public static <T,E extends Throwable> T callNotInStartedTransaction(DataSource dataSource, com.landawn.abacus.util.Throwables.Callable<T, E> cmd) throws E- Type Parameters:
T
-E
-- Parameters:
dataSource
-cmd
-- Returns:
- Throws:
E
-
callNotInStartedTransaction
@Beta public static <T,E extends Throwable> T callNotInStartedTransaction(DataSource dataSource, com.landawn.abacus.util.Throwables.Function<DataSource, T, throws EE> cmd) - Type Parameters:
T
-E
-- Parameters:
dataSource
-cmd
-- Returns:
- Throws:
E
-
runNotInStartedTransaction
@Beta public static <E extends Throwable> void runNotInStartedTransaction(DataSource dataSource, com.landawn.abacus.util.Throwables.Runnable<E> cmd) throws E - Type Parameters:
E
-- Parameters:
dataSource
-cmd
-- Throws:
E
-
runNotInStartedTransaction
@Beta public static <E extends Throwable> void runNotInStartedTransaction(DataSource dataSource, com.landawn.abacus.util.Throwables.Consumer<DataSource, E> cmd) throws E- Type Parameters:
E
-- Parameters:
dataSource
-cmd
-- Throws:
E
-
prepareQuery
If this method is called where a transaction is started byJdbcUtil.beginTransaction
or inSpring
with the sameDataSource
in the same thread, theConnection
started the Transaction will be used here. Otherwise aConnection
directly from the specifiedDataSource
(Connection pool) will be borrowed and used.- Parameters:
ds
-sql
-- Returns:
- Throws:
SQLException
- See Also:
-
prepareQuery
public static PreparedQuery prepareQuery(DataSource ds, String sql, boolean autoGeneratedKeys) throws SQLException If this method is called where a transaction is started byJdbcUtil.beginTransaction
or inSpring
with the sameDataSource
in the same thread, theConnection
started the Transaction will be used here. Otherwise aConnection
directly from the specifiedDataSource
(Connection pool) will be borrowed and used.- Parameters:
ds
-sql
-autoGeneratedKeys
-- Returns:
- Throws:
SQLException
- See Also:
-
prepareQuery
public static PreparedQuery prepareQuery(DataSource ds, String sql, int[] returnColumnIndexes) throws SQLException - Parameters:
ds
-sql
-returnColumnIndexes
-- Returns:
- Throws:
SQLException
-
prepareQuery
public static PreparedQuery prepareQuery(DataSource ds, String sql, String[] returnColumnNames) throws SQLException - Parameters:
ds
-sql
-returnColumnNames
-- Returns:
- Throws:
SQLException
-
prepareQuery
public static PreparedQuery prepareQuery(DataSource ds, String sql, com.landawn.abacus.util.Throwables.BiFunction<Connection, String, throws SQLExceptionPreparedStatement, SQLException> stmtCreator) If this method is called where a transaction is started byJdbcUtil.beginTransaction
or inSpring
with the sameDataSource
in the same thread, theConnection
started the Transaction will be used here. Otherwise aConnection
directly from the specifiedDataSource
(Connection pool) will be borrowed and used.- Parameters:
ds
-sql
-stmtCreator
- the createdPreparedStatement
will be closed after any execution methods inPreparedQuery/PreparedCallableQuery
is called. An execution method is a method which will trigger the backedPreparedStatement/CallableStatement
to be executed, for example: get/query/queryForInt/Long/../findFirst/findOnlyOne/list/execute/....- Returns:
- Throws:
SQLException
- See Also:
-
prepareQuery
Never write below code because it will definitely causeConnection
leak:JdbcUtil.prepareQuery(dataSource.getConnection(), sql);
- Parameters:
conn
- the specifiedconn
won't be close after this query is executed.sql
-- Returns:
- Throws:
SQLException
-
prepareQuery
public static PreparedQuery prepareQuery(Connection conn, String sql, boolean autoGeneratedKeys) throws SQLException Never write below code because it will definitely causeConnection
leak:JdbcUtil.prepareQuery(dataSource.getConnection(), sql, autoGeneratedKeys);
- Parameters:
conn
- the specifiedconn
won't be close after this query is executed.sql
-autoGeneratedKeys
-- Returns:
- Throws:
SQLException
-
prepareQuery
public static PreparedQuery prepareQuery(Connection conn, String sql, int[] returnColumnIndexes) throws SQLException Never write below code because it will definitely causeConnection
leak:JdbcUtil.prepareQuery(dataSource.getConnection(), sql, returnColumnIndexes);
- Parameters:
conn
-sql
-returnColumnIndexes
-- Returns:
- Throws:
SQLException
-
prepareQuery
public static PreparedQuery prepareQuery(Connection conn, String sql, String[] returnColumnNames) throws SQLException Never write below code because it will definitely causeConnection
leak:JdbcUtil.prepareQuery(dataSource.getConnection(), sql, returnColumnNames);
- Parameters:
conn
-sql
-returnColumnNames
-- Returns:
- Throws:
SQLException
-
prepareQuery
public static PreparedQuery prepareQuery(Connection conn, String sql, com.landawn.abacus.util.Throwables.BiFunction<Connection, String, throws SQLExceptionPreparedStatement, SQLException> stmtCreator) Never write below code because it will definitely causeConnection
leak:JdbcUtil.prepareQuery(dataSource.getConnection(), sql, stmtCreator);
- Parameters:
conn
- the specifiedconn
won't be close after this query is executed.sql
-stmtCreator
- the createdPreparedStatement
will be closed after any execution methods inPreparedQuery/PreparedCallableQuery
is called. An execution method is a method which will trigger the backedPreparedStatement/CallableStatement
to be executed, for example: get/query/queryForInt/Long/../findFirst/findOnlyOne/list/execute/....- Returns:
- Throws:
SQLException
-
prepareQueryForBigResult
@Beta public static PreparedQuery prepareQueryForBigResult(DataSource ds, String sql) throws SQLException Prepareselect
query for big result set. Fetch direction will be set toFetchDirection.FORWARD
and fetch size will be set toDEFAULT_FETCH_SIZE_FOR_BIG_RESULT=1000
.- Parameters:
ds
-sql
-- Returns:
- Throws:
SQLException
-
prepareQueryForBigResult
@Beta public static PreparedQuery prepareQueryForBigResult(Connection conn, String sql) throws SQLException Prepareselect
query for big result set. Fetch direction will be set toFetchDirection.FORWARD
and fetch size will be set toDEFAULT_FETCH_SIZE_FOR_BIG_RESULT=1000
.- Parameters:
conn
-sql
-- Returns:
- Throws:
SQLException
-
prepareNamedQuery
If this method is called where a transaction is started byJdbcUtil.beginTransaction
or inSpring
with the sameDataSource
in the same thread, theConnection
started the Transaction will be used here. Otherwise aConnection
directly from the specifiedDataSource
(Connection pool) will be borrowed and used.- Parameters:
ds
-namedSql
- for exampleSELECT first_name, last_name FROM account where id = :id
- Returns:
- Throws:
SQLException
- See Also:
-
prepareNamedQuery
public static NamedQuery prepareNamedQuery(DataSource ds, String namedSql, boolean autoGeneratedKeys) throws SQLException If this method is called where a transaction is started byJdbcUtil.beginTransaction
or inSpring
with the sameDataSource
in the same thread, theConnection
started the Transaction will be used here. Otherwise aConnection
directly from the specifiedDataSource
(Connection pool) will be borrowed and used.- Parameters:
ds
-namedSql
- for exampleSELECT first_name, last_name FROM account where id = :id
autoGeneratedKeys
-- Returns:
- Throws:
SQLException
- See Also:
-
prepareNamedQuery
public static NamedQuery prepareNamedQuery(DataSource ds, String namedSql, int[] returnColumnIndexes) throws SQLException If this method is called where a transaction is started byJdbcUtil.beginTransaction
or inSpring
with the sameDataSource
in the same thread, theConnection
started the Transaction will be used here. Otherwise aConnection
directly from the specifiedDataSource
(Connection pool) will be borrowed and used.- Parameters:
ds
-namedSql
- for exampleSELECT first_name, last_name FROM account where id = :id
returnColumnIndexes
-- Returns:
- Throws:
SQLException
-
prepareNamedQuery
public static NamedQuery prepareNamedQuery(DataSource ds, String namedSql, String[] returnColumnNames) throws SQLException If this method is called where a transaction is started byJdbcUtil.beginTransaction
or inSpring
with the sameDataSource
in the same thread, theConnection
started the Transaction will be used here. Otherwise aConnection
directly from the specifiedDataSource
(Connection pool) will be borrowed and used.- Parameters:
ds
-namedSql
- for exampleSELECT first_name, last_name FROM account where id = :id
returnColumnNames
-- Returns:
- Throws:
SQLException
-
prepareNamedQuery
public static NamedQuery prepareNamedQuery(DataSource ds, String namedSql, com.landawn.abacus.util.Throwables.BiFunction<Connection, String, throws SQLExceptionPreparedStatement, SQLException> stmtCreator) If this method is called where a transaction is started byJdbcUtil.beginTransaction
or inSpring
with the sameDataSource
in the same thread, theConnection
started the Transaction will be used here. Otherwise aConnection
directly from the specifiedDataSource
(Connection pool) will be borrowed and used.- Parameters:
ds
-namedSql
- for exampleSELECT first_name, last_name FROM account where id = :id
stmtCreator
- the createdPreparedStatement
will be closed after any execution methods inNamedQuery/PreparedCallableQuery
is called. An execution method is a method which will trigger the backedPreparedStatement/CallableStatement
to be executed, for example: get/query/queryForInt/Long/../findFirst/findOnlyOne/list/execute/....- Returns:
- Throws:
SQLException
- See Also:
-
prepareNamedQuery
Never write below code because it will definitely causeConnection
leak:JdbcUtil.prepareNamedQuery(dataSource.getConnection(), namedSql);
- Parameters:
conn
- the specifiedconn
won't be close after this query is executed.namedSql
- for exampleSELECT first_name, last_name FROM account where id = :id
- Returns:
- Throws:
SQLException
-
prepareNamedQuery
public static NamedQuery prepareNamedQuery(Connection conn, String namedSql, boolean autoGeneratedKeys) throws SQLException Never write below code because it will definitely causeConnection
leak:JdbcUtil.prepareNamedQuery(dataSource.getConnection(), namedSql, autoGeneratedKeys);
- Parameters:
conn
- the specifiedconn
won't be close after this query is executed.namedSql
- for exampleSELECT first_name, last_name FROM account where id = :id
autoGeneratedKeys
-- Returns:
- Throws:
SQLException
-
prepareNamedQuery
public static NamedQuery prepareNamedQuery(Connection conn, String namedSql, int[] returnColumnIndexes) throws SQLException Never write below code because it will definitely causeConnection
leak:JdbcUtil.prepareNamedQuery(dataSource.getConnection(), namedSql);
- Parameters:
conn
- the specifiedconn
won't be close after this query is executed.namedSql
- for exampleSELECT first_name, last_name FROM account where id = :id
returnColumnIndexes
-- Returns:
- Throws:
SQLException
-
prepareNamedQuery
public static NamedQuery prepareNamedQuery(Connection conn, String namedSql, String[] returnColumnNames) throws SQLException Never write below code because it will definitely causeConnection
leak:JdbcUtil.prepareNamedQuery(dataSource.getConnection(), namedSql);
- Parameters:
conn
- the specifiedconn
won't be close after this query is executed.namedSql
- for exampleSELECT first_name, last_name FROM account where id = :id
returnColumnNames
-- Returns:
- Throws:
SQLException
-
prepareNamedQuery
public static NamedQuery prepareNamedQuery(Connection conn, String namedSql, com.landawn.abacus.util.Throwables.BiFunction<Connection, String, throws SQLExceptionPreparedStatement, SQLException> stmtCreator) Never write below code because it will definitely causeConnection
leak:JdbcUtil.prepareNamedQuery(dataSource.getConnection(), namedSql, stmtCreator);
- Parameters:
conn
- the specifiedconn
won't be close after this query is executed.namedSql
- for exampleSELECT first_name, last_name FROM account where id = :id
stmtCreator
- the createdPreparedStatement
will be closed after any execution methods inNamedQuery/PreparedCallableQuery
is called. An execution method is a method which will trigger the backedPreparedStatement/CallableStatement
to be executed, for example: get/query/queryForInt/Long/../findFirst/findOnlyOne/list/execute/....- Returns:
- Throws:
SQLException
-
prepareNamedQuery
public static NamedQuery prepareNamedQuery(DataSource ds, com.landawn.abacus.util.ParsedSql namedSql) throws SQLException If this method is called where a transaction is started byJdbcUtil.beginTransaction
or inSpring
with the sameDataSource
in the same thread, theConnection
started the Transaction will be used here. Otherwise aConnection
directly from the specifiedDataSource
(Connection pool) will be borrowed and used.- Parameters:
ds
-namedSql
- for exampleSELECT first_name, last_name FROM account where id = :id
- Returns:
- Throws:
SQLException
- See Also:
-
prepareNamedQuery
public static NamedQuery prepareNamedQuery(DataSource ds, com.landawn.abacus.util.ParsedSql namedSql, boolean autoGeneratedKeys) throws SQLException If this method is called where a transaction is started byJdbcUtil.beginTransaction
or inSpring
with the sameDataSource
in the same thread, theConnection
started the Transaction will be used here. Otherwise aConnection
directly from the specifiedDataSource
(Connection pool) will be borrowed and used.- Parameters:
ds
-namedSql
- for exampleSELECT first_name, last_name FROM account where id = :id
autoGeneratedKeys
-- Returns:
- Throws:
SQLException
- See Also:
-
prepareNamedQuery
public static NamedQuery prepareNamedQuery(DataSource ds, com.landawn.abacus.util.ParsedSql namedSql, int[] returnColumnIndexes) throws SQLException If this method is called where a transaction is started byJdbcUtil.beginTransaction
or inSpring
with the sameDataSource
in the same thread, theConnection
started the Transaction will be used here. Otherwise aConnection
directly from the specifiedDataSource
(Connection pool) will be borrowed and used.- Parameters:
ds
-namedSql
- for exampleSELECT first_name, last_name FROM account where id = :id
returnColumnIndexes
-- Returns:
- Throws:
SQLException
-
prepareNamedQuery
public static NamedQuery prepareNamedQuery(DataSource ds, com.landawn.abacus.util.ParsedSql namedSql, String[] returnColumnNames) throws SQLException If this method is called where a transaction is started byJdbcUtil.beginTransaction
or inSpring
with the sameDataSource
in the same thread, theConnection
started the Transaction will be used here. Otherwise aConnection
directly from the specifiedDataSource
(Connection pool) will be borrowed and used.- Parameters:
ds
-namedSql
- for exampleSELECT first_name, last_name FROM account where id = :id
returnColumnNames
-- Returns:
- Throws:
SQLException
-
prepareNamedQuery
public static NamedQuery prepareNamedQuery(DataSource ds, com.landawn.abacus.util.ParsedSql namedSql, com.landawn.abacus.util.Throwables.BiFunction<Connection, String, throws SQLExceptionPreparedStatement, SQLException> stmtCreator) If this method is called where a transaction is started byJdbcUtil.beginTransaction
or inSpring
with the sameDataSource
in the same thread, theConnection
started the Transaction will be used here. Otherwise aConnection
directly from the specifiedDataSource
(Connection pool) will be borrowed and used.- Parameters:
ds
-namedSql
- for exampleSELECT first_name, last_name FROM account where id = :id
stmtCreator
- the createdPreparedStatement
will be closed after any execution methods inNamedQuery/PreparedCallableQuery
is called. An execution method is a method which will trigger the backedPreparedStatement/CallableStatement
to be executed, for example: get/query/queryForInt/Long/../findFirst/findOnlyOne/list/execute/....- Returns:
- Throws:
SQLException
- See Also:
-
prepareNamedQuery
public static NamedQuery prepareNamedQuery(Connection conn, com.landawn.abacus.util.ParsedSql namedSql) throws SQLException Never write below code because it will definitely causeConnection
leak:JdbcUtil.prepareNamedQuery(dataSource.getConnection(), namedSql);
- Parameters:
conn
- the specifiedconn
won't be close after this query is executed.namedSql
- for exampleSELECT first_name, last_name FROM account where id = :id
- Returns:
- Throws:
SQLException
-
prepareNamedQuery
public static NamedQuery prepareNamedQuery(Connection conn, com.landawn.abacus.util.ParsedSql namedSql, boolean autoGeneratedKeys) throws SQLException Never write below code because it will definitely causeConnection
leak:JdbcUtil.prepareNamedQuery(dataSource.getConnection(), namedSql, autoGeneratedKeys);
- Parameters:
conn
- the specifiedconn
won't be close after this query is executed.namedSql
- for exampleSELECT first_name, last_name FROM account where id = :id
autoGeneratedKeys
-- Returns:
- Throws:
SQLException
-
prepareNamedQuery
public static NamedQuery prepareNamedQuery(Connection conn, com.landawn.abacus.util.ParsedSql namedSql, int[] returnColumnIndexes) throws SQLException Never write below code because it will definitely causeConnection
leak:JdbcUtil.prepareNamedQuery(dataSource.getConnection(), namedSql);
- Parameters:
conn
- the specifiedconn
won't be close after this query is executed.namedSql
- for exampleSELECT first_name, last_name FROM account where id = :id
returnColumnIndexes
-- Returns:
- Throws:
SQLException
-
prepareNamedQuery
public static NamedQuery prepareNamedQuery(Connection conn, com.landawn.abacus.util.ParsedSql namedSql, String[] returnColumnNames) throws SQLException Never write below code because it will definitely causeConnection
leak:JdbcUtil.prepareNamedQuery(dataSource.getConnection(), namedSql);
- Parameters:
conn
- the specifiedconn
won't be close after this query is executed.namedSql
- for exampleSELECT first_name, last_name FROM account where id = :id
returnColumnNames
-- Returns:
- Throws:
SQLException
-
prepareNamedQuery
public static NamedQuery prepareNamedQuery(Connection conn, com.landawn.abacus.util.ParsedSql namedSql, com.landawn.abacus.util.Throwables.BiFunction<Connection, String, throws SQLExceptionPreparedStatement, SQLException> stmtCreator) Never write below code because it will definitely causeConnection
leak:JdbcUtil.prepareNamedQuery(dataSource.getConnection(), namedSql, stmtCreator);
- Parameters:
conn
- the specifiedconn
won't be close after this query is executed.namedSql
- for exampleSELECT first_name, last_name FROM account where id = :id
stmtCreator
- the createdPreparedStatement
will be closed after any execution methods inNamedQuery/PreparedCallableQuery
is called. An execution method is a method which will trigger the backedPreparedStatement/CallableStatement
to be executed, for example: get/query/queryForInt/Long/../findFirst/findOnlyOne/list/execute/....- Returns:
- Throws:
SQLException
-
prepareNamedQueryForBigResult
@Beta public static NamedQuery prepareNamedQueryForBigResult(DataSource ds, String sql) throws SQLException Prepareselect
query for big result set. Fetch direction will be set toFetchDirection.FORWARD
and fetch size will be set toDEFAULT_FETCH_SIZE_FOR_BIG_RESULT=1000
.- Parameters:
ds
-sql
-- Returns:
- Throws:
SQLException
-
prepareNamedQueryForBigResult
@Beta public static NamedQuery prepareNamedQueryForBigResult(Connection conn, String sql) throws SQLException Prepareselect
query for big result set. Fetch direction will be set toFetchDirection.FORWARD
and fetch size will be set toDEFAULT_FETCH_SIZE_FOR_BIG_RESULT=1000
.- Parameters:
conn
-sql
-- Returns:
- Throws:
SQLException
-
prepareCallableQuery
public static PreparedCallableQuery prepareCallableQuery(DataSource ds, String sql) throws SQLException If this method is called where a transaction is started byJdbcUtil.beginTransaction
or inSpring
with the sameDataSource
in the same thread, theConnection
started the Transaction will be used here. Otherwise aConnection
directly from the specifiedDataSource
(Connection pool) will be borrowed and used.- Parameters:
ds
-sql
-- Returns:
- Throws:
SQLException
- See Also:
-
prepareCallableQuery
public static PreparedCallableQuery prepareCallableQuery(DataSource ds, String sql, com.landawn.abacus.util.Throwables.BiFunction<Connection, String, throws SQLExceptionCallableStatement, SQLException> stmtCreator) If this method is called where a transaction is started byJdbcUtil.beginTransaction
or inSpring
with the sameDataSource
in the same thread, theConnection
started the Transaction will be used here. Otherwise aConnection
directly from the specifiedDataSource
(Connection pool) will be borrowed and used.- Parameters:
ds
-sql
-stmtCreator
- the createdCallableStatement
will be closed after any execution methods inPreparedQuery/PreparedCallableQuery
is called. An execution method is a method which will trigger the backedPreparedStatement/CallableStatement
to be executed, for example: get/query/queryForInt/Long/../findFirst/findOnlyOne/list/execute/....- Returns:
- Throws:
SQLException
- See Also:
-
prepareCallableQuery
public static PreparedCallableQuery prepareCallableQuery(Connection conn, String sql) throws SQLException Never write below code because it will definitely causeConnection
leak:JdbcUtil.prepareCallableQuery(dataSource.getConnection(), sql);
- Parameters:
conn
- the specifiedconn
won't be close after this query is executed.sql
-- Returns:
- Throws:
SQLException
- See Also:
-
prepareCallableQuery
public static PreparedCallableQuery prepareCallableQuery(Connection conn, String sql, com.landawn.abacus.util.Throwables.BiFunction<Connection, String, throws SQLExceptionCallableStatement, SQLException> stmtCreator) Never write below code because it will definitely causeConnection
leak:JdbcUtil.prepareCallableQuery(dataSource.getConnection(), sql, stmtCreator);
- Parameters:
conn
- the specifiedconn
won't be close after this query is executed.sql
-stmtCreator
- the createdCallableStatement
will be closed after any execution methods inPreparedQuery/PreparedCallableQuery
is called. An execution method is a method which will trigger the backedPreparedStatement/CallableStatement
to be executed, for example: get/query/queryForInt/Long/../findFirst/findOnlyOne/list/execute/....- Returns:
- Throws:
SQLException
-
executeQuery
@SafeVarargs public static com.landawn.abacus.util.DataSet executeQuery(DataSource ds, String sql, Object... parameters) throws SQLException - Parameters:
ds
-sql
-parameters
-- Returns:
- Throws:
SQLException
-
executeQuery
@SafeVarargs public static com.landawn.abacus.util.DataSet executeQuery(Connection conn, String sql, Object... parameters) throws SQLException - Parameters:
conn
-sql
-parameters
-- Returns:
- Throws:
SQLException
-
executeUpdate
@SafeVarargs public static int executeUpdate(DataSource ds, String sql, Object... parameters) throws SQLException - Parameters:
ds
-sql
-parameters
-- Returns:
- Throws:
SQLException
-
executeUpdate
@SafeVarargs public static int executeUpdate(Connection conn, String sql, Object... parameters) throws SQLException - Parameters:
conn
-sql
-parameters
-- Returns:
- Throws:
SQLException
-
executeBatchUpdate
public static int executeBatchUpdate(DataSource ds, String sql, List<?> listOfParameters) throws SQLException - Parameters:
ds
-sql
-listOfParameters
-- Returns:
- Throws:
SQLException
-
executeBatchUpdate
public static int executeBatchUpdate(DataSource ds, String sql, List<?> listOfParameters, int batchSize) throws SQLException - Parameters:
ds
-sql
-listOfParameters
-batchSize
-- Returns:
- Throws:
SQLException
-
executeBatchUpdate
public static int executeBatchUpdate(Connection conn, String sql, List<?> listOfParameters) throws SQLException Execute batch update.- Parameters:
conn
-sql
-listOfParameters
-- Returns:
- Throws:
SQLException
-
executeBatchUpdate
public static int executeBatchUpdate(Connection conn, String sql, List<?> listOfParameters, int batchSize) throws SQLException Execute batch update.- Parameters:
conn
-sql
-listOfParameters
-batchSize
-- Returns:
- Throws:
SQLException
-
executeLargeBatchUpdate
public static long executeLargeBatchUpdate(DataSource ds, String sql, List<?> listOfParameters) throws SQLException - Parameters:
ds
-sql
-listOfParameters
-- Returns:
- Throws:
SQLException
-
executeLargeBatchUpdate
public static long executeLargeBatchUpdate(DataSource ds, String sql, List<?> listOfParameters, int batchSize) throws SQLException - Parameters:
ds
-sql
-listOfParameters
-batchSize
-- Returns:
- Throws:
SQLException
-
executeLargeBatchUpdate
public static long executeLargeBatchUpdate(Connection conn, String sql, List<?> listOfParameters) throws SQLException Execute batch update.- Parameters:
conn
-sql
-listOfParameters
-- Returns:
- Throws:
SQLException
-
executeLargeBatchUpdate
public static long executeLargeBatchUpdate(Connection conn, String sql, List<?> listOfParameters, int batchSize) throws SQLException Execute batch update.- Parameters:
conn
-sql
-listOfParameters
-batchSize
-- Returns:
- Throws:
SQLException
-
execute
@SafeVarargs public static boolean execute(DataSource ds, String sql, Object... parameters) throws SQLException - Parameters:
ds
-sql
-parameters
-- Returns:
- Throws:
SQLException
-
execute
@SafeVarargs public static boolean execute(Connection conn, String sql, Object... parameters) throws SQLException - Parameters:
conn
-sql
-parameters
-- Returns:
- true, if successful
- Throws:
SQLException
-
extractData
- Parameters:
rs
-- Returns:
- Throws:
SQLException
-
extractData
public static com.landawn.abacus.util.DataSet extractData(ResultSet rs, boolean closeResultSet) throws SQLException - Parameters:
rs
-closeResultSet
-- Returns:
- Throws:
SQLException
-
extractData
public static com.landawn.abacus.util.DataSet extractData(ResultSet rs, int offset, int count) throws SQLException - Parameters:
rs
-offset
-count
-- Returns:
- Throws:
SQLException
-
extractData
public static com.landawn.abacus.util.DataSet extractData(ResultSet rs, int offset, int count, boolean closeResultSet) throws SQLException - Parameters:
rs
-offset
-count
-closeResultSet
-- Returns:
- Throws:
SQLException
-
extractData
public static com.landawn.abacus.util.DataSet extractData(ResultSet rs, int offset, int count, Jdbc.RowFilter filter, boolean closeResultSet) throws SQLException - Parameters:
rs
-offset
-count
-filter
-closeResultSet
-- Returns:
- Throws:
SQLException
-
extractData
public static com.landawn.abacus.util.DataSet extractData(ResultSet rs, int offset, int count, Jdbc.RowExtractor rowExtractor, boolean closeResultSet) throws SQLException - Parameters:
rs
-offset
-count
-rowExtractor
-closeResultSet
-- Returns:
- Throws:
SQLException
-
extractData
public static com.landawn.abacus.util.DataSet extractData(ResultSet rs, int offset, int count, Jdbc.RowFilter filter, Jdbc.RowExtractor rowExtractor, boolean closeResultSet) throws SQLException - Parameters:
rs
-offset
-count
-filter
-rowExtractor
-closeResultSet
-- Returns:
- Throws:
SQLException
-
extractAllResultSets
public static com.landawn.abacus.util.ExceptionalStream<com.landawn.abacus.util.DataSet,SQLException> extractAllResultSets(Statement stmt) It's user's responsibility to close the inputstmt
after the stream is finished, or call:
JdbcUtil.extractAllResultSets(stmt).onClose(Fn.closeQuietly(stmt))...
- Type Parameters:
T
-- Parameters:
stmt
-rowMapper
-- Returns:
-
extractAllResultSets
public static <T> com.landawn.abacus.util.ExceptionalStream<T,SQLException> extractAllResultSets(Statement stmt, Jdbc.ResultExtractor<T> resultExtractor) It's user's responsibility to close the inputstmt
after the stream is finished, or call:
JdbcUtil.extractAllResultSets(stmt, resultExtractor).onClose(Fn.closeQuietly(stmt))...
- Type Parameters:
T
-- Parameters:
stmt
-rowMapper
-- Returns:
-
extractAllResultSets
public static <T> com.landawn.abacus.util.ExceptionalStream<T,SQLException> extractAllResultSets(Statement stmt, Jdbc.BiResultExtractor<T> resultExtractor) It's user's responsibility to close the inputstmt
after the stream is finished, or call:
JdbcUtil.extractAllResultSets(stmt, resultExtractor).onClose(Fn.closeQuietly(stmt))...
- Type Parameters:
T
-- Parameters:
stmt
-rowMapper
-- Returns:
-
stream
public static com.landawn.abacus.util.ExceptionalStream<Object[],SQLException> stream(ResultSet resultSet) It's user's responsibility to close the inputresultSet
after the stream is finished, or call:
JdbcUtil.stream(resultset).onClose(Fn.closeQuietly(resultSet))...
- Parameters:
resultSet
-- Returns:
-
stream
public static <T> com.landawn.abacus.util.ExceptionalStream<T,SQLException> stream(Class<? extends T> targetClass, ResultSet resultSet) It's user's responsibility to close the inputresultSet
after the stream is finished, or call:
JdbcUtil.stream(resultset).onClose(Fn.closeQuietly(resultSet))...
- Type Parameters:
T
-- Parameters:
targetClass
- Array/List/Map or Entity with getter/setter methods.resultSet
-- Returns:
-
stream
public static <T> com.landawn.abacus.util.ExceptionalStream<T,SQLException> stream(ResultSet resultSet, Jdbc.RowMapper<? extends T> rowMapper) It's user's responsibility to close the inputresultSet
after the stream is finished, or call:
JdbcUtil.stream(resultset).onClose(Fn.closeQuietly(resultSet))...
- Type Parameters:
T
-- Parameters:
resultSet
-rowMapper
-- Returns:
-
stream
public static <T> com.landawn.abacus.util.ExceptionalStream<T,SQLException> stream(ResultSet resultSet, Jdbc.RowFilter rowFilter, Jdbc.RowMapper<? extends T> rowMapper) It's user's responsibility to close the inputresultSet
after the stream is finished, or call:
JdbcUtil.stream(resultset).onClose(Fn.closeQuietly(resultSet))...
- Type Parameters:
T
-- Parameters:
resultSet
-rowFilter
-rowMapper
-- Returns:
-
stream
public static <T> com.landawn.abacus.util.ExceptionalStream<T,SQLException> stream(ResultSet resultSet, Jdbc.BiRowMapper<? extends T> rowMapper) It's user's responsibility to close the inputresultSet
after the stream is finished, or call:
JdbcUtil.stream(resultset).onClose(Fn.closeQuietly(resultSet))...
- Type Parameters:
T
-- Parameters:
resultSet
-rowMapper
-- Returns:
-
stream
public static <T> com.landawn.abacus.util.ExceptionalStream<T,SQLException> stream(ResultSet resultSet, Jdbc.BiRowFilter rowFilter, Jdbc.BiRowMapper<? extends T> rowMapper) It's user's responsibility to close the inputresultSet
after the stream is finished, or call:
JdbcUtil.stream(resultset).onClose(Fn.closeQuietly(resultSet))...
- Type Parameters:
T
-- Parameters:
resultSet
-rowFilter
-rowMapper
-- Returns:
-
stream
public static <T> com.landawn.abacus.util.ExceptionalStream<T,SQLException> stream(ResultSet resultSet, int columnIndex) It's user's responsibility to close the inputresultSet
after the stream is finished, or call:
JdbcUtil.stream(resultset).onClose(Fn.closeQuietly(resultSet))...
- Type Parameters:
T
-- Parameters:
resultSet
-columnIndex
- starts from 1, not 0.- Returns:
-
stream
public static <T> com.landawn.abacus.util.ExceptionalStream<T,SQLException> stream(ResultSet resultSet, String columnName) It's user's responsibility to close the inputresultSet
after the stream is finished, or call:
JdbcUtil.stream(resultset).onClose(Fn.closeQuietly(resultSet))...
- Type Parameters:
T
-- Parameters:
resultSet
-columnName
-- Returns:
-
streamAllResultSets
public static <T> com.landawn.abacus.util.ExceptionalStream<T,SQLException> streamAllResultSets(Statement stmt, Jdbc.RowMapper<? extends T> rowMapper) It's user's responsibility to close the inputstmt
after the stream is finished, or call:
JdbcUtil.streamAllResultSets(stmt, rowMapper).onClose(Fn.closeQuietly(stmt))...
- Type Parameters:
T
-- Parameters:
stmt
-rowMapper
-- Returns:
-
streamAllResultSets
public static <T> com.landawn.abacus.util.ExceptionalStream<T,SQLException> streamAllResultSets(Statement stmt, Jdbc.RowFilter rowFilter, Jdbc.RowMapper<? extends T> rowMapper) It's user's responsibility to close the inputstmt
after the stream is finished, or call:
JdbcUtil.streamAllResultSets(stmt, rowFilter, rowMapper).onClose(Fn.closeQuietly(stmt))...
- Type Parameters:
T
-- Parameters:
stmt
-rowFilter
-rowMapper
-- Returns:
-
streamAllResultSets
public static <T> com.landawn.abacus.util.ExceptionalStream<T,SQLException> streamAllResultSets(Statement stmt, Jdbc.BiRowMapper<? extends T> rowMapper) It's user's responsibility to close the inputstmt
after the stream is finished, or call:
JdbcUtil.streamAllResultSets(stmt, rowMapper).onClose(Fn.closeQuietly(stmt))...
- Type Parameters:
T
-- Parameters:
stmt
-rowMapper
-- Returns:
-
streamAllResultSets
public static <T> com.landawn.abacus.util.ExceptionalStream<T,SQLException> streamAllResultSets(Statement stmt, Jdbc.BiRowFilter rowFilter, Jdbc.BiRowMapper<? extends T> rowMapper) It's user's responsibility to close the inputstmt
after the stream is finished, or call:
JdbcUtil.streamAllResultSets(stmt, rowFilter, rowMapper).onClose(Fn.closeQuietly(stmt))...
- Type Parameters:
T
-- Parameters:
stmt
-rowFilter
-rowMapper
-- Returns:
-
getOutParameters
public static Jdbc.OutParamResult getOutParameters(CallableStatement stmt, List<Jdbc.OutParam> outParams) throws SQLException - Parameters:
stmt
-outParams
-- Returns:
- Throws:
SQLException
-
doesTableExist
Does table exist.- Parameters:
conn
-tableName
-- Returns:
- true, if successful
-
createTableIfNotExists
Returnstrue
if succeed to create table, otherwisefalse
is returned.- Parameters:
conn
-tableName
-schema
-- Returns:
- true, if successful
-
dropTableIfExists
Returnstrue
if succeed to drop table, otherwisefalse
is returned.- Parameters:
conn
-tableName
-- Returns:
- true, if successful
-
getNamedParameters
Gets the named parameters.- Parameters:
sql
-- Returns:
-
getDBSequence
Gets the DB sequence.- Parameters:
tableName
-seqName
-- Returns:
-
getDBSequence
public static DBSequence getDBSequence(DataSource ds, String tableName, String seqName, long startVal, int seqBufferSize) Supports global sequence by db table.- Parameters:
tableName
-seqName
-startVal
-seqBufferSize
- the numbers to allocate/reserve from database table when cached numbers are used up.- Returns:
-
getDBLock
Supports global lock by db table.- Parameters:
tableName
-- Returns:
-
turnOffSqlLogGlobally
public static void turnOffSqlLogGlobally() -
turnOffSqlPerfLogGlobally
public static void turnOffSqlPerfLogGlobally() -
turnOffDaoMethodPerfLogGlobally
public static void turnOffDaoMethodPerfLogGlobally() -
enableSqlLog
Deprecated.replaced byenableSqlLog/disableSqlLog
.Enable/Disable sql log in current thread.- Parameters:
b
-true
to enable,false
to disable.
-
enableSqlLog
Deprecated.replaced byenableSqlLog/disableSqlLog
.Enable/Disable sql log in current thread.- Parameters:
b
-true
to enable,false
to disable.maxSqlLogLength
- default value is 1024
-
enableSqlLog
public static void enableSqlLog()Enable sql log in current thread. -
enableSqlLog
public static void enableSqlLog(int maxSqlLogLength) Enable sql log in current thread.- Parameters:
maxSqlLogLength
- default value is 1024
-
disableSqlLog
public static void disableSqlLog()Disable sql log in current thread. -
isSqlLogEnabled
public static boolean isSqlLogEnabled()Checks if sql log is enabled or not in current thread.- Returns:
true
if it's enabled, otherwisefalse
is returned.
-
setMinExecutionTimeForSqlPerfLog
public static void setMinExecutionTimeForSqlPerfLog(long minExecutionTimeForSqlPerfLog) Set minimum execution time to log sql performance in current thread.- Parameters:
minExecutionTimeForSqlPerfLog
-
-
setMinExecutionTimeForSqlPerfLog
public static void setMinExecutionTimeForSqlPerfLog(long minExecutionTimeForSqlPerfLog, int maxSqlLogLength) Set minimum execution time to log sql performance in current thread.- Parameters:
minExecutionTimeForSqlPerfLog
- Default value is 1000 (milliseconds).maxSqlLogLength
- default value is 1024
-
getMinExecutionTimeForSqlPerfLog
public static long getMinExecutionTimeForSqlPerfLog()Return the minimum execution time in milliseconds to log SQL performance in current thread. Default value is 1000 (milliseconds).- Returns:
-
disableSpringTransactional
Deprecated.replaced bydoNotUseSpringTransactional(boolean)
Don't share or shareSpring Transactional
in current thread.Spring Transactional
won't be used in fetching Connection if it's disabled.- Parameters:
b
-true
to not share,false
to share it again.
-
doNotUseSpringTransactional
public static void doNotUseSpringTransactional(boolean b) Don't share or shareSpring Transactional
in current thread.Spring Transactional
won't be used in fetching Connection if it's disabled.- Parameters:
b
-true
to not share,false
to share it again.
-
isSpringTransactionalDisabled
Deprecated.replaced byisSpringTransactionalNotUsed()
Check ifSpring Transactional
is shared or not in current thread.- Returns:
true
if it's not share, otherwisefalse
is returned.
-
isSpringTransactionalNotUsed
public static boolean isSpringTransactionalNotUsed()Check ifSpring Transactional
is shared or not in current thread.- Returns:
true
if it's not share, otherwisefalse
is returned.
-
runWithSqlLogDisabled
public static <E extends Exception> void runWithSqlLogDisabled(com.landawn.abacus.util.Throwables.Runnable<E> sqlAction) throws E Since enable/disable sql log flag is attached with current thread, so don't execute the specifiedsqlAction
in another thread.- Type Parameters:
E
-- Parameters:
sqlAction
-- Throws:
E
-
callWithSqlLogDisabled
public static <R,E extends Exception> R callWithSqlLogDisabled(com.landawn.abacus.util.Throwables.Callable<R, E> sqlAction) throws ESince enable/disable sql log flag is attached with current thread, so don't execute the specifiedsqlAction
in another thread.- Type Parameters:
R
-E
-- Parameters:
sqlAction
-- Returns:
- Throws:
E
-
runWithoutUsingSpringTransaction
public static <E extends Exception> void runWithoutUsingSpringTransaction(com.landawn.abacus.util.Throwables.Runnable<E> sqlAction) throws E Since using or not using Spring transaction flag is attached with current thread, so don't execute the specifiedsqlAction
in another thread.- Type Parameters:
E
-- Parameters:
sqlAction
-- Throws:
E
-
callWithoutUsingSpringTransaction
public static <R,E extends Exception> R callWithoutUsingSpringTransaction(com.landawn.abacus.util.Throwables.Callable<R, E> sqlAction) throws ESince using or not using Spring transaction flag is attached with current thread, so don't execute the specifiedsqlAction
in another thread.- Type Parameters:
R
-E
-- Parameters:
sqlAction
-- Returns:
- Throws:
E
-
getInsertPropNames
-
getInsertPropNames
-
getInsertPropNames
-
getInsertPropNames
public static Collection<String> getInsertPropNames(Class<?> entityClass, Set<String> excludedPropNames) -
getSelectPropNames
-
getSelectPropNames
public static Collection<String> getSelectPropNames(Class<?> entityClass, Set<String> excludedPropNames) -
getSelectPropNames
public static Collection<String> getSelectPropNames(Class<?> entityClass, boolean includeSubEntityProperties, Set<String> excludedPropNames) -
getUpdatePropNames
-
getUpdatePropNames
public static Collection<String> getUpdatePropNames(Class<?> entityClass, Set<String> excludedPropNames) -
getSqlExtractor
-
setSqlExtractor
-
run
-
run
@Beta public static <T> void run(T t, com.landawn.abacus.util.Throwables.Consumer<? super T, Exception> sqlAction) -
run
@Beta public static <T,U> void run(T t, U u, com.landawn.abacus.util.Throwables.BiConsumer<? super T, ? super U, Exception> sqlAction) -
run
@Beta public static <A,B, void runC> (A a, B b, C c, com.landawn.abacus.util.Throwables.TriConsumer<? super A, ? super B, ? super C, Exception> sqlAction) -
call
-
call
@Beta public static <T,R> R call(T t, com.landawn.abacus.util.Throwables.Function<? super T, ? extends R, Exception> sqlAction) -
call
@Beta public static <T,U, R callR> (T t, U u, com.landawn.abacus.util.Throwables.BiFunction<? super T, ? super U, ? extends R, Exception> sqlAction) -
call
@Beta public static <A,B, R callC, R> (A a, B b, C c, com.landawn.abacus.util.Throwables.TriFunction<? super A, ? super B, ? super C, ? extends R, Exception> sqlAction) -
asyncRun
@Beta public static com.landawn.abacus.util.ContinuableFuture<Void> asyncRun(com.landawn.abacus.util.Throwables.Runnable<Exception> sqlAction) Any transaction started in current thread won't be automatically applied to specifiedsqlAction
which will be executed in another thread.- Parameters:
sqlAction
-- Returns:
-
asyncRun
@Beta public static com.landawn.abacus.util.Tuple.Tuple2<com.landawn.abacus.util.ContinuableFuture<Void>,com.landawn.abacus.util.ContinuableFuture<Void>> asyncRun(com.landawn.abacus.util.Throwables.Runnable<Exception> sqlAction1, com.landawn.abacus.util.Throwables.Runnable<Exception> sqlAction2) Any transaction started in current thread won't be automatically applied to specifiedsqlAction
which will be executed in another thread.- Parameters:
sqlAction1
-sqlAction2
-- Returns:
-
asyncRun
@Beta public static com.landawn.abacus.util.Tuple.Tuple3<com.landawn.abacus.util.ContinuableFuture<Void>,com.landawn.abacus.util.ContinuableFuture<Void>, asyncRuncom.landawn.abacus.util.ContinuableFuture<Void>> (com.landawn.abacus.util.Throwables.Runnable<Exception> sqlAction1, com.landawn.abacus.util.Throwables.Runnable<Exception> sqlAction2, com.landawn.abacus.util.Throwables.Runnable<Exception> sqlAction3) Any transaction started in current thread won't be automatically applied to specifiedsqlAction
which will be executed in another thread.- Parameters:
sqlAction1
-sqlAction2
-sqlAction3
-- Returns:
-
asyncRun
@Beta public static <T> com.landawn.abacus.util.ContinuableFuture<Void> asyncRun(T t, com.landawn.abacus.util.Throwables.Consumer<? super T, Exception> sqlAction) Any transaction started in current thread won't be automatically applied to specifiedsqlAction
which will be executed in another thread.- Type Parameters:
T
-- Parameters:
t
-sqlAction
-- Returns:
-
asyncRun
@Beta public static <T,U> com.landawn.abacus.util.ContinuableFuture<Void> asyncRun(T t, U u, com.landawn.abacus.util.Throwables.BiConsumer<? super T, ? super U, Exception> sqlAction) Any transaction started in current thread won't be automatically applied to specifiedsqlAction
which will be executed in another thread.- Type Parameters:
T
-U
-- Parameters:
t
-u
-sqlAction
-- Returns:
-
asyncRun
@Beta public static <A,B, com.landawn.abacus.util.ContinuableFuture<Void> asyncRunC> (A a, B b, C c, com.landawn.abacus.util.Throwables.TriConsumer<? super A, ? super B, ? super C, Exception> sqlAction) Any transaction started in current thread won't be automatically applied to specifiedsqlAction
which will be executed in another thread.- Type Parameters:
A
-B
-C
-- Parameters:
a
-b
-c
-sqlAction
-- Returns:
-
asyncCall
@Beta public static <R> com.landawn.abacus.util.ContinuableFuture<R> asyncCall(Callable<R> sqlAction) Any transaction started in current thread won't be automatically applied to specifiedsqlAction
which will be executed in another thread.- Type Parameters:
R
-- Parameters:
sqlAction
-- Returns:
-
asyncCall
@Beta public static <R1,R2> com.landawn.abacus.util.Tuple.Tuple2<com.landawn.abacus.util.ContinuableFuture<R1>,com.landawn.abacus.util.ContinuableFuture<R2>> asyncCall(Callable<R1> sqlAction1, Callable<R2> sqlAction2) Any transaction started in current thread won't be automatically applied to specifiedsqlAction
which will be executed in another thread.- Type Parameters:
R1
-R2
-- Parameters:
sqlAction1
-sqlAction2
-- Returns:
-
asyncCall
@Beta public static <R1,R2, com.landawn.abacus.util.Tuple.Tuple3<com.landawn.abacus.util.ContinuableFuture<R1>,R3> com.landawn.abacus.util.ContinuableFuture<R2>, asyncCallcom.landawn.abacus.util.ContinuableFuture<R3>> (Callable<R1> sqlAction1, Callable<R2> sqlAction2, Callable<R3> sqlAction3) Any transaction started in current thread won't be automatically applied to specifiedsqlAction
which will be executed in another thread.- Type Parameters:
R1
-R2
-R3
-- Parameters:
sqlAction1
-sqlAction2
-sqlAction3
-- Returns:
-
asyncCall
@Beta public static <T,R> com.landawn.abacus.util.ContinuableFuture<R> asyncCall(T t, com.landawn.abacus.util.Throwables.Function<? super T, ? extends R, Exception> sqlAction) Any transaction started in current thread won't be automatically applied to specifiedsqlAction
which will be executed in another thread.- Type Parameters:
T
-R
-- Parameters:
t
-sqlAction
-- Returns:
-
asyncCall
@Beta public static <T,U, com.landawn.abacus.util.ContinuableFuture<R> asyncCallR> (T t, U u, com.landawn.abacus.util.Throwables.BiFunction<? super T, ? super U, ? extends R, Exception> sqlAction) Any transaction started in current thread won't be automatically applied to specifiedsqlAction
which will be executed in another thread.- Type Parameters:
T
-U
-R
-- Parameters:
t
-u
-sqlAction
-- Returns:
-
asyncCall
@Beta public static <A,B, com.landawn.abacus.util.ContinuableFuture<R> asyncCallC, R> (A a, B b, C c, com.landawn.abacus.util.Throwables.TriFunction<? super A, ? super B, ? super C, ? extends R, Exception> sqlAction) Any transaction started in current thread won't be automatically applied to specifiedsqlAction
which will be executed in another thread.- Type Parameters:
A
-B
-C
-R
-- Parameters:
a
-b
-c
-sqlAction
-- Returns:
-
setIdExtractorForDao
public static <T,ID, void setIdExtractorForDaoSB extends com.landawn.abacus.util.SQLBuilder, TD extends CrudDao<T, ID, SB, TD>> (Class<? extends CrudDao<T, ID, SB, TD>> daoInterface, Jdbc.RowMapper<? extends ID> idExtractor) -
setIdExtractorForDao
public static <T,ID, void setIdExtractorForDaoSB extends com.landawn.abacus.util.SQLBuilder, TD extends CrudDao<T, ID, SB, TD>> (Class<? extends CrudDao<T, ID, SB, TD>> daoInterface, Jdbc.BiRowMapper<? extends ID> idExtractor) -
createDao
- Type Parameters:
TD
-- Parameters:
daoInterface
-ds
-- Returns:
-
createDao
public static <TD extends Dao> TD createDao(Class<TD> daoInterface, DataSource ds, com.landawn.abacus.util.SQLMapper sqlMapper) - Type Parameters:
TD
-- Parameters:
daoInterface
-ds
-sqlMapper
-- Returns:
-
createDao
@Deprecated public static <TD extends Dao> TD createDao(Class<TD> daoInterface, DataSource ds, com.landawn.abacus.util.SQLMapper sqlMapper, com.landawn.abacus.cache.Cache<String, Object> cache) Deprecated.- Type Parameters:
TD
-- Parameters:
daoInterface
-ds
-sqlMapper
-cache
- don't share cache between Dao instances.- Returns:
-
createDao
public static <TD extends Dao> TD createDao(Class<TD> daoInterface, DataSource ds, Executor executor) - Type Parameters:
TD
-- Parameters:
daoInterface
-ds
-executor
-- Returns:
-
createDao
public static <TD extends Dao> TD createDao(Class<TD> daoInterface, DataSource ds, com.landawn.abacus.util.SQLMapper sqlMapper, Executor executor) - Type Parameters:
TD
-- Parameters:
daoInterface
-ds
-sqlMapper
-executor
-- Returns:
-
createDao
@Deprecated public static <TD extends Dao> TD createDao(Class<TD> daoInterface, DataSource ds, com.landawn.abacus.util.SQLMapper sqlMapper, com.landawn.abacus.cache.Cache<String, Object> cache, Executor executor) Deprecated.- Type Parameters:
TD
-- Parameters:
daoInterface
-ds
-sqlMapper
-cache
- don't share cache between Dao instances.executor
-- Returns:
-
generateEntityClass
-
generateEntityClass
-
generateEntityClass
-
generateEntityClass
public static String generateEntityClass(Connection conn, String tableName, EntityCodeConfig config) -
generateEntityClass
-
generateEntityClass
public static String generateEntityClass(DataSource ds, String entityName, String query, EntityCodeConfig config) -
generateEntityClass
-
generateEntityClass
public static String generateEntityClass(Connection conn, String entityName, String query, EntityCodeConfig config) -
isNullOrDefault
-
releaseConnection(Connection, javax.sql.DataSource)