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<Long,Customer> {
public CustomerFinder() {
super(Customer.class);
}
// Add your customer finder methods ...
public Customer byName(String name) {
return query().eq("name", name).findOne();
}
public List<Customer> findNew() {
return query().where()
.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.
|
Transaction |
currentTransaction()
Return the current transaction.
|
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.
|
void |
flush()
Flush the JDBC batch on the current transaction.
|
Query<T> |
nativeSql(String nativeSql)
Creates a native sql query.
|
Query<T> |
query()
Creates a query.
|
Query<T> |
query(String ormQuery)
Creates a query using the ORM query language.
|
T |
ref(I id)
Creates an entity reference for this ID.
|
UpdateQuery<T> |
update()
Creates an update query.
|
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 Transaction currentTransaction()
public void flush()
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.@Nonnull 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 UpdateQuery<T> update()
int rows =
finder.update()
.set("status", Customer.Status.ACTIVE)
.set("updtime", new Timestamp(System.currentTimeMillis()))
.where()
.gt("id", 1000)
.update();
Equivalent to EbeanServer.update(Class)
public Query<T> query()
Equivalent to EbeanServer.find(Class)
Copyright © 2019. All rights reserved.