E
- the generic type of entities being queriedpublic class SmartQuery<E extends SQLEntity> extends Query<SmartQuery<E>,E,SQLConstraint>
SQLEntity
instances from the database.Modifier and Type | Class and Description |
---|---|
static class |
SmartQuery.Compiler
Represents the compiler which is used to generate SQL statements based on a
SmartQuery . |
Modifier and Type | Field and Description |
---|---|
protected List<SQLConstraint> |
constaints |
protected Database |
db |
protected boolean |
distinct |
protected List<Mapping> |
fields |
protected List<sirius.kernel.commons.Tuple<Mapping,Boolean>> |
orderBys |
descriptor, limit, MAX_LIST_SIZE, mixing, skip
Modifier | Constructor and Description |
---|---|
protected |
SmartQuery(EntityDescriptor descriptor,
Database db)
Creates a new query instance.
|
Modifier and Type | Method and Description |
---|---|
SQLQuery |
asSQLQuery()
Converts this query into a plain
SQLQuery which will return rows instead of entities. |
SmartQuery<E> |
copy()
Creates a full copy of the query which can be modified without modifying this query.
|
long |
count()
Executes the query and counts the number of results.
|
void |
delete()
Deletes all matches using the
BaseMapper.delete(BaseEntity) of the appropriate mapper. |
SmartQuery<E> |
distinctFields(Mapping... fields)
Specifies the fields to select, which also have to be DISTINCT.
|
protected long |
execCount(SmartQuery.Compiler compiler,
Connection c) |
protected void |
execIterate(Function<E,Boolean> handler,
SmartQuery.Compiler compiler,
sirius.kernel.commons.Limit limit,
boolean nativeLimit,
ResultSet rs) |
boolean |
exists()
Determines if the query would have at least one matching entity.
|
SmartQuery<E> |
fields(Mapping... fields)
Specifies which fields to select.
|
FilterFactory<SQLConstraint> |
filters() |
EntityDescriptor |
getEntityDescriptor()
Returns the EntityDescriptor for the type of entities addressed by this query.
|
void |
iterate(Function<E,Boolean> handler)
Calls the given function on all items in the result, as long as it returns true.
|
SmartQuery<E> |
orderAsc(Mapping field)
Adds a sort constraint to order by the given field ascending.
|
SmartQuery<E> |
orderDesc(Mapping field)
Adds a sort constraint to order by the given field descending.
|
protected sirius.kernel.health.HandledException |
queryError(SmartQuery.Compiler compiler,
Exception e) |
String |
toString() |
void |
truncate()
Deletes all matches using the capabilities of the underlying database.
|
protected void |
tuneStatement(PreparedStatement stmt,
sirius.kernel.commons.Limit limit,
boolean nativeLimit) |
SmartQuery<E> |
where(SQLConstraint constraint)
Applies the given contraints to the query.
|
eq, eqIgnoreNull, ne, queryString
failOnOverflow, first, getDescriptor, getLimit, iterateAll, limit, one, queryFirst, queryList, queryOne, skip
protected boolean distinct
protected List<SQLConstraint> constaints
protected Database db
protected SmartQuery(EntityDescriptor descriptor, Database db)
Use OMA.select(Class)
to create a new query.
descriptor
- the descriptor of the type to querydb
- the database to operate onpublic EntityDescriptor getEntityDescriptor()
public SmartQuery<E> where(SQLConstraint constraint)
Query
where
in class Query<SmartQuery<E extends SQLEntity>,E extends SQLEntity,SQLConstraint>
constraint
- the constraint which has to be fullfilledpublic FilterFactory<SQLConstraint> filters()
filters
in class Query<SmartQuery<E extends SQLEntity>,E extends SQLEntity,SQLConstraint>
public SmartQuery<E> orderAsc(Mapping field)
Query
orderAsc
in class Query<SmartQuery<E extends SQLEntity>,E extends SQLEntity,SQLConstraint>
field
- the field to order by.public SmartQuery<E> orderDesc(Mapping field)
Query
orderDesc
in class Query<SmartQuery<E extends SQLEntity>,E extends SQLEntity,SQLConstraint>
field
- the field to order by.public SmartQuery<E> distinctFields(Mapping... fields)
fields
- the fields to select and to apply a DISTINCT filter on.public SmartQuery<E> fields(Mapping... fields)
If no fields are given, * is selected
fields
- the list of fields to selectpublic long count()
Query
count
in class Query<SmartQuery<E extends SQLEntity>,E extends SQLEntity,SQLConstraint>
protected sirius.kernel.health.HandledException queryError(SmartQuery.Compiler compiler, Exception e)
protected long execCount(SmartQuery.Compiler compiler, Connection c) throws SQLException
SQLException
public boolean exists()
Query
exists
in class Query<SmartQuery<E extends SQLEntity>,E extends SQLEntity,SQLConstraint>
public void delete()
Query
BaseMapper.delete(BaseEntity)
of the appropriate mapper.
Be aware that this might be slow for very large result sets.
delete
in class Query<SmartQuery<E extends SQLEntity>,E extends SQLEntity,SQLConstraint>
public void truncate()
Query
Therefore no checks or anything will be invoked for the deleted entities.
Use this for larger result sets where integrity and constraints do not matter or are managed manually.
truncate
in class Query<SmartQuery<E extends SQLEntity>,E extends SQLEntity,SQLConstraint>
public SQLQuery asSQLQuery()
SQLQuery
which will return rows instead of entities.public SmartQuery<E> copy()
public void iterate(Function<E,Boolean> handler)
BaseQuery
Note that this method is intended for large results as not all items in the result need to be kept in memory when iterating through them.
protected void execIterate(Function<E,Boolean> handler, SmartQuery.Compiler compiler, sirius.kernel.commons.Limit limit, boolean nativeLimit, ResultSet rs) throws Exception
Exception
protected void tuneStatement(PreparedStatement stmt, sirius.kernel.commons.Limit limit, boolean nativeLimit) throws SQLException
SQLException
Copyright © 2018. All rights reserved.