|
||||||||||
| PREV NEXT | FRAMES NO FRAMES | |||||||||
See:
Description
| Public API | |
|---|---|
| com.avaje.ebean | Core API (see Ebean and EbeanServer). |
| com.avaje.ebean.annotation | Extra deployment annotations |
| com.avaje.ebean.bean | Enhanced beans API and Support objects |
| com.avaje.ebean.cache | Server Cache Service |
| com.avaje.ebean.common | Common non-public interfaces and implementation. |
| com.avaje.ebean.config | Configuration settings for EbeanServer construction |
| com.avaje.ebean.config.dbplatform | Database platform specific support |
| com.avaje.ebean.config.ldap | LDAP configuration objects. |
| com.avaje.ebean.event | Persist and Query Event Controllers and Listeners |
| com.avaje.ebean.meta | Entity Beans for getting "Meta" data from Ebean |
| com.avaje.ebean.text | Utility objects for CSV, JSON and XML processing. |
| com.avaje.ebean.text.csv | CSV processing objects. |
| com.avaje.ebean.text.json | JSON formatting and parsing objects (See JsonContext). |
| com.avaje.ebean.validation | Annotations for validating entity beans. |
| com.avaje.ebean.validation.factory | Factories to create validators. |
Ebean Object Relational Mapping (start at Ebean or EbeanServer).
Provides the main API for fetching and persisting beans with Ebean.
For a full description of the query language refer to Query.
// fetch order 10 Order order = Ebean.find(Order.class, 10);
// fetch Customer 7 including their billing and shipping addresses
Customer customer = Ebean.find(Customer.class)
.fetch("billingAddress");
.fetch("shippingAddress");
.setId(7)
.findUnique();
Address billAddr = customer.getBillingAddress();
Address shipAddr = customer.getShippingAddress();
// Note: This example shows a "Partial Object".
// For the product objects associated with the
// order details only the product id and name is
// fetched (the product objects are partially populated).
// fetch orders for customer.id = 2
List<Order> orderList = Ebean.find(Order.class);
.fetch("customer")
.fetch("customer.shippingAddress")
.fetch("details")
.fetch("details.product","name")
.where().eq("customer.id",2)
.findList();
// Note: Only the product id and name is fetched for the
// product details. This is referred to as a
// "Partial Object" (one that is partially populated).
// code that traverses the object graph...
Order order = orderList.get(0);
Customer customer = order.getCustomer();
Address shipAddr = customer.getShippingAddress();
List<OrderDetail> details = order.getDetails();
OrderDetail detail = details.get(0);
Product product = detail.getProduct();
String productName = product.getName();
// get a Customer reference so we don't hit the database Customer custRef = Ebean.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); ... // 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);
// Get access to the Human Resources EbeanServer/Database
EbeanServer hrServer = Ebean.getServer("HR");
// fetch contact 3 from the HR database
Contact contact = hrServer.find(Contact.class, 3);
contact.setStatus(Contact.Status.INACTIVE);
...
// save the contact back to the HR database
hrServer.save(contact);
|
||||||||||
| PREV NEXT | FRAMES NO FRAMES | |||||||||