Hi Lukas, This is exactly what I was looking for, thank you for responding.
Regarding just using org.jooq.DAO: I am using it where I can, but perhaps my lack of JOOQ knowledge is causing me to run into some issues. I think I ran into a few things, one being I wasn't sure how to get the query granularity for sorting, limiting and ordering that I wanted to using the DAO methods. I haven't looked at this specifically in a while, so I could very well be missing something. So, my next questions are: 1. What would you recommend if I were to implement this using just org.jooq.DAO? Again, I'll go off on my own and do some more research on the generated DAO methods, but I'd like some expert input. 2. What needs to be used in place of the TABLE object in my code example? I can see situations where I'll want to drop straight into jooq queries and it would be helpful to be able to do that without having to duplicate code. Thanks again! On Tue, May 17, 2016 at 1:19 AM, Lukas Eder <[email protected]> wrote: > Hi Devin, > > I think you should introduce parametric polymorphism here, just like > org.jooq.DAO. Instead of your version, I'd write: > > public abstract class BaseService<P, R extends Record> { > > protected void create(P tableObject) { > R g = buildRecordObject(tableObject); > g.store(); > } > > protected void update(P tableObject) { > R g = buildGenericRecord(tableObject); > g.store(); > } > > protected void delete(P tableObject) { > R g = buildGenericRecord(tableObject); > g.delete(); > } > > protected P find(String slug) { > return dao().fetchOneBySlug(slug); > } > > public List<R> list(int pageNumber) { > pager = new Page(count()); > TABLE table = table(); > RecordMapper genericMapper = mapper(); > return sql.select() > .from(table) > .orderBy(table.CREATED_ON.desc()) > .limit(pageSize) > .offset(pager.offsetFromPage(pageNumber)) > .fetch(genericMapper); > } > > // these would need to be provided by the subclass > protected abstract R buildRecordObject(P tableObject); > > protected abstract TABLE table(); > > protected abstract BaseDao dao(); > > protected abstract RecordMapper mapper(); > } > > > But then again, why not just use the org.jooq.DAO from jOOQ, which already > does most of this? Quite possibly, though, the existing DAOs are lacking > features, so I'm very open to discussing potential new features that we > could add to them to make your life easier. > > Hope this helps, > Lukas > > > 2016-05-16 20:53 GMT+02:00 Devin Austin <[email protected]>: > >> Hi all, >> >> Currently, I'm generating my DAOs on build through maven with the jooq >> code generator. This saves me a lot of work on getting the methods I need >> for DAOs created. However, I have a "service" layer on top of those that I >> like to use for CRUD operations that calls either the appropriate DAO >> methods or if I need a little more granularity, dropping down into straight >> jooq queries. Most of the CRUD stuff is exactly the same for each of these >> classes, so it would be nice to have a base service class that implements >> these methods and leaves service layer specific queries to be defined in >> their respective classes. >> >> I'm relatively new to Java, but I've been programming for several years >> professionally. I'm struggling to determine how to create such a base >> class with the appropriate DAO/table class types such that they can be >> called in a subclass without much, or any, instantiation/modification. >> Here is a basic pseudo-example of what I'm talking about: >> https://gist.github.com/dhoss/539650094085c2ef152acab6d5884a0d >> >> I hope what I'm saying makes sense. Thanks in advance, and please let me >> know if I can provide anything else. >> >> -Devin >> >> -- >> You received this message because you are subscribed to the Google Groups >> "jOOQ User Group" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> For more options, visit https://groups.google.com/d/optout. >> > > -- > You received this message because you are subscribed to a topic in the > Google Groups "jOOQ User Group" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/jooq-user/KUPyMa2581g/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- Devin Austin https://www.stonecolddev.in -- You received this message because you are subscribed to the Google Groups "jOOQ User Group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
