Package openbook.server
Interface OpenBookService
-
public interface OpenBookService
A simple service to select Books, purchase them and manage their inventory. A service handle can be obtained fromService Factory
.- Author:
- Pinaki Poddar
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DEFAULT_UNIT_NAME
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
clean()
Cleans everything.long
count(java.lang.Class<?> cls)
Count the number of instances of the given persistent type.PurchaseOrder
deliver(PurchaseOrder order)
Delivers the given order.<T> java.util.List<T>
getExtent(java.lang.Class<T> entity)
java.util.List<PurchaseOrder>
getOrders(PurchaseOrder.Status status, Customer customer)
Gets the list of orders of given status.java.lang.String
getQuery(java.lang.String title, java.lang.Double min, java.lang.Double max, java.lang.String author)
Gets the query String for the given parameters.java.util.List<Inventory>
getReorderableBooks(int limit)
Gets the list of Books whose inventory is lower than the given limit.jakarta.persistence.EntityManagerFactory
getUnit()
Gets the underlying persistence unit.java.lang.String
getUnitName()
Gets the name of the underlying persistence unit.boolean
initialize(java.util.Map<java.lang.String,java.lang.Object> loadParameters)
Populates the underlying data repository with sample values, only if the data repository is empty.boolean
isManaged()
Affirms if the transaction on this persistence unit is managed by a container.Customer
login(java.lang.String name)
Starts a session for the given named Customer.PurchaseOrder
placeOrder(ShoppingCart cart)
Buys the content of the given cart.<T> java.util.List<T>
query(java.lang.String jpql, java.lang.Class<T> resultClass, QueryDecorator... decorators)
Runs an arbitrary JPQL query to return a list of result.java.util.List<Book>
select(java.lang.String title, java.lang.Double min, java.lang.Double max, java.lang.String author, QueryDecorator... decorators)
Selects a list of Books matching the given conditions.Book
supply(Book b, int quantity)
Add inventory of the given Book by the given quantity.
-
-
-
Field Detail
-
DEFAULT_UNIT_NAME
static final java.lang.String DEFAULT_UNIT_NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
login
Customer login(java.lang.String name)
Starts a session for the given named Customer. If no record of the given name exists, a new Customer record is created.- Parameters:
name
- name of a possibly existing customer. Or a new one.- Returns:
- a Customer
-
select
java.util.List<Book> select(java.lang.String title, java.lang.Double min, java.lang.Double max, java.lang.String author, QueryDecorator... decorators)
Selects a list of Books matching the given conditions. Each of the conditional parameter can be null. A null parameter implies that the resultant query should ignore that parameter.- Parameters:
title
- title of the Bookmin
- minimum pricemax
- maximum priceauthor
- name of authordecorators
- to modify the executable query such as its range.
-
getQuery
java.lang.String getQuery(java.lang.String title, java.lang.Double min, java.lang.Double max, java.lang.String author)
Gets the query String for the given parameters. Each of the conditional parameter can be null. A null parameter implies that the resultant query should ignore that parameter.- Parameters:
title
- title of the Bookmin
- minimum pricemax
- maximum priceauthor
- name of authordecorators
- to modify the executable query such as its range.
-
query
<T> java.util.List<T> query(java.lang.String jpql, java.lang.Class<T> resultClass, QueryDecorator... decorators)
Runs an arbitrary JPQL query to return a list of result.- Parameters:
jpql
- a valid JPQL query string.resultClass
- type of the result.decorators
- zero or more QueryDecorators to be applied before Query is executed.- Returns:
- the selected instances.
-
getExtent
<T> java.util.List<T> getExtent(java.lang.Class<T> entity)
-
placeOrder
PurchaseOrder placeOrder(ShoppingCart cart)
Buys the content of the given cart.- Parameters:
cart
- a non-empty cart.- Returns:
- a PurchaseOrder for the content of the cart.
-
deliver
PurchaseOrder deliver(PurchaseOrder order)
Delivers the given order. Delivery changes the status of the order, decrements inventory and finally removes the line items.- Parameters:
order
- a PENDING order to be delivered.- Returns:
- the PurchaseOrder after delivery.
-
supply
Book supply(Book b, int quantity)
Add inventory of the given Book by the given quantity.- Parameters:
b
- a Book whose inventory is to be incrementedquantity
- positive number.- Returns:
- the Book after incrementing its inventory.
-
getOrders
java.util.List<PurchaseOrder> getOrders(PurchaseOrder.Status status, Customer customer)
Gets the list of orders of given status.- Parameters:
status
- status of the orders. null implies all orders.- Returns:
- list of orders sorted by their placement dates.
-
getReorderableBooks
java.util.List<Inventory> getReorderableBooks(int limit)
Gets the list of Books whose inventory is lower than the given limit.- Parameters:
limit
- reorder limit. null implies all inventory.- Returns:
- list of Books with inventory lower than the given limit.
-
count
long count(java.lang.Class<?> cls)
Count the number of instances of the given persistent type.- Parameters:
cls
- a persistent type.- Returns:
- number of persistent entity of the given type.
-
initialize
boolean initialize(java.util.Map<java.lang.String,java.lang.Object> loadParameters)
Populates the underlying data repository with sample values, only if the data repository is empty.- Parameters:
loadParameters
- control the number of Books etc. to be created. null is allowed.- Returns:
- true if the repository is initialized by this invocation.
-
clean
void clean()
Cleans everything. Be careful.
-
getUnit
jakarta.persistence.EntityManagerFactory getUnit()
Gets the underlying persistence unit.
-
getUnitName
java.lang.String getUnitName()
Gets the name of the underlying persistence unit.
-
isManaged
boolean isManaged()
Affirms if the transaction on this persistence unit is managed by a container.
-
-