mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#2362 - ENH: Add lock(bean) method as convenience for DB pessimistic locking
This commit is contained in:
@@ -1272,6 +1272,21 @@ public final class DB {
|
||||
return beanId(bean);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load and lock the bean using {@code select for update}.
|
||||
* <p>
|
||||
* This should be executed inside a transaction.
|
||||
* <p>
|
||||
* The bean needs to have an ID property set and can be a reference bean (only has ID)
|
||||
* or partially or fully populated bean. This will load all the properties of the bean
|
||||
* from the database using {@code select for update}.
|
||||
*
|
||||
* @param bean The entity bean that we wish to obtain a database lock on.
|
||||
*/
|
||||
public static void lock(Object bean) {
|
||||
getDefault().lock(bean);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated migrate to cacheManager().
|
||||
*/
|
||||
|
||||
@@ -1714,6 +1714,20 @@ public interface Database {
|
||||
*/
|
||||
<T> Set<String> validateQuery(Query<T> query);
|
||||
|
||||
/**
|
||||
* Load and lock the bean using {@code select for update}.
|
||||
* <p>
|
||||
* This should be executed inside a transaction and results in the bean being loaded or
|
||||
* refreshed from the database and a database row lock held via {@code select for update}.
|
||||
* <p>
|
||||
* The bean needs to have an ID property set and can be a reference bean (only has ID)
|
||||
* or partially or fully populated bean. This will load all the properties of the bean
|
||||
* from the database using {@code select for update} obtaining a database row lock (using WAIT).
|
||||
*
|
||||
* @param bean The entity bean that we wish to obtain a database lock on.
|
||||
*/
|
||||
void lock(Object bean);
|
||||
|
||||
/**
|
||||
* Truncate all the given tables.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user