I
- The Id type. This is most often a Long
but is also often a UUID
or
String
.T
- The entity bean typepublic abstract static class Model.Find<I,T> extends Object
Typically a Find instance is defined as a public static field on an entity bean class to provide a nice way to write queries.
@Entity
public class Customer extends BaseModel {
public static final Find<Long,Customer> find = new Find<Long,Customer>(){};
...
Customer customer = Customer.find.byId(42L);
List<Customer> customers =
Customer.find
.select("name, dateOfBirth")
.findList();
// kotlin
companion object : Model.Find<Long, Product>() {}
Modifier | Constructor and Description |
---|---|
|
Find()
Creates a finder for entity of type
T with ID of type I . |
protected |
Find(String serverName,
Class<T> type)
Construct passing the class literal type of the entity type.
|
Modifier and Type | Method and Description |
---|---|
List<T> |
all()
Retrieves all entities of the given type.
|
Query<T> |
apply(FetchPath fetchPath)
Creates a query applying the path properties to set the select and fetch clauses.
|
T |
byId(I id)
Retrieves an entity by ID.
|
EbeanServer |
db()
Return the underlying 'default' EbeanServer.
|
EbeanServer |
db(String server)
Return typically a different EbeanServer to the default.
|
void |
deleteById(I id)
Delete a bean by Id.
|
Query<T> |
fetch(String path)
Specifies a path to load including all its properties.
|
Query<T> |
fetch(String path,
FetchConfig joinConfig)
Additionally specifies a
FetchConfig to specify a 'query join' and/or define the
lazy loading query. |
Query<T> |
fetch(String path,
String fetchProperties)
Specifies a path to fetch with a specific list properties to include, to load a partial
object.
|
Query<T> |
fetch(String assocProperty,
String fetchProperties,
FetchConfig fetchConfig)
Additionally specifies a
FetchConfig to use a separate query or lazy loading to
load this path. |
Filter<T> |
filter()
Creates a filter for sorting and filtering lists of entities locally without going back to
the database.
|
void |
findEach(QueryEachConsumer<T> consumer)
Execute the query consuming each bean one at a time.
|
void |
findEachWhile(QueryEachWhileConsumer<T> consumer)
Execute the query consuming each bean one at a time.
|
FutureRowCount<T> |
findFutureRowCount()
Executes a find row count query in a background thread.
|
List<Object> |
findIds()
Executes a query and returns the results as a list of IDs.
|
List<T> |
findList()
Retrieves all entities of the given type.
|
Map<?,T> |
findMap()
Retrieves all entities of the given type as a map of objects.
|
<K> Map<K,T> |
findMap(String keyProperty,
Class<K> keyType)
Executes the query and returns the results as a map of the objects specifying the map key
property.
|
int |
findRowCount()
Returns the total number of entities for this type.
|
Set<T> |
findSet()
Returns all the entities of the given type as a set.
|
ExpressionFactory |
getExpressionFactory()
Returns the
ExpressionFactory used by this query. |
I |
nextId()
Returns the next identity value.
|
Model.Finder<I,T> |
on(String server)
Creates a Finder for the named EbeanServer.
|
OrderBy<T> |
order()
Returns the
order by clause so that you can append an ascending or descending
property to the order by clause. |
Query<T> |
order(String orderByClause)
Sets the
order by clause, replacing the existing order by clause if
there is one. |
OrderBy<T> |
orderBy()
Returns the
order by clause so that you can append an ascending or descending
property to the order by clause. |
Query<T> |
orderBy(String orderByClause)
Set the
order by clause replacing the existing order by clause if
there is one. |
Query<T> |
query()
Creates a query.
|
T |
ref(I id)
Creates an entity reference for this ID.
|
Query<T> |
select(String fetchProperties)
Explicitly sets a comma delimited list of the properties to fetch on the 'main' entity bean,
to load a partial object.
|
Query<T> |
setAutoTune(boolean autoTune)
Create a query with explicit 'AutoTune' use.
|
Query<T> |
setFirstRow(int firstRow)
Sets the first row to return for this query.
|
Query<T> |
setForUpdate(boolean forUpdate)
Create a query with the select with "for update" specified.
|
Query<T> |
setId(Object id)
Sets the ID value to query.
|
Query<T> |
setLoadBeanCache(boolean loadBeanCache)
Create a query specifying if the beans should be loaded into the L2 cache.
|
Query<T> |
setMaxRows(int maxRows)
Sets the maximum number of rows to return in the query.
|
Query<T> |
setRawSql(RawSql rawSql)
Create and return a new query based on the
RawSql . |
Query<T> |
setReadOnly(boolean readOnly)
Create a query specifying whether the returned beans will be read-only.
|
Query<T> |
setUseCache(boolean useBeanCache)
Create a query specifying if the L2 bean cache should be used.
|
Query<T> |
setUseQueryCache(boolean useQueryCache)
Create a query specifying if the L2 query cache should be used.
|
ExpressionList<T> |
where()
Adds expressions to the
where clause with the ability to chain on the
ExpressionList . |
public Find()
T
with ID of type I
.
Typically you create Find as a public static field on each entity bean as the example below.
Note that Find is an abstract class and hence {}
is required. This is done so
that the type (class literal) of the entity bean can be derived from the generics parameter.
@Entity
public class Customer extends BaseModel {
// Note the trailing {} as Find is an abstract class.
// We do this so that we can derive the type literal Customer.class
// via reflection
public static final Find<Long,Customer> find = new Find<Long,Customer>(){};
...
Customer customer = Customer.find.byId(42L);
List<Customer> customers =
Customer.find
.select("name, email, dateOfBirth")
.findList();
// kotlin
companion object : Model.Find<Long, Product>() {}
public EbeanServer db()
This provides full access to the API such as explicit transaction demarcation etc.
public EbeanServer db(String server)
This is equivilent to Ebean.getServer(String)
server
- The name of the EbeanServer. If this is null then the default EbeanServer is
returned.public Model.Finder<I,T> on(String server)
Create and return a new Finder for a different server.
public void deleteById(I id)
Equivalent to EbeanServer.delete(Class, Object)
public List<T> all()
This is the same as (synonym for) findList()
@Nullable public T byId(I id)
Equivalent to EbeanServer.find(Class, Object)
public T ref(I id)
Equivalent to EbeanServer.getReference(Class, Object)
public Filter<T> filter()
Equivalent to EbeanServer.filter(Class)
public Query<T> query()
Equivalent to EbeanServer.find(Class)
public Query<T> apply(FetchPath fetchPath)
Equivalent to Query.apply(FetchPath)
public I nextId()
EbeanServer.nextId(Class)
public List<Object> findIds()
Equivalent to Query.findIds()
public void findEach(QueryEachConsumer<T> consumer)
This is generally used to process large queries where unlike findList you do not want to hold all the results in memory at once but instead process them one at a time (requiring far less memory).
Equivalent toQuery.findEach(QueryEachConsumer)
public void findEachWhile(QueryEachWhileConsumer<T> consumer)
Equivalent to Query.findEachWhile(QueryEachWhileConsumer)
This is similar to #findEach except that you return boolean true to continue processing beans and return false to stop processing early.
This is generally used to process large queries where unlike findList you do not want to hold all the results in memory at once but instead process them one at a time (requiring far less memory).
Equivalent toQuery.findEachWhile(QueryEachWhileConsumer)
public List<T> findList()
The same as all()
Equivalent to Query.findList()
public Set<T> findSet()
Equivalent to Query.findSet()
public Map<?,T> findMap()
Equivalent to Query.findMap()
public <K> Map<K,T> findMap(String keyProperty, Class<K> keyType)
Equivalent to Query.findMap(String, Class)
public FutureRowCount<T> findFutureRowCount()
Equivalent to Query.findFutureRowCount()
public int findRowCount()
Equivalent to Query.findRowCount()
public ExpressionFactory getExpressionFactory()
ExpressionFactory
used by this query.public Query<T> select(String fetchProperties)
Equivalent to Query.select(String)
public Query<T> fetch(String path)
Equivalent to Query.fetch(String)
public Query<T> fetch(String path, FetchConfig joinConfig)
FetchConfig
to specify a 'query join' and/or define the
lazy loading query.
Equivalent to Query.fetch(String, FetchConfig)
public Query<T> fetch(String path, String fetchProperties)
Equivalent to Query.fetch(String, String)
public Query<T> fetch(String assocProperty, String fetchProperties, FetchConfig fetchConfig)
FetchConfig
to use a separate query or lazy loading to
load this path.
Equivalent to Query.fetch(String, String, FetchConfig)
public ExpressionList<T> where()
where
clause with the ability to chain on the
ExpressionList
.
Equivalent to Query.where()
public OrderBy<T> order()
order by
clause so that you can append an ascending or descending
property to the order by
clause.
This is exactly the same as orderBy()
.
Equivalent to Query.order()
public Query<T> order(String orderByClause)
order by
clause, replacing the existing order by
clause if
there is one.
This is exactly the same as orderBy(String)
.
public OrderBy<T> orderBy()
order by
clause so that you can append an ascending or descending
property to the order by
clause.
This is exactly the same as order()
.
Equivalent to Query.orderBy()
public Query<T> orderBy(String orderByClause)
order by
clause replacing the existing order by
clause if
there is one.
This is exactly the same as order(String)
.
public Query<T> setFirstRow(int firstRow)
Equivalent to Query.setFirstRow(int)
public Query<T> setMaxRows(int maxRows)
Equivalent to Query.setMaxRows(int)
public Query<T> setId(Object id)
Use this to perform a find byId query but with additional control over the query such as using select and fetch to control what parts of the object graph are returned.
Equivalent to Query.setId(Object)
public Query<T> setRawSql(RawSql rawSql)
RawSql
.
Equivalent to Query.setRawSql(RawSql)
public Query<T> setAutoTune(boolean autoTune)
public Query<T> setForUpdate(boolean forUpdate)
This will typically create row level database locks on the selected rows.
public Query<T> setReadOnly(boolean readOnly)
public Query<T> setLoadBeanCache(boolean loadBeanCache)
public Query<T> setUseCache(boolean useBeanCache)
public Query<T> setUseQueryCache(boolean useQueryCache)
Copyright © 2016. All rights reserved.