Package io.ebean

Class Finder<I,T>

java.lang.Object
io.ebean.Finder<I,T>

@NonNullApi public class Finder<I,T> extends Object
Intended to be used as a base class for 'Finder' implementations that can then be injected or used as public static fields on the associated entity bean.

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).

Testing

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 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)
       .order("name")
       .findList()
   }
 }

 @Entity
 public class Customer extends BaseModel {

   public static final CustomerFinder find = new CustomerFinder();
   ...

 }
 

When the Finder is registered as a field on Customer it can then be used like:



   Customer rob = Customer.find.byName("Rob");

 
  • Constructor Details

    • Finder

      public Finder(Class<T> type)
      Create with the type of the entity bean.
      
      
       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();
         ...
      
       }
       
    • Finder

      public Finder(Class<T> type, String databaseName)
      Create with the type of the entity bean and specific database name.
  • Method Details