Spring Data JDBC Extensions

org.springframework.data.jdbc.query
Class QueryDslJdbcTemplate

java.lang.Object
  extended by org.springframework.data.jdbc.query.QueryDslJdbcTemplate
All Implemented Interfaces:
QueryDslJdbcOperations

public class QueryDslJdbcTemplate
extends Object
implements QueryDslJdbcOperations

Template class with a basic set of JDBC operations, allowing the use of QueryDSL features.

This class delegates to a wrapped JdbcTemplate.

The underlying JdbcTemplate is exposed to allow for convenient access to the traditional JdbcTemplate methods. Thanks to Alex Soto (@alexsotob) for getting this started and implementing the initial prototype version.

Since:
1.0
Author:
Thomas Risberg
See Also:
JdbcTemplate

Constructor Summary
QueryDslJdbcTemplate(DataSource dataSource)
           
QueryDslJdbcTemplate(JdbcTemplate jdbcTemplate)
           
 
Method Summary
 long count(com.mysema.query.sql.SQLQuery sqlQuery)
          Count the rows that are part of the results for the given SQLQuery
 long countDistinct(com.mysema.query.sql.SQLQuery sqlQuery)
          Count the distinct rows that are part of the results for the given SQLQuery
 long delete(com.mysema.query.sql.RelationalPath<?> entity, SqlDeleteCallback callback)
          Execute a database delete using the provided SqlDeleteCallback.
 boolean exists(com.mysema.query.sql.SQLQuery sqlQuery)
          Determine if the result for the given SQLQuery contains some rows
 JdbcOperations getJdbcOperations()
          Expose the classic Spring JdbcTemplate to allow invocation of classic JDBC operations.
 long insert(com.mysema.query.sql.RelationalPath<?> entity, SqlInsertCallback callback)
          Execute a database insert using the provided SqlInsertCallback.
<K> K
insertWithKey(com.mysema.query.sql.RelationalPath<?> entity, SqlInsertWithKeyCallback<K> callback)
          Execute a database insert using the provided SqlInsertWithKeyCallback.
 com.mysema.query.sql.SQLQuery newSqlQuery()
          Create a new SQLQuery for this configuration.
 boolean notExists(com.mysema.query.sql.SQLQuery sqlQuery)
          Determine if the result for the given SQLQuery is empty
<T> List<T>
query(com.mysema.query.sql.SQLQuery sqlQuery, com.mysema.query.types.Expression<T> expression)
          Query for a list of objects using the SQLQuery.
<T> List<T>
query(com.mysema.query.sql.SQLQuery sqlQuery, ResultSetExtractor<List<T>> resultSetExtractor, com.mysema.query.types.Expression<?>... projection)
          Query for a list of objects using the SQLQuery.
<T> List<T>
query(com.mysema.query.sql.SQLQuery sqlQuery, RowMapper<T> rowMapper, com.mysema.query.types.Expression<?>... projection)
          Query for a list of objects using the SQLQuery.
<T> T
queryForObject(com.mysema.query.sql.SQLQuery sqlQuery, com.mysema.query.types.Expression<T> expression)
          Query for a single object using the SQLQuery.
<T> T
queryForObject(com.mysema.query.sql.SQLQuery sqlQuery, ResultSetExtractor<T> resultSetExtractor, com.mysema.query.types.Expression<?>... projection)
          Query for a single object using the SQLQuery.
<T> T
queryForObject(com.mysema.query.sql.SQLQuery sqlQuery, RowMapper<T> rowMapper, com.mysema.query.types.Expression<?>... projection)
          Query for a single object using the SQLQuery.
 long update(com.mysema.query.sql.RelationalPath<?> entity, SqlUpdateCallback callback)
          Execute a database update using the provided SqlUpdateCallback.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QueryDslJdbcTemplate

public QueryDslJdbcTemplate(DataSource dataSource)

QueryDslJdbcTemplate

public QueryDslJdbcTemplate(JdbcTemplate jdbcTemplate)
Method Detail

getJdbcOperations

public JdbcOperations getJdbcOperations()
Description copied from interface: QueryDslJdbcOperations
Expose the classic Spring JdbcTemplate to allow invocation of classic JDBC operations.

Specified by:
getJdbcOperations in interface QueryDslJdbcOperations

newSqlQuery

public com.mysema.query.sql.SQLQuery newSqlQuery()
Description copied from interface: QueryDslJdbcOperations
Create a new SQLQuery for this configuration.

Specified by:
newSqlQuery in interface QueryDslJdbcOperations
Returns:
the new SQLQuery object

count

public long count(com.mysema.query.sql.SQLQuery sqlQuery)
Description copied from interface: QueryDslJdbcOperations
Count the rows that are part of the results for the given SQLQuery

Specified by:
count in interface QueryDslJdbcOperations
Parameters:
sqlQuery - query to be used
Returns:
the count

countDistinct

public long countDistinct(com.mysema.query.sql.SQLQuery sqlQuery)
Description copied from interface: QueryDslJdbcOperations
Count the distinct rows that are part of the results for the given SQLQuery

Specified by:
countDistinct in interface QueryDslJdbcOperations
Parameters:
sqlQuery - query to be used
Returns:
the count

exists

public boolean exists(com.mysema.query.sql.SQLQuery sqlQuery)
Description copied from interface: QueryDslJdbcOperations
Determine if the result for the given SQLQuery contains some rows

Specified by:
exists in interface QueryDslJdbcOperations
Parameters:
sqlQuery - query to be used
Returns:
whether result exist

notExists

public boolean notExists(com.mysema.query.sql.SQLQuery sqlQuery)
Description copied from interface: QueryDslJdbcOperations
Determine if the result for the given SQLQuery is empty

Specified by:
notExists in interface QueryDslJdbcOperations
Parameters:
sqlQuery - query to be used
Returns:
whether result are empty

queryForObject

public <T> T queryForObject(com.mysema.query.sql.SQLQuery sqlQuery,
                            ResultSetExtractor<T> resultSetExtractor,
                            com.mysema.query.types.Expression<?>... projection)
Description copied from interface: QueryDslJdbcOperations
Query for a single object using the SQLQuery. The results are mapped using the RowMapper based on the specified projection.

Specified by:
queryForObject in interface QueryDslJdbcOperations
Parameters:
sqlQuery - the SQLQuery to use
resultSetExtractor - the ResultSetExtractor to extract the results
projection - the column projection to be used for the mapping
Returns:
the mapped object

queryForObject

public <T> T queryForObject(com.mysema.query.sql.SQLQuery sqlQuery,
                            RowMapper<T> rowMapper,
                            com.mysema.query.types.Expression<?>... projection)
Description copied from interface: QueryDslJdbcOperations
Query for a single object using the SQLQuery. The results are mapped using the RowMapper based on the specified projection.

Specified by:
queryForObject in interface QueryDslJdbcOperations
Parameters:
sqlQuery - the SQLQuery to use
rowMapper - the RowMapper to map the results
projection - the column projection to be used for the mapping
Returns:
the mapped object

queryForObject

public <T> T queryForObject(com.mysema.query.sql.SQLQuery sqlQuery,
                            com.mysema.query.types.Expression<T> expression)
Description copied from interface: QueryDslJdbcOperations
Query for a single object using the SQLQuery. The results are mapped using the Expression which could be a QBean or a MappingProjection.

Specified by:
queryForObject in interface QueryDslJdbcOperations
Parameters:
sqlQuery - the SQLQuery to use
expression - the implementation to be used for the projection/mapping
Returns:
the mapped object

query

public <T> List<T> query(com.mysema.query.sql.SQLQuery sqlQuery,
                         ResultSetExtractor<List<T>> resultSetExtractor,
                         com.mysema.query.types.Expression<?>... projection)
Description copied from interface: QueryDslJdbcOperations
Query for a list of objects using the SQLQuery. The results are mapped using the RowMapper based on the specified projection.

Specified by:
query in interface QueryDslJdbcOperations
Parameters:
sqlQuery - the SQLQuery to use
resultSetExtractor - the ResultSetExtractor to extract the results
projection - the column projection to be used for the mapping
Returns:
the mapped object

query

public <T> List<T> query(com.mysema.query.sql.SQLQuery sqlQuery,
                         RowMapper<T> rowMapper,
                         com.mysema.query.types.Expression<?>... projection)
Description copied from interface: QueryDslJdbcOperations
Query for a list of objects using the SQLQuery. The results are mapped using the RowMapper based on the specified projection.

Specified by:
query in interface QueryDslJdbcOperations
Parameters:
sqlQuery - the SQLQuery to use
rowMapper - the RowMapper to map the results
projection - the column projection to be used for the mapping
Returns:
the mapped object

query

public <T> List<T> query(com.mysema.query.sql.SQLQuery sqlQuery,
                         com.mysema.query.types.Expression<T> expression)
Description copied from interface: QueryDslJdbcOperations
Query for a list of objects using the SQLQuery. The results are mapped using the Expression which could be a QBean or a MappingProjection.

Specified by:
query in interface QueryDslJdbcOperations
Parameters:
sqlQuery - the SQLQuery to use
expression - the implementation to be used for the projection/mapping
Returns:
the mapped object

insert

public long insert(com.mysema.query.sql.RelationalPath<?> entity,
                   SqlInsertCallback callback)
Description copied from interface: QueryDslJdbcOperations
Execute a database insert using the provided SqlInsertCallback.

Specified by:
insert in interface QueryDslJdbcOperations
Parameters:
entity - RelationalPath representing the table for the entity
callback - the SqlInsertCallback implementation that operates on the SQLInsertClause
Returns:
number of affected rows

insertWithKey

public <K> K insertWithKey(com.mysema.query.sql.RelationalPath<?> entity,
                           SqlInsertWithKeyCallback<K> callback)
Description copied from interface: QueryDslJdbcOperations
Execute a database insert using the provided SqlInsertWithKeyCallback.

Specified by:
insertWithKey in interface QueryDslJdbcOperations
Parameters:
entity - RelationalPath representing the table for the entity
callback - the SqlInsertWithKeyCallback implementation that operates on the SQLInsertClause
Returns:
the key of the inserted row

update

public long update(com.mysema.query.sql.RelationalPath<?> entity,
                   SqlUpdateCallback callback)
Description copied from interface: QueryDslJdbcOperations
Execute a database update using the provided SqlUpdateCallback.

Specified by:
update in interface QueryDslJdbcOperations
Parameters:
entity - RelationalPath representing the table for the entity
callback - the SqlUpdateCallback implementation that operates on the SQLUpdateClause
Returns:
number of affected rows

delete

public long delete(com.mysema.query.sql.RelationalPath<?> entity,
                   SqlDeleteCallback callback)
Description copied from interface: QueryDslJdbcOperations
Execute a database delete using the provided SqlDeleteCallback.

Specified by:
delete in interface QueryDslJdbcOperations
Parameters:
entity - RelationalPath representing the table for the entity
callback - the SqlDeleteCallback implementation that operates on the SQLDeleteClause
Returns:
number of affected rows

Spring Data JDBC Extensions