-
Notifications
You must be signed in to change notification settings - Fork 16
Select projection on arbirtraty POJO
xcesco edited this page Apr 17, 2020
·
2 revisions
In the ORM module, the DAO interfaces allow managing the POJO associated with the DAO. Moreover is possible to define some queries that return another type of POJO. There are two constraints:
- The POJO has to be marked with @BindSqlType annotation
- The POJO doesn't have its DAO.
An example:
@BindDao(Loan.class)
public interface LoanDao {
@BindSqlSelect
LiveData<List<Loan>> findAllLoans();
@BindSqlSelect(jql = "SELECT Loan.id, Book.title as bookTitle, User.name as userName, Loan.startTime, "+
"Loan.endTime From Loan " +
"INNER JOIN Book ON Loan.bookId = Book.id "+
"INNER JOIN User ON Loan.userId = User.id ")
List<LoanWithUserAndBook> findAllWithUserAndBook();
@BindSqlSelect(jql = "SELECT "+
"Loan.id, Book.title as bookTitle, User.name as userName, Loan.startTime, Loan.endTime " +
"FROM Book INNER JOIN Loan ON Loan.bookId = Book.id " +
"INNER JOIN User on User.id = Loan.userId WHERE User.name LIKE :userName " +
"AND Loan.endTime > :after ")
LiveData<List<LoanWithUserAndBook>> findLoansByNameAfter(String userName, Date after);
@BindSqlInsert
void insertLoan(Loan loan);
@BindSqlDelete
void deleteAll();
}
The DAO manages Loan
bean. Thus, the queries LoanWithUserAndBook
and findLoansByNameAfter
allows obtaining LoanWithUserAndBook
POJOs
@BindSqlType
public class LoanWithUserAndBook {
public String id;
@BindSqlColumn("title")
public String bookTitle;
@BindSqlColumn("name")
public String userName;
public Date startTime;
public Date endTime;
}
- 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