-
Notifications
You must be signed in to change notification settings - Fork 16
SQL Update
To bind a DAO interface method to an UPDATE SQL statement is necessary to decorate it with @BindSqlUpdate. Like other SQL statement type, you can write the entire JQL statement or write only specific parts of the JQL statement.
There are two kinds of UPDATE:
-
Raw update: method parameters are directly used like table column or query parameter: method's parameter that is not used as the query parameter is used to update column name with the same name or alias (with @BindSqlParam). If you specify a return type for methods (like method
updateTwo
), it has to be of typeint
,long
,Integer
,Long
. In this case, the return value will be the updated rows count. @BindSqlParam annotation can be used to specify a different column name associated to a specific method's parameter. -
Managed bean update: method has only one managed bean as parameter: method accepts only one managed bean class type parameter. It is possible to use
excludedFields
attribute to avoid to update some fields, or you can useincludeFields
attribute to include only specific fields. If you specify a return type for methods, it has to be of typeint
,long
,Integer
,Long
and it will contain updated rows count.
Suppose we want to persist bean Person
defined as follow:
@BindType
public class Person {
public long id;
public String name;
public String surname;
public String birthCity;
public Date birthDay;
}
The associated DAO interface is
@BindDao(Person.class)
public interface PersonDAO {
@BindSqlUpdate(where="name=${name}")
void updateOne(String name, String surname, String birthCity, Date birthDay);
@BindSqlUpdate
long updateTwo(String name, String surname, String birthCity, @BindSqlParam("birthDay") Date date);
@BindSqlUpdate(where="id=${bean.id}")
void updateThree(Person bean);
@BindSqlUpdate(jql="UPDATE person SET surname=${bean.surname}, birthCity=${bean.birthCity}, birthDay=${bean.birthDay} WHERE name=${bean.name}")
void updateFour(Person bean)
}
For more details about SQL Insert, please consult @BindSqlUpdate page.
- Introduction
- Goals & Features
- Kotlin
- Immutable or Mutable Pojo
- Annotation Processor Args
- Credits
- Articles
- Benchmarks
- Setup
- Tutorial
- Usage
- Dependencies and inspirations
- Stackoverflow
- Documentation
- SQL logging
- Data source options
- Indices
- SQL Type adapter
- Global SQL Type adapter
- Constraints
- Live data: welcome Architectural components!!
- Paged Live data
- Dynamic parts
- Transactional and batch operations
- Async Transactional and batch operations
- Global transaction
- Support for immutable POJO
- Generate Content provider
- Generate Database schema generation
- Database migration
- BindSqlColumn
- BindContentProvider
- BindContentProviderEntry
- BindContentProviderPath
- BindDao
- BindDaoMany2Many
- BindDataSource
- BindDataSourceOptions
- BindDataSourceUpdateTask
- BindIndex
- BindSqlRelation
- BindSqlAdapter
- BindSqlChildSelect
- BindSqlDelete
- BindSqlDynamicOrderBy
- BindSqlDynamicWhere
- BindSqlDynamicWhereParams
- BindSqlInsert
- BindSqlPageSize
- BindSqlParam
- BindSqlSelect
- BindSqlUpdate
- BindSqlType
- BindSqlTransaction