-
Notifications
You must be signed in to change notification settings - Fork 16
@BindSqlChildSelect
xcesco edited this page Sep 17, 2021
·
2 revisions
DAOs work with associated entities, so usually it can be used to insert/update/select/delete a specific type of bean. Suppose you have a data source which data model is composed by two entities: album
and song
. There is a one-2-many relation between them.
@BindTable
public class Album {
public long id;
public String name;
@BindRelation(foreignKey = "albumId")
public List<Song> songs;
}
@BindTable
public class Song {
public long id;
public String name;
@BindColumn(parentEntity=Album.class)
public long albumId;
}
albumId
is the foreign key of the relation. songs
field, marked with @BindRelation, can contains all album's songs and it can not be stored in a table column. Every class is managed by its DAO. If you want, you can link associated DAO to load an album and its songs with the use of child selects
.
@BindDao(Album.class)
public interface DaoAlbum extends DaoBase<Album> {
@BindSqlSelect(childrenSelects={
@BindSqlChildSelect(relation="songs", method="selectByAlbumId")
})
List<Album> selectAlbums();
}
@BindDao(Song.class)
public interface DaoSong extends DaoBase<Song> {
@BindSqlSelect
List<Song> selectAll();
@BindSqlSelect(where="albumId=${albumId}")
List<Song> selectByAlbumId(@BindSqlParam("albumId") long dummy);
}
In the above DAO definitions, method selectAlbum
load all albums and for each album, to valorize songs
field, uses the DaoSong#selectByAlbumId
.
- 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