diff --git a/ebean-api/src/main/java/io/ebean/BeanFinder.java b/ebean-api/src/main/java/io/ebean/BeanFinder.java index 1f5c0a12c..62a9bd6f9 100644 --- a/ebean-api/src/main/java/io/ebean/BeanFinder.java +++ b/ebean-api/src/main/java/io/ebean/BeanFinder.java @@ -12,6 +12,7 @@ import java.util.Optional; *

*
{@code
  *
+ * @Component
  * public class CustomerFinder extends BeanFinder {
  *
  *   @Inject
@@ -26,29 +27,37 @@ import java.util.Optional;
  *
  * @param  The ID type
  * @param  The Bean type
+ *
+ * @see BeanRepository
  */
 @NonNullApi
 public abstract class BeanFinder {
 
+  /**
+   * Migrate to using database rather than server.
+   */
+  @Deprecated
   protected final Database server;
+  protected final Database database;
   protected final Class type;
 
   /**
    * Create with the given bean type and Database instance.
    *
    * @param type The bean type
-   * @param server The Database instance typically created via Spring factory or equivalent.
+   * @param database The Database instance typically created via Spring factory or equivalent.
    */
-  protected BeanFinder(Class type, Database server) {
+  protected BeanFinder(Class type, Database database) {
     this.type = type;
-    this.server = server;
+    this.database = database;
+    this.server = database;
   }
 
   /**
    * Return the Database to use.
    */
   public Database db() {
-    return server;
+    return database;
   }
 
   /**
@@ -70,10 +79,10 @@ public abstract class BeanFinder {
    * 

* This is equivalent to {@link DB#byName(String)} * - * @param server The name of the Database. If this is null then the default Database is returned. + * @param name The name of the Database. If this is null then the default Database is returned. */ - public Database db(String server) { - return DB.byName(server); + public Database db(String name) { + return DB.byName(name); } /** diff --git a/ebean-api/src/main/java/io/ebean/BeanRepository.java b/ebean-api/src/main/java/io/ebean/BeanRepository.java index ad973e261..f5ca84500 100644 --- a/ebean-api/src/main/java/io/ebean/BeanRepository.java +++ b/ebean-api/src/main/java/io/ebean/BeanRepository.java @@ -6,11 +6,15 @@ import io.ebean.bean.EntityBean; import java.util.Collection; /** - * Provides finder functionality for use with "Dependency Injection style" use of Ebean. + * Provides find and persist functionality for use with "Dependency Injection style" use of Ebean. *

+ * Extend the BeanRepository with additional finder and persisting methods as needed by the + * application. The intention is to keep all the related logic together, for example, all the + * persisting and finding logic for Customer would be in CustomerRepository. + * *

{@code
  *
- * @Repository
+ * @Component
  * public class CustomerRepository extends BeanRepository {
  *
  *   @Inject
@@ -50,10 +54,10 @@ public abstract class BeanRepository extends BeanFinder {
    * }
* * @param type The bean type - * @param server The Database instance typically created via Spring factory or equivalent + * @param database The Database instance typically created via Spring factory or equivalent */ - protected BeanRepository(Class type, Database server) { - super(type, server); + protected BeanRepository(Class type, Database database) { + super(type, database); } /** @@ -122,8 +126,8 @@ public abstract class BeanRepository extends BeanFinder { /** * Save all the beans in the collection. */ - public int saveAll(Collection bean) { - return db().saveAll(bean); + public int saveAll(Collection beans) { + return db().saveAll(beans); } /** diff --git a/ebean-api/src/main/java/io/ebean/Finder.java b/ebean-api/src/main/java/io/ebean/Finder.java index 2bb927640..8dd4088fb 100644 --- a/ebean-api/src/main/java/io/ebean/Finder.java +++ b/ebean-api/src/main/java/io/ebean/Finder.java @@ -8,6 +8,9 @@ import java.util.List; * 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. *

+ * When using dependency injection {@link BeanRepository} and {@link BeanFinder} + * are expected to be used rather than this Finder. + *

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

@@ -54,6 +57,8 @@ import java.util.List; * * }
* + * @see BeanRepository + * @see BeanFinder */ @NonNullApi public class Finder { diff --git a/ebean-test/src/test/java/org/tests/repository/CustomerRepository.java b/ebean-test/src/test/java/org/tests/repository/CustomerRepository.java index f9fc7f59b..97179c38a 100644 --- a/ebean-test/src/test/java/org/tests/repository/CustomerRepository.java +++ b/ebean-test/src/test/java/org/tests/repository/CustomerRepository.java @@ -6,8 +6,6 @@ import org.tests.model.basic.Customer; import java.util.List; -//import javax.inject.Inject; - public class CustomerRepository extends BeanRepository { //@Inject @@ -28,7 +26,6 @@ public class CustomerRepository extends BeanRepository { } public int updateNotes(String blah, String whot) { - return updateQuery() .set("smallnote", whot) .where().eq("name", blah)