Package tech.yanand.flyingmybatis
Interface AutoMapper<E,K>
- Type Parameters:
E- The entity mapping to the DB tableK- The key of the table. It can only be a subtype ofNumberorCharSequence
public interface AutoMapper<E,K>
The auto mapper, inherit this interface to get some basic CRUD methods.
-
Method Summary
Modifier and TypeMethodDescriptionlongcountAll()Count all entities.voidDelete all entities using the SQLtruncate table <table_name>.intdeleteAllById(Collection<K> ids) Delete entities by the ID collection.intdeleteById(K id) Delete an entity by IDintInsert an entity.intinsertAll(Collection<E> entities) Insert multiple entitiesSelect all entities.selectAllByColumn(String column, Object value) Select entities by a column.selectAllById(Collection<K> ids) Select entities by the ID collection.selectById(K id) Select an entity by the ID.intUpdate an entity by the ID.default intupdateAll(Collection<E> entities) Update entities by their ID.default intupdateAllSelective(Collection<E> entities) Selectively update entities by their ID.intupdateSelective(E entity) Selectively update an entity by the ID.
-
Method Details
-
insert
@InsertProvider(tech.yanand.flyingmybatis.AutoMapperProvider.class) int insert(@Param("entity") E entity) Insert an entity.- Parameters:
entity- The entity to be inserted.- Returns:
- Inserted count.
-
insertAll
@InsertProvider(tech.yanand.flyingmybatis.AutoMapperProvider.class) int insertAll(@Param("entities") Collection<E> entities) Insert multiple entities- Parameters:
entities- Entities to be inserted.- Returns:
- Inserted count.
-
selectById
Select an entity by the ID.- Parameters:
id- ID- Returns:
- Selected entity.
-
selectAllById
@SelectProvider(tech.yanand.flyingmybatis.AutoMapperProvider.class) List<E> selectAllById(@Param("ids") Collection<K> ids) Select entities by the ID collection.- Parameters:
ids- ID collection.- Returns:
- Selected entities.
-
selectAllByColumn
@SelectProvider(tech.yanand.flyingmybatis.AutoMapperProvider.class) List<E> selectAllByColumn(@Param("column") String column, @Param("value") Object value) Select entities by a column.- Parameters:
column- Column name.value- The value to be selected of thecolumn.- Returns:
- Selected entities.
-
selectAll
Select all entities.- Returns:
- Selected entities.
-
countAll
@SelectProvider(tech.yanand.flyingmybatis.AutoMapperProvider.class) long countAll()Count all entities.- Returns:
- All entities count.
-
deleteById
@DeleteProvider(tech.yanand.flyingmybatis.AutoMapperProvider.class) int deleteById(@Param("id") K id) Delete an entity by ID- Parameters:
id- Entity ID.- Returns:
- Deleted count.
-
deleteAllById
@DeleteProvider(tech.yanand.flyingmybatis.AutoMapperProvider.class) int deleteAllById(@Param("ids") Collection<K> ids) Delete entities by the ID collection.- Parameters:
ids- ID collection.- Returns:
- Deleted count.
-
deleteAll
@DeleteProvider(tech.yanand.flyingmybatis.AutoMapperProvider.class) void deleteAll()Delete all entities using the SQLtruncate table <table_name>. -
update
@UpdateProvider(tech.yanand.flyingmybatis.AutoMapperProvider.class) int update(@Param("entity") E entity) Update an entity by the ID.Note: If fields in the entity are passed
nullvalues, the column values in DB are updated to benull.- Parameters:
entity- The entity to be updated.- Returns:
- Updated count.
-
updateAll
Update entities by their ID.Note: If fields in the entity are passed
nullvalues, the column values in DB are updated to benull.- Parameters:
entities- Entities to be updated.- Returns:
- Updated count.
-
updateSelective
@UpdateProvider(tech.yanand.flyingmybatis.AutoMapperProvider.class) int updateSelective(@Param("entity") E entity) Selectively update an entity by the ID. If a field in entity is passednullvalue, it will not be updated.- Parameters:
entity- The entity to be updated.- Returns:
- Updated count.
-
updateAllSelective
Selectively update entities by their ID. If a field in entity is passednullvalue, it will not be updated.- Parameters:
entities- Entities to be updated.- Returns:
- Updated count.
-