Skip to content

SQL Update

xcesco edited this page Apr 26, 2018 · 2 revisions

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 type int, 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 use includeFields attribute to include only specific fields. If you specify a return type for methods, it has to be of type int, 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.

Table of Contents

Query definition

Features

Relations

Multithread supports

Modularization

Annotations for data convertion

Annotations for SQLite ORM

Annotations for shared preferences

Clone this wiki locally