T
- The type of entity bean being updatedpublic interface UpdateQuery<T>
Also note that you can also just use a raw SQL update via SqlUpdate
which is pretty light and simple.
This UpdateQuery is more for the cases where we want to build the where expression of the update using the
ExpressionList
"Criteria API" that is used with a normal ORM query.
int rows = DB.update(Customer.class)
.set("status", Customer.Status.ACTIVE)
.set("updtime", new Timestamp(System.currentTimeMillis()))
.where()
.gt("id", 1000)
.update();
update o_customer set status=?, updtime=? where id > ?
Note that if the where() clause contains a join then the SQL update changes to use a
WHERE ID IN ()
form.
In this example the expression .eq("billingAddress.country", nz)
requires a join
to the address table.
int rows = DB.update(Customer.class)
.set("status", Customer.Status.ACTIVE)
.set("updtime", new Timestamp(System.currentTimeMillis()))
.where()
.eq("status", Customer.Status.NEW)
.eq("billingAddress.country", nz)
.gt("id", 1000)
.update();
update o_customer set status=?, updtime=?
where id in (
select t0.id c0
from o_customer t0
left join o_address t1 on t1.id = t0.billing_address_id
where t0.status = ?
and t1.country_code = ?
and t0.id > ? )
SqlUpdate
Modifier and Type | Method and Description |
---|---|
UpdateQuery<T> |
set(String property,
Object value)
Set the value of a property.
|
UpdateQuery<T> |
setLabel(String label)
Set the label on the update query.
|
UpdateQuery<T> |
setNull(String property)
Set the property to be null.
|
UpdateQuery<T> |
setProfileLocation(ProfileLocation profileLocation)
Set the profile location of this update query.
|
UpdateQuery<T> |
setRaw(String propertyExpression)
Set using a property expression that does not need any bind values.
|
UpdateQuery<T> |
setRaw(String propertyExpression,
Object... values)
Set using a property expression that can contain
? bind value placeholders. |
int |
update()
Execute the update returning the number of rows updated.
|
ExpressionList<T> |
where()
Return the query expression list to add predicates to.
|
UpdateQuery<T> set(String property, Object value)
int rows = DB.update(Customer.class)
.set("status", Customer.Status.ACTIVE)
.set("updtime", new Timestamp(System.currentTimeMillis()))
.where()
.gt("id", 1000)
.update();
property
- The bean property to be setvalue
- The value to set the property toUpdateQuery<T> setNull(String property)
int rows = DB.update(Customer.class)
.setNull("notes")
.where()
.gt("id", 1000)
.update();
property
- The property to be set to null.UpdateQuery<T> setRaw(String propertyExpression)
The property expression typically contains database functions.
int rows = DB.update(Customer.class)
.setRaw("status = coalesce(status, 'A')")
.where()
.gt("id", 1000)
.update();
propertyExpression
- A property expressionUpdateQuery<T> setRaw(String propertyExpression, Object... values)
?
bind value placeholders.
For each ?
in the property expression there should be a matching bind value supplied.
int rows = DB.update(Customer.class)
.setRaw("status = coalesce(status, ?)", Customer.Status.ACTIVE)
.where()
.gt("id", 1000)
.update();
propertyExpression
- A raw property expressionvalues
- The values to bind with the property expressionUpdateQuery<T> setProfileLocation(ProfileLocation profileLocation)
UpdateQuery<T> setLabel(String label)
ExpressionList<T> where()
int update()
Copyright © 2019. All rights reserved.