-
Notifications
You must be signed in to change notification settings - Fork 16
SQL Insert
To bind a DAO interface method to an INSERT SQL statement is necessary to decorate it with @BindSqlInsert. Like other SQL statement type, you can write entire JQL statement or write only specific parts of the JQL statment.
Moreover there are two kind of INSERT:
-
Raw insert: method parameters are directly used like table column: all method parameter's name are used are transformed in column with same name. It is possibile define an alias with @BindSqlParam. If you specify a return type for methods, it has to be of type
int
,long
,Integer
,Long
. In this case, the return value will be the inserted row's id. @BindSqlParam annotation can be used to specify a different column name associated to a specific method's parameter. Moreover, you can useboolean
as return type, just to receivetrue
if insert operation was completed (row id != -1). -
Managed bean insert: method has only one managed bean as parameter: method accepts only one managed bean type parameter. It is possible to use
excludedFields
attribute to avoid to insert 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 contains inserted rows count, or boolean to receive a true value if insert statement was successfully completed (row id != -1).
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;
}
So define a DAO interface for class Person
:
@BindDao(Person.class)
public interface PersonDAO {
// raw insert - Method using a bean type parameter
@BindSqlInsert
void insertOne(String name, String surname, String birthCity, Date birthDay);
// raw insert - Method use a bean type parameter
@BindSqlInsert
long insertTwo(String name, String surname, String birthCity, @BindSqlParam("birthDay") Date date);
// managed bean insert - method use its parameters like bean properties
@BindSqlInsert(excludedFields={"name", "surname"})
void insertThree(Person bean);
@BindSqlInsert(jql="INSERT INTO person (name, surname, birth_city, birth_day) VALUES (${bean.name}, ${bean.surname}, ${bean.birthCity},{bean.birthDay}")
void insertFour(Person bean);
}
For more details about SQL Insert, please consult @BindSqlInsert 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