public class SQLSelect<T> extends IndirectQuery implements Select<T>
Modifier and Type | Field and Description |
---|---|
protected String |
cacheGroup |
protected QueryCacheStrategy |
cacheStrategy |
protected CapsStrategy |
columnNameCaps |
protected String |
dataMapName |
protected int |
limit |
protected int |
offset |
protected int |
pageSize |
protected Map<String,Object> |
params |
protected Class<T> |
persistentType |
protected List<Object> |
positionalParams |
protected Class<T> |
scalarType |
protected StringBuilder |
sqlBuffer |
protected int |
statementFetchSize |
dataMap, lastResolver, name, replacementQuery
Constructor and Description |
---|
SQLSelect(Class<T> persistentType,
String sql) |
SQLSelect(String sql) |
Modifier and Type | Method and Description |
---|---|
SQLSelect<T> |
append(String sqlChunk)
Appends a piece of SQL to the previously stored SQL template.
|
ResultBatchIterator<T> |
batchIterator(ObjectContext context,
int size)
Creates a ResultBatchIterator based on the provided context and batch
size.
|
SQLSelect<T> |
cacheGroup(String cacheGroup) |
SQLSelect<T> |
cacheStrategy(QueryCacheStrategy strategy) |
SQLSelect<T> |
cacheStrategy(QueryCacheStrategy strategy,
String cacheGroup) |
SQLSelect<T> |
columnNameCaps(CapsStrategy columnNameCaps)
Sets a column name capitalization policy applied to selecting queries.
|
protected Query |
createReplacementQuery(EntityResolver resolver)
Creates a substitute query.
|
static SQLSelect<DataRow> |
dataRowQuery(String sql)
Creates a query that selects DataRows and uses default routing.
|
static SQLSelect<DataRow> |
dataRowQuery(String dataMapName,
String sql)
Creates a query that selects DataRows and uses routing based on the
provided DataMap name.
|
String |
getCacheGroup() |
QueryCacheStrategy |
getCacheStrategy() |
CapsStrategy |
getColumnNameCaps()
Returns a column name capitalization policy applied to selecting queries.
|
int |
getLimit() |
int |
getOffset() |
int |
getPageSize() |
Map<String,Object> |
getParams()
Returns a potentially immmutable map of named parameters that will be
bound to SQL.
|
List<Object> |
getPositionalParams()
Returns a potentially immmutable list of positional parameters that will
be bound to SQL.
|
String |
getSql() |
int |
getStatementFetchSize() |
boolean |
isFetchingDataRows() |
boolean |
isFetchingScalars() |
void |
iterate(ObjectContext context,
ResultIteratorCallback<T> callback)
Creates a ResultIterator based on the provided context and passes it to a
callback for processing.
|
ResultIterator<T> |
iterator(ObjectContext context)
Creates a ResultIterator based on the provided context.
|
SQLSelect<T> |
limit(int fetchLimit) |
SQLSelect<T> |
localCache()
Instructs Cayenne to look for query results in the "local" cache when
running the query.
|
SQLSelect<T> |
localCache(String cacheGroup)
Instructs Cayenne to look for query results in the "local" cache when
running the query.
|
SQLSelect<T> |
lowerColumnNames()
Equivalent of setting
CapsStrategy.LOWER |
SQLSelect<T> |
offset(int fetchOffset) |
SQLSelect<T> |
pageSize(int pageSize) |
SQLSelect<T> |
params(Map<String,?> parameters) |
SQLSelect<T> |
params(String name,
Object value) |
SQLSelect<T> |
paramsArray(Object... params)
Initializes positional parameters of the query.
|
SQLSelect<T> |
paramsList(List<Object> params)
Initializes positional parameters of the query.
|
static <T> SQLSelect<T> |
query(Class<T> type,
String sql)
Creates a query that selects DataObjects.
|
static <T> SQLSelect<T> |
scalarQuery(Class<T> type,
String sql)
Creates a query that selects scalar values and uses default routing.
|
static <T> SQLSelect<T> |
scalarQuery(Class<T> type,
String dataMapName,
String sql)
Creates a query that selects scalar values and uses routing based on the
provided DataMap name.
|
List<T> |
select(ObjectContext context)
Selects objects using provided context.
|
T |
selectFirst(ObjectContext context)
Selects a single object using provided context.
|
T |
selectOne(ObjectContext context)
Selects a single object using provided context.
|
SQLSelect<T> |
sharedCache()
Instructs Cayenne to look for query results in the "shared" cache when
running the query.
|
SQLSelect<T> |
sharedCache(String cacheGroup)
Instructs Cayenne to look for query results in the "shared" cache when
running the query.
|
SQLSelect<T> |
statementFetchSize(int size)
Sets JDBC statement's fetch size (0 for no default size)
|
SQLSelect<T> |
upperColumnNames()
Equivalent of setting
CapsStrategy.UPPER |
createSQLAction, getDataMap, getMetaData, getName, getReplacementQuery, route, setDataMap, setName
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
createSQLAction, getDataMap, getMetaData, getName, route
protected String dataMapName
protected StringBuilder sqlBuffer
protected QueryCacheStrategy cacheStrategy
protected String cacheGroup
protected CapsStrategy columnNameCaps
protected int limit
protected int offset
protected int pageSize
protected int statementFetchSize
public SQLSelect(String sql)
public static SQLSelect<DataRow> dataRowQuery(String sql)
public static SQLSelect<DataRow> dataRowQuery(String dataMapName, String sql)
public static <T> SQLSelect<T> query(Class<T> type, String sql)
public static <T> SQLSelect<T> scalarQuery(Class<T> type, String sql)
public static <T> SQLSelect<T> scalarQuery(Class<T> type, String dataMapName, String sql)
public List<T> select(ObjectContext context)
Select
Essentially the inversion of "ObjectContext.select(Select)".
public T selectOne(ObjectContext context)
Select
CayenneRuntimeException
is thrown.
Essentially the inversion of "ObjectContext.selectOne(Select)".
public T selectFirst(ObjectContext context)
Select
If it matched more than one object, the first object from the list is
returned. This makes 'selectFirst' different from
Select.selectOne(ObjectContext)
, which would throw in this situation.
'selectFirst' is useful e.g. when the query is ordered and we only want
to see the first object (e.g. "most recent news article"), etc.
Selecting the first object via "Select.selectFirst(ObjectContext)" is more comprehensible than selecting via "ObjectContext.selectFirst(Select)", because implementations of "Select" set fetch size limit to one.
selectFirst
in interface Select<T>
public void iterate(ObjectContext context, ResultIteratorCallback<T> callback)
Select
Essentially the inversion of "ObjectContext.iterate(Select, ResultIteratorCallback)".
public ResultIterator<T> iterator(ObjectContext context)
Select
Select.iterate(ObjectContext, ResultIteratorCallback)
as an
alternative.
Essentially the inversion of "ObjectContext.iterator(Select)".
public ResultBatchIterator<T> batchIterator(ObjectContext context, int size)
Select
batchIterator
in interface Select<T>
public boolean isFetchingDataRows()
public boolean isFetchingScalars()
public String getSql()
public SQLSelect<T> append(String sqlChunk)
public SQLSelect<T> paramsArray(Object... params)
Note that calling this method will reset any previously set *named* parameters.
public SQLSelect<T> paramsList(List<Object> params)
Note that calling this method will reset any previously set *named* parameters.
public Map<String,Object> getParams()
public List<Object> getPositionalParams()
protected Query createReplacementQuery(EntityResolver resolver)
IndirectQuery
createReplacementQuery
in class IndirectQuery
public SQLSelect<T> localCache()
query.cacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
public SQLSelect<T> localCache(String cacheGroup)
query.cacheStrategy(QueryCacheStrategy.LOCAL_CACHE, cacheGroup);
public SQLSelect<T> sharedCache()
query.cacheStrategy(QueryCacheStrategy.SHARED_CACHE);
public SQLSelect<T> sharedCache(String cacheGroup)
query.cacheStrategy(QueryCacheStrategy.SHARED_CACHE, cacheGroup);
public QueryCacheStrategy getCacheStrategy()
public SQLSelect<T> cacheStrategy(QueryCacheStrategy strategy)
public SQLSelect<T> cacheStrategy(QueryCacheStrategy strategy, String cacheGroup)
public String getCacheGroup()
public CapsStrategy getColumnNameCaps()
public SQLSelect<T> columnNameCaps(CapsStrategy columnNameCaps)
Note that while a non-default setting is useful for queries that do not rely on a #result directive to describe columns, it works for all SQLTemplates the same way.
public SQLSelect<T> upperColumnNames()
CapsStrategy.UPPER
public SQLSelect<T> lowerColumnNames()
CapsStrategy.LOWER
public int getLimit()
public int getOffset()
public int getPageSize()
public SQLSelect<T> statementFetchSize(int size)
public int getStatementFetchSize()
Copyright © 2001–2018 Apache Cayenne. All rights reserved.