From 7ea6f16207d7614ad514b7e0892a73016a2811ff Mon Sep 17 00:00:00 2001
From: rob bygrave
* This would be similar to using the
- *
diff --git a/src/main/java/io/ebean/DtoQuery.java b/src/main/java/io/ebean/DtoQuery.java
index c72a16216..1603e1d10 100644
--- a/src/main/java/io/ebean/DtoQuery.java
+++ b/src/main/java/io/ebean/DtoQuery.java
@@ -30,7 +30,7 @@ import java.util.function.Predicate;
* String sql = "select id, name from customer where name like :name and status_code = :status";
*
* List
- * See also {@link Ebean#getExpressionFactory()}
+ * See also {@link DB#getExpressionFactory()}
*
* Creates standard common expressions for using in a Query Where or Having
* clause.
*
- * This returns the list so that add() can be chained.
- *
@@ -926,7 +911,7 @@ public interface ExpressionList
*
*
* Ebean.externalModification() method. It may be easier and make
+ * DB.externalModification() method. It may be easier and make
* more sense to set it here with the CallableSql.
* {@code
- *
- * // Example: Using an Expr.or() method
- * Query
*
* @see Query#where()
*/
diff --git a/src/main/java/io/ebean/ExpressionFactory.java b/src/main/java/io/ebean/ExpressionFactory.java
index 0ea9071e4..42177057d 100644
--- a/src/main/java/io/ebean/ExpressionFactory.java
+++ b/src/main/java/io/ebean/ExpressionFactory.java
@@ -30,9 +30,9 @@ import java.util.Map;
* Expr.or(Expr.eq("status", Order.Status.NEW),
* Expr.gt("orderDate", lastWeek));
*
- * Query{@code
*
* List{@code
*
* List{@code
*
* String name =
- * Ebean.find(Customer.class)
+ * DB.find(Customer.class)
* .select("name")
* .where().eq("id", 42)
* .findSingleAttribute();
@@ -435,7 +435,7 @@ public interface ExpressionList{@code
*
- * PagedList
*/
diff --git a/src/main/java/io/ebean/ExtendedServer.java b/src/main/java/io/ebean/ExtendedServer.java
index deb3582f2..25e4c27ea 100644
--- a/src/main/java/io/ebean/ExtendedServer.java
+++ b/src/main/java/io/ebean/ExtendedServer.java
@@ -272,7 +272,7 @@ public interface ExtendedServer {
* {@code
*
* List
* {@code
- *
- * Query
*/
ExpressionList{@code
*
- * PagedList{@code
*
* List{@code
*
* List{@code
* // Normal fetch join results in a single SQL query
- * List
@@ -36,7 +36,7 @@ import java.io.Serializable;
*
* // This will use 2 SQL queries to build this object graph
* List{@code
* // This will use 3 SQL queries to build this object graph
* List{@code
*
* List{@code
*
- * List{@code
*
* // create a query to find all orders
- * Query
{@code
* Query q =
- * Ebean.find(Person.class)
+ * DB.find(Person.class)
* .where()
* .or()
* .like("name", "Rob%")
@@ -30,7 +30,7 @@ package io.ebean;
* {@code
*
* Query q =
- * Ebean.find(Person.class)
+ * DB.find(Person.class)
* .where()
* .or()
* .like("name", "Rob%")
@@ -50,7 +50,7 @@ package io.ebean;
*
* {@code
* Query q =
- * Ebean.find(Customer.class)
+ * DB.find(Customer.class)
* .where()
* .or()
* .and()
diff --git a/src/main/java/io/ebean/Pairs.java b/src/main/java/io/ebean/Pairs.java
index 3c99bceed..3e7f125ae 100644
--- a/src/main/java/io/ebean/Pairs.java
+++ b/src/main/java/io/ebean/Pairs.java
@@ -26,7 +26,7 @@ import java.util.List;
* pairs.add("sj2", 1001);
* pairs.add("pf3", 1000);
*
- * List list = Ebean.find(OCachedNatKeyBean3.class)
+ * List list = DB.find(OCachedNatKeyBean3.class)
* .where()
* .eq("store", "def")
* .inPairs(pairs) // IN clause with 'pairs' of values
diff --git a/src/main/java/io/ebean/Query.java b/src/main/java/io/ebean/Query.java
index bf9717f12..308669fbf 100644
--- a/src/main/java/io/ebean/Query.java
+++ b/src/main/java/io/ebean/Query.java
@@ -377,7 +377,7 @@ public interface Query {
* {@code
*
* // fetch a bean with JSON content
- * EBasicJsonList bean= Ebean.find(EBasicJsonList.class)
+ * EBasicJsonList bean= DB.find(EBasicJsonList.class)
* .setId(42)
* .setAllowLoadErrors() // collect errors into bean state if we have invalid JSON
* .findOne();
@@ -843,7 +843,7 @@ public interface Query {
* {@code
*
* List names =
- * Ebean.find(Customer.class)
+ * DB.find(Customer.class)
* .select("name")
* .orderBy().asc("name")
* .findSingleAttributeList();
@@ -854,7 +854,7 @@ public interface Query {
* {@code
*
* List names =
- * Ebean.find(Customer.class)
+ * DB.find(Customer.class)
* .setDistinct(true)
* .select("name")
* .where().eq("status", Customer.Status.NEW)
@@ -875,7 +875,7 @@ public interface Query {
* {@code
*
* String name =
- * Ebean.find(Customer.class)
+ * DB.find(Customer.class)
* .select("name")
* .where().eq("id", 42)
* .findSingleAttribute();
@@ -1089,7 +1089,7 @@ public interface Query {
*
* {@code
*
- * PagedList pagedList = Ebean.find(Order.class)
+ * PagedList pagedList = DB.find(Order.class)
* .setFirstRow(50)
* .setMaxRows(20)
* .findPagedList();
@@ -1375,7 +1375,7 @@ public interface Query {
* {@code
*
* List customers =
- * Ebean.find(Customer.class)
+ * DB.find(Customer.class)
* .setDistinct(true)
* .select("name")
* .findList();
@@ -1391,7 +1391,7 @@ public interface Query {
*
* List> orderStatusCount =
*
- * Ebean.find(Order.class)
+ * DB.find(Order.class)
* .select("status")
* .where()
* .gt("orderDate", LocalDate.now().minusMonths(3))
diff --git a/src/main/java/io/ebean/RawSql.java b/src/main/java/io/ebean/RawSql.java
index 857ce7328..66781155b 100644
--- a/src/main/java/io/ebean/RawSql.java
+++ b/src/main/java/io/ebean/RawSql.java
@@ -87,7 +87,7 @@ package io.ebean;
* // .columnMapping("sum(d.order_qty*d.unit_price)", "totalAmount")
* .create();
*
- * List list = Ebean.find(OrderAggregate.class)
+ * List list = DB.find(OrderAggregate.class)
* .setRawSql(rawSql)
* .where().gt("order.id", 0)
* .having().gt("totalAmount", 20)
@@ -114,7 +114,7 @@ package io.ebean;
* .columnMappingIgnore("'ignoreMe'")
* .create();
*
- * List orders = Ebean.find(OrderAggregate.class)
+ * List orders = DB.find(OrderAggregate.class)
* .setRawSql(rawSql)
* .fetch("order", "status,orderDate", new FetchConfig().query())
* .fetch("order.customer", "name")
@@ -146,7 +146,7 @@ package io.ebean;
* .tableAliasMapping("p", "details.product")
* .create();
*
- * List ordersFromRaw = Ebean.find(Order.class)
+ * List ordersFromRaw = DB.find(Order.class)
* .setRawSql(rawSql)
* .setParameter("maxOrderId", 2)
* .setParameter("productId", 1)
diff --git a/src/main/java/io/ebean/RowConsumer.java b/src/main/java/io/ebean/RowConsumer.java
index 4845f18ea..3a02964f2 100644
--- a/src/main/java/io/ebean/RowConsumer.java
+++ b/src/main/java/io/ebean/RowConsumer.java
@@ -13,7 +13,7 @@ import java.sql.SQLException;
*
* String sql = "select id, name, status from o_customer order by name desc";
*
- * Ebean.createSqlQuery(sql)
+ * DB.sqlQuery(sql)
* .findEachRow((resultSet, rowNum) -> {
*
* // read directly from ResultSet
diff --git a/src/main/java/io/ebean/RowMapper.java b/src/main/java/io/ebean/RowMapper.java
index 1cc067372..5ef6e64de 100644
--- a/src/main/java/io/ebean/RowMapper.java
+++ b/src/main/java/io/ebean/RowMapper.java
@@ -40,7 +40,7 @@ import java.sql.SQLException;
*
* String sql = "select id, name, status from o_customer where name = ?";
*
- * CustomerDto rob = Ebean.createSqlQuery(sql)
+ * CustomerDto rob = DB.sqlQuery(sql)
* .setParameter(1, "Rob")
* .findOne(CUSTOMER_MAPPER);
*
diff --git a/src/main/java/io/ebean/ScriptRunner.java b/src/main/java/io/ebean/ScriptRunner.java
index b9130d57b..2336d1628 100644
--- a/src/main/java/io/ebean/ScriptRunner.java
+++ b/src/main/java/io/ebean/ScriptRunner.java
@@ -13,20 +13,8 @@ import java.util.Map;
* Example of simple use
* {@code
*
- * EbeanServer server = Ebean.getDefaultServer();
- * server.script().run("/scripts/test-script.sql");
- *
- * }
- *
- *
- * Example using place holders in the script
- * {@code
- *
- * Map placeholders = new HashMap<>();
- * placeholders.put("tableName", "e_basic");
- *
- * EbeanServer server = Ebean.getDefaultServer();
- * server.script().run("/scripts/test-script.sql");
+ * Database database = DB.getDefault();
+ * database.script().run("/scripts/test-script.sql");
*
* }
*/
@@ -45,8 +33,8 @@ public interface ScriptRunner {
* Map placeholders = new HashMap<>();
* placeholders.put("tableName", "e_basic");
*
- * EbeanServer server = Ebean.getDefaultServer();
- * server.script().run("/scripts/test-script.sql");
+ * Database database = DB.getDefault();
+ * database.script().run("/scripts/test-script.sql", placeholders);
*
* }
*/
diff --git a/src/main/java/io/ebean/Transaction.java b/src/main/java/io/ebean/Transaction.java
index 4b0f24bf1..465df6732 100644
--- a/src/main/java/io/ebean/Transaction.java
+++ b/src/main/java/io/ebean/Transaction.java
@@ -14,18 +14,18 @@ import java.sql.Connection;
public interface Transaction extends AutoCloseable {
/**
- * Return the current transaction (of the default server) or null if there is
+ * Return the current transaction (of the default database) or null if there is
* no current transaction in scope.
*
- * This is the same as Ebean.currentTransaction()
+ * This is the same as DB.currentTransaction()
*
*
* This returns the current transaction for the 'default server'. If you are using
- * multiple EbeanServer's then use {@link EbeanServer#currentTransaction()}.
+ * multiple EbeanServer's then use {@link DB#currentTransaction()}.
*
*
- * @see Ebean#currentTransaction()
- * @see EbeanServer#currentTransaction()
+ * @see DB#currentTransaction()
+ * @see Database#currentTransaction()
*/
static Transaction current() {
return Ebean.currentTransaction();
diff --git a/src/main/java/io/ebean/Update.java b/src/main/java/io/ebean/Update.java
index 70c225ce3..95fb5b412 100644
--- a/src/main/java/io/ebean/Update.java
+++ b/src/main/java/io/ebean/Update.java
@@ -41,7 +41,7 @@ package io.ebean;
*
*
{@code
*
- * Update update = Ebean.createUpdate(Topic.class, "incrementPostCount");
+ * Update update = DB.createUpdate(Topic.class, "incrementPostCount");
* update.setParameter("id", 1);
* int rows = update.execute();
*
diff --git a/src/main/java/io/ebean/config/ServerConfig.java b/src/main/java/io/ebean/config/ServerConfig.java
index 9979057d0..27c1098d7 100644
--- a/src/main/java/io/ebean/config/ServerConfig.java
+++ b/src/main/java/io/ebean/config/ServerConfig.java
@@ -2328,8 +2328,7 @@ public class ServerConfig {
*
* // assume Customer has L2 bean caching enabled ...
*
- * Transaction transaction = Ebean.beginTransaction();
- * try {
+ * try (Transaction transaction = DB.beginTransaction()) {
*
* // this uses L2 bean cache as the transaction
* // ... is considered "query only" at this point
@@ -2337,7 +2336,7 @@ public class ServerConfig {
*
* // transaction no longer "query only" once
* // ... a bean has been saved etc
- * Ebean.save(someBean);
+ * DB.save(someBean);
*
* // will NOT use L2 bean cache as the transaction
* // ... is no longer considered "query only"
@@ -2356,9 +2355,6 @@ public class ServerConfig {
* transaction.setSkipCache(true);
* Customer.find.byId(99); // skips l2 bean cache
*
- *
- * } finally {
- * transaction.end();
* }
*
* }
diff --git a/src/main/java/io/ebean/package.html b/src/main/java/io/ebean/package.html
index e3b4f6a25..4aa8efb94 100644
--- a/src/main/java/io/ebean/package.html
+++ b/src/main/java/io/ebean/package.html
@@ -3,19 +3,20 @@
Ebean core API
-Core API (see EbeanServer and Ebean).
+Core API (see Database, DB and Query).
-Ebean
+Database
- Provides the main API for fetching and persisting beans with eBean.
+ Provides the main API for fetching and persisting beans. We can obtain the "default database"
+ via DB.getDefault() or just use methods on DB.
{@code
-// EXAMPLE 1: Simple fetch
+// EXAMPLE 1: Simple fetch.
//========================
// fetch order 10
-Order order = Ebean.find(Order.class, 10);
+Order order = DB.find(Order.class, 10);
@@ -24,7 +25,7 @@ Order order = Ebean.find(Order.class, 10);
// fetch Customer 7 including their billing and shipping addresses
Customer customer =
- Ebean.find(Customer.class)
+ DB.find(Customer.class)
.setId(7)
.fetch("billingAddress")
.fetch("shippingAddress")
@@ -40,28 +41,16 @@ Address shipAddr = customer.getShippingAddress();
//=====================================
// get a Customer reference so we don't hit the database
-Customer custRef = Ebean.getReference(Customer.class, 7);
+Customer customer = DB.getReference(Customer.class, 7);
// create a new Order object
Order newOrder = new Order();
newOrder.setStatus(Order.Status.NEW);
-newOrder.setCustomer(custRef);
-
-ArrayList orderLines = new ArrayList();
-newOrder.setLines(orderLines);
+newOrder.setCustomer(customer);
...
-// add a line to the order
-Product prodRef = Ebean.getReference(Product.class, 41);
-OrderLine line = new OrderLine();
-line.setProduct(prodRef);
-line.setQuantity(10);
-orderLines.add(line);
-...
-// save the order and its lines in a single transaction
-// NB: assumes CascadeType.PERSIST is set on the order lines association
-Ebean.save(newOrder);
+DB.save(newOrder);
@@ -69,17 +58,16 @@ Ebean.save(newOrder);
//=================================
// Get access to the Human Resources EbeanServer/Database
-EbeanServer hrServer = Ebean.getServer("HR");
+Database hrDatabase = DB.byName("HR");
-// fetch contact 3 from the HR database
-Contact contact = hrServer.find(Contact.class, 3);
+Contact contact = hrDatabase.find(Contact.class, 42);
contact.setStatus(Contact.Status.INACTIVE);
...
// save the contact back to the HR database
-hrServer.save(contact);
+hrDatabase.save(contact);
}
diff --git a/src/main/java/io/ebean/text/csv/CsvReader.java b/src/main/java/io/ebean/text/csv/CsvReader.java
index cff4a49d0..de64444ab 100644
--- a/src/main/java/io/ebean/text/csv/CsvReader.java
+++ b/src/main/java/io/ebean/text/csv/CsvReader.java
@@ -20,7 +20,7 @@ import java.util.Locale;
*
* FileReader reader = new FileReader(f);
*
- * CsvReader<Customer> csvReader = Ebean.createCsvReader(Customer.class);
+ * CsvReader csvReader = DB.createCsvReader(Customer.class);
*
* csvReader.setPersistBatchSize(20);
*
diff --git a/src/main/java/io/ebean/text/json/package-info.java b/src/main/java/io/ebean/text/json/package-info.java
index a5033072f..62badf679 100644
--- a/src/main/java/io/ebean/text/json/package-info.java
+++ b/src/main/java/io/ebean/text/json/package-info.java
@@ -10,7 +10,7 @@
* {@code
* // find some customers ...
*
- * List list = Ebean.find(Customer.class)
+ * List list = DB.find(Customer.class)
* .select("id, name, status, shippingAddress")
* .fetch("billingAddress","line1, city")
* .fetch("billingAddress.country", "*")
@@ -18,7 +18,7 @@
* .order().desc("id")
* .findList();
*
- * JsonContext json = Ebean.json();
+ * JsonContext json = DB.json();
*
* // output as a JSON string
* String jsonOutput = json.toJson(list);