Skip to content

SQL Delete

xcesco edited this page Apr 26, 2018 · 2 revisions

To bind a DAO interface method to an DELETE SQL statement is necessary to decorate it with @BindSqlDelete. Like other SQL statement type, you can write the entire JQL statement or write only specific parts of the JQL statement. You can use the bean as the input parameter or method parameters like bean property, but you can not use mixed case. This annotation can be used only on DAO's interface methods.

For example, suppose we 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 { }

Case 1 - Method using a bean type parameter

It's possible to define a DELETE query with annotation BindSqlDelete. It is possible to define query parameter simply using method parameter with the same name of the bean property.

@BindDao(Person.class)
public interface PersonDAO {
 
  @BindDelete(where="name=${name} and surname=${surname}")
  void deleteOne(String name, @BindSqlParam("surname") temp);
 
  @BindDelete(where="name=${name} and surname=${surname}")
  long deleteTwo(String name, @BindSqlParam("surname") temp);
}

Each method parameter will be used like input parameter for the query. The name of parameters will be used to map field bean and then the column name of the associated table. If you specify a return type for methods (like method insertTwo), it has to be of type int, long, Integer, Long. In this case, the return value will be the id value of just inserted row.

Case 2 - method use its parameters like bean properties

The other way to define a DELETE SQL is using a bean as input parameter:

@BindDao(Person.class)
public interface PersonDAO { 
  @BindDelete(where = " id = ${bean.id} ")
  void deleteThree(Person bean);
}

If you specify a return type for methods, it has to be of type int, long, Integer, Long and it will contain the number of deleted rows.

For more informations, consult @BindSqlDelete.

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