diff --git a/src/main/java/com/avaje/ebean/Model.java b/src/main/java/com/avaje/ebean/Model.java index c10183402..a46a5093a 100644 --- a/src/main/java/com/avaje/ebean/Model.java +++ b/src/main/java/com/avaje/ebean/Model.java @@ -7,16 +7,19 @@ import java.util.Set; import javax.persistence.MappedSuperclass; /** - * A MappedSuperclass base class that provides convenience methods for inserting, updating and deleting beans. + * A MappedSuperclass base class that provides convenience methods for inserting, updating and + * deleting beans. * - *

By having your entity beans extend this it provides a 'Active Record' style programming model for Ebean users. + *

+ * 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 tools to still - * mock out the underlying 'default EbeanServer' for testing purposes. + *

+ * Note that there is a avaje-ebeanorm-mocker project that enables you to use Mockito or similar + * tools to still mock out the underlying 'default EbeanServer' for testing purposes. */ @MappedSuperclass public class Model { - private Object _getId() { try { @@ -31,21 +34,23 @@ public class Model { /** * Return the underlying 'default' EbeanServer. * - *

This provides full access to the API such as explicit transaction demarcation etc. + *

+ * This provides full access to the API such as explicit transaction demarcation etc. */ public EbeanServer db() { return Ebean.getServer(null); } - + /** * Return typically a different EbeanServer to the default. * - * @param server The name of the EbeanServer. If this is null then the default EbeanServer is returned. + * @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); } - + /** * Inserts or update this entity depending on its state. */ @@ -74,7 +79,6 @@ public class Model { Ebean.refresh(this); } - @Override public boolean equals(Object other) { if (this == other) @@ -108,7 +112,8 @@ public class Model { /** * Creates a finder for entity of type T with ID of type I. * - *

Typically you use this constructor to have a static "find" field on each entity bean. + *

+ * Typically you use this constructor to have a static "find" field on each entity bean. */ public Finder(Class idType, Class type) { this(null, idType, type); @@ -118,7 +123,8 @@ public class Model { * Creates a finder for entity of type T with ID of type I, using a * specific Ebean server. * - *

Typically you don't need to use this method. + *

+ * Typically you don't need to use this method. */ public Finder(String serverName, Class idType, Class type) { this.type = type; @@ -133,26 +139,29 @@ public class Model { /** * Return the underlying 'default' EbeanServer. * - *

This provides full access to the API such as explicit transaction demarcation etc. + *

+ * This provides full access to the API such as explicit transaction demarcation etc. */ public EbeanServer db() { return Ebean.getServer(null); } - + /** * Return typically a different EbeanServer to the default. * - * @param server The name of the EbeanServer. If this is null then the default EbeanServer is returned. + * @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); } - + /** * Changes the Ebean server. */ public Finder on(String server) { - return new Finder(server, idType, type); + return new Finder(server, idType, type); } /** @@ -199,6 +208,101 @@ public class Model { return (I) server().nextId(type); } + /** + * Executes a find IDs query in a background thread. + * + * @deprecated RB: Hmm, this is a "find all" - less is more, prefer to hide this - just get from + * query(). + */ + public FutureIds findFutureIds() { + return query().findFutureIds(); + } + + /** + * Executes a query and returns the results as a list of IDs. + */ + public List findIds() { + return query().findIds(); + } + + /** + * Retrieves all entities of the given type. + * + *

+ * The same as {@link #all()} + */ + public List findList() { + return query().findList(); + } + + /** + * Returns all the entities of the given type as a set. + */ + public Set findSet() { + return query().findSet(); + } + + /** + * Retrieves all entities of the given type as a map of objects. + */ + public Map findMap() { + return query().findMap(); + } + + /** + * Executes the query and returns the results as a map of the objects specifying the map key + * property. + */ + public Map findMap(String keyProperty, Class keyType) { + return query().findMap(keyProperty, keyType); + } + + /** + * Return a PagedList of all entities of the given type (use where() to specify predicates as + * needed). + */ + public PagedList findPagedList(int pageIndex, int pageSize) { + return query().findPagedList(pageIndex, pageSize); + } + + /** + * Returns a PagingList for this query. + * + * @deprecated RB: PagingList deprecated - migrate to findPagedList(). + */ + public PagingList findPagingList(int pageSize) { + return query().findPagingList(pageSize); + } + + /** + * Executes a find row count query in a background thread. + */ + public FutureRowCount findFutureRowCount() { + return query().findFutureRowCount(); + } + + /** + * Returns the total number of entities for this type. + */ + public int findRowCount() { + return query().findRowCount(); + } + + /** + * Returns the ExpressionFactory 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. + */ + public Query select(String fetchProperties) { + return query().select(fetchProperties); + } + /** * Specifies a path to load including all its properties. */ @@ -231,86 +335,25 @@ public class Model { } /** - * Executes a find IDs query in a background thread. - * - * @deprecated RB: Hmm, this is a "find all" - less is more, prefer to hide this - just get from query(). + * Adds expressions to the where clause with the ability to chain on the + * ExpressionList. */ - public FutureIds findFutureIds() { - return query().findFutureIds(); + public ExpressionList where() { + return query().where(); } /** - * Executes a find row count query in a background thread. + * Adds a single Expression to the where clause and returns the query. */ - public FutureRowCount findFutureRowCount() { - return query().findFutureRowCount(); + public Query where(com.avaje.ebean.Expression expression) { + return query().where(expression); } /** - * Executes a query and returns the results as a list of IDs. + * Adds additional clauses to the where clause. */ - public List findIds() { - return query().findIds(); - } - - /** - * Retrieves all entities of the given type. - * - *

The same as {@link #all()} - */ - public List findList() { - return query().findList(); - } - - /** - * Retrieves all entities of the given type as a map of objects. - */ - public Map findMap() { - return query().findMap(); - } - - /** - * Executes the query and returns the results as a map of the objects specifying the map key property. - */ - public Map findMap(String keyProperty, Class keyType) { - return query().findMap(keyProperty, keyType); - } - - /** - * Return a PagedList of all entities of the given type (use where() to specify predicates as needed). - */ - public PagedList findPagedList(int pageIndex, int pageSize) { - return query().findPagedList(pageIndex, pageSize); - } - - /** - * Returns a PagingList for this query. - * - * @deprecated RB: PagingList deprecated - migrate to findPagedList(). - */ - public PagingList findPagingList(int pageSize) { - return query().findPagingList(pageSize); - } - - /** - * Returns the total number of entities for this type. - */ - public int findRowCount() { - return query().findRowCount(); - } - - /** - * Returns all the entities of the given type as a set. - */ - public Set findSet() { - return query().findSet(); - } - - /** - * Returns the ExpressionFactory used by this query. - */ - public ExpressionFactory getExpressionFactory() { - return query().getExpressionFactory(); + public Query where(String addToWhereClause) { + return query().where(addToWhereClause); } /** @@ -353,21 +396,6 @@ public class Model { return query().orderBy(orderByClause); } - /** - * Explicitly sets a comma delimited list of the properties to fetch on the 'main' entity bean, - * to load a partial object. - */ - public Query select(String fetchProperties) { - return query().select(fetchProperties); - } - - /** - * Explicitly specifies whether to use 'Autofetch' for this query. - */ - public Query setAutofetch(boolean autofetch) { - return query().setAutofetch(autofetch); - } - /** * Sets the first row to return for this query. */ @@ -375,27 +403,6 @@ public class Model { return query().setFirstRow(firstRow); } - /** - * Sets the ID value to query. - */ - public Query setId(Object id) { - return query().setId(id); - } - - /** - * When set to true, all the beans from this query are loaded into the bean cache. - */ - public Query setLoadBeanCache(boolean loadBeanCache) { - return query().setLoadBeanCache(loadBeanCache); - } - - /** - * Sets the property to use as keys for a map. - */ - public Query setMapKey(String mapKey) { - return query().setMapKey(mapKey); - } - /** * Sets the maximum number of rows to return in the query. */ @@ -403,6 +410,13 @@ public class Model { return query().setMaxRows(maxRows); } + /** + * Sets the ID value to query. + */ + public Query setId(Object id) { + return query().setId(id); + } + /** * Sets the OQL query to run */ @@ -417,6 +431,27 @@ public class Model { return query().setRawSql(rawSql); } + /** + * Sets the property to use as keys for a {@link Query#findMap()} query. + */ + public Query setMapKey(String mapKey) { + return query().setMapKey(mapKey); + } + + /** + * Explicitly specifies whether to use 'Autofetch' for this query. + */ + public Query setAutofetch(boolean autofetch) { + return query().setAutofetch(autofetch); + } + + /** + * Execute the select with "for update" which should lock the record "on read" + */ + public Query setForUpdate(boolean forUpdate) { + return query().setForUpdate(forUpdate); + } + /** * Sets whether the returned beans will be read-only. */ @@ -424,6 +459,13 @@ public class Model { return query().setReadOnly(readOnly); } + /** + * When set to true, all the beans from this query are loaded into the bean cache. + */ + public Query setLoadBeanCache(boolean loadBeanCache) { + return query().setLoadBeanCache(loadBeanCache); + } + /** * Sets whether to use the bean cache. */ @@ -438,34 +480,5 @@ public class Model { return query().setUseQueryCache(useQueryCache); } - /** - * Adds expressions to the where clause with the ability to chain on the - * ExpressionList. - */ - public ExpressionList where() { - return query().where(); - } - - /** - * Adds a single Expression to the where clause and returns the query. - */ - public Query where(com.avaje.ebean.Expression expression) { - return query().where(expression); - } - - /** - * Adds additional clauses to the where clause. - */ - public Query where(String addToWhereClause) { - return query().where(addToWhereClause); - } - - /** - * Execute the select with "for update" which should lock the record "on read" - */ - public Query setForUpdate(boolean forUpdate) { - return query().setForUpdate(forUpdate); - } - } } \ No newline at end of file