diff --git a/src/main/java/com/avaje/ebean/Ebean.java b/src/main/java/com/avaje/ebean/Ebean.java index f06638c9b..5d2dd5c2a 100644 --- a/src/main/java/com/avaje/ebean/Ebean.java +++ b/src/main/java/com/avaje/ebean/Ebean.java @@ -63,34 +63,38 @@ import com.avaje.ebean.text.json.JsonContext; * created automatically they are configured using information in the * ebean.properties file. *

+ * + *
{@code
+ *
+ *   // fetch shipped orders (and also their customer)
+ *   List list = Ebean.find(Order.class)
+ * 	  .fetch("customer")
+ * 	  .where()
+ * 	  .eq("status.code", Order.Status.SHIPPED)
+ * 	  .findList();
+ *
+ *   // read/use the order list ...
+ *   for (Order order : list) {
+ * 	   Customer customer = order.getCustomer();
+ * 	   ...
+ *   }
+ *
+ * }
* - *
- * // fetch shipped orders (and also their customer)
- * List<Order> list = Ebean.find(Order.class)
- * 	.fetch("customer")
- * 	.where() 
- * 	.eq("status.code", Order.Status.SHIPPED) 
- * 	.findList();
+ * 
{@code
+ *
+ *   // fetch order 10, modify and save
+ *   Order order = Ebean.find(Order.class, 10);
  * 
- * // read/use the order list ... 
- * for (Order order : list) { 
- * 	Customer customer = order.getCustomer(); 
- * 	... 
- * }
- * 
+ * OrderStatus shipped = Ebean.getReference(OrderStatus.class,"SHIPPED"); + * order.setStatus(shipped); + * order.setShippedDate(shippedDate); + * ... * - *
- * // fetch order 10, modify and save 
- * Order order = Ebean.find(Order.class, 10);
- * 
- * OrderStatus shipped = Ebean.getReference(OrderStatus.class,"SHIPPED"); 
- * order.setStatus(shipped);
- * order.setShippedDate(shippedDate); 
- * ...
- * 
- * // implicitly creates a transaction and commits 
- * Ebean.save(order);
- * 
+ * // implicitly creates a transaction and commits + * Ebean.save(order); + * + * }
* *

* When you have multiple databases and need access to a specific one the @@ -98,20 +102,22 @@ import com.avaje.ebean.text.json.JsonContext; * specific database. *

* - *
- * // Get access to the Human Resources EbeanServer/Database
- * EbeanServer hrDb = Ebean.getServer("hr");
+ * 
 {@code
+ *
+ *   // Get access to the Human Resources EbeanServer/Database
+ *   EbeanServer hrDb = Ebean.getServer("hr");
  * 
  * 
- * // fetch contact 3 from the HR database 
- * Contact contact = hrDb.find(Contact.class, 3);
+ *   // fetch contact 3 from the HR database
+ *   Contact contact = hrDb.find(Contact.class, 3);
  * 
- * contact.setName("I'm going to change"); 
- * ...
+ *   contact.setName("I'm going to change");
+ *   ...
  * 
- * // save the contact back to the HR database 
- * hrDb.save(contact);
- * 
+ * // save the contact back to the HR database + * hrDb.save(contact); + * + * }
*/ public final class Ebean { private static final Logger logger = LoggerFactory.getLogger(Ebean.class); @@ -242,12 +248,12 @@ public final class Ebean { * Ebean. *

* - *
-   * // use the "hr" database
-   * EbeanServer hrDatabase = Ebean.getServer("hr");
+   * 
{@code
+   * // use the "hr" database
+   * EbeanServer hrDatabase = Ebean.getServer("hr");
    * 
    * Person person = hrDatabase.find(Person.class, 10);
-   * 
+ * }
* * @param name * the name of the server, use null for the 'default server' @@ -323,22 +329,24 @@ public final class Ebean { * etc. *

* - *
-   * // start a transaction (stored in a ThreadLocal)
-   * Ebean.beginTransaction(); 
-   * try { 
-   * 	Order order = Ebean.find(Order.class,10); ...
+   * 
{@code
+   *
+   *   // start a transaction (stored in a ThreadLocal)
+   *   Ebean.beginTransaction();
+   *   try {
+   * 	   Order order = Ebean.find(Order.class,10); ...
+   *
+   * 	   Ebean.save(order);
    * 
-   * 	Ebean.save(order);
+   * 	   Ebean.commitTransaction();
    * 
-   * 	Ebean.commitTransaction();
-   * 
-   * } finally { 
-   * 	// rollback if we didn't commit 
-   * 	// i.e. an exception occurred before commitTransaction(). 
-   * 	Ebean.endTransaction(); 
-   * }
-   * 
+ * } finally { + * // rollback if we didn't commit + * // i.e. an exception occurred before commitTransaction(). + * Ebean.endTransaction(); + * } + * + * }
* *

* If you want to externalise the transaction management then you should be @@ -377,9 +385,9 @@ public final class Ebean { *

* If there is no currently active transaction then a PersistenceException is thrown. * - * @param transactionCallback The transaction callback to be registered with the current transaction. + * @param transactionCallback the transaction callback to be registered with the current transaction * - * @throws PersistenceException If there is no currently active transaction + * @throws PersistenceException if there is no currently active transaction */ public static void register(TransactionCallback transactionCallback) throws PersistenceException { serverMgr.getPrimaryServer().register(transactionCallback); @@ -410,17 +418,19 @@ public final class Ebean { * Code example: *

* - *
-   * Ebean.beginTransaction();
-   * try {
-   *   // do some fetching and or persisting
-   *   // commit at the end Ebean.commitTransaction();
+   * 
{@code
+   *   Ebean.beginTransaction();
+   *   try {
+   *     // do some fetching and or persisting
+   *
+   *     // commit at the end
+   *     Ebean.commitTransaction();
    * 
-   * } finally {
-   *   // if commit didn't occur then rollback the transaction
-   *   Ebean.endTransaction();
-   * }
-   * 
+ * } finally { + * // if commit didn't occur then rollback the transaction + * Ebean.endTransaction(); + * } + * }
*/ public static void endTransaction() { serverMgr.getPrimaryServer().endTransaction(); @@ -453,15 +463,15 @@ public final class Ebean { * saving an order will also save all its details. *

* - *
-   * public class Order { ...
+   * 
{@code
+   *   public class Order { ...
    * 	
-   * 	@OneToMany(cascade=CascadeType.ALL, mappedBy="order")
-   * 	@JoinColumn(name="order_id") 
-   * 	List<OrderDetail> details; 
-   * 	... 
-   * }
-   * 
+ * @OneToMany(cascade=CascadeType.ALL, mappedBy="order") + * @JoinColumn(name="order_id") + * List details; + * ... + * } + * }
* *

* When a save cascades via a OneToMany or ManyToMany Ebean will automatically @@ -498,16 +508,16 @@ public final class Ebean { * An unmodified bean that is saved or updated is normally skipped and this marks the bean as * dirty so that it is not skipped. * - *

+   * 
{@code
    * 
-   * Customer customer = Ebean.find(Customer, id);
+   *   Customer customer = Ebean.find(Customer, id);
    * 
-   * // mark the bean as dirty so that a save() or update() will
-   * // increment the version property
-   * Ebean.markAsDirty(customer);
-   * Ebean.save(customer);
+   *   // mark the bean as dirty so that a save() or update() will
+   *   // increment the version property
+   *   Ebean.markAsDirty(customer);
+   *   Ebean.save(customer);
    * 
-   * 
+ * }
*/ public static void markAsDirty(Object bean) throws OptimisticLockException { serverMgr.getPrimaryServer().markAsDirty(bean); @@ -536,15 +546,15 @@ public final class Ebean { * properties are included instead. *

* - *
+   * 
{@code
    * 
-   * // A 'stateless update' example
-   * Customer customer = new Customer();
-   * customer.setId(7);
-   * customer.setName("ModifiedNameNoOCC");
-   * ebeanServer.update(customer);
+   *   // A 'stateless update' example
+   *   Customer customer = new Customer();
+   *   customer.setId(7);
+   *   customer.setName("ModifiedNameNoOCC");
+   *   ebeanServer.update(customer);
    * 
-   * 
+ * }
* * @see ServerConfig#setUpdatesDeleteMissingChildren(boolean) * @see ServerConfig#setUpdateChangesOnly(boolean) @@ -678,12 +688,14 @@ public final class Ebean { /** * Refresh a 'many' property of a bean. * - *
-   * Order order = ...;
-   * ...
-   * // refresh the order details...
-   * Ebean.refreshMany(order, "details");
-   * 
+ *
{@code
+   *
+   *   Order order = ...;
+   *   ...
+   *   // refresh the order details...
+   *   Ebean.refreshMany(order, "details");
+   *
+   * }
* * @param bean * the entity bean containing the List Set or Map to refresh. @@ -700,16 +712,18 @@ public final class Ebean { * This is sometimes described as a proxy (with lazy loading). *

* - *
-   * Product product = Ebean.getReference(Product.class, 1);
+   * 
{@code
+   *
+   *   Product product = Ebean.getReference(Product.class, 1);
    * 
-   * // You can get the id without causing a fetch/lazy load
-   * Integer productId = product.getId();
+   *   // You can get the id without causing a fetch/lazy load
+   *   Integer productId = product.getId();
    * 
-   * // If you try to get any other property a fetch/lazy loading will occur
-   * // This will cause a query to execute...
-   * String name = product.getName();
-   * 
+ * // If you try to get any other property a fetch/lazy loading will occur + * // This will cause a query to execute... + * String name = product.getName(); + * + * }
* * @param beanType * the type of entity bean @@ -739,23 +753,23 @@ public final class Ebean { * not invoke a DB query. *

* - *
+   * 
{@code
    * 
-   * // find orders and their customers
-   * List<Order> list = Ebean.find(Order.class)
-   *     .fetch("customer")
-   *     .orderBy("id")
+   *   // find orders and their customers
+   *   List list = Ebean.find(Order.class)
+   *     .fetch("customer")
+   *     .orderBy("id")
    *     .findList();
    * 
-   * // sort by customer name ascending, then by order shipDate
-   * // ... then by the order status descending
-   * Ebean.sort(list, "customer.name, shipDate, status desc");
+   *   // sort by customer name ascending, then by order shipDate
+   *   // ... then by the order status descending
+   *   Ebean.sort(list, "customer.name, shipDate, status desc");
    * 
-   * // sort by customer name descending (with nulls low)
-   * // ... then by the order id
-   * Ebean.sort(list, "customer.name desc nullsLow, id");
+   *   // sort by customer name descending (with nulls low)
+   *   // ... then by the order id
+   *   Ebean.sort(list, "customer.name desc nullsLow, id");
    * 
-   * 
+ * }
* * @param list * the list of entity beans @@ -769,41 +783,43 @@ public final class Ebean { /** * Find a bean using its unique id. This will not use caching. * - *
-   * // Fetch order 1
-   * Order order = Ebean.find(Order.class, 1);
-   * 
+ *
{@code
+   *   // Fetch order 1
+   *   Order order = Ebean.find(Order.class, 1);
+   * }
* *

* If you want more control over the query then you can use createQuery() and * Query.findUnique(); *

* - *
-   * // ... additionally fetching customer, customer shipping address,
-   * // order details, and the product associated with each order detail.
-   * // note: only product id and name is fetch (its a "partial object").
-   * // note: all other objects use "*" and have all their properties fetched.
+   * 
{@code
+   *   // ... additionally fetching customer, customer shipping address,
+   *   // order details, and the product associated with each order detail.
+   *   // note: only product id and name is fetch (its a "partial object").
+   *   // note: all other objects use "*" and have all their properties fetched.
    * 
-   * Query<Order> query = Ebean.createQuery(Order.class);
-   * query.setId(1);
-   * query.fetch("customer");
-   * query.fetch("customer.shippingAddress");
-   * query.fetch("details");
+   *   Query query = Ebean.find(Order.class)
+   *     .setId(1)
+   *     .fetch("customer")
+   *     .fetch("customer.shippingAddress")
+   *     .fetch("details")
+   *     .query();
    * 
-   * // fetch associated products but only fetch their product id and name
-   * query.fetch("details.product", "name");
+   *   // fetch associated products but only fetch their product id and name
+   *   query.fetch("details.product", "name");
    * 
-   * // traverse the object graph...
+   *   // traverse the object graph...
    * 
-   * Order order = query.findUnique();
-   * Customer customer = order.getCustomer();
-   * Address shippingAddress = customer.getShippingAddress();
-   * List<OrderDetail> details = order.getDetails();
-   * OrderDetail detail0 = details.get(0);
-   * Product product = detail0.getProduct();
-   * String productName = product.getName();
-   * 
+ * Order order = query.findUnique(); + * Customer customer = order.getCustomer(); + * Address shippingAddress = customer.getShippingAddress(); + * List details = order.getDetails(); + * OrderDetail detail0 = details.get(0); + * Product product = detail0.getProduct(); + * String productName = product.getName(); + * + * }
* * @param beanType * the type of entity bean to fetch @@ -815,7 +831,7 @@ public final class Ebean { } /** - * Create a SqlQuery for executing native sql + * Create a SqlQuery for executing native sql * query statements. *

* Note that you can use raw SQL with entity beans, refer to the SqlSelect @@ -873,15 +889,17 @@ public final class Ebean { * deployment orm xml file. *

* - *
-   * // Use a namedQuery
-   * UpdateSql update = Ebean.createNamedSqlUpdate("update.topic.count");
+   * 
{@code
+   *
+   *   // Use a namedQuery
+   *   UpdateSql update = Ebean.createNamedSqlUpdate("update.topic.count");
    * 
-   * update.setParameter("count", 1);
-   * update.setParameter("topicId", 50);
+   *   update.setParameter("count", 1);
+   *   update.setParameter("topicId", 50);
    * 
-   * int modifiedCount = update.execute();
-   * 
+ * int modifiedCount = update.execute(); + * + * }
*/ public static SqlUpdate createNamedSqlUpdate(String namedQuery) { return serverMgr.getPrimaryServer().createNamedSqlUpdate(namedQuery); @@ -896,12 +914,14 @@ public final class Ebean { * need to bind required parameters and then execute the query. *

* - *
-   * // example
-   * Query<Order> query = Ebean.createNamedQuery(Order.class, "new.for.customer");
-   * query.setParameter("customerId", 23);
-   * List<Order> newOrders = query.findList();
-   * 
+ *
{@code
+   *
+   *   // example
+   *   Query query = Ebean.createNamedQuery(Order.class, "new.for.customer");
+   *   query.setParameter("customerId", 23);
+   *   List newOrders = query.findList();
+   *
+   * }
* * @param beanType * the class of entity to be fetched @@ -924,14 +944,15 @@ public final class Ebean { * moved to {@link #createNamedQuery(Class, String)}. *

* - *
+   * 
{@code
    * 
-   * String q = "find order fetch details where status = :st";
+   *   String q = "find order fetch details where status = :st";
    * 
-   * List<Order> newOrders = Ebean.createQuery(Order.class, q)
-   *     .setParameter("st", Order.Status.NEW)
+   *   List newOrders = Ebean.>findOrder.class, q)
+   *     .setParameter("st", Order.Status.NEW)
    *     .findList();
-   * 
+ * + * }
* * @param query * the object query @@ -956,40 +977,43 @@ public final class Ebean { * Example named updates: *

* - *
-   * package app.data;
+   * 
{@code
+   *   package app.data;
    * 
-   * import ...
+   *   import ...
    * 
-   * @NamedUpdates(value = { 
-   * 	@NamedUpdate( name = "setTitle", 
-   * 		isSql = false, 
-   * 		notifyCache = false, 
-   * 		update = "update topic set title = :title, postCount = :postCount where id = :id"), 
-   * 	@NamedUpdate( name = "setPostCount",
-   * 		notifyCache = false,
-   * 		update = "update f_topic set post_count = :postCount where id = :id"), 
-   * 	@NamedUpdate( name = "incrementPostCount", 
-   * 		notifyCache = false, 
-   * 		isSql = false,
-   * 		update = "update Topic set postCount = postCount + 1 where id = :id") }) 
-   * @Entity 
-   * @Table(name = "f_topic") 
-   * public class Topic { ...
-   * 
+ * @NamedUpdates(value = { + * @NamedUpdate( name = "setTitle", + * isSql = false, + * notifyCache = false, + * update = "update topic set title = :title, postCount = :postCount where id = :id"), + * @NamedUpdate( name = "setPostCount", + * notifyCache = false, + * update = "update f_topic set post_count = :postCount where id = :id"), + * @NamedUpdate( name = "incrementPostCount", + * notifyCache = false, + * isSql = false, + * update = "update Topic set postCount = postCount + 1 where id = :id") }) + * @Entity + * @Table(name = "f_topic") + * public class Topic { ... + * + * }
* *

* Example using a named update: *

* - *
-   * Update<Topic> update = Ebean.createNamedUpdate(Topic.class, "setPostCount");
-   * update.setParameter("postCount", 10);
-   * update.setParameter("id", 3);
+   * 
{@code
+   *
+   *   Update update = Ebean.createNamedUpdate(Topic.class, "setPostCount");
+   *   update.setParameter("postCount", 10);
+   *   update.setParameter("id", 3);
    * 
-   * int rows = update.execute();
-   * System.out.println("rows updated: " + rows);
-   * 
+ * int rows = update.execute(); + * System.out.println("rows updated: " + rows); + * + * }
*/ public static Update createNamedUpdate(Class beanType, String namedUpdate) { @@ -1008,21 +1032,22 @@ public final class Ebean { * An example: *

* - *
+   * 
{@code
    * 
-   * // The bean name and properties - "topic","postCount" and "id"
+   *   // The bean name and properties - "topic","postCount" and "id"
    * 
-   * // will be converted into their associated table and column names
-   * String updStatement = "update topic set postCount = :pc where id = :id";
+   *   // will be converted into their associated table and column names
+   *   String updStatement = "update topic set postCount = :pc where id = :id";
    * 
-   * Update<Topic> update = Ebean.createUpdate(Topic.class, updStatement);
+   *   Update update = Ebean.createUpdate(Topic.class, updStatement);
    * 
-   * update.set("pc", 9);
-   * update.set("id", 3);
+   *   update.set("pc", 9);
+   *   update.set("id", 3);
    * 
-   * int rows = update.execute();
-   * System.out.println("rows updated:" + rows);
-   * 
+ * int rows = update.execute(); + * System.out.println("rows updated:" + rows); + * + * }
*/ public static Update createUpdate(Class beanType, String ormUpdate) { @@ -1053,38 +1078,37 @@ public final class Ebean { * which is was created. *

* - *
-   * // Find order 2 additionally fetching the customer, details and details.product
-   * // name.
+   * 
{@code
+   *   // Find order 2 additionally fetching the customer, details and details.product
+   *   // name.
    * 
-   * Query<Order> query = Ebean.createQuery(Order.class);
-   * query.fetch("customer");
-   * query.fetch("details");
-   * query.fetch("detail.product", "name");
-   * query.setId(2);
+   *   Order order = Ebean.find(Order.class)
+   *     .fetch("customer")
+   *     .fetch("details")
+   *     .fetch("detail.product", "name")
+   *     .setId(2)
+   *     .findUnique();
    * 
-   * Order order = query.findUnique();
+   *   // Find order 2 additionally fetching the customer, details and details.product
+   *   // name.
+   *   // Note: same query as above but using the query language
+   *   // Note: using a named query would be preferred practice
    * 
-   * // Find order 2 additionally fetching the customer, details and details.product
-   * // name.
-   * // Note: same query as above but using the query language
-   * // Note: using a named query would be preferred practice
+   *   String oql = "find order fetch customer fetch details fetch details.product (name) where id = :orderId ";
    * 
-   * String oql = "find order fetch customer fetch details fetch details.product (name) where id = :orderId ";
+   *   Query query = Ebean.find(Order.class);
+   *   query.setQuery(oql);
+   *   query.setParameter("orderId", 2);
    * 
-   * Query<Order> query = Ebean.createQuery(Order.class);
-   * query.setQuery(oql);
-   * query.setParameter("orderId", 2);
+   *   Order order = query.findUnique();
    * 
-   * Order order = query.findUnique();
+   *   // Using a named query
+   *   Query query = Ebean.find(Order.class, "with.details");
+   *   query.setParameter("orderId", 2);
    * 
-   * // Using a named query
-   * Query<Order> query = Ebean.createQuery(Order.class, "with.details");
-   * query.setParameter("orderId", 2);
+   *   Order order = query.findUnique();
    * 
-   * Order order = query.findUnique();
-   * 
-   * 
+ * }
* * @param beanType * the class of entity to be fetched @@ -1144,19 +1168,21 @@ public final class Ebean { * Example: *

* - *
-   * // example that uses 'named' parameters 
-   * String s = "UPDATE f_topic set post_count = :count where id = :id"
+   * 
{@code
+   *
+   *   // example that uses 'named' parameters
+   *   String s = "UPDATE f_topic set post_count = :count where id = :id"
    * 
-   * SqlUpdate update = Ebean.createSqlUpdate(s);
+   *   SqlUpdate update = Ebean.createSqlUpdate(s);
    * 
-   * update.setParameter("id", 1);
-   * update.setParameter("count", 50);
+   *   update.setParameter("id", 1);
+   *   update.setParameter("count", 50);
    * 
-   * int modifiedCount = Ebean.execute(update);
+   *   int modifiedCount = Ebean.execute(update);
    * 
-   * String msg = "There where " + modifiedCount + "rows updated";
-   * 
+ * String msg = "There where " + modifiedCount + "rows updated"; + * + * }
* * @param sqlUpdate * the update sql potentially with bind values @@ -1177,19 +1203,21 @@ public final class Ebean { * Example: *

* - *
-   * String sql = "{call sp_order_modify(?,?,?)}";
+   * 
{@code
+   *
+   *   String sql = "{call sp_order_modify(?,?,?)}";
    * 
-   * CallableSql cs = Ebean.createCallableSql(sql);
-   * cs.setParameter(1, 27);
-   * cs.setParameter(2, "SHIPPED");
-   * cs.registerOut(3, Types.INTEGER);
+   *   CallableSql cs = Ebean.createCallableSql(sql);
+   *   cs.setParameter(1, 27);
+   *   cs.setParameter(2, "SHIPPED");
+   *   cs.registerOut(3, Types.INTEGER);
    * 
-   * Ebean.execute(cs);
+   *   Ebean.execute(cs);
    * 
-   * // read the out parameter
-   * Integer returnValue = (Integer) cs.getObject(3);
-   * 
+ * // read the out parameter + * Integer returnValue = (Integer) cs.getObject(3); + * + * }
* * @see CallableSql * @see Ebean#execute(SqlUpdate) @@ -1205,18 +1233,19 @@ public final class Ebean { * semantics. *

* - *
-   * // set specific transactional scope settings 
-   * TxScope scope = TxScope.requiresNew().setIsolation(TxIsolation.SERIALIZABLE);
-   * 
-   * Ebean.execute(scope, new TxRunnable() { 
-   * 	public void run() { 
-   * 		User u1 = Ebean.find(User.class, 1); 
-   * 		...
-   * 
-   * 	} 
-   * });
-   * 
+ *
{@code
+   *
+   *   // set specific transactional scope settings
+   *   TxScope scope = TxScope.requiresNew().setIsolation(TxIsolation.SERIALIZABLE);
+   *
+   *   Ebean.execute(scope, new TxRunnable() {
+   * 	   public void run() {
+   * 		   User u1 = Ebean.find(User.class, 1);
+   * 		   ...
+   * 	   }
+   *   });
+   *
+   * }
*/ public static void execute(TxScope scope, TxRunnable r) { serverMgr.getPrimaryServer().execute(scope, r); @@ -1229,20 +1258,22 @@ public final class Ebean { * exception (checked or runtime). *

* - *
-   * Ebean.execute(new TxRunnable() {
-   *   public void run() {
-   *     User u1 = Ebean.find(User.class, 1);
-   *     User u2 = Ebean.find(User.class, 2);
+   * 
{@code
+   *
+   *   Ebean.execute(new TxRunnable() {
+   *     public void run() {
+   *       User u1 = Ebean.find(User.class, 1);
+   *       User u2 = Ebean.find(User.class, 2);
    * 
-   *     u1.setName("u1 mod");
-   *     u2.setName("u2 mod");
+   *       u1.setName("u1 mod");
+   *       u2.setName("u2 mod");
    * 
-   *     Ebean.save(u1);
-   *     Ebean.save(u2);
-   *   }
-   * });
-   * 
+ * Ebean.save(u1); + * Ebean.save(u2); + * } + * }); + * + * }
*/ public static void execute(TxRunnable r) { serverMgr.getPrimaryServer().execute(r); @@ -1255,18 +1286,20 @@ public final class Ebean { * semantics. *

* - *
-   * // set specific transactional scope settings 
-   * TxScope scope = TxScope.requiresNew().setIsolation(TxIsolation.SERIALIZABLE);
-   * 
-   * Ebean.execute(scope, new TxCallable<String>() {
-   * 	public String call() { 
-   * 		User u1 = Ebean.find(User.class, 1); 
-   * 		...
-   * 		return u1.getEmail(); 
-   * 	} 
-   * });
-   * 
+ *
{@code
+   *
+   *   // set specific transactional scope settings
+   *   TxScope scope = TxScope.requiresNew().setIsolation(TxIsolation.SERIALIZABLE);
+   *
+   *   Ebean.execute(scope, new TxCallable() {
+   * 	   public String call() {
+   * 		   User u1 = Ebean.find(User.class, 1);
+   * 		   ...
+   * 		   return u1.getEmail();
+   * 	   }
+   *   });
+   *
+   * }
* */ public static T execute(TxScope scope, TxCallable c) { @@ -1284,22 +1317,24 @@ public final class Ebean { * (and you specify the return type via generics). *

* - *
-   * Ebean.execute(new TxCallable<String>() {
-   *   public String call() {
-   *     User u1 = Ebean.find(User.class, 1);
-   *     User u2 = Ebean.find(User.class, 2);
+   * 
{@code
+   *
+   *   Ebean.execute(new TxCallable() {
+   *     public String call() {
+   *       User u1 = Ebean.find(User.class, 1);
+   *       User u2 = Ebean.find(User.class, 2);
    * 
-   *     u1.setName("u1 mod");
-   *     u2.setName("u2 mod");
+   *       u1.setName("u1 mod");
+   *       u2.setName("u2 mod");
    * 
-   *     Ebean.save(u1);
-   *     Ebean.save(u2);
+   *       Ebean.save(u1);
+   *       Ebean.save(u2);
    * 
-   *     return u1.getEmail();
-   *   }
-   * });
-   * 
+ * return u1.getEmail(); + * } + * }); + * + * }
*/ public static T execute(TxCallable c) { return serverMgr.getPrimaryServer().execute(c); @@ -1320,7 +1355,7 @@ public final class Ebean { *

*

* If there is a transaction then this information is placed into the current - * transactions event information. When the transaction is commited this + * transactions event information. When the transaction is committed this * information is registered (with the transaction manager). If this * transaction is rolled back then none of the transaction event information * registers including the information you put in via this method. diff --git a/src/main/java/com/avaje/ebean/EbeanServer.java b/src/main/java/com/avaje/ebean/EbeanServer.java index 45f4bdc18..cce74e938 100644 --- a/src/main/java/com/avaje/ebean/EbeanServer.java +++ b/src/main/java/com/avaje/ebean/EbeanServer.java @@ -49,18 +49,18 @@ import com.avaje.ebean.text.json.JsonContext; * Example: Get a EbeanServer *

* - *
+ * 
{@code
  * // Get access to the Human Resources EbeanServer/Database
- * EbeanServer hrServer = Ebean.getServer("HR");
+ * EbeanServer hrServer = Ebean.getServer("HR");
  * 
  * 
  * // fetch contact 3 from the HR database Contact contact =
  * hrServer.find(Contact.class, new Integer(3));
  * 
- * contact.setStatus("INACTIVE"); ...
+ * contact.setStatus("INACTIVE"); ...
  * 
  * // save the contact back to the HR database hrServer.save(contact);
- * 
+ * }
* *

* EbeanServer has more API than Ebean
@@ -128,7 +128,6 @@ public interface EbeanServer { */ public MetaInfoManager getMetaInfoManager(); - /** * Return the BeanState for a given entity bean. *

@@ -192,15 +191,15 @@ public interface EbeanServer { * moved to {@link #createNamedQuery(Class, String)}. *

* - *
+   * 
{@code
    *  EbeanServer ebeanServer = ... ;
    *  String q = "find order fetch details where status = :st";
    *  
-   *  List<Order> newOrders 
+   *  List newOrders
    *        = ebeanServer.createQuery(Order.class, q)
    *             .setParameter("st", Order.Status.NEW)
    *             .findList();
-   * 
+ * }
* * @param query * the object query @@ -208,16 +207,14 @@ public interface EbeanServer { public Query createQuery(Class beanType, String query); /** - * Create a query for an entity bean (refer {@link Ebean#createQuery(Class)} - * ). + * Create a query for an entity bean (refer {@link Ebean#createQuery(Class)}). * * @see Ebean#createQuery(Class) */ public Query createQuery(Class beanType); /** - * Create a query for a type of entity bean (the same as - * {@link EbeanServer#createQuery(Class)}). + * Create a query for a type of entity bean (the same as {@link EbeanServer#createQuery(Class)}). */ public Query find(Class beanType); @@ -273,8 +270,7 @@ public interface EbeanServer { public SqlQuery createSqlQuery(String sql); /** - * Create a named sql query (refer {@link Ebean#createNamedSqlQuery(String)} - * ). + * Create a named sql query (refer {@link Ebean#createNamedSqlQuery(String)}). *

* The query statement will be defined in a deployment orm xml file. *

@@ -284,8 +280,7 @@ public interface EbeanServer { public SqlQuery createNamedSqlQuery(String namedQuery); /** - * Create a sql update for executing native dml statements (refer - * {@link Ebean#createSqlUpdate(String)}). + * Create a sql update for executing native dml statements (refer {@link Ebean#createSqlUpdate(String)}). * * @see Ebean#createSqlUpdate(String) */ @@ -297,8 +292,7 @@ public interface EbeanServer { public CallableSql createCallableSql(String callableSql); /** - * Create a named sql update (refer {@link Ebean#createNamedSqlUpdate(String)} - * ). + * Create a named sql update (refer {@link Ebean#createNamedSqlUpdate(String)}). *

* The statement (an Insert Update or Delete statement) will be defined in a * deployment orm xml file. @@ -350,8 +344,7 @@ public interface EbeanServer { public Transaction beginTransaction(TxIsolation isolation); /** - * Returns the current transaction or null if there is no current transaction - * in scope. + * Returns the current transaction or null if there is no current transaction in scope. */ public Transaction currentTransaction(); @@ -379,15 +372,19 @@ public interface EbeanServer { *

* Code example: * - *

-   * Ebean.startTransaction(); try { // do some fetching
-   * and or persisting
+   * 
{@code
+   *   ebeanServer.startTransaction();
+   *   try {
+   *     // do some fetching and or persisting ...
    * 
-   * // commit at the end Ebean.commitTransaction();
+   *     // commit at the end
+   *     ebeanServer.commitTransaction();
    * 
-   * } finally { // if commit didn't occur then rollback the transaction
-   * Ebean.endTransaction(); }
-   * 
+ * } finally { + * // if commit didn't occur then rollback the transaction + * ebeanServer.endTransaction(); + * } + * }
* *

* @@ -429,7 +426,7 @@ public interface EbeanServer { *

* This will not perform a query against the database. *

- *
+   * 
{@code
    * Product product = Ebean.getReference(Product.class, 1);
    * 
    * // You can get the id without causing a fetch/lazy load
@@ -438,7 +435,7 @@ public interface EbeanServer {
    * // If you try to get any other property a fetch/lazy loading will occur
    * // This will cause a query to execute...
    * String name = product.getName();
-   * 
+ * }
* * @param beanType * the type of entity bean @@ -882,7 +879,7 @@ public interface EbeanServer { * An unmodified bean that is saved or updated is normally skipped and this marks the bean as * dirty so that it is not skipped. * - *
+   * 
{@code
    * 
    * Customer customer = ebeanServer.find(Customer, id);
    * 
@@ -891,7 +888,7 @@ public interface EbeanServer {
    * ebeanServer.markAsDirty(customer);
    * ebeanServer.save(customer);
    * 
-   * 
+ * }
*/ public void markAsDirty(Object bean); @@ -918,15 +915,15 @@ public interface EbeanServer { * properties are included instead. *

* - *
+   * 
{@code
    * 
    * // A 'stateless update' example
    * Customer customer = new Customer();
    * customer.setId(7);
-   * customer.setName("ModifiedNameNoOCC");
+   * customer.setName("ModifiedNameNoOCC");
    * ebeanServer.update(customer);
    * 
-   * 
+ * }
* * @see ServerConfig#setUpdatesDeleteMissingChildren(boolean) * @see ServerConfig#setUpdateChangesOnly(boolean)