- java.lang.Object
-
- io.ebean.BeanFinder<I,T>
-
- Type Parameters:
I- The ID typeT- The Bean type
- Direct Known Subclasses:
BeanRepository
@NonNullApi public abstract class BeanFinder<I,T> extends Object
Provides finder functionality for use with "Dependency Injection style" use of Ebean.Note that typically users would extend BeanRepository rather than BeanFinder.
{@code public class CustomerFinder extends BeanFinder{
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedBeanFinder(Class<T> type, Database server)Create with the given bean type and Database instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TransactioncurrentTransaction()Return the current transaction.Databasedb()Return the Database to use.Databasedb(String server)Return typically a different Database to the default.voiddeleteById(I id)Delete a bean by Id.List<T>findAll()Retrieves all entities of the given type.TfindById(I id)Retrieves an entity by ID.Optional<T>findByIdOrEmpty(I id)Find an entity by ID returning an Optional.voidflush()Flush the JDBC batch on the current transaction.protected Query<T>nativeSql(String nativeSql)Creates a native sql query.protected Query<T>query()Creates a query.protected Query<T>query(String ormQuery)Creates a query using the ORM query language.Tref(I id)Creates an entity reference for this ID.protected UpdateQuery<T>updateQuery()Creates an update query.
-
-
-
Method Detail
-
db
public Database db()
Return the Database to use.
-
currentTransaction
public Transaction currentTransaction()
Return the current transaction.
-
flush
public void flush()
Flush the JDBC batch on the current transaction.
-
db
public Database db(String server)
Return typically a different Database to the default.This is equivalent to
DB.byName(String)- Parameters:
server- The name of the Database. If this is null then the default Database is returned.
-
ref
public T ref(I id)
Creates an entity reference for this ID.Equivalent to
Database.reference(Class, Object)
-
findByIdOrEmpty
public Optional<T> findByIdOrEmpty(I id)
Find an entity by ID returning an Optional.
-
deleteById
public void deleteById(I id)
Delete a bean by Id.
-
updateQuery
protected UpdateQuery<T> 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
protected Query<T> query()
Creates a query.Equivalent to
Database.find(Class)
-
-