public class SQLSelect<T> extends IndirectQuery implements Select<T>
Modifier and Type | Field and Description |
---|---|
protected String[] |
cacheGroups |
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.
|
SQLSelect<T> |
cacheGroups(Collection<String> cacheGroups) |
SQLSelect<T> |
cacheGroups(String... cacheGroups) |
SQLSelect<T> |
cacheStrategy(QueryCacheStrategy strategy,
String... cacheGroups) |
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[] |
getCacheGroups() |
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() |
SQLSelect<T> |
limit(int fetchLimit) |
SQLSelect<T> |
localCache(String... cacheGroups)
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(String... cacheGroups)
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 |
acceptVisitor, createSQLAction, getDataMap, getMetaData, getName, getReplacementQuery, route, setDataMap, setName
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
createSQLAction, getDataMap, getMetaData, getName, route
acceptVisitor
protected String dataMapName
protected StringBuilder sqlBuffer
protected QueryCacheStrategy cacheStrategy
protected String[] cacheGroups
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)
public T selectOne(ObjectContext context)
CayenneRuntimeException
is
thrown.
Essentially the inversion of "ObjectContext.selectOne(Select)".
public T selectFirst(ObjectContext context)
If it matched more than one object, the first object from the list is
returned. This makes 'selectFirst' different from
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.
This method is equivalent to calling "limit(1).selectOne(context)".
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(String... cacheGroups)
query.cacheStrategy(QueryCacheStrategy.LOCAL_CACHE, cacheGroups);
public SQLSelect<T> sharedCache(String... cacheGroups)
query.cacheStrategy(QueryCacheStrategy.SHARED_CACHE, cacheGroups);
public QueryCacheStrategy getCacheStrategy()
public SQLSelect<T> cacheStrategy(QueryCacheStrategy strategy, String... cacheGroups)
public String[] getCacheGroups()
public SQLSelect<T> cacheGroups(Collection<String> cacheGroups)
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–2015 Apache Cayenne. All rights reserved.