@Retention(value=RUNTIME) @Target(value=METHOD) public @interface BindSqlDelete
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 {
}
It's possible define a DELETE query with annotation BindSqlDelete. It
is possibile to define query parameter simply using method parameter with
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 use like input parameter for 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.
The other way to define an INSERT query is using a bean as input parameter:
@BindDao(Person.class)
public interface PersonDAO {
@BindDelete(where = " id = ${bean.id} ")
void deleteThree(Person bean);
}
You can use attribute value to define which property insert into query
or you can use attribute excludedFields to avoid to insert some
fields, but you can not use both attributes in the same method
definition. Values of this attribute will be used like bean property
name. At the end of the insert, bean will have id value set to last row id
used to insert bean into table. If you specify a return type for methods, it
has to be of type int, long, Integer, Long and it will contains
same value like row id.
public abstract String where
public abstract String jql
JQL value. With this attribute, it is possibile to specify directly the
JQL code. JQL means that you can write SQL using field's names and class
name indeed of column and table names. Moreover, it is possibile to
specify where to use the dynamic parts of query through dynamic
statements like DYNAMIC_WHERE, DYNAMIC_ORDER_BY, DYNAMIC_PAGE_SIZE,
DYNAMIC_PAGE_OFFSET, encapsulated in
#{
For example, for a select statement, you can write:
SELECT * FROM media WHERE mediaId IN (SELECT mediaId FROM fav WHERE #{DYNAMIC_WHERE}) ORDER BY indx DESC LIMIT 0, 100
If you use this attribute, no other attributes can be defined for
the annotation.Copyright © 2018. All rights reserved.