Skip to content

Examples

Christian Meyer edited this page Dec 26, 2020 · 3 revisions

Java

public class MyTestRepo extends CRUDService<TestRecord, Long, TestDomain> {
    
    private DSLContext dslContext;
    
    public MyTestRepo(DSLContext dslContext) {
        this.dslContext = dslContext;
    }

    // create, update, delete, exists and other methods are now available in a typesafe way

    public String findNameWhereIsActive() {
        return fetchOptionalWhere(TEST.NAME, TEST.NAME::isActive).orElseThrow(() -> new NotFoundException(name + " not found"));
    }
    
}

Kotlin

class MyTestRepo(dslContext: DSLContext): CRUDService<TestRecord, Long, TestDomain>(dslContext) {

    // create, update, delete, exists and other methods are now available in a typesafe way

    fun findNameWhereIsActive(): String {
        return fetchOneWhere(TEST.NAME) {
            TEST.NAME.isActive()
        } ?: throw NotFoundException("$name not found")
    }

}

Clone this wiki locally