java.lang.Object
io.ebean.BeanFinder<I,T>
- Type Parameters:
I
- The ID typeT
- The Bean type
- Direct Known Subclasses:
BeanRepository
Provides finder functionality for use with "Dependency Injection style" use of Ebean.
Note that typically users would extend BeanRepository rather than BeanFinder.
@Component
public class CustomerFinder extends BeanFinder<Long,Customer> {
@Inject
public CustomerFinder(Database database) {
super(Customer.class, database);
}
// ... add customer specific finders
}
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
BeanFinder
(Class<T> type, Database database) Create with the given bean type and Database instance. -
Method Summary
Modifier and TypeMethodDescriptionReturn the current transaction.db()
Return the Database to use.Return typically a different Database to the default.void
deleteById
(I id) Delete a bean by Id.findAll()
Retrieves all entities of the given type.Retrieves an entity by ID.findByIdOrEmpty
(I id) Find an entity by ID returning an Optional.void
flush()
Flush the JDBC batch on the current transaction.Creates a native sql query.query()
Creates a query.Creates an entity reference for this ID.protected UpdateQuery
<T> Creates an update query.
-
Field Details
-
database
-
type
-
-
Constructor Details
-
BeanFinder
Create with the given bean type and Database instance.- Parameters:
type
- The bean typedatabase
- The Database instance typically created via Spring factory or equivalent.
-
-
Method Details
-
db
Return the Database to use. -
currentTransaction
Return the current transaction. -
flush
public void flush()Flush the JDBC batch on the current transaction. -
db
Return typically a different Database to the default.This is equivalent to
DB.byName(String)
- Parameters:
name
- The name of the Database. If this is null then the default Database is returned.
-
ref
Creates an entity reference for this ID.Equivalent to
Database.reference(Class, Object)
-
findById
Retrieves an entity by ID. -
findByIdOrEmpty
Find an entity by ID returning an Optional. -
deleteById
Delete a bean by Id. -
findAll
Retrieves all entities of the given type. -
updateQuery
Creates an update query.int rows = updateQuery() .set("status", Customer.Status.ACTIVE) .set("updtime", new Timestamp(System.currentTimeMillis())) .where() .gt("id", 1000) .update();
Equivalent to
Database.update(Class)
-
query
Creates a query.Equivalent to
Database.find(Class)
-
nativeSql
Creates a native sql query.
-