diff --git a/src/main/java/io/ebean/DB.java b/src/main/java/io/ebean/DB.java index 03822a79f..198795856 100644 --- a/src/main/java/io/ebean/DB.java +++ b/src/main/java/io/ebean/DB.java @@ -17,6 +17,50 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.Callable; +/** + * DB is a registry of {@link Database} by name. + *

+ * DB additionally provides a convenient way to use the 'default' Database. + *

+ *

Default database

+ *

+ * One of the Database instances can be registered as the "default database" + * and can be obtained using DB.getDefault() + *

+ *
{@code
+ *
+ * Database database = DB.getDefault();
+ *
+ * }
+ * + *

Named database

+ *

+ * Multiple database instances can be registered with DB and we can obtain them + * using DB.byName() + *

+ *
{@code
+ *
+ * Database hrDatabase = DB.byName("hr");
+ *
+ * }
+ * + *

Convenience methods

+ *

+ * DB has methods like {@link #find(Class)} and {@link #save(Object)} which are + * just convenience for using the default database. + *

+ * + *
{@code
+ *
+ *   // fetch using the default database
+ *   Order order = DB.find(Order.class, 10);
+ *
+ *   // is the same as
+ *   Database database = DB.getDefault();
+ *   Order order = database.find(Order.class, 10);
+ *
+ * }
+ */ public class DB { /** diff --git a/src/main/java/io/ebean/Ebean.java b/src/main/java/io/ebean/Ebean.java index 2751cd3bf..eb85c9509 100644 --- a/src/main/java/io/ebean/Ebean.java +++ b/src/main/java/io/ebean/Ebean.java @@ -24,97 +24,11 @@ import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentHashMap; /** - * This Ebean object is effectively a singleton that holds a map of registered - * {@link EbeanServer}s. It additionally provides a convenient way to use the - * 'default' EbeanServer. + * Ebean is a registry of {@link Database} by name. Ebean has now been renamed to {@link DB}. *

- * If you are using a Dependency Injection framework such as - * Spring or Guice you will probably - * NOT use this Ebean singleton object. Instead you will - * configure and construct EbeanServer instances using {@link ServerConfig} and - * {@link EbeanServerFactory} and inject those EbeanServer instances into your - * data access objects. - *

+ * Ebean is effectively this is an alias for {@link DB} which is the new and improved name for Ebean. *

- * In documentation "Ebean singleton" refers to this object. - *

- * - *

- * For developer convenience Ebean has static methods that proxy through to the - * methods on the 'default' EbeanServer. These methods are provided for - * developers who are mostly using a single database. Many developers will be - * able to use the methods on Ebean rather than get a EbeanServer. - *

- *

- * EbeanServers can be created and used without ever needing or using the Ebean - * singleton. Refer to {@link ServerConfig#setRegister(boolean)}. - *

- *

- * You can either programmatically create/register EbeanServers via - * {@link EbeanServerFactory} or they can automatically be created and - * registered when you first use the Ebean singleton. When EbeanServers are - * 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();
- * 	   ...
- *   }
- *
- * }
- *
{@code
- *
- *   // 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);
- *
- * }
- *

- * When you have multiple databases and need access to a specific one the - * {@link #getServer(String)} method provides access to the EbeanServer for that - * specific database. - *

- *
{@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);
- *
- *   contact.setName("I'm going to change");
- *   ...
- *
- *   // save the contact back to the HR database
- *   hrDb.save(contact);
- *
- * }
+ * The preference is to use DB and Database rather than Ebean and EbeanServer. */ public final class Ebean { private static final Logger logger = LoggerFactory.getLogger(Ebean.class);