public class Finder<I,T> extends Object
These 'finders' are a place to organise all the finder methods for that bean type and specific finder methods are expected to be added (find by unique properties etc).
For testing the mocki-ebean project has the ability to replace the finder implementation
public class CustomerFinder extends Finder<Customer> {
public CustomerFinder() {
super(Customer.class);
}
// Add your customer finder methods ...
public Customer byName(String name) {
return query().eq("name", name).findUnique();
}
public List<Customer> findNew() {
return query()
.eq("status", Customer.Status.NEW)
.orderBy("name")
.findList()
}
}
@Entity
public class Customer extends BaseModel {
public static final CustomerFinder find = new CustomerFinder();
...
| Constructor and Description |
|---|
Finder(Class<T> type)
Create with the type of the entity bean.
|
Finder(Class<T> type,
String serverName)
Create with the type of the entity bean and specific server name.
|
| Modifier and Type | Method and Description |
|---|---|
List<T> |
all()
Retrieves all entities of the given type.
|
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> |
query()
Creates a query.
|
T |
ref(I id)
Creates an entity reference for this ID.
|
public Finder(Class<T> type)
public class CustomerFinder extends Finder<Customer> {
public CustomerFinder() {
super(Customer.class);
}
// ... add extra customer specific finder methods
}
@Entity
public class Customer extends BaseModel {
public static final CustomerFinder find = new CustomerFinder();
...
public EbeanServer db()
This provides full access to the API such as explicit transaction demarcation etc.
public EbeanServer db(String server)
This is equivalent to Ebean.getServer(String)
server - The name of the EbeanServer. If this is null then the default EbeanServer is
returned.public T ref(I id)
Equivalent to EbeanServer.getReference(Class, Object)
@Nullable public T byId(I id)
Equivalent to EbeanServer.find(Class, Object)
public void deleteById(I id)
Equivalent to EbeanServer.delete(Class, Object)
public Query<T> query()
Equivalent to EbeanServer.find(Class)
Copyright © 2016. All rights reserved.