Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package com.avaje.ebean;
import com.avaje.ebean.cache.ServerCacheManager;
import com.avaje.ebean.config.ServerConfig;
import com.avaje.ebean.meta.MetaInfoManager;
import com.avaje.ebean.plugin.SpiServer;
import com.avaje.ebean.text.csv.CsvReader;
import com.avaje.ebean.text.json.JsonContext;
import org.jetbrains.annotations.Nullable;
import javax.persistence.NonUniqueResultException;
import javax.persistence.OptimisticLockException;
import javax.persistence.PersistenceException;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Provides the API for fetching and saving beans to a particular DataSource.
*
* Registration with the Ebean Singleton:
* When a EbeanServer is constructed it can be registered with the Ebean
* singleton (see {@link ServerConfig#setRegister(boolean)}). The Ebean
* singleton is essentially a map of EbeanServer's that have been registered
* with it. The EbeanServer can then be retrieved later via
* {@link Ebean#getServer(String)}.
*
*
* The 'default' EbeanServer
* One EbeanServer can be designated as the 'default' or 'primary' EbeanServer
* (see {@link ServerConfig#setDefaultServer(boolean)}. Many methods on Ebean
* such as {@link Ebean#find(Class)} etc are actually just a convenient way to
* call methods on the 'default/primary' EbeanServer. This is handy for
* applications that use a single DataSource.
*
* There is one EbeanServer per Database (javax.sql.DataSource). One EbeanServer
* is referred to as the 'default' server and that is the one that
* Ebean methods such as {@link Ebean#find(Class)} use.
*
*
* Constructing a EbeanServer
* EbeanServer's are constructed by the EbeanServerFactory. They can be created
* programmatically via {@link EbeanServerFactory#create(ServerConfig)} or they
* can be automatically constructed on demand using configuration information in
* the ebean.properties file.
*
*
* Example: Get a EbeanServer
*
*
*
{@code
* // 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, new Integer(3));
*
* contact.setStatus("INACTIVE"); ...
*
* // save the contact back to the HR database hrServer.save(contact);
* }
*
*
* EbeanServer has more API than Ebean
* EbeanServer provides additional API compared with Ebean. For example it
* provides more control over the use of Transactions that is not available in
* the Ebean API.
*
*
* External Transactions: If you wanted to use transactions created
* externally to eBean then EbeanServer provides additional methods where you
* can explicitly pass a transaction (that can be created externally).
*
*
* Bypass ThreadLocal Mechanism: If you want to bypass the built in
* ThreadLocal transaction management you can use the createTransaction()
* method. Example: a single thread requires more than one transaction.
*
* This method is not normally required. Ebean registers a shutdown hook and shuts down cleanly.
*
*
* If the under underlying DataSource is the Ebean implementation then you
* also have the option of shutting down the DataSource and deregistering the
* JDBC driver.
*
*
* @param shutdownDataSource
* if true then shutdown the underlying DataSource if it is the EbeanORM
* DataSource implementation.
* @param deregisterDriver
* if true then deregister the JDBC driver if it is the EbeanORM
* DataSource implementation.
*/
void shutdown(boolean shutdownDataSource, boolean deregisterDriver);
/**
* Return AutoTune which is used to control the AutoTune service at runtime.
*/
AutoTune getAutoTune();
/**
* Return the name. This is used with {@link Ebean#getServer(String)} to get a
* EbeanServer that was registered with the Ebean singleton.
*/
String getName();
/**
* Return the ExpressionFactory for this server.
*/
ExpressionFactory getExpressionFactory();
/**
* Return the MetaInfoManager which is used to get meta data from the EbeanServer
* such as query execution statistics.
*/
MetaInfoManager getMetaInfoManager();
/**
* Return the extended API intended for use by plugins.
*/
SpiServer getPluginApi();
/**
* Return the BeanState for a given entity bean.
*
* This will return null if the bean is not an enhanced entity bean.
*
*/
BeanState getBeanState(Object bean);
/**
* Return the value of the Id property for a given bean.
*/
Object getBeanId(Object bean);
/**
* Set the Id value onto the bean converting the type of the id value if necessary.
*
* For example, if the id value passed in is a String but ought to be a Long or UUID etc
* then it will automatically be converted.
*
* @param bean The entity bean to set the id value on.
* @param id The id value to set.
*/
Object setBeanId(Object bean, Object id);
/**
* Return a map of the differences between two objects of the same type.
*
* When null is passed in for b, then the 'OldValues' of a is used for the
* difference comparison.
*
*/
Map diff(Object newBean, Object oldBean);
/**
* Create a new instance of T that is an EntityBean.
*
* Generally not expected to be useful (now dynamic subclassing support was removed in
* favour of always using enhancement).
*
*/
T createEntityBean(Class type);
/**
* Create a CsvReader for a given beanType.
*/
CsvReader createCsvReader(Class beanType);
/**
* Return a named Query that will have defined fetch paths, predicates etc.
*
* The query is created from a statement that will be defined in a deployment
* orm xml file or NamedQuery annotations. The query will typically already
* define fetch paths, predicates, order by clauses etc so often you will just
* need to bind required parameters and then execute the query.
*
*/
Query createNamedQuery(Class beanType, String namedQuery);
/**
* Create a query using the query language.
*
* Note that you are allowed to add additional clauses using where() as well
* as use fetch() and setOrderBy() after the query has been created.
*
*
* Note that this method signature used to map to named queries and that has
* moved to {@link #createNamedQuery(Class, String)}.
*
*
*
{@code
* EbeanServer ebeanServer = ... ;
* String q = "find order fetch details where status = :st";
*
* List newOrders
* = ebeanServer.createQuery(Order.class, q)
* .setParameter("st", Order.Status.NEW)
* .findList();
* }
*
* @param query
* the object query
*/
Query createQuery(Class beanType, String query);
/**
* Create a query for an entity bean and synonym for {@link #find(Class)}.
*
* @see #find(Class)
*/
Query createQuery(Class beanType);
/**
* Create a query for a type of entity bean.
*
* You can use the methods on the Query object to specify fetch paths,
* predicates, order by, limits etc.
*
*
* You then use findList(), findSet(), findMap() and findUnique() to execute
* the query and return the collection or bean.
*
*
* Note that a query executed by {@link Query#findList()}
* {@link Query#findSet()} etc will execute against the same EbeanServer from
* which is was created.
*
*
*
{@code
*
* // Find order 2 specifying explicitly the parts of the object graph to
* // eagerly fetch. In this case eagerly fetch the associated customer,
* // details and details.product.name
*
* Order order = ebeanServer.find(Order.class)
* .fetch("customer")
* .fetch("details")
* .fetch("detail.product", "name")
* .setId(2)
* .findUnique();
*
* // find some new orders ... with firstRow/maxRows
* List orders =
* ebeanServer.find(Order.class)
* .where().eq("status", Order.Status.NEW)
* .setFirstRow(20)
* .setMaxRows(10)
* .findList();
*
* }
*
*/
Query find(Class beanType);
/**
* Return the next unique identity value for a given bean type.
*
* This will only work when a IdGenerator is on the bean such as for beans
* that use a DB sequence or UUID.
*
*
* For DB's supporting getGeneratedKeys and sequences such as Oracle10 you do
* not need to use this method generally. It is made available for more
* complex cases where it is useful to get an ID prior to some processing.
*
*/
Object nextId(Class> beanType);
/**
* Create a filter for sorting and filtering lists of entities locally without
* going back to the database.
*
* This produces and returns a new list with the sort and filters applied.
*
*
* Refer to {@link Filter} for an example of its use.
*
*/
Filter filter(Class beanType);
/**
* Sort the list in memory using the sortByClause which can contain a comma delimited
* list of property names and keywords asc, desc, nullsHigh and nullsLow.
*
*
asc - ascending order (which is the default)
*
desc - Descending order
*
nullsHigh - Treat null values as high/large values (which is the
* default)
*
nullsLow- Treat null values as low/very small values
*
*
* If you leave off any keywords the defaults are ascending order and treating
* nulls as high values.
*
*
* Note that the sorting uses a Comparator and Collections.sort(); and does
* not invoke a DB query.
*
*
*
{@code
*
* // find orders and their customers
* List list = ebeanServer.find(Order.class)
* .fetch("customer")
* .orderBy("id")
* .findList();
*
* // sort by customer name ascending, then by order shipDate
* // ... then by the order status descending
* ebeanServer.sort(list, "customer.name, shipDate, status desc");
*
* // sort by customer name descending (with nulls low)
* // ... then by the order id
* ebeanServer.sort(list, "customer.name desc nullsLow, id");
*
* }
*
* @param list
* the list of entity beans
* @param sortByClause
* the properties to sort the list by
*/
void sort(List list, String sortByClause);
/**
* Create a named orm update. The update statement is specified via the
* NamedUpdate annotation.
*
* The orm update differs from the SqlUpdate in that it uses the bean name and
* bean property names rather than table and column names.
*
*
* Note that named update statements can be specified in raw sql (with column
* and table names) or using bean name and bean property names. This can be
* specified with the isSql flag.
*
*
* Example named updates:
*
*
*
{@code
* package app.data;
*
* 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 { ...
*
* }
*/
Update createNamedUpdate(Class beanType, String namedUpdate);
/**
* Create a orm update where you will supply the insert/update or delete
* statement (rather than using a named one that is already defined using the
* @NamedUpdates annotation).
*
* The orm update differs from the sql update in that it you can use the bean
* name and bean property names rather than table and column names.
*
*
* An example:
*
*
*
{@code
*
* // 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";
*
* Update update = ebeanServer.createUpdate(Topic.class, updStatement);
*
* update.set("pc", 9);
* update.set("id", 3);
*
* int rows = update.execute();
* System.out.println("rows updated:" + rows);
*
* }
*/
Update createUpdate(Class beanType, String ormUpdate);
/**
* Create a SqlQuery for executing native sql
* query statements.
*
* Note that you can use raw SQL with entity beans, refer to the SqlSelect
* annotation for examples.
*
*/
SqlQuery createSqlQuery(String sql);
/**
* Create a named sql query.
*
* The query statement will be defined in a deployment orm xml file.
*
*
* @param namedQuery
* the name of the query
*/
SqlQuery createNamedSqlQuery(String namedQuery);
/**
* Create a sql update for executing native dml statements.
*
* Use this to execute a Insert Update or Delete statement. The statement will
* be native to the database and contain database table and column names.
*
*
* See {@link SqlUpdate} for example usage.
*
*
* Where possible it would be expected practice to put the statement in a orm
* xml file (named update) and use {@link #createNamedSqlUpdate(String)} .
*
*/
SqlUpdate createSqlUpdate(String sql);
/**
* Create a CallableSql to execute a given stored procedure.
*/
CallableSql createCallableSql(String callableSql);
/**
* Create a named sql update.
*
* The statement (an Insert Update or Delete statement) will be defined in a
* deployment orm xml file.
*
*
*
{@code
*
* // Use a namedQuery
* UpdateSql update = Ebean.createNamedSqlUpdate("update.topic.count");
*
* update.setParameter("count", 1);
* update.setParameter("topicId", 50);
*
* int modifiedCount = update.execute();
*
* }
*/
SqlUpdate createNamedSqlUpdate(String namedQuery);
/**
* Register a TransactionCallback on the currently active transaction.
*
* If there is no currently active transaction then a PersistenceException is thrown.
*
* @param transactionCallback The transaction callback to be registered with the current transaction.
*
* @throws PersistenceException If there is no currently active transaction
*/
void register(TransactionCallback transactionCallback) throws PersistenceException;
/**
* Create a new transaction that is not held in TransactionThreadLocal.
*
* You will want to do this if you want multiple Transactions in a single
* thread or generally use transactions outside of the TransactionThreadLocal
* management.
*
*/
Transaction createTransaction();
/**
* Create a new transaction additionally specifying the isolation level.
*
* Note that this transaction is NOT stored in a thread local.
*
*/
Transaction createTransaction(TxIsolation isolation);
/**
* Start a transaction with 'REQUIRED' semantics.
*
* With REQUIRED semantics if an active transaction already exists that transaction will be used.
*
*
* The transaction is stored in a ThreadLocal variable and typically you only
* need to use the returned Transaction IF you wish to do things like
* use batch mode, change the transaction isolation level, use savepoints or
* log comments to the transaction log.
*
*
* Example of using a transaction to span multiple calls to find(), save()
* etc.
*
*
*
{@code
*
* // start a transaction (stored in a ThreadLocal)
* ebeanServer.beginTransaction();
* try {
* Order order = ebeanServer.find(Order.class,10);
*
* ebeanServer.save(order);
*
* ebeanServer.commitTransaction();
*
* } finally {
* // rollback if we didn't commit
* // i.e. an exception occurred before commitTransaction().
* ebeanServer.endTransaction();
* }
*
* }
*
*
Transaction options:
*
{@code
*
* Transaction txn = ebeanServer.beginTransaction();
* try {
* // explicitly turn on/off JDBC batch use
* txn.setBatchMode(true);
* txn.setBatchSize(50);
*
* // control flushing when mixing save and queries
* txn.setBatchFlushOnQuery(false);
*
* // turn off persist cascade if needed
* txn.setPersistCascade(false);
*
* // for large batch insert processing when we do not
* // ... need the generatedKeys, don't get them
* txn.setBatchGetGeneratedKeys(false);
*
* // explicitly flush the JDBC batch buffer
* txn.flushBatch();
*
* ...
*
* txn.commit();
*
* } finally {
* // rollback if necessary
* txn.end();
* }
*
* }
*
*
* If you want to externalise the transaction management then you use
* createTransaction() and pass the transaction around to the various methods on
* EbeanServer yourself.
*
*/
Transaction beginTransaction();
/**
* Start a transaction additionally specifying the isolation level.
*/
Transaction beginTransaction(TxIsolation isolation);
/**
* Start a transaction typically specifying REQUIRES_NEW or REQUIRED semantics.
*
*
* Note that this provides an try finally alternative to using {@link #execute(TxScope, TxCallable)} or
* {@link #execute(TxScope, TxRunnable)}.
*
*
*
REQUIRES_NEW example:
*
{@code
* // Start a new transaction. If there is a current transaction
* // suspend it until this transaction ends
* Transaction txn = server.beginTransaction(TxScope.requiresNew());
* try {
*
* ...
*
* // commit the transaction
* txn.commit();
*
* } finally {
* // end this transaction which:
* // A) will rollback transaction if it has not been committed already
* // B) will restore a previously suspended transaction
* txn.end();
* }
*
* }
*
*
REQUIRED example:
*
{@code
*
* // start a new transaction if there is not a current transaction
* Transaction txn = server.beginTransaction(TxScope.required());
* try {
*
* ...
*
* // commit the transaction if it was created or
* // do nothing if there was already a current transaction
* txn.commit();
*
* } finally {
* // end this transaction which will rollback the transaction
* // if it was created for this try finally scope and has not
* // already been committed
* txn.end();
* }
*
* }
*/
Transaction beginTransaction(TxScope scope);
/**
* Returns the current transaction or null if there is no current transaction in scope.
*/
Transaction currentTransaction();
/**
* Commit the current transaction.
*/
void commitTransaction();
/**
* Rollback the current transaction.
*/
void rollbackTransaction();
/**
* If the current transaction has already been committed do nothing otherwise
* rollback the transaction.
*
* Useful to put in a finally block to ensure the transaction is ended, rather
* than a rollbackTransaction() in each catch block.
*
*
* Code example:
*
*
{@code
*
* ebeanServer.beginTransaction();
* try {
* // do some fetching and or persisting ...
*
* // commit at the end
* ebeanServer.commitTransaction();
*
* } finally {
* // if commit didn't occur then rollback the transaction
* ebeanServer.endTransaction();
* }
*
* }
*
*
*
*/
void endTransaction();
/**
* Refresh the values of a bean.
*
* Note that this resets OneToMany and ManyToMany properties so that if they
* are accessed a lazy load will refresh the many property.
*
*/
void refresh(Object bean);
/**
* Refresh a many property of an entity bean.
*
* @param bean
* the entity bean containing the 'many' property
* @param propertyName
* the 'many' property to be refreshed
*
*/
void refreshMany(Object bean, String propertyName);
/**
* Find a bean using its unique id.
*
*
{@code
* // Fetch order 1
* Order order = ebeanServer.find(Order.class, 1);
* }
*
*
* If you want more control over the query then you can use createQuery() and
* Query.findUnique();
*
*
*
{@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 query = ebeanServer.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");
*
*
* Order order = query.findUnique();
*
* // traverse the object graph...
*
* 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
* @param id
* the id value
*/
T find(Class beanType, Object id);
/**
* Get a reference object.
*
* This will not perform a query against the database unless some property other
* that the id property is accessed.
*
*
* It is most commonly used to set a 'foreign key' on another bean like:
*
{@code
*
* Product product = ebeanServer.getReference(Product.class, 1);
*
* // You can get the id without causing a fetch/lazy load
* Long 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();
*
* }
*
* @param beanType
* the type of entity bean
* @param id
* the id value
*/
T getReference(Class beanType, Object id);
/**
* Return the number of 'top level' or 'root' entities this query should
* return.
*
* @see Query#findRowCount()
* @see com.avaje.ebean.Query#findFutureRowCount()
*/
int findRowCount(Query query, Transaction transaction);
/**
* Return the Id values of the query as a List.
*
* @see com.avaje.ebean.Query#findIds()
*/
List