Class GenericQuery<T>
- java.lang.Object
-
- jetbrains.buildServer.serverSide.db.queries.GenericQuery<T>
-
- Direct Known Subclasses:
CachingGenericQuery,DebugQuery,HistoryInsertQuery
public class GenericQuery<T> extends Object
Handy class to overcome JDBC verbosity. Provides vararg params, compact result set processing and batch operations, etc. Typicaly used as static object. Completely threadsafe.- Author:
- Pavel.Sher Date: 27.03.2006
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classGenericQuery.CheckExistsReturns true if result set contains at least one recordstatic classGenericQuery.CollectionBatchParamsIterator<I>Construct Object[] param arrays from items supplied by given iterator or collection.static classGenericQuery.CollectStringsThis processor collects string values from the first column into the given collection.static interfaceGenericQuery.ResultSetProcessor<T>Implementations are used to process query result set.static classGenericQuery.ReturnListOfLongsstatic classGenericQuery.ReturnSetOfIntegerstatic classGenericQuery.ReturnSetOfLongsstatic classGenericQuery.ReturnSetOfStringsstatic classGenericQuery.ReturnSingle<T>This processor will return single 1st column of 1st row of statement result set or default if none available.static classGenericQuery.ReturnSingleBooleanstatic classGenericQuery.ReturnSingleIntegerstatic classGenericQuery.ReturnSingleLongstatic classGenericQuery.ReturnSingleStringThis processor will return single 1st column of 1st row of statement result set or default if none available.static classGenericQuery.ReturnSmallSetOfInteger
-
Constructor Summary
Constructors Constructor Description GenericQuery(String sqlStatement)Creates instance parametrized by given SQL statement.GenericQuery(String sqlStatement, GenericQuery.ResultSetProcessor<T> processor)Creates instance parametrized by given SQL statement and result set processor instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Texecute(DBFunctions dbf, Object... params)Executes statement as query with given parametersTexecute(DBFunctions dbf, GenericQuery.ResultSetProcessor<T> processor, Object... params)Executes statement as query with given parameters and specific result set processor instance.Texecute(SQLRunnerEx runner, Object... params)Executes statement as query with given parameters and specific result set processor instance.Texecute(SQLRunnerEx runner, GenericQuery.ResultSetProcessor<T> processor, Object... params)Executes statement as query with given parameters and specific result set processor instance.voidexecuteBatch(DBFunctions dbf, Iterator<Object[]> paramsIterator)Executes (same) SQL statement in a batch, parametrizing it by provided iterator.voidexecuteBatch(SQLRunnerEx runner, Iterator<Object[]> paramsIterator)Executes (same) SQL statement in a batch, parametrizing it by provided iterator.intexecuteUpdate(DBFunctions dbf, Object... params)Executes an update statement and returns number of affected rows.intexecuteUpdate(SQLRunner runner, Object... params)Executes an update statement and returns number of affected rows.protected StringgetOriginalSqlStatement()protected GenericQuery.ResultSetProcessor<T>getResultSetProcessor()voidsetOptions(QueryOptions options)StringtoString()
-
-
-
Constructor Detail
-
GenericQuery
public GenericQuery(@NotNull String sqlStatement)Creates instance parametrized by given SQL statement.- Parameters:
sqlStatement- SQL statement
-
GenericQuery
public GenericQuery(@NotNull String sqlStatement, @Nullable GenericQuery.ResultSetProcessor<T> processor)Creates instance parametrized by given SQL statement and result set processor instance.- Parameters:
sqlStatement- SQL statementprocessor- default result set processor instance for this query
-
-
Method Detail
-
setOptions
public void setOptions(@Nullable QueryOptions options)
-
getOriginalSqlStatement
@NotNull protected String getOriginalSqlStatement()
-
execute
public T execute(@NotNull DBFunctions dbf, @Nullable Object... params)
Executes statement as query with given parameters- Parameters:
dbf- database access objectparams- parameters- Returns:
- result as declared
- Throws:
org.springframework.dao.DataAccessException- underlying JDBC exceptions are wrapped with extra details- Since:
- 7.0
-
execute
public T execute(@NotNull DBFunctions dbf, @NotNull GenericQuery.ResultSetProcessor<T> processor, @Nullable Object... params)
Executes statement as query with given parameters and specific result set processor instance.- Parameters:
dbf- database access objectparams- parametersprocessor- result set processor instance- Returns:
- result as declared
- Throws:
org.springframework.dao.DataAccessException- underlying JDBC exceptions are wrapped with extra details- Since:
- 7.0
-
execute
public T execute(@NotNull SQLRunnerEx runner, @Nullable Object... params)
Executes statement as query with given parameters and specific result set processor instance.- Parameters:
runner- SQL runnerparams- parameters- Returns:
- result as declared
- Throws:
org.springframework.dao.DataAccessException- underlying JDBC exceptions are wrapped with extra details
-
execute
public T execute(@NotNull SQLRunnerEx runner, @NotNull GenericQuery.ResultSetProcessor<T> processor, @Nullable Object... params)
Executes statement as query with given parameters and specific result set processor instance.- Parameters:
runner- SQL runnerparams- parametersprocessor- result set processor instance- Returns:
- result as declared
- Throws:
org.springframework.dao.DataAccessException- underlying JDBC exceptions are wrapped with extra details
-
executeUpdate
public int executeUpdate(@NotNull SQLRunner runner, Object... params)Executes an update statement and returns number of affected rows. Use this for updates, inserts and deletes.- Parameters:
runner- SQL runner.params- parameters.- Returns:
- affected rows count.
- Throws:
DBExceptionorg.springframework.dao.DataAccessException- See Also:
executeUpdate(jetbrains.buildServer.serverSide.db.DBFunctions, Object...)
-
executeUpdate
public int executeUpdate(@NotNull DBFunctions dbf, Object... params)Executes an update statement and returns number of affected rows. Use this for updates, inserts and deletes.- Parameters:
dbf- database access session.params- parameters.- Returns:
- affected rows count.
- Throws:
DBException- Since:
- 7.0
-
executeBatch
public void executeBatch(SQLRunnerEx runner, Iterator<Object[]> paramsIterator)
Executes (same) SQL statement in a batch, parametrizing it by provided iterator.- Parameters:
runner- SQL runnerparamsIterator- parameter arrays generator
-
executeBatch
public void executeBatch(@NotNull DBFunctions dbf, @NotNull Iterator<Object[]> paramsIterator)Executes (same) SQL statement in a batch, parametrizing it by provided iterator.- Parameters:
dbf- database functions instanceparamsIterator- parameter arrays generator
-
getResultSetProcessor
@Nullable protected GenericQuery.ResultSetProcessor<T> getResultSetProcessor()
-
-