Skip to content

Instantly share code, notes, and snippets.

@xcesco
Created October 1, 2018 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xcesco/d70a0956a7426dfe62923802271492bb to your computer and use it in GitHub Desktop.
Save xcesco/d70a0956a7426dfe62923802271492bb to your computer and use it in GitHub Desktop.
@BindDao(Person.class)
public interface DaoPerson {
@BindSqlSelect(where = "name like ${name} || '%'")
PagedLiveData<List<Person>> selectPaged(String name);
@BindSqlInsert
void insert(Person bean);
@BindSqlUpdate(where = "id=${bean.id}")
void update(Person bean);
}
@Test
public void testRun() throws InterruptedException {
BindAppDataSource ds = BindAppDataSource.getInstance();
final PagedLiveData<List<Person>> liveData = ds.getDaoPerson().selectPaged("Manero");
liveData.observeForever(t -> {
log("--> Page %s -- size %s", liveData.getPage(), t.size());
});
ds.execute(daoFactory -> {
for (int i = 0; i < 100; i++) {
Person person = new Person();
person.name = "Manero" + i;
person.surname = "Tonj" + i;
daoFactory.getDaoPerson().insert(person);
}
return TransactionResult.COMMIT;
});
liveData.nextPage();
ds.execute(daoFactory -> {
Person person = new Person();
person.name = "Manero";
person.surname = "Tonj";
daoFactory.getDaoPerson().insert(person);
return TransactionResult.COMMIT;
});
liveData.createPageRequestBuilder().pageSize(41).offset(11).apply();
liveData.setOffset(liveData.getOffset() + 100);
liveData.setPage(1);
liveData.nextPage();
liveData.previousPage();
liveData.nextPage();
Thread.sleep(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment