com.avaje.ebean
Interface EbeanServer


public interface EbeanServer

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 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 Ebean.getServer(String).

The 'default' EbeanServer
One EbeanServer can be designated as the 'default' or 'primary' EbeanServer (see ServerConfig.setDefaultServer(boolean). Many methods on Ebean such as 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 Ebean.find(Class) use.

Constructing a EbeanServer
EbeanServer's are constructed by the EbeanServerFactory. They can be created programmatically via EbeanServerFactory.create(ServerConfig) or they can be automatically constructed on demand using configuration information in the ebean.properties file.

Example: Get a EbeanServer

 // 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.

See Also:
Ebean, EbeanServerFactory, ServerConfig

Method Summary
 Transaction beginTransaction()
          Start a new transaction putting it into a ThreadLocal.
 Transaction beginTransaction(TxIsolation isolation)
          Start a transaction additionally specifying the isolation level.
 void commitTransaction()
          Commit the current transaction.
 CallableSql createCallableSql(String callableSql)
          Create a CallableSql to execute a given stored procedure.
<T> CsvReader<T>
createCsvReader(Class<T> beanType)
          Create a CsvReader for a given beanType.
<T> T
createEntityBean(Class<T> type)
          Create a new instance of T that is an EntityBean (for subclassing).
 JsonContext createJsonContext()
          Create a JsonContext that will use the default configuration options.
<T> Query<T>
createNamedQuery(Class<T> beanType, String namedQuery)
          Create a named query for an entity bean (refer Ebean.createQuery(Class, String))
 SqlQuery createNamedSqlQuery(String namedQuery)
          Create a named sql query (refer Ebean.createNamedSqlQuery(String) ).
 SqlUpdate createNamedSqlUpdate(String namedQuery)
          Create a named sql update (refer Ebean.createNamedSqlUpdate(String)).
<T> Update<T>
createNamedUpdate(Class<T> beanType, String namedUpdate)
          Create a named update for an entity bean (refer Ebean.createNamedUpdate(Class, String)).
 ObjectInputStream createProxyObjectInputStream(InputStream is)
          Create a ObjectInputStream that can be used to deserialise "Proxy" or "SubClassed" entity beans.
<T> Query<T>
createQuery(Class<T> beanType)
          Create a query for an entity bean (refer Ebean.createQuery(Class) ).
<T> Query<T>
createQuery(Class<T> beanType, String query)
          Create a query using the query language.
 SqlQuery createSqlQuery(String sql)
          Create a sql query for executing native sql query statements (refer Ebean.createSqlQuery(String)).
 SqlUpdate createSqlUpdate(String sql)
          Create a sql update for executing native dml statements (refer Ebean.createSqlUpdate(String)).
 Transaction createTransaction()
          Create a new transaction that is not held in TransactionThreadLocal.
 Transaction createTransaction(TxIsolation isolation)
          Create a new transaction additionally specifying the isolation level.
<T> Update<T>
createUpdate(Class<T> beanType, String ormUpdate)
          Create a update for an entity bean where you will manually specify the insert update or delete statement.
 Transaction currentTransaction()
          Returns the current transaction or null if there is no current transaction in scope.
 void delete(Class<?> beanType, Collection<?> ids)
          Delete several beans given their type and id values.
 void delete(Class<?> beanType, Collection<?> ids, Transaction t)
          Delete several beans given their type and id values with an explicit transaction.
 int delete(Class<?> beanType, Object id)
          Delete the bean given its type and id.
 int delete(Class<?> beanType, Object id, Transaction t)
          Delete the bean given its type and id with an explicit transaction.
 int delete(Collection<?> c)
          Delete all the beans in the collection.
 int delete(Iterator<?> it)
          Delete all the beans from an Iterator.
 int delete(Iterator<?> it, Transaction t)
          Delete all the beans from an iterator.
 void delete(Object bean)
          Delete the bean.
 void delete(Object bean, Transaction t)
          Delete the bean with an explicit transaction.
 int deleteManyToManyAssociations(Object ownerBean, String propertyName)
          Delete the associations (from the intersection table) of a ManyToMany given the owner bean and the propertyName of the ManyToMany collection.
 int deleteManyToManyAssociations(Object ownerBean, String propertyName, Transaction t)
          Delete the associations (from the intersection table) of a ManyToMany given the owner bean and the propertyName of the ManyToMany collection.
 Map<String,ValuePair> diff(Object a, Object b)
          Return a map of the differences between two objects of the same type.
 void endTransaction()
          If the current transaction has already been committed do nothing otherwise rollback the transaction.
 int execute(CallableSql callableSql)
          Call a stored procedure.
 int execute(CallableSql callableSql, Transaction t)
          Execute explicitly passing a transaction.
 int execute(SqlUpdate updSql)
          Execute a SQL Update Delete or Insert statement using the current transaction.
 int execute(SqlUpdate updSql, Transaction t)
          Execute explicitly passing a transaction.
<T> T
execute(TxCallable<T> c)
          Execute a TxCallable in a Transaction with the default scope.
 void execute(TxRunnable r)
          Execute a TxRunnable in a Transaction with the default scope.
<T> T
execute(TxScope scope, TxCallable<T> c)
          Execute a TxCallable in a Transaction with an explicit scope.
 void execute(TxScope scope, TxRunnable r)
          Execute a TxRunnable in a Transaction with an explicit scope.
 int execute(Update<?> update)
          Execute a ORM insert update or delete statement using the current transaction.
 int execute(Update<?> update, Transaction t)
          Execute a ORM insert update or delete statement with an explicit transaction.
 void externalModification(String tableName, boolean inserted, boolean updated, boolean deleted)
          Process committed changes from another framework.
<T> Filter<T>
filter(Class<T> beanType)
          Create a filter for filtering lists of entity beans.
<T> Query<T>
find(Class<T> beanType)
          Create a query for a type of entity bean (the same as createQuery(Class)).
<T> T
find(Class<T> beanType, Object uid)
          Find a bean using its unique id.
<T> T
find(Class<T> beanType, Object uid, Transaction transaction)
          Find a entity bean with an explicit transaction.
<T> FutureIds<T>
findFutureIds(Query<T> query, Transaction t)
          Execute find Id's query in a background thread.
<T> FutureList<T>
findFutureList(Query<T> query, Transaction t)
          Execute find list query in a background thread.
 SqlFutureList findFutureList(SqlQuery query, Transaction t)
          Execute find list SQL query in a background thread.
<T> FutureRowCount<T>
findFutureRowCount(Query<T> query, Transaction t)
          Execute find row count query in a background thread.
<T> List<Object>
findIds(Query<T> query, Transaction t)
          Return the Id values of the query as a List.
<T> List<T>
findList(Query<T> query, Transaction transaction)
          Execute a query returning a list of beans.
 List<SqlRow> findList(SqlQuery query, Transaction transaction)
          Execute the sql query returning a list of MapBean.
<T> Map<?,T>
findMap(Query<T> query, Transaction transaction)
          Execute the query returning the entity beans in a Map.
 Map<?,SqlRow> findMap(SqlQuery query, Transaction transaction)
          Execute the sql query returning a map of MapBean.
<T> PagingList<T>
findPagingList(Query<T> query, Transaction t, int pageSize)
           
<T> int
findRowCount(Query<T> query, Transaction transaction)
          Return the number of 'top level' or 'root' entities this query should return.
<T> Set<T>
findSet(Query<T> query, Transaction transaction)
          Execute the query returning a set of entity beans.
 Set<SqlRow> findSet(SqlQuery query, Transaction transaction)
          Execute the sql query returning a set of MapBean.
<T> T
findUnique(Query<T> query, Transaction transaction)
          Execute the query returning at most one entity bean.
 SqlRow findUnique(SqlQuery query, Transaction transaction)
          Execute the sql query returning a single MapBean or null.
 AdminAutofetch getAdminAutofetch()
          Return the AdminAutofetch which is used to control and configure the Autofetch service at runtime.
 AdminLogging getAdminLogging()
          Return the AdminLogging which is used to control and configure the Transaction logging at runtime.
 BackgroundExecutor getBackgroundExecutor()
          Return the BackgroundExecutor service for asynchronous processing of queries.
 Object getBeanId(Object bean)
          Return the value of the Id property for a given bean.
 BeanState getBeanState(Object bean)
          Return the BeanState for a given entity bean.
 ExpressionFactory getExpressionFactory()
          Return the ExpressionFactory for this server.
 String getName()
          Return the name.
<T> T
getReference(Class<T> beanType, Object uid)
          Get a reference Object (see Ebean.getReference(Class, Object).
 ServerCacheManager getServerCacheManager()
          Return the manager of the server cache ("L2" cache).
 void logComment(String msg)
          Log a comment to the transaction log of the current transaction.
 Object nextId(Class<?> beanType)
          Return the next unique identity value for a given bean type.
 void refresh(Object bean)
          Refresh the values of a bean.
 void refreshMany(Object bean, String propertyName)
          Refresh a many property of an entity bean.
 void rollbackTransaction()
          Rollback the current transaction.
 void runCacheWarming()
          Run the cache warming queries on all bean types that have one defined.
 void runCacheWarming(Class<?> beanType)
          Run the cache warming query for a specific bean type.
 int save(Collection<?> it)
          Save all the beans in the collection.
 int save(Iterator<?> it)
          Save all the beans in the iterator.
 int save(Iterator<?> it, Transaction t)
          Save all the beans in the iterator with an explicit transaction.
 void save(Object bean)
          Persist the bean by either performing an insert or update.
 void save(Object bean, Transaction t)
          Insert or update a bean with an explicit transaction.
 void saveAssociation(Object ownerBean, String propertyName)
          Save the associated collection or bean given the property name.
 void saveAssociation(Object ownerBean, String propertyName, Transaction t)
          Save the associated collection or bean given the property name with a specific transaction.
 void saveManyToManyAssociations(Object ownerBean, String propertyName)
          Save the associations of a ManyToMany given the owner bean and the propertyName of the ManyToMany collection.
 void saveManyToManyAssociations(Object ownerBean, String propertyName, Transaction t)
          Save the associations of a ManyToMany given the owner bean and the propertyName of the ManyToMany collection.
<T> void
sort(List<T> list, String sortByClause)
          Sort the list using the sortByClause.
 void update(Object bean)
          Force an update using the bean.
 void update(Object bean, Set<String> updateProps)
          Force an update using the bean explicitly stating the properties to update.
 void update(Object bean, Set<String> updateProps, Transaction t)
          Force an update of the specified properties of the bean with an explicit transaction.
 void update(Object bean, Transaction t)
          Force an update of the non-null properties of the bean with an explicit transaction.
 InvalidValue validate(Object bean)
          Validate an entity bean.
 InvalidValue[] validate(Object bean, String propertyName, Object value)
          Validate a single property on an entity bean.
 

Method Detail

getAdminLogging

AdminLogging getAdminLogging()
Return the AdminLogging which is used to control and configure the Transaction logging at runtime.


getAdminAutofetch

AdminAutofetch getAdminAutofetch()
Return the AdminAutofetch which is used to control and configure the Autofetch service at runtime.


getName

String getName()
Return the name. This is used with Ebean.getServer(String) to get a EbeanServer that was registered with the Ebean singleton.


getExpressionFactory

ExpressionFactory getExpressionFactory()
Return the ExpressionFactory for this server.


getBeanState

BeanState getBeanState(Object bean)
Return the BeanState for a given entity bean.

This will return null if the bean is not an enhanced (or subclassed) entity bean.


getBeanId

Object getBeanId(Object bean)
Return the value of the Id property for a given bean.


diff

Map<String,ValuePair> diff(Object a,
                           Object b)
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.


validate

InvalidValue validate(Object bean)
Validate an entity bean.

The returned InvalidValue holds a tree of InvalidValue's. Typically you will use InvalidValue.getErrors()) to get a flat list of all the validation errors.


validate

InvalidValue[] validate(Object bean,
                        String propertyName,
                        Object value)
Validate a single property on an entity bean.

Parameters:
bean - the entity bean that owns the property.
propertyName - the name of the property to validate.
value - if the value is null then the value from the bean is used to perform the validation.
Returns:
the validation errors or an empty array.

createEntityBean

<T> T createEntityBean(Class<T> type)
Create a new instance of T that is an EntityBean (for subclassing).

Note that if you are using enhancement (rather than subclassing) then you do not need to use this method and just new up a bean.

Potentially useful when using subclassing and you wish to programmatically load a entity bean . Otherwise this method is generally not required.


createProxyObjectInputStream

ObjectInputStream createProxyObjectInputStream(InputStream is)
Create a ObjectInputStream that can be used to deserialise "Proxy" or "SubClassed" entity beans.

This is NOT required when entity beans are "Enhanced" (via java agent or ant task etc).

The reason this is needed to deserialise "Proxy" beans is because Ebean creates the "Proxy/SubClass" classes in a class loader - and generally the class loader deserialising the inputStream is not aware of these other classes.


createCsvReader

<T> CsvReader<T> createCsvReader(Class<T> beanType)
Create a CsvReader for a given beanType.


createNamedQuery

<T> Query<T> createNamedQuery(Class<T> beanType,
                              String namedQuery)
Create a named query for an entity bean (refer Ebean.createQuery(Class, String))

The query statement will be defined in a deployment orm xml file.

See Also:
Ebean.createQuery(Class, String)

createQuery

<T> Query<T> createQuery(Class<T> beanType,
                         String query)
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 createNamedQuery(Class, String).

  EbeanServer ebeanServer = ... ;
  String q = "find order fetch details where status = :st";
  
  List<Order> newOrders 
        = ebeanServer.createQuery(Order.class, q)
             .setParameter("st", Order.Status.NEW)
             .findList();
 

Parameters:
query - the object query

createQuery

<T> Query<T> createQuery(Class<T> beanType)
Create a query for an entity bean (refer Ebean.createQuery(Class) ).

See Also:
Ebean.createQuery(Class)

find

<T> Query<T> find(Class<T> beanType)
Create a query for a type of entity bean (the same as createQuery(Class)).


nextId

Object nextId(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.


filter

<T> Filter<T> filter(Class<T> beanType)
Create a filter for filtering lists of entity beans.


sort

<T> void sort(List<T> list,
              String sortByClause)
Sort the list using the sortByClause.

Parameters:
list - the list of entity beans
sortByClause - the properties to sort the list by
See Also:
Ebean.sort(List, String)

createNamedUpdate

<T> Update<T> createNamedUpdate(Class<T> beanType,
                                String namedUpdate)
Create a named update for an entity bean (refer Ebean.createNamedUpdate(Class, String)).


createUpdate

<T> Update<T> createUpdate(Class<T> beanType,
                           String ormUpdate)
Create a update for an entity bean where you will manually specify the insert update or delete statement.


createSqlQuery

SqlQuery createSqlQuery(String sql)
Create a sql query for executing native sql query statements (refer Ebean.createSqlQuery(String)).

See Also:
Ebean.createSqlQuery(String)

createNamedSqlQuery

SqlQuery createNamedSqlQuery(String namedQuery)
Create a named sql query (refer Ebean.createNamedSqlQuery(String) ).

The query statement will be defined in a deployment orm xml file.

See Also:
Ebean.createNamedSqlQuery(String)

createSqlUpdate

SqlUpdate createSqlUpdate(String sql)
Create a sql update for executing native dml statements (refer Ebean.createSqlUpdate(String)).

See Also:
Ebean.createSqlUpdate(String)

createCallableSql

CallableSql createCallableSql(String callableSql)
Create a CallableSql to execute a given stored procedure.


createNamedSqlUpdate

SqlUpdate createNamedSqlUpdate(String namedQuery)
Create a named sql update (refer Ebean.createNamedSqlUpdate(String)).

The statement (an Insert Update or Delete statement) will be defined in a deployment orm xml file.

See Also:
Ebean.createNamedSqlUpdate(String)

createTransaction

Transaction createTransaction()
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.


createTransaction

Transaction createTransaction(TxIsolation isolation)
Create a new transaction additionally specifying the isolation level.

Note that this transaction is NOT stored in a thread local.


beginTransaction

Transaction beginTransaction()
Start a new transaction putting it into a ThreadLocal.

See Also:
Ebean.beginTransaction()

beginTransaction

Transaction beginTransaction(TxIsolation isolation)
Start a transaction additionally specifying the isolation level.


currentTransaction

Transaction currentTransaction()
Returns the current transaction or null if there is no current transaction in scope.


commitTransaction

void commitTransaction()
Commit the current transaction.

See Also:
Ebean.commitTransaction()

rollbackTransaction

void rollbackTransaction()
Rollback the current transaction.

See Also:
Ebean.rollbackTransaction()

endTransaction

void endTransaction()
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:

 Ebean.startTransaction(); try { // do some fetching
 and or persisting
 
 // commit at the end Ebean.commitTransaction();
 
 } finally { // if commit didn't occur then rollback the transaction
 Ebean.endTransaction(); }
 

See Also:
Ebean.endTransaction()

logComment

void logComment(String msg)
Log a comment to the transaction log of the current transaction.

See Also:
Ebean.logComment(String)

refresh

void refresh(Object bean)
Refresh the values of a bean.

Note that this does not refresh any OneToMany or ManyToMany properties.

See Also:
Ebean.refresh(Object)

refreshMany

void refreshMany(Object bean,
                 String propertyName)
Refresh a many property of an entity bean.

Parameters:
bean - the entity bean containing the 'many' property
propertyName - the 'many' property to be refreshed
See Also:
Ebean.refreshMany(Object, String)

find

<T> T find(Class<T> beanType,
           Object uid)
Find a bean using its unique id.

See Also:
Ebean.find(Class, Object)

getReference

<T> T getReference(Class<T> beanType,
                   Object uid)
Get a reference Object (see Ebean.getReference(Class, Object).

This will not perform a query against the database.

See Also:
Ebean.getReference(Class, Object)

findRowCount

<T> int findRowCount(Query<T> query,
                     Transaction transaction)
Return the number of 'top level' or 'root' entities this query should return.


findIds

<T> List<Object> findIds(Query<T> query,
                         Transaction t)
Return the Id values of the query as a List.


findList

<T> List<T> findList(Query<T> query,
                     Transaction transaction)
Execute a query returning a list of beans.

Generally you are able to use Query.findList() rather than explicitly calling this method. You could use this method if you wish to explicitly control the transaction used for the query.

Type Parameters:
T - the type of entity bean to fetch.
Parameters:
query - the query to execute.
transaction - the transaction to use (can be null).
Returns:
the list of fetched beans.
See Also:
Query.findList()

findFutureRowCount

<T> FutureRowCount<T> findFutureRowCount(Query<T> query,
                                         Transaction t)
Execute find row count query in a background thread.

This returns a Future object which can be used to cancel, check the execution status (isDone etc) and get the value (with or without a timeout).

Parameters:
query - the query to execute the row count on
t - the transaction (can be null).
Returns:
a Future object for the row count query

findFutureIds

<T> FutureIds<T> findFutureIds(Query<T> query,
                               Transaction t)
Execute find Id's query in a background thread.

This returns a Future object which can be used to cancel, check the execution status (isDone etc) and get the value (with or without a timeout).

Parameters:
query - the query to execute the fetch Id's on
t - the transaction (can be null).
Returns:
a Future object for the list of Id's

findFutureList

<T> FutureList<T> findFutureList(Query<T> query,
                                 Transaction t)
Execute find list query in a background thread.

This returns a Future object which can be used to cancel, check the execution status (isDone etc) and get the value (with or without a timeout).

Parameters:
query - the query to execute in the background
t - the transaction (can be null).
Returns:
a Future object for the list result of the query

findFutureList

SqlFutureList findFutureList(SqlQuery query,
                             Transaction t)
Execute find list SQL query in a background thread.

This returns a Future object which can be used to cancel, check the execution status (isDone etc) and get the value (with or without a timeout).

Parameters:
query - the query to execute in the background
t - the transaction (can be null).
Returns:
a Future object for the list result of the query

findPagingList

<T> PagingList<T> findPagingList(Query<T> query,
                                 Transaction t,
                                 int pageSize)

findSet

<T> Set<T> findSet(Query<T> query,
                   Transaction transaction)
Execute the query returning a set of entity beans.

Generally you are able to use Query.findSet() rather than explicitly calling this method. You could use this method if you wish to explicitly control the transaction used for the query.

Type Parameters:
T - the type of entity bean to fetch.
Parameters:
query - the query to execute
transaction - the transaction to use (can be null).
Returns:
the set of fetched beans.
See Also:
Query.findSet()

findMap

<T> Map<?,T> findMap(Query<T> query,
                     Transaction transaction)
Execute the query returning the entity beans in a Map.

Generally you are able to use Query.findMap() rather than explicitly calling this method. You could use this method if you wish to explicitly control the transaction used for the query.

Type Parameters:
T - the type of entity bean to fetch.
Parameters:
query - the query to execute.
transaction - the transaction to use (can be null).
Returns:
the map of fetched beans.
See Also:
Query.findMap()

findUnique

<T> T findUnique(Query<T> query,
                 Transaction transaction)
Execute the query returning at most one entity bean. This will throw a PersistenceException if the query finds more than one result.

Generally you are able to use Query.findUnique() rather than explicitly calling this method. You could use this method if you wish to explicitly control the transaction used for the query.

Type Parameters:
T - the type of entity bean to fetch.
Parameters:
query - the query to execute.
transaction - the transaction to use (can be null).
Returns:
the list of fetched beans.
See Also:
Query.findUnique()

findList

List<SqlRow> findList(SqlQuery query,
                      Transaction transaction)
Execute the sql query returning a list of MapBean.

Generally you are able to use SqlQuery.findList() rather than explicitly calling this method. You could use this method if you wish to explicitly control the transaction used for the query.

Parameters:
query - the query to execute.
transaction - the transaction to use (can be null).
Returns:
the list of fetched MapBean.
See Also:
SqlQuery.findList()

findSet

Set<SqlRow> findSet(SqlQuery query,
                    Transaction transaction)
Execute the sql query returning a set of MapBean.

Generally you are able to use SqlQuery.findSet() rather than explicitly calling this method. You could use this method if you wish to explicitly control the transaction used for the query.

Parameters:
query - the query to execute.
transaction - the transaction to use (can be null).
Returns:
the set of fetched MapBean.
See Also:
SqlQuery.findSet()

findMap

Map<?,SqlRow> findMap(SqlQuery query,
                      Transaction transaction)
Execute the sql query returning a map of MapBean.

Generally you are able to use SqlQuery.findMap() rather than explicitly calling this method. You could use this method if you wish to explicitly control the transaction used for the query.

Parameters:
query - the query to execute.
transaction - the transaction to use (can be null).
Returns:
the set of fetched MapBean.
See Also:
SqlQuery.findMap()

findUnique

SqlRow findUnique(SqlQuery query,
                  Transaction transaction)
Execute the sql query returning a single MapBean or null.

This will throw a PersistenceException if the query found more than one result.

Generally you are able to use SqlQuery.findUnique() rather than explicitly calling this method. You could use this method if you wish to explicitly control the transaction used for the query.

Parameters:
query - the query to execute.
transaction - the transaction to use (can be null).
Returns:
the fetched MapBean or null if none was found.
See Also:
SqlQuery.findUnique()

save

void save(Object bean)
          throws javax.persistence.OptimisticLockException
Persist the bean by either performing an insert or update.

Throws:
javax.persistence.OptimisticLockException
See Also:
Ebean.save(Object)

save

int save(Iterator<?> it)
         throws javax.persistence.OptimisticLockException
Save all the beans in the iterator.

Throws:
javax.persistence.OptimisticLockException

save

int save(Collection<?> it)
         throws javax.persistence.OptimisticLockException
Save all the beans in the collection.

Throws:
javax.persistence.OptimisticLockException

delete

void delete(Object bean)
            throws javax.persistence.OptimisticLockException
Delete the bean.

Throws:
javax.persistence.OptimisticLockException
See Also:
Ebean.delete(Object)

delete

int delete(Iterator<?> it)
           throws javax.persistence.OptimisticLockException
Delete all the beans from an Iterator.

Throws:
javax.persistence.OptimisticLockException

delete

int delete(Collection<?> c)
           throws javax.persistence.OptimisticLockException
Delete all the beans in the collection.

Throws:
javax.persistence.OptimisticLockException

delete

int delete(Class<?> beanType,
           Object id)
Delete the bean given its type and id.


delete

int delete(Class<?> beanType,
           Object id,
           Transaction t)
Delete the bean given its type and id with an explicit transaction.


delete

void delete(Class<?> beanType,
            Collection<?> ids)
Delete several beans given their type and id values.


delete

void delete(Class<?> beanType,
            Collection<?> ids,
            Transaction t)
Delete several beans given their type and id values with an explicit transaction.


execute

int execute(SqlUpdate updSql)
Execute a SQL Update Delete or Insert statement using the current transaction. This returns the number of rows that where updated, deleted or inserted.

Refer to Ebean.execute(UpdateSql) for full documentation.

See Also:
Ebean.execute(SqlUpdate)

execute

int execute(Update<?> update)
Execute a ORM insert update or delete statement using the current transaction.

This returns the number of rows that where inserted, updated or deleted.


execute

int execute(Update<?> update,
            Transaction t)
Execute a ORM insert update or delete statement with an explicit transaction.


execute

int execute(CallableSql callableSql)
Call a stored procedure.

Refer to Ebean.execute(CallableSql) for full documentation.

See Also:
Ebean.execute(CallableSql)

externalModification

void externalModification(String tableName,
                          boolean inserted,
                          boolean updated,
                          boolean deleted)
Process committed changes from another framework.

This notifies this instance of the framework that beans have been committed externally to it. Either by another framework or clustered server. It uses this to maintain its cache and lucene indexes appropriately.

See Also:
Ebean.externalModification(String, boolean, boolean, boolean)

find

<T> T find(Class<T> beanType,
           Object uid,
           Transaction transaction)
Find a entity bean with an explicit transaction.

Type Parameters:
T - the type of entity bean to find
Parameters:
beanType - the type of entity bean to find
uid - the bean id value
transaction - the transaction to use (can be null)

save

void save(Object bean,
          Transaction t)
          throws javax.persistence.OptimisticLockException
Insert or update a bean with an explicit transaction.

Throws:
javax.persistence.OptimisticLockException

save

int save(Iterator<?> it,
         Transaction t)
         throws javax.persistence.OptimisticLockException
Save all the beans in the iterator with an explicit transaction.

Throws:
javax.persistence.OptimisticLockException

update

void update(Object bean)
Force an update using the bean.

You can use this method to FORCE an update to occur. When save(Object) is used Ebean determines whether to use an insert or an update based on the state of the bean. Using this method will force an update to occur.

It is expected that this method is most useful in stateless web applications where you have the values you wish to update but no existing bean.

 
 Customer c = new Customer();
 c.setId(7);
 c.setName("ModifiedNameNoOCC");
 
 // generally you should set the version property 
 // so that Optimistic Concurrency Checking is used.
 // If a version property is not set then no Optimistic
 // Concurrency Checking occurs for the update
 //c.setLastUpdate(lastUpdateTime);
 
 // by default the Non-null properties 
 // are included in the update
 ebeanServer.update(c);
 
 


update

void update(Object bean,
            Set<String> updateProps)
Force an update using the bean explicitly stating the properties to update.
 
 Customer c = new Customer();
 c.setId(7);
 c.setName("ModifiedNameNoOCC");
 
 // generally you should set the version property 
 // so that Optimistic Concurrency Checking is used.
 // If a version property is not set then no Optimistic
 // Concurrency Checking occurs for the update
 //c.setLastUpdate(lastUpdateTime);
 
 // by default the Non-null properties 
 // are included in the update
 ebeanServer.update(c);
 
 


update

void update(Object bean,
            Set<String> updateProps,
            Transaction t)
Force an update of the specified properties of the bean with an explicit transaction.


update

void update(Object bean,
            Transaction t)
Force an update of the non-null properties of the bean with an explicit transaction.


deleteManyToManyAssociations

int deleteManyToManyAssociations(Object ownerBean,
                                 String propertyName)
Delete the associations (from the intersection table) of a ManyToMany given the owner bean and the propertyName of the ManyToMany collection.

Typically these deletions occur automatically when persisting a ManyToMany collection and this provides a way to invoke those deletions directly.

Returns:
the number of associations deleted (from the intersection table).

deleteManyToManyAssociations

int deleteManyToManyAssociations(Object ownerBean,
                                 String propertyName,
                                 Transaction t)
Delete the associations (from the intersection table) of a ManyToMany given the owner bean and the propertyName of the ManyToMany collection.

Additionally specify a transaction to use.

Typically these deletions occur automatically when persisting a ManyToMany collection and this provides a way to invoke those deletions directly.

Returns:
the number of associations deleted (from the intersection table).

saveManyToManyAssociations

void saveManyToManyAssociations(Object ownerBean,
                                String propertyName)
Save the associations of a ManyToMany given the owner bean and the propertyName of the ManyToMany collection.

Typically the saving of these associations (inserting into the intersection table) occurs automatically when persisting a ManyToMany. This provides a way to invoke those insertions directly.


saveManyToManyAssociations

void saveManyToManyAssociations(Object ownerBean,
                                String propertyName,
                                Transaction t)
Save the associations of a ManyToMany given the owner bean and the propertyName of the ManyToMany collection.

Typically the saving of these associations (inserting into the intersection table) occurs automatically when persisting a ManyToMany. This provides a way to invoke those insertions directly.


saveAssociation

void saveAssociation(Object ownerBean,
                     String propertyName)
Save the associated collection or bean given the property name.

This is similar to performing a save cascade on a specific property manually.

Note that you can turn on/off cascading for a transaction via Transaction.setPersistCascade(boolean)

Parameters:
ownerBean - the bean instance holding the property we want to save
propertyName - the property we want to save

saveAssociation

void saveAssociation(Object ownerBean,
                     String propertyName,
                     Transaction t)
Save the associated collection or bean given the property name with a specific transaction.

This is similar to performing a save cascade on a specific property manually.

Note that you can turn on/off cascading for a transaction via Transaction.setPersistCascade(boolean)

Parameters:
ownerBean - the bean instance holding the property we want to save
propertyName - the property we want to save

delete

void delete(Object bean,
            Transaction t)
            throws javax.persistence.OptimisticLockException
Delete the bean with an explicit transaction.

Throws:
javax.persistence.OptimisticLockException

delete

int delete(Iterator<?> it,
           Transaction t)
           throws javax.persistence.OptimisticLockException
Delete all the beans from an iterator.

Throws:
javax.persistence.OptimisticLockException

execute

int execute(SqlUpdate updSql,
            Transaction t)
Execute explicitly passing a transaction.


execute

int execute(CallableSql callableSql,
            Transaction t)
Execute explicitly passing a transaction.


execute

void execute(TxScope scope,
             TxRunnable r)
Execute a TxRunnable in a Transaction with an explicit scope.

The scope can control the transaction type, isolation and rollback semantics.


execute

void execute(TxRunnable r)
Execute a TxRunnable in a Transaction with the default scope.

The default scope runs with REQUIRED and by default will rollback on any exception (checked or runtime).


execute

<T> T execute(TxScope scope,
              TxCallable<T> c)
Execute a TxCallable in a Transaction with an explicit scope.

The scope can control the transaction type, isolation and rollback semantics.


execute

<T> T execute(TxCallable<T> c)
Execute a TxCallable in a Transaction with the default scope.

The default scope runs with REQUIRED and by default will rollback on any exception (checked or runtime).


getServerCacheManager

ServerCacheManager getServerCacheManager()
Return the manager of the server cache ("L2" cache).


getBackgroundExecutor

BackgroundExecutor getBackgroundExecutor()
Return the BackgroundExecutor service for asynchronous processing of queries.


runCacheWarming

void runCacheWarming()
Run the cache warming queries on all bean types that have one defined.

A cache warming query can be defined via CacheStrategy.


runCacheWarming

void runCacheWarming(Class<?> beanType)
Run the cache warming query for a specific bean type.

A cache warming query can be defined via CacheStrategy.


createJsonContext

JsonContext createJsonContext()
Create a JsonContext that will use the default configuration options.



Copyright © 2010. All Rights Reserved.