Created
October 1, 2018 11:57
-
-
Save xcesco/d70a0956a7426dfe62923802271492bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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