Class Ebean
- java.lang.Object
-
- io.ebean.Ebean
-
@Deprecated public final class Ebean extends Object
Deprecated.
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static Transaction
beginTransaction()
Deprecated.Start a transaction with 'REQUIRED' semantics.static Transaction
beginTransaction(io.ebean.annotation.TxIsolation isolation)
Deprecated.Start a transaction additionally specifying the isolation level.static Transaction
beginTransaction(TxScope scope)
Deprecated.Start a transaction typically specifying REQUIRES_NEW or REQUIRED semantics.static Set<Property>
checkUniqueness(Object bean)
Deprecated.This method checks the uniqueness of a bean.static Set<Property>
checkUniqueness(Object bean, Transaction transaction)
Deprecated.Same ascheckUniqueness(Object)
.static void
commitTransaction()
Deprecated.Commit the current transaction.static CallableSql
createCallableSql(String sql)
Deprecated.Create a CallableSql to execute a given stored procedure.static <T> CsvReader<T>
createCsvReader(Class<T> beanType)
Deprecated.Create a CsvReader for a given beanType.static <T> Query<T>
createNamedQuery(Class<T> beanType, String namedQuery)
Deprecated.Create a named query.static <T> Query<T>
createQuery(Class<T> beanType)
Deprecated.Create a query for a type of entity bean.static <T> Query<T>
createQuery(Class<T> beanType, String eql)
Deprecated.Parse the Ebean query language statement returning the query which can then be modified (add expressions, change order by clause, change maxRows, change fetch and select paths etc).static SqlQuery
createSqlQuery(String sql)
Deprecated.static SqlUpdate
createSqlUpdate(String sql)
Deprecated.static <T> Update<T>
createUpdate(Class<T> beanType, String ormUpdate)
Deprecated.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).static Transaction
currentTransaction()
Deprecated.Returns the current transaction or null if there is no current transaction in scope.static int
delete(Class<?> beanType, Object id)
Deprecated.Delete the bean given its type and id.static boolean
delete(Object bean)
Deprecated.Delete the bean.static int
deleteAll(Class<?> beanType, Collection<?> ids)
Deprecated.Delete several beans given their type and id values.static int
deleteAll(Collection<?> beans)
Deprecated.Delete all the beans in the Collection.static int
deleteAllPermanent(Class<?> beanType, Collection<?> ids)
Deprecated.Delete permanent several beans given their type and id values.static int
deleteAllPermanent(Collection<?> beans)
Deprecated.Delete permanent all the beans in the Collection (will not use soft delete).static int
deletePermanent(Class<?> beanType, Object id)
Deprecated.Delete permanent the bean given its type and id.static boolean
deletePermanent(Object bean)
Deprecated.Delete the bean in permanent fashion (will not use soft delete).static Map<String,ValuePair>
diff(Object a, Object b)
Deprecated.Return a map of the differences between two objects of the same type.static void
endTransaction()
Deprecated.If the current transaction has already been committed do nothing otherwise rollback the transaction.static int
execute(CallableSql callableSql)
Deprecated.For making calls to stored procedures.static int
execute(SqlUpdate sqlUpdate)
Deprecated.Execute a Sql Update Delete or Insert statement.static void
execute(TxScope scope, Runnable r)
Deprecated.Execute a TxRunnable in a Transaction with an explicit scope.static void
execute(Runnable r)
Deprecated.Execute a Runnable in a Transaction with the default scope.static <T> T
executeCall(TxScope scope, Callable<T> c)
Deprecated.Execute a Callable in a Transaction with an explicit scope.static <T> T
executeCall(Callable<T> c)
Deprecated.Execute a Callable in a Transaction with the default scope.static void
externalModification(String tableName, boolean inserts, boolean updates, boolean deletes)
Deprecated.Inform Ebean that tables have been modified externally.static <T> Filter<T>
filter(Class<T> beanType)
Deprecated.Create a filter for sorting and filtering lists of entities locally without going back to the database.static <T> Query<T>
find(Class<T> beanType)
Deprecated.Create a query for a type of entity bean.static <T> T
find(Class<T> beanType, Object id)
Deprecated.Find a bean using its unique id.static <T> DtoQuery<T>
findDto(Class<T> dtoType, String sql)
Deprecated.Create a Query for DTO beans.static <T> Query<T>
findNative(Class<T> beanType, String nativeSql)
Deprecated.Create a query using native SQL.static void
flush()
Deprecated.The batch will be flushing automatically but you can use this to explicitly flush the batch if you like.static BackgroundExecutor
getBackgroundExecutor()
Deprecated.Return the BackgroundExecutor service for asynchronous processing of queries.static BeanState
getBeanState(Object bean)
Deprecated.Return the BeanState for a given entity bean.static EbeanServer
getDefaultServer()
Deprecated.Returns the default EbeanServer.static ExpressionFactory
getExpressionFactory()
Deprecated.Return the ExpressionFactory from the default database.static <T> T
getReference(Class<T> beanType, Object id)
Deprecated.Get a reference object.static EbeanServer
getServer(String name)
Deprecated.Get the Database for a given DataSource.static ServerCacheManager
getServerCacheManager()
Deprecated.Return the manager of the server cache ("L2" cache).static void
insert(Object bean)
Deprecated.Insert the bean.static void
insertAll(Collection<?> beans)
Deprecated.Insert a collection of beans.static JsonContext
json()
Deprecated.Return the JsonContext for reading/writing JSON.static void
markAsDirty(Object bean)
Deprecated.Marks the entity bean as dirty.static void
merge(Object bean)
Deprecated.Merge the bean using the default merge options.static void
merge(Object bean, MergeOptions options)
Deprecated.Merge the bean using the given merge options.static Object
nextId(Class<?> beanType)
Deprecated.Return the next identity value for a given bean type.static void
refresh(Object bean)
Deprecated.Refresh the values of a bean.static void
refreshMany(Object bean, String manyPropertyName)
Deprecated.Refresh a 'many' property of a bean.static void
register(EbeanServer server, boolean defaultServer)
Deprecated.static void
register(TransactionCallback transactionCallback)
Deprecated.Register a TransactionCallback on the currently active transaction.static void
rollbackTransaction()
Deprecated.Rollback the current transaction.static void
save(Object bean)
Deprecated.Either Insert or Update the bean depending on its state.static int
saveAll(Collection<?> beans)
Deprecated.Save all the beans from a Collection.static void
setRollbackOnly()
Deprecated.Mark the current transaction as rollback only.static <T> void
sort(List<T> list, String sortByClause)
Deprecated.Sort the list using the sortByClause which can contain a comma delimited list of property names and keywords asc, desc, nullsHigh and nullsLow.static <T> UpdateQuery<T>
update(Class<T> beanType)
Deprecated.Create an Update query to perform a bulk update.static void
update(Object bean)
Deprecated.Saves the bean using an update.static void
updateAll(Collection<?> beans)
Deprecated.Update the beans in the collection.
-
-
-
Method Detail
-
getServer
public static EbeanServer getServer(String name)
Deprecated.Get the Database for a given DataSource. If name is null this will return the 'default' EbeanServer.This is provided to access EbeanServer for databases other than the 'default' database. EbeanServer also provides more control over transactions and the ability to use transactions created externally to Ebean.
// use the "hr" database EbeanServer hrDatabase = Ebean.getServer("hr"); Person person = hrDatabase.find(Person.class, 10);
- Parameters:
name
- the name of the server, can use null for the 'default server'
-
getDefaultServer
public static EbeanServer getDefaultServer()
Deprecated.Returns the default EbeanServer.This is equivalent to
Ebean.getServer(null);
-
register
@Deprecated public static void register(EbeanServer server, boolean defaultServer)
Deprecated.Register the server with this Ebean singleton. Specify if the registered server is the primary/default database.
-
getExpressionFactory
public static ExpressionFactory getExpressionFactory()
Deprecated.Return the ExpressionFactory from the default database.The ExpressionFactory is used internally by the query and ExpressionList to build the WHERE and HAVING clauses. Alternatively you can use the ExpressionFactory directly to create expressions to add to the query where clause.
Alternatively you can use the
Expr
as a shortcut to the ExpressionFactory of the 'Default' EbeanServer.You generally need to the an ExpressionFactory (or
Expr
) to build an expression that uses OR like Expression e = Expr.or(..., ...);
-
nextId
public static Object nextId(Class<?> beanType)
Deprecated.Return the next identity value for a given bean type.This will only work when a IdGenerator is on this bean type such as 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.
-
beginTransaction
public static Transaction beginTransaction()
Deprecated.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.
// start a transaction (stored in a ThreadLocal) Ebean.beginTransaction(); try { Order order = Ebean.find(Order.class,10); ... Ebean.save(order); Ebean.commitTransaction(); } finally { // rollback if we didn't commit // i.e. an exception occurred before commitTransaction(). Ebean.endTransaction(); }
If you want to externalise the transaction management then you should be able to do this via EbeanServer. Specifically with EbeanServer you can pass the transaction to the various find() and save() execute() methods. This gives you the ability to create the transactions yourself externally from Ebean and pass those transactions through to the various methods available on EbeanServer.
-
beginTransaction
public static Transaction beginTransaction(io.ebean.annotation.TxIsolation isolation)
Deprecated.Start a transaction additionally specifying the isolation level.- Parameters:
isolation
- the Transaction isolation level
-
beginTransaction
public static Transaction beginTransaction(TxScope scope)
Deprecated.Start a transaction typically specifying REQUIRES_NEW or REQUIRED semantics.Note that this provides an try finally alternative to using
executeCall(TxScope, Callable)
orexecute(TxScope, Runnable)
.REQUIRES_NEW example:
// Start a new transaction. If there is a current transaction // suspend it until this transaction ends Transaction txn = Ebean.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:
// start a new transaction if there is not a current transaction Transaction txn = Ebean.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(); }
-
currentTransaction
public static Transaction currentTransaction()
Deprecated.Returns the current transaction or null if there is no current transaction in scope.
-
flush
public static void flush()
Deprecated.The batch will be flushing automatically but you can use this to explicitly flush the batch if you like.Flushing occurs automatically when:
- the batch size is reached
- A query is executed on the same transaction
- UpdateSql or CallableSql are mixed with bean save and delete
- Transaction commit occurs
- A getter method is called on a batched bean
-
register
public static void register(TransactionCallback transactionCallback) throws javax.persistence.PersistenceException
Deprecated.Register a TransactionCallback on the currently active transaction. If there is no currently active transaction then a PersistenceException is thrown.- Parameters:
transactionCallback
- the transaction callback to be registered with the current transaction- Throws:
javax.persistence.PersistenceException
- if there is no currently active transaction
-
commitTransaction
public static void commitTransaction()
Deprecated.Commit the current transaction.
-
rollbackTransaction
public static void rollbackTransaction()
Deprecated.Rollback the current transaction.
-
endTransaction
public static void endTransaction()
Deprecated.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.beginTransaction(); 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(); }
-
setRollbackOnly
public static void setRollbackOnly()
Deprecated.Mark the current transaction as rollback only.
-
diff
public static Map<String,ValuePair> diff(Object a, Object b)
Deprecated.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.
-
save
public static void save(Object bean) throws javax.persistence.OptimisticLockException
Deprecated.Either Insert or Update the bean depending on its state.If there is no current transaction one will be created and committed for you automatically.
Save can cascade along relationships. For this to happen you need to specify a cascade of CascadeType.ALL or CascadeType.PERSIST on the OneToMany, OneToOne or ManyToMany annotation.
In this example below the details property has a CascadeType.ALL set so saving an order will also save all its details.
{@code public class Order { ...
- Throws:
javax.persistence.OptimisticLockException
-
insert
public static void insert(Object bean)
Deprecated.Insert the bean. This is useful when you set the Id property on a bean and want to explicitly insert it.
-
insertAll
public static void insertAll(Collection<?> beans)
Deprecated.Insert a collection of beans.
-
markAsDirty
public static void markAsDirty(Object bean) throws javax.persistence.OptimisticLockException
Deprecated.Marks the entity bean as dirty.This is used so that when a bean that is otherwise unmodified is updated with the version property updated.
An unmodified bean that is saved or updated is normally skipped and this marks the bean as dirty so that it is not skipped.
Customer customer = Ebean.find(Customer, id); // mark the bean as dirty so that a save() or update() will // increment the version property Ebean.markAsDirty(customer); Ebean.save(customer);
- Throws:
javax.persistence.OptimisticLockException
-
update
public static void update(Object bean) throws javax.persistence.OptimisticLockException
Deprecated.Saves the bean using an update. If you know you are updating a bean then it is preferrable to use this update() method rather than save().Stateless updates: Note that the bean does not have to be previously fetched to call update().You can create a new instance and set some of its properties programmatically for via JSON/XML marshalling etc. This is described as a 'stateless update'.
Optimistic Locking: Note that if the version property is not set when update() is called then no optimistic locking is performed (internally ConcurrencyMode.NONE is used).
// A 'stateless update' example Customer customer = new Customer(); customer.setId(7); customer.setName("ModifiedNameNoOCC"); DB.update(customer);
- Throws:
javax.persistence.OptimisticLockException
-
updateAll
public static void updateAll(Collection<?> beans) throws javax.persistence.OptimisticLockException
Deprecated.Update the beans in the collection.- Throws:
javax.persistence.OptimisticLockException
-
merge
public static void merge(Object bean)
Deprecated.Merge the bean using the default merge options.- Parameters:
bean
- The bean to merge
-
merge
public static void merge(Object bean, MergeOptions options)
Deprecated.Merge the bean using the given merge options.- Parameters:
bean
- The bean to mergeoptions
- The options to control the merge
-
saveAll
public static int saveAll(Collection<?> beans) throws javax.persistence.OptimisticLockException
Deprecated.Save all the beans from a Collection.- Throws:
javax.persistence.OptimisticLockException
-
checkUniqueness
@Nonnull public static Set<Property> checkUniqueness(Object bean)
Deprecated.This method checks the uniqueness of a bean. I.e. if the save will work. It will return the properties that violates an unique / primary key. This may be done in an UI save action to validate if the user has entered correct values.Note: This method queries the DB for uniqueness of all indices, so do not use it in a batch update.
Note: This checks only the root bean!
// there is a unique constraint on title Document doc = new Document(); doc.setTitle("One flew over the cuckoo's nest"); doc.setBody("clashes with doc1"); Set<Property> properties = server().checkUniqueness(doc); if (properties.isEmpty()) { // it is unique ... carry on } else { // build a user friendly message // to return message back to user String uniqueProperties = properties.toString(); StringBuilder msg = new StringBuilder(); properties.forEach((it)-> { Object propertyValue = it.getVal(doc); String propertyName = it.getName(); msg.append(" property["+propertyName+"] value["+propertyValue+"]"); }); // uniqueProperties > [title] // custom msg > property[title] value[One flew over the cuckoo's nest] }
- Parameters:
bean
- The entity bean to check uniqueness on- Returns:
- a set of Properties if constraint validation was detected or empty list.
-
checkUniqueness
@Nonnull public static Set<Property> checkUniqueness(Object bean, Transaction transaction)
Deprecated.Same ascheckUniqueness(Object)
. but with given transaction.
-
delete
public static boolean delete(Object bean) throws javax.persistence.OptimisticLockException
Deprecated.Delete the bean.This will return true if the bean was deleted successfully or JDBC batch is being used.
If there is no current transaction one will be created and committed for you automatically.
If the bean is configured with
@SoftDelete
then this will perform a soft delete rather than a hard/permanent delete.If the Bean does not have a version property (or loaded version property) and the bean does not exist then this returns false indicating that nothing was deleted. Note that, if JDBC batch mode is used then this always returns true.
- Throws:
javax.persistence.OptimisticLockException
-
deletePermanent
public static boolean deletePermanent(Object bean) throws javax.persistence.OptimisticLockException
Deprecated.Delete the bean in permanent fashion (will not use soft delete).- Throws:
javax.persistence.OptimisticLockException
-
delete
public static int delete(Class<?> beanType, Object id)
Deprecated.Delete the bean given its type and id.
-
deletePermanent
public static int deletePermanent(Class<?> beanType, Object id)
Deprecated.Delete permanent the bean given its type and id.
-
deleteAll
public static int deleteAll(Class<?> beanType, Collection<?> ids)
Deprecated.Delete several beans given their type and id values.
-
deleteAllPermanent
public static int deleteAllPermanent(Class<?> beanType, Collection<?> ids)
Deprecated.Delete permanent several beans given their type and id values.
-
deleteAll
public static int deleteAll(Collection<?> beans) throws javax.persistence.OptimisticLockException
Deprecated.Delete all the beans in the Collection.- Throws:
javax.persistence.OptimisticLockException
-
deleteAllPermanent
public static int deleteAllPermanent(Collection<?> beans) throws javax.persistence.OptimisticLockException
Deprecated.Delete permanent all the beans in the Collection (will not use soft delete).- Throws:
javax.persistence.OptimisticLockException
-
refresh
public static void refresh(Object bean)
Deprecated.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.
-
refreshMany
public static void refreshMany(Object bean, String manyPropertyName)
Deprecated.Refresh a 'many' property of a bean.Order order = ...; ... // refresh the order details... Ebean.refreshMany(order, "details");
- Parameters:
bean
- the entity bean containing the List Set or Map to refresh.manyPropertyName
- the property name of the List Set or Map to refresh.
-
getReference
public static <T> T getReference(Class<T> beanType, Object id)
Deprecated.Get a reference object.This is sometimes described as a proxy (with lazy loading).
Product product = Ebean.getReference(Product.class, 1); // You can get the id without causing a fetch/lazy load Integer 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();
- Parameters:
beanType
- the type of entity beanid
- the id value
-
sort
public static <T> void sort(List<T> list, String sortByClause)
Deprecated.Sort the list 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.
// find orders and their customers List<Order> list = Ebean.find(Order.class) .fetch("customer") .order("id") .findList(); // sort by customer name ascending, then by order shipDate // ... then by the order status descending Ebean.sort(list, "customer.name, shipDate, status desc"); // sort by customer name descending (with nulls low) // ... then by the order id Ebean.sort(list, "customer.name desc nullsLow, id");
- Parameters:
list
- the list of entity beanssortByClause
- the properties to sort the list by
-
find
@Nullable public static <T> T find(Class<T> beanType, Object id)
Deprecated.Find a bean using its unique id. This will not use caching.// Fetch order 1 Order order = Ebean.find(Order.class, 1);
If you want more control over the query then you can use createQuery() and Query.findOne();
// ... 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<Order> query = Ebean.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"); // traverse the object graph... Order order = query.findOne(); Customer customer = order.getCustomer(); Address shippingAddress = customer.getShippingAddress(); List<OrderDetail> details = order.getDetails(); OrderDetail detail0 = details.get(0); Product product = detail0.getProduct(); String productName = product.getName();
- Parameters:
beanType
- the type of entity bean to fetchid
- the id value
-
createSqlQuery
@Deprecated public static SqlQuery createSqlQuery(String sql)
Deprecated.Deprecated - migrate to DB.sqlQuery().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.
-
createSqlUpdate
@Deprecated public static SqlUpdate createSqlUpdate(String sql)
Deprecated.Deprecated - migrate to DB.sqlUpdate().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
SqlUpdate
for example usage.
-
createCallableSql
public static CallableSql createCallableSql(String sql)
Deprecated.Create a CallableSql to execute a given stored procedure.- See Also:
CallableSql
-
createUpdate
public static <T> Update<T> createUpdate(Class<T> beanType, String ormUpdate)
Deprecated.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:
// 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<Topic> update = Ebean.createUpdate(Topic.class, updStatement); update.set("pc", 9); update.set("id", 3); int rows = update.execute(); System.out.println("rows updated:" + rows);
-
createCsvReader
public static <T> CsvReader<T> createCsvReader(Class<T> beanType)
Deprecated.Create a CsvReader for a given beanType.
-
createNamedQuery
public static <T> Query<T> createNamedQuery(Class<T> beanType, String namedQuery)
Deprecated.Create a named query.For RawSql the named query is expected to be in ebean.xml.
- Type Parameters:
T
- The type of entity bean- Parameters:
beanType
- The type of entity beannamedQuery
- The name of the query- Returns:
- The query
-
createQuery
public static <T> Query<T> createQuery(Class<T> beanType)
Deprecated.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 findOne() to execute the query and return the collection or bean.
Note that a query executed by
Query.findList()
Query.findSet()
etc will execute against the same EbeanServer from which is was created.- Parameters:
beanType
- the class of entity to be fetched- Returns:
- A ORM Query object for this beanType
-
createQuery
public static <T> Query<T> createQuery(Class<T> beanType, String eql)
Deprecated.Parse the Ebean query language statement returning the query which can then be modified (add expressions, change order by clause, change maxRows, change fetch and select paths etc).Example
// Find order additionally fetching the customer, details and details.product name. String eql = "fetch customer fetch details fetch details.product (name) where id = :orderId "; Query<Order> query = Ebean.createQuery(Order.class, eql); query.setParameter("orderId", 2); Order order = query.findOne(); // This is the same as: Order order = Ebean.find(Order.class) .fetch("customer") .fetch("details") .fetch("detail.product", "name") .setId(2) .findOne();
- Type Parameters:
T
- The type of the entity bean- Parameters:
beanType
- The type of bean to fetcheql
- The Ebean query- Returns:
- The query with expressions defined as per the parsed query statement
-
find
public static <T> Query<T> find(Class<T> beanType)
Deprecated.Create a query for a type of entity bean.This is actually the same as
createQuery(Class)
. The reason it exists is that people used to JPA will probably be looking for a createQuery method (the same as entityManager).- Parameters:
beanType
- the type of entity bean to find- Returns:
- A ORM Query object for this beanType
-
findNative
public static <T> Query<T> findNative(Class<T> beanType, String nativeSql)
Deprecated.Create a query using native SQL.The native SQL can contain named parameters or positioned parameters.
String sql = "select c.id, c.name from customer c where c.name like ? order by c.name"; List<Customer> customers = DB.findNative(Customer.class, sql) .setParameter(1, "Rob%") .findList()
- Parameters:
beanType
- The type of entity bean to fetchnativeSql
- The SQL that can contain named or positioned parameters- Returns:
- The query to set parameters and execute
-
findDto
public static <T> DtoQuery<T> findDto(Class<T> dtoType, String sql)
Deprecated.Create a Query for DTO beans.DTO beans are just normal bean like classes with public constructor(s) and setters. They do not need to be registered with Ebean before use.
- Type Parameters:
T
- The type of the DTO bean.- Parameters:
dtoType
- The type of the DTO bean the rows will be mapped into.sql
- The SQL query to execute.
-
update
public static <T> UpdateQuery<T> update(Class<T> beanType)
Deprecated.Create an Update query to perform a bulk update.int rows = Ebean.update(Customer.class) .set("status", Customer.Status.ACTIVE) .set("updtime", new Timestamp(System.currentTimeMillis())) .where() .gt("id", 1000) .update();
- Type Parameters:
T
- The type of entity bean- Parameters:
beanType
- The type of entity bean to update- Returns:
- The update query to use
-
filter
public static <T> Filter<T> filter(Class<T> beanType)
Deprecated.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
Filter
for an example of its use.
-
execute
public static int execute(SqlUpdate sqlUpdate)
Deprecated.Execute a Sql Update Delete or Insert statement. This returns the number of rows that where updated, deleted or inserted. If is executed in batch then this returns -1. You can get the actual rowCount after commit() from updateSql.getRowCount().If you wish to execute a Sql Select natively then you should use the FindByNativeSql object.
Note that the table modification information is automatically deduced and you do not need to call the Ebean.externalModification() method when you use this method.
Example:
// example that uses 'named' parameters String s = "UPDATE f_topic set post_count = :count where id = :id" SqlUpdate update = Ebean.createSqlUpdate(s); update.setParameter("id", 1); update.setParameter("count", 50); int modifiedCount = Ebean.execute(update); String msg = "There where " + modifiedCount + "rows updated";
- Parameters:
sqlUpdate
- the update sql potentially with bind values- Returns:
- the number of rows updated or deleted. -1 if executed in batch.
- See Also:
SqlUpdate
,CallableSql
,execute(CallableSql)
-
execute
public static int execute(CallableSql callableSql)
Deprecated.For making calls to stored procedures.Example:
String sql = "{call sp_order_modify(?,?,?)}"; CallableSql cs = Ebean.createCallableSql(sql); cs.setParameter(1, 27); cs.setParameter(2, "SHIPPED"); cs.registerOut(3, Types.INTEGER); Ebean.execute(cs); // read the out parameter Integer returnValue = (Integer) cs.getObject(3);
- See Also:
CallableSql
,execute(SqlUpdate)
-
execute
public static void execute(TxScope scope, Runnable r)
Deprecated.Execute a TxRunnable in a Transaction with an explicit scope.The scope can control the transaction type, isolation and rollback semantics.
// set specific transactional scope settings TxScope scope = TxScope.requiresNew().setIsolation(TxIsolation.SERIALIZABLE); Ebean.execute(scope, new TxRunnable() { public void run() { User u1 = Ebean.find(User.class, 1); ... } });
-
execute
public static void execute(Runnable r)
Deprecated.Execute a Runnable in a Transaction with the default scope.The default scope runs with REQUIRED and by default will rollback on any exception (checked or runtime).
Ebean.execute(() -> { User u1 = Ebean.find(User.class, 1); User u2 = Ebean.find(User.class, 2); u1.setName("u1 mod"); u2.setName("u2 mod"); Ebean.save(u1); Ebean.save(u2); });
-
executeCall
public static <T> T executeCall(TxScope scope, Callable<T> c)
Deprecated.Execute a Callable in a Transaction with an explicit scope.The scope can control the transaction type, isolation and rollback semantics.
// set specific transactional scope settings TxScope scope = TxScope.requiresNew().setIsolation(TxIsolation.SERIALIZABLE); Ebean.executeCall(scope, new Callable<String>() { public String call() { User u1 = Ebean.find(User.class, 1); ... return u1.getEmail(); } });
-
executeCall
public static <T> T executeCall(Callable<T> c)
Deprecated.Execute a Callable in a Transaction with the default scope.The default scope runs with REQUIRED and by default will rollback on any exception (checked or runtime).
This is basically the same as TxRunnable except that it returns an Object (and you specify the return type via generics).
Ebean.executeCall(() -> { User u1 = Ebean.find(User.class, 1); User u2 = Ebean.find(User.class, 2); u1.setName("u1 mod"); u2.setName("u2 mod"); Ebean.save(u1); Ebean.save(u2); return u1.getEmail(); });
-
externalModification
public static void externalModification(String tableName, boolean inserts, boolean updates, boolean deletes)
Deprecated.Inform Ebean that tables have been modified externally. These could be the result of from calling a stored procedure, other JDBC calls or external programs including other frameworks.If you use Ebean.execute(UpdateSql) then the table modification information is automatically deduced and you do not need to call this method yourself.
This information is used to invalidate objects out of the cache and potentially text indexes. This information is also automatically broadcast across the cluster.
If there is a transaction then this information is placed into the current transactions event information. When the transaction is committed this information is registered (with the transaction manager). If this transaction is rolled back then none of the transaction event information registers including the information you put in via this method.
If there is NO current transaction when you call this method then this information is registered immediately (with the transaction manager).
- Parameters:
tableName
- the name of the table that was modifiedinserts
- true if rows where inserted into the tableupdates
- true if rows on the table where updateddeletes
- true if rows on the table where deleted
-
getBeanState
public static BeanState getBeanState(Object bean)
Deprecated.Return the BeanState for a given entity bean.This will return null if the bean is not an enhanced entity bean.
-
getServerCacheManager
public static ServerCacheManager getServerCacheManager()
Deprecated.Return the manager of the server cache ("L2" cache).
-
getBackgroundExecutor
public static BackgroundExecutor getBackgroundExecutor()
Deprecated.Return the BackgroundExecutor service for asynchronous processing of queries.
-
json
public static JsonContext json()
Deprecated.Return the JsonContext for reading/writing JSON.
-
-