diff --git a/src/main/java/com/avaje/ebean/Model.java b/src/main/java/com/avaje/ebean/Model.java index ec66a0c7e..c10183402 100644 --- a/src/main/java/com/avaje/ebean/Model.java +++ b/src/main/java/com/avaje/ebean/Model.java @@ -1,73 +1,26 @@ package com.avaje.ebean; -import java.util.*; -import java.beans.*; -import java.lang.reflect.*; +import java.util.List; +import java.util.Map; +import java.util.Set; -import com.avaje.ebean.Ebean; -import com.avaje.ebean.OrderBy; -import com.avaje.ebean.ExpressionList; -import com.avaje.ebean.Query; -import com.avaje.ebean.RawSql; -import com.avaje.ebean.ExpressionFactory; -import com.avaje.ebean.PagingList; -import com.avaje.ebean.FutureRowCount; -import com.avaje.ebean.FutureList; -import com.avaje.ebean.FutureIds; -import com.avaje.ebean.FetchConfig; -//import com.avaje.ebean.QueryListener; -//import com.avaje.ebean.QueryIterator; -import com.avaje.ebean.EbeanServer; -import com.avaje.ebean.Filter; -//import com.avaje.ebean.QueryResultVisitor; - -//import play.Play; -//import play.libs.F.*; -//import static play.libs.F.*; - -//import org.springframework.beans.*; +import javax.persistence.MappedSuperclass; /** - * Base-class for Ebean-mapped models that provides convenience methods. + * 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. + * + *
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.
*/
-@javax.persistence.MappedSuperclass
+@MappedSuperclass
public class Model {
-
- // -- Magic to dynamically access the @Id property
-
- // @javax.persistence.Transient
- // private Tuple This provides full access to the API such as explicit transaction demarcation etc.
*/
public EbeanServer db() {
return Ebean.getServer(null);
@@ -103,53 +39,19 @@ public class Model {
/**
* 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.
*/
public EbeanServer db(String server) {
return Ebean.getServer(server);
}
- // RB: Actually they should probably not use save() but insert() in this case
-// /**
-// * Saves (inserts) this entity.
-// *
-// * @param server
-// * the Ebean server to use
-// */
-// public void save(String server) {
-// Ebean.getServer(server).save(this);
-// }
-
- // RB: Uncommonly used so get this method off the db() so ... db().saveManyToManyAssociations(this, path)
-//
-// /**
-// * Persist a many-to-many association.
-// */
-// public void saveManyToManyAssociations(String path) {
-// Ebean.saveManyToManyAssociations(this, path);
-// }
-
- // RB: Uncommonly used so get this method off the db()
-// /**
-// * Persist a many-to-many association.
-// *
-// * @param server
-// * the Ebean server to use
-// */
-// public void saveManyToManyAssociations(String server, String path) {
-// Ebean.getServer(server).saveManyToManyAssociations(this, path);
-// }
-
- // RB: Uncommonly used so get this method off the db()
-// /**
-// * Deletes a many-to-many association
-// *
-// * @param path
-// * name of the many-to-many association we want to delete
-// */
-// public void deleteManyToManyAssociations(String path) {
-// Ebean.deleteManyToManyAssociations(this, path);
-// }
+ /**
+ * Inserts or update this entity depending on its state.
+ */
+ public void save() {
+ Ebean.save(this);
+ }
/**
* Updates this entity.
@@ -158,38 +60,6 @@ public class Model {
Ebean.update(this);
}
- // RB: Uncommon - just use db(server).update(this);
-// /**
-// * Updates this entity, using a specific Ebean server.
-// *
-// * @param server
-// * the Ebean server to use
-// */
-// public void update(String server) {
-// Ebean.getServer(server).update(this);
-// }
-
- // RB: ??
-// /**
-// * Updates this entity, by specifying the entity ID.
-// */
-// public void update(Object id) {
-// _setId(id);
-// Ebean.update(this);
-// }
-
- // RB: Again ??
-// /**
-// * Updates this entity, by specifying the entity ID, using a specific Ebean server.
-// *
-// * @param server
-// * the Ebean server to use
-// */
-// public void update(Object id, String server) {
-// _setId(id);
-// Ebean.getServer(server).update(this);
-// }
-
/**
* Deletes this entity.
*/
@@ -197,17 +67,6 @@ public class Model {
Ebean.delete(this);
}
- // RB: Uncommon - always use db(server) to get other EbeanServer instances
-// /**
-// * Deletes this entity, using a specific Ebean server.
-// *
-// * @param server
-// * the Ebean server to use
-// */
-// public void delete(String server) {
-// Ebean.getServer(server).delete(this);
-// }
-
/**
* Refreshes this entity from the database.
*/
@@ -215,15 +74,6 @@ public class Model {
Ebean.refresh(this);
}
-// /**
-// * Refreshes this entity from the database, using a specific Ebean server.
-// *
-// * @param server
-// * the Ebean server to use
-// */
-// public void refresh(String server) {
-// Ebean.getServer(server).refresh(this);
-// }
@Override
public boolean equals(Object other) {
@@ -247,9 +97,9 @@ public class Model {
}
/**
- * Helper for Ebean queries.
+ * Helper for queries.
*/
- public static class Finder {// implements Query Typically you use this constructor to have a static "find" field on each entity bean.
*/
public Finder(Class idType, Class Typically you don't need to use this method.
*/
public Finder(String serverName, Class idType, Class 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.
+ */
+ public EbeanServer db(String server) {
+ return Ebean.getServer(server);
+ }
+
/**
* Changes the Ebean server.
*/
@@ -298,9 +170,7 @@ public class Model {
}
/**
- * Retrieves an entity reference for this ID.
- *
- * @deprecated RB: Move to Model
+ * Creates an entity reference for this ID.
*/
public T ref(I id) {
return server().getReference(type, id);
@@ -323,27 +193,12 @@ public class Model {
/**
* Returns the next identity value.
- *
- * @deprecated RB: move to model
*/
+ @SuppressWarnings("unchecked")
public I nextId() {
return (I) server().nextId(type);
}
- // /**
- // * Cancels query execution, if supported by the underlying database and driver.
- // */
- // public void cancel() {
- // query().cancel();
- // }
-
- // /**
- // * Copies this query.
- // */
- // public Query The same as {@link #all()}
*/
public List
- // * This is exactly the same as {@link #setOrderBy(com.avaje.ebean.OrderBy)}.
- // */
- // public Query
- // * This is exactly the same as {@link #setOrder(com.avaje.ebean.OrderBy)}.
- // */
- // public QueryT with ID of type I.
+ *
+ * T with ID of type I, using a
* specific Ebean server.
+ *
+ * null, if
- // no matching bean is found.
- // */
- // public T findUnique() {
- // return query().findUnique();
- // }
-
- // public void findVisit(QueryResultVisitorExpressionFactory used by this query.
*/
@@ -485,62 +313,6 @@ public class Model {
return query().getExpressionFactory();
}
- // /**
- // * Returns the first row value.
- // */
- // public int getFirstRow() {
- // return query().getFirstRow();
- // }
-
- // /**
- // * Returns the SQL that was generated for executing this query.
- // */
- // public String getGeneratedSql() {
- // return query().getGeneratedSql();
- // }
-
- // /**
- // * Returns the maximum of rows for this query.
- // */
- // public int getMaxRows() {
- // return query().getMaxRows();
- // }
-
- // /**
- // * Returns the RawSql that was set to use for this query.
- // */
- // public RawSql getRawSql() {
- // return query().getRawSql();
- // }
-
- // /**
- // * Returns the query's having clause.
- // */
- // public ExpressionListhaving clause and returns the query.
- // */
- // public Queryhaving clause and returns the query.
- // */
- // public Querytrue if this query was tuned by autoFetch.
- // */
- // public boolean isAutofetchTuned() {
- // return query().isAutofetchTuned();
- // }
-
/**
* Returns the order by clause so that you can append an ascending or descending
* property to the order by clause.
@@ -596,27 +368,6 @@ public class Model {
return query().setAutofetch(autofetch);
}
- // /**
- // * Sets the rows after which fetching should continue in a background thread.
- // */
- // public QueryStatement.fetchSize().
- // */
- // public QueryDISTINCT.
- // */
- // public Querytrue, all the beans from this query are loaded into the bean cache.
*/
@@ -659,38 +403,6 @@ public class Model {
return query().setMaxRows(maxRows);
}
- // /**
- // * Replaces any existing order by clause using an OrderBy object.
- // * order by clause.
- // *