Class SQLSelect<T>
- All Implemented Interfaces:
Serializable
,Query
,Select<T>
- Since:
- 4.0
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected String
protected QueryCacheStrategy
protected CapsStrategy
protected String
protected int
protected int
protected int
protected PrefetchTreeNode
protected int
protected StringBuilder
protected int
Fields inherited from class org.apache.cayenne.query.IndirectQuery
dataMap, lastResolver, name, replacementQuery
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddPrefetch
(String path, int semantics) Merges a prefetch path with specified semantics into the query prefetch tree.addPrefetch
(PrefetchTreeNode node) Merges a prefetch into the query prefetch tree.Appends a piece of SQL to the previously stored SQL template.batchIterator
(ObjectContext context, int size) Creates a ResultBatchIterator based on the provided context and batch size.cacheGroup
(String cacheGroup) cacheStrategy
(QueryCacheStrategy strategy) cacheStrategy
(QueryCacheStrategy strategy, String cacheGroup) columnNameCaps
(CapsStrategy columnNameCaps) Sets a column name capitalization policy applied to selecting queries.columnQuery
(String sql) Creates query that selects scalar values (as Object[]) and uses default routingcolumnQuery
(String sql, Class<?>... types) Creates query that selects scalar values (as Object[]) and uses default routingcolumnQuery
(String sql, String dataMapName) Creates query that selects scalar values (as Object[]) and uses routing based on the provided DataMap name.columnQuery
(String sql, String dataMapName, Class<?>... types) Creates query that selects scalar values (as Object[]) and uses routing based on the provided DataMap name.protected Query
createReplacementQuery
(EntityResolver resolver) Creates a substitute query.dataRowQuery
(String sql) Creates a query that selects DataRows and uses default routing.dataRowQuery
(String sql, Class<?>... types) Creates a query that selects DataRows and uses default routing.dataRowQuery
(String dataMapName, String sql) Creates a query that selects DataRows and uses routing based on the provided DataMap name.dataRowQuery
(String dataMapName, String sql, Class<?>... types) Creates a query that selects DataRows and uses routing based on the provided DataMap name.Returns a column name capitalization policy applied to selecting queries.int
getLimit()
int
int
Returns a potentially immmutable map of named parameters that will be bound to SQL.Returns a potentially immmutable list of positional parameters that will be bound to SQL.int
getSql()
int
boolean
void
iterate
(ObjectContext context, ResultIteratorCallback<T> callback) Creates a ResultIterator based on the provided context and passes it to a callback for processing.iterator
(ObjectContext context) Creates a ResultIterator based on the provided context.limit
(int fetchLimit) Instructs Cayenne to look for query results in the "local" cache when running the query.localCache
(String cacheGroup) Instructs Cayenne to look for query results in the "local" cache when running the query.Equivalent of settingCapsStrategy.LOWER
<E> SQLSelect
<E> Map result of this query by processing with a given function.offset
(int fetchOffset) pageSize
(int pageSize) Deprecated.paramsArray
(Object... params) Initializes positional parameters of the query.paramsList
(List<Object> params) Initializes positional parameters of the query.static <T> SQLSelect
<T> Creates a query that selects DataObjects.queryTimeout
(int queryTimeout) Sets query timeoutstatic <T> SQLSelect
<T> scalarQuery
(Class<T> type, String sql) Deprecated.since 4.2.static <T> SQLSelect
<T> scalarQuery
(Class<T> type, String dataMapName, String sql) Deprecated.since 4.2.scalarQuery
(String sql) Deprecated.since 4.2.scalarQuery
(String sql, Class<?>... types) Deprecated.since 4.2.static <T> SQLSelect
<T> scalarQuery
(String sql, Class<T> type) Creates query that selects scalar value and uses default routingscalarQuery
(String sql, String dataMapName) Deprecated.since 4.2.scalarQuery
(String sql, String dataMapName, Class<?>... types) Deprecated.since 4.2.static <T> SQLSelect
<T> scalarQuery
(String sql, String dataMapName, Class<T> type) Creates query that selects scalar value and uses default routingselect
(ObjectContext context) Selects objects using provided context.selectFirst
(ObjectContext context) Selects a single object using provided context.selectOne
(ObjectContext context) Selects a single object using provided context.Instructs Cayenne to look for query results in the "shared" cache when running the query.sharedCache
(String cacheGroup) Instructs Cayenne to look for query results in the "shared" cache when running the query.statementFetchSize
(int size) Sets JDBC statement's fetch size (0 for no default size)Equivalent of settingCapsStrategy.UPPER
Methods inherited from class org.apache.cayenne.query.IndirectQuery
createSQLAction, getMetaData, getReplacementQuery, route
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.cayenne.query.Query
createSQLAction, getMetaData, route
-
Field Details
-
persistentType
-
dataMapName
-
sqlBuffer
-
cacheStrategy
-
cacheGroup
-
params
-
positionalParams
-
columnNameCaps
-
limit
protected int limit -
offset
protected int offset -
pageSize
protected int pageSize -
statementFetchSize
protected int statementFetchSize -
queryTimeout
protected int queryTimeout -
prefetches
-
-
Constructor Details
-
SQLSelect
-
SQLSelect
-
-
Method Details
-
dataRowQuery
Creates a query that selects DataRows and uses default routing. -
dataRowQuery
Creates a query that selects DataRows and uses default routing.- Since:
- 4.1
-
dataRowQuery
Creates a query that selects DataRows and uses routing based on the provided DataMap name.- Since:
- 4.1
-
dataRowQuery
Creates a query that selects DataRows and uses routing based on the provided DataMap name. -
query
Creates a query that selects DataObjects. -
scalarQuery
Deprecated.since 4.2. UsescalarQuery(String, Class)
method.Creates a query that selects scalar values and uses default routing. -
scalarQuery
@Deprecated public static <T> SQLSelect<T> scalarQuery(Class<T> type, String dataMapName, String sql) Deprecated.since 4.2. UsescalarQuery(String, String, Class)
method.Creates a query that selects scalar values and uses routing based on the provided DataMap name. -
scalarQuery
Creates query that selects scalar value and uses default routing- Since:
- 4.1
-
scalarQuery
Creates query that selects scalar value and uses default routing- Since:
- 4.1
-
scalarQuery
Deprecated.since 4.2. UsecolumnQuery(String)
Creates query that selects scalar value and uses default routing- Since:
- 4.1
-
columnQuery
Creates query that selects scalar values (as Object[]) and uses default routing- Since:
- 4.2
-
scalarQuery
Deprecated.since 4.2. UsecolumnQuery(String, String)
Creates query that selects scalar values (as Object[]) and uses routing based on the provided DataMap name.- Since:
- 4.1
-
columnQuery
Creates query that selects scalar values (as Object[]) and uses routing based on the provided DataMap name.- Since:
- 4.2
-
scalarQuery
Deprecated.since 4.2. UsecolumnQuery(String, Class...)
Creates query that selects scalar values (as Object[]) and uses default routing- Since:
- 4.1
-
columnQuery
Creates query that selects scalar values (as Object[]) and uses default routing- Since:
- 4.2
-
scalarQuery
@Deprecated public static SQLSelect<Object[]> scalarQuery(String sql, String dataMapName, Class<?>... types) Deprecated.since 4.2. UsecolumnQuery(String, String, Class...)
Creates query that selects scalar values (as Object[]) and uses routing based on the provided DataMap name.- Since:
- 4.1
-
columnQuery
Creates query that selects scalar values (as Object[]) and uses routing based on the provided DataMap name.- Since:
- 4.2
-
select
Description copied from interface:Select
Selects objects using provided context.Essentially the inversion of "ObjectContext.select(Select)".
-
selectOne
Description copied from interface:Select
Selects a single object using provided context. The query is expected to match zero or one object. It returns null if no objects were matched. If query matched more than one object,CayenneRuntimeException
is thrown.Essentially the inversion of "ObjectContext.selectOne(Select)".
-
selectFirst
Description copied from interface:Select
Selects a single object using provided context. The query itself can match any number of objects, but will return only the first one. It returns null if no objects were matched.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.
- Specified by:
selectFirst
in interfaceSelect<T>
-
iterate
Description copied from interface:Select
Creates a ResultIterator based on the provided context and passes it to a callback for processing. The caller does not need to worry about closing the iterator. This method takes care of it.Essentially the inversion of "ObjectContext.iterate(Select, ResultIteratorCallback)".
-
iterator
Description copied from interface:Select
Creates a ResultIterator based on the provided context. It is usually backed by an open result set and is useful for processing of large data sets, preserving a constant memory footprint. The caller must wrap iteration in try/finally (or try-with-resources for Java 1.7 and higher) and close the ResultIterator explicitly. Or useSelect.iterate(ObjectContext, ResultIteratorCallback)
as an alternative.Essentially the inversion of "ObjectContext.iterator(Select)".
-
batchIterator
Description copied from interface:Select
Creates a ResultBatchIterator based on the provided context and batch size. It is usually backed by an open result set and is useful for processing of large data sets, preserving a constant memory footprint. The caller must wrap iteration in try/finally (or try-with-resources for Java 1.7 and higher) and close the ResultBatchIterator explicitly.- Specified by:
batchIterator
in interfaceSelect<T>
-
isFetchingDataRows
public boolean isFetchingDataRows() -
getSql
-
append
Appends a piece of SQL to the previously stored SQL template. -
params
Deprecated.since 4.2 Useparam(String, Object)
-
param
- Since:
- 4.2
-
params
-
paramsArray
Initializes positional parameters of the query. Parameters are bound in the order they are found in the SQL template. If a given parameter name is used more than once, only the first occurrence is treated as "position", subsequent occurrences are bound with the same value as the first one. If template parameters count is different from the array parameter count, an exception will be thrown.Note that calling this method will reset any previously set *named* parameters.
-
paramsList
Initializes positional parameters of the query. Parameters are bound in the order they are found in the SQL template. If a given parameter name is used more than once, only the first occurrence is treated as "position", subsequent occurrences are bound with the same value as the first one. If template parameters count is different from the list parameter count, an exception will be thrown.Note that calling this method will reset any previously set *named* parameters.
-
getParams
Returns a potentially immmutable map of named parameters that will be bound to SQL. -
getPositionalParams
Returns a potentially immmutable list of positional parameters that will be bound to SQL. -
createReplacementQuery
Description copied from class:IndirectQuery
Creates a substitute query. An implementor is free to provide an arbitrary replacement query.- Specified by:
createReplacementQuery
in classIndirectQuery
-
localCache
Instructs Cayenne to look for query results in the "local" cache when running the query. This is a short-hand notation for:query.cacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
-
localCache
Instructs Cayenne to look for query results in the "local" cache when running the query. This is a short-hand notation for:query.cacheStrategy(QueryCacheStrategy.LOCAL_CACHE, cacheGroup);
-
getCacheStrategy
-
cacheStrategy
-
cacheStrategy
-
getCacheGroup
-
cacheGroup
-
getColumnNameCaps
Returns a column name capitalization policy applied to selecting queries. This is used to simplify mapping of the queries like "SELECT * FROM ...", ensuring that a chosen Cayenne column mapping strategy (e.g. all column names in uppercase) is portable across database engines that can have varying default capitalization. Default (null) value indicates that column names provided in result set are used unchanged. -
columnNameCaps
Sets a column name capitalization policy applied to selecting queries. This is used to simplify mapping of the queries like "SELECT * FROM ...", ensuring that a chosen Cayenne column mapping strategy (e.g. all column names in uppercase) is portable across database engines that can have varying default capitalization. Default (null) value indicates that column names provided in result set are used unchanged.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.
-
upperColumnNames
Equivalent of settingCapsStrategy.UPPER
-
lowerColumnNames
Equivalent of settingCapsStrategy.LOWER
-
getLimit
public int getLimit() -
limit
-
getOffset
public int getOffset() -
offset
-
getPageSize
public int getPageSize() -
pageSize
-
statementFetchSize
Sets JDBC statement's fetch size (0 for no default size) -
queryTimeout
Sets query timeout- Since:
- 4.2
-
getStatementFetchSize
public int getStatementFetchSize()- Returns:
- JBDC statement's fetch size
-
getQueryTimeout
public int getQueryTimeout() -
addPrefetch
Merges a prefetch path with specified semantics into the query prefetch tree.- Parameters:
path
- Path expressionsemantics
- Defines a strategy to prefetch relationships. SeePrefetchTreeNode
- Returns:
- this object
- Since:
- 4.1
-
addPrefetch
Merges a prefetch into the query prefetch tree.- Parameters:
node
- Prefetch which will added to query prefetch tree- Returns:
- this object
- Since:
- 4.1
-
map
Map result of this query by processing with a given function.
Could be used to map plain Object[] to some domain-specific object.
Note: this method could be called multiple time, result will be mapped by all functions in the call order.- Type Parameters:
E
- new result type- Parameters:
mapper
- function that maps result to the required type.- Returns:
- this query with changed result type
- Since:
- 4.2
- See Also:
-
param(String, Object)