diff --git a/src/main/java/com/avaje/ebean/Model.java b/src/main/java/com/avaje/ebean/Model.java index 711075c59..1fbd81f44 100644 --- a/src/main/java/com/avaje/ebean/Model.java +++ b/src/main/java/com/avaje/ebean/Model.java @@ -1,16 +1,8 @@ package com.avaje.ebean; import com.avaje.ebean.bean.EntityBean; -import com.avaje.ebean.util.ClassUtil; -import org.jetbrains.annotations.Nullable; import javax.persistence.MappedSuperclass; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.UUID; -import java.util.function.Consumer; -import java.util.function.Predicate; /** * A MappedSuperclass base class that provides convenience methods for inserting, updating and @@ -19,7 +11,7 @@ import java.util.function.Predicate; * By having your entity beans extend this it provides a 'Active Record' style programming model for * Ebean users. *
- * Note that there is a avaje-ebeanorm-mocker project that enables you to use Mockito or similar + * Note that there is a ebean-mocker project that enables you to use Mockito or similar * tools to still mock out the underlying 'default EbeanServer' for testing purposes. *
* You may choose not use this Model mapped superclass if you don't like the 'Active Record' style @@ -32,7 +24,7 @@ import java.util.function.Predicate; * that same instance also used to support the Model and Finder active record style. *
* If you choose to use the Model mapped superclass you will probably also chose to additionally add - * a {@link Find} as a public static field to complete the active record pattern and provide a + * a {@link Finder} as a public static field to complete the active record pattern and provide a * relatively nice clean way to write queries. *
*
- *
{@code
- *
- * // find byId
- * Customer customer = Customer.find.byId(42);
- *
- * }
- * - *
{@code
- *
- * // find where ...
- * List customers =
- * Customer.find
- * .where().gt("startDate", lastMonth)
- * .findList();
- *
- * }
*/
@MappedSuperclass
public abstract class Model {
@@ -305,584 +272,4 @@ public abstract class Model {
db().refresh(this);
}
- /**
- * A concrete implementation of Find.
- * - * It should be preferred to use {@link Find} instead of Finder as that can use reflection to determine the class - * literal type of the entity bean. - *
- * - * @param type of the Id property - * @param- *
{@code
- *
- * @Entity
- * public class Customer extends BaseModel {
- *
- * public static final Finder find = new Finder(Customer.class);
- * ...
- *
- * }
- * - *
- * The preferred approach is to instead useFind as below. This approach is more DRY in that it does
- * not require the class literal Customer.class to be passed into the constructor.
- * - *
{@code
- *
- * @Entity
- * public class Customer extends BaseModel {
- *
- * public static final Find find = new Find(){};
- * ...
- *
- * }
- */
- public Finder(Class- *
- * Typically a Find instance is defined as a public static field on an entity bean class to provide a - * nice way to write queries. - *
- *
- *
{@code
- *
- * @Entity
- * public class Customer extends BaseModel {
- *
- * public static final Find find = new Find(){};
- *
- * ...
- *
- * }
- *
- * This enables you to write code like:
- * {@code
- *
- * Customer customer = Customer.find.byId(42L);
- *
- * List customers =
- * Customer.find
- * .select("name, dateOfBirth")
- * .findList();
- *
- * }
- * - *
{@code
- *
- * // kotlin
- * companion object : Model.Find() {}
- *
- * }
- *
- * @param The Id type. This is most often a {@link Long} but is also often a {@link UUID} or
- * {@link String}.
- * @param T with ID of type I.
- *
- * Typically you create Find as a public static field on each entity bean as the example below.
- * - *
- * Note that Find is an abstract class and hence{} is required. This is done so
- * that the type (class literal) of the entity bean can be derived from the generics parameter.
- * - *
{@code
- *
- * @Entity
- * public class Customer extends BaseModel {
- *
- * // Note the trailing {} as Find is an abstract class.
- * // We do this so that we can derive the type literal Customer.class
- * // via reflection
- * public static final Find find = new Find(){};
- * ...
- *
- * }
- *
- * This enables you to write code like:
- * {@code
- *
- * Customer customer = Customer.find.byId(42L);
- *
- * List customers =
- * Customer.find
- * .select("name, email, dateOfBirth")
- * .findList();
- *
- * }
- * - *
- *
{@code
- *
- * // kotlin
- * companion object : Model.Find() {}
- *
- * }
- */
- @SuppressWarnings("unchecked")
- public Find() {
- this.serverName = null;
- this.type = (Class- *
- * This provides full access to the API such as explicit transaction demarcation etc. - */ - public EbeanServer db() { - return Ebean.getServer(serverName); - } - - /** - * Return typically a different EbeanServer to the default. - *
- * This is equivalent to {@link Ebean#getServer(String)} - * - * @param server The name of the EbeanServer. If this is null then the default EbeanServer is - * returned. - */ - public EbeanServer db(String server) { - return Ebean.getServer(server); - } - - /** - * Creates a Finder for the named EbeanServer. - *
- *
- * Create and return a new Finder for a different server. - */ - public Finder on(String server) { - return new Finder<>(server, type); - } - - /** - * Delete a bean by Id. - *
- * Equivalent to {@link EbeanServer#delete(Class, Object)} - */ - public void deleteById(I id) { - db().delete(type, id); - } - - /** - * Retrieves all entities of the given type. - *
- *
- * This is the same as (synonym for) {@link #findList()}
- */
- public List
- *
- * Equivalent to {@link EbeanServer#find(Class, Object)}
- */
- @Nullable
- public T byId(I id) {
- return db().find(type, id);
- }
-
- /**
- * Creates an entity reference for this ID.
- *
- *
- * Equivalent to {@link EbeanServer#getReference(Class, Object)}
- */
- public T ref(I id) {
- return db().getReference(type, id);
- }
-
- /**
- * Creates a filter for sorting and filtering lists of entities locally without going back to
- * the database.
- *
- * Equivalent to {@link EbeanServer#filter(Class)}
- */
- public Filter
- * Equivalent to {@link EbeanServer#find(Class)}
- */
- public Query
- * Equivalent to {@link Query#apply(FetchPath)}
- */
- public Query
- * Equivalent to {@link Query#findIds()}
- */
- public List findIds() {
- return query().findIds();
- }
-
- /**
- * Execute the query consuming each bean one at a time.
- *
- * This is generally used to process large queries where unlike findList
- * you do not want to hold all the results in memory at once but instead
- * process them one at a time (requiring far less memory).
- *
- * Equivalent to {@link Query#findEachWhile(Predicate)}
- *
- * This is similar to #findEach except that you return boolean
- * true to continue processing beans and return false to stop
- * processing early.
- *
- * This is generally used to process large queries where unlike findList
- * you do not want to hold all the results in memory at once but instead
- * process them one at a time (requiring far less memory).
- *
- * The same as {@link #all()}
- *
- * Equivalent to {@link Query#findList()}
- */
- public List
- * Equivalent to {@link Query#findSet()}
- */
- public Set
- * Equivalent to {@link Query#findMap()}
- */
- public
- * Equivalent to {@link Query#findFutureCount()}
- */
- public FutureRowCount
- * Equivalent to {@link Query#findFutureCount()}
- */
- public FutureRowCount
- * Equivalent to {@link Query#findCount()}
- */
- public int findCount() {
- return query().findCount();
- }
-
- /**
- * Deprecated in favor of findCount().
- *
- * @deprecated
- */
- public int findRowCount() {
- return query().findCount();
- }
-
- /**
- * Returns the
- * Equivalent to {@link Query#select(String)}
- */
- public Query
- * Equivalent to {@link Query#fetch(String)}
- */
- public Query
- * Equivalent to {@link Query#fetch(String, FetchConfig)}
- */
- public Query
- * Equivalent to {@link Query#fetch(String, String)}
- */
- public Query
- * Equivalent to {@link Query#fetch(String, String, FetchConfig)}
- */
- public Query
- * Equivalent to {@link Query#where()}
- */
- public ExpressionList
- * This is exactly the same as {@link #orderBy}.
- *
- * Equivalent to {@link Query#order()}
- */
- public OrderBy
- * This is exactly the same as {@link #orderBy(String)}.
- */
- public Query
- * This is exactly the same as {@link #order}.
- *
- * Equivalent to {@link Query#orderBy()}
- */
- public OrderBy
- * This is exactly the same as {@link #order(String)}.
- */
- public Query
- * Equivalent to {@link Query#setFirstRow(int)}
- */
- public Query
- * Equivalent to {@link Query#setMaxRows(int)}
- */
- public Query
- *
- * Use this to perform a find byId query but with additional control over the query such as
- * using select and fetch to control what parts of the object graph are returned.
- *
- * Equivalent to {@link Query#setId(Object)}
- */
- public Query
- * Equivalent to {@link Query#setRawSql(RawSql)}
- */
- public Query
- *
- * This will typically create row level database locks on the selected rows.
- */
- public QueryExpressionFactory used by this query.
- */
- public ExpressionFactory getExpressionFactory() {
- return query().getExpressionFactory();
- }
-
- /**
- * Explicitly sets a comma delimited list of the properties to fetch on the 'main' entity bean,
- * to load a partial object.
- * FetchConfig to specify a 'query join' and/or define the
- * lazy loading query.
- * FetchConfig to use a separate query or lazy loading to
- * load this path.
- * where clause with the ability to chain on the
- * ExpressionList.
- * order by clause so that you can append an ascending or descending
- * property to the order by clause.
- * order by clause, replacing the existing order by clause if
- * there is one.
- * order by clause so that you can append an ascending or descending
- * property to the order by clause.
- * order by clause replacing the existing order by clause if
- * there is one.
- * RawSql.
- *