2016-05-26 20:15 GMT+02:00 Devin Austin <[email protected]>: > > I think at this point it's going to be easiest to sort of lump common > queries into service classes and use whatever available DAO methods get > generated. I've had a lot of success in the past just dropping down closer > to bare metal when features I want aren't immediately present in the > current layer. >
That certainly makes sense > Yes it is. I cannot seem to find the issue on GitHub right now, but it >> might be a nice feature. The only question is the same as the one above. >> Should we really expose the jOOQ API? > > > Please do let me know when/if you find it, and I'll be happy to fork and > submit PRs. I think it would at least be nice to have the ability to > either call something like .sort(COLUMN.asc()), or pass in a > "configuration" object that potentially contains limit, order by and group > by information, or pass in a parameter somehow. My background is mostly > ruby/perl, so I don't know how this even translates to Java but something > like this would be neat: .fetchAllBySlug(:order_by => 'created_on DESC'). > I realize there's not a clean way to implement anonymous maps in Java, but > it conveys my point, I think. > See, at some point, I stop understanding why we still need these DAOs if we end up writing our own query language that is *not* the ordinary jOOQ API :) It would be possible to pass lambdas to such a method, but I'm starting to feel uneasy about this - at least as long as we're talking about core code. What clients do in client code is entirely up to them, of course... > > How about implementing that using either a trigger, or the DDL "DEFAULT" >> clause? >> >> If you want to implement that on the jOOQ layer, the RecordListener SPI >> might be interesting to you, given that you intend to implement a CRUD >> layer anyway. >> > > I dug through my code and I actually have the default getting set in my > add() method. The problem I'm running into is still my mapper. Right > after I submitted my question regarding the mapping error, I had actually > implemented what you suggested for the generics, but it still doesn't like > my method signature (up to date code: > https://gist.github.com/dhoss/d40edcbfc111ad7604bc8ce0d3c9bdec): > [ERROR] Failed to execute goal > org.apache.maven.plugins:maven-compiler-plugin:3.2:compile > (default-compile) on project gallery: Compilation failure > [ERROR] > /home/devin/projects/lumos-gallery/gallery/src/main/java/com/lumos/service/BaseService.java:[73,14] > method map in interface org.jooq.Result<R> cannot be applied to given types; > [ERROR] required: org.jooq.RecordMapper<? super org.jooq.Record,E> > [ERROR] found: org.jooq.RecordMapper<R,P> > [ERROR] reason: cannot infer type-variable(s) E > [ERROR] (argument mismatch; org.jooq.RecordMapper<R,P> cannot be converted > to org.jooq.RecordMapper<? super org.jooq.Record,E>) > That's a different error. Note the subtle difference between: sql.select().from(table())...fetch() // Type is Result<Record> and sql.selectFrom(table())...fetch() // Type is Result<R> You obviously want the latter. At this point, I just need something that will turn the objects I get back > from jOOQ into my POJOs. It would be really neat if I could get the > "implement your own damn mapper" per table/service working. > Well, jOOQ uses generics. Writing API based on jOOQ requires studying generics. Inevitably :) But I know it can be hard at times. The compiler's error messages aren't always obvious when it comes to generic type errors. > Previously, I had each table service passing a lambda to fetch() (pulled > from here: > https://github.com/lukaseder/minitwit/blob/master/src/main/java/com/minitwit/dao/MessageDao.java#L69), > and that worked fine, but it doesn't lend itself very well to a base > service that individual table service classes can inherit default CRUD > methods from. I've been staring at this code for too long and am making > things convoluted in my head, so forgive me if I'm making this whole thing > too complicated, but making the record mapper piece generic enough, and > implemented in the correct spot is what's confusing me the most. Looking > through the docs, you can add one in your DSL context configuration ( > http://www.jooq.org/doc/3.7/manual/sql-execution/fetching/pojos-with-recordmapper-provider/), > but that looks like it's still expecting a distinct class name to > fetchInto(). You can also call .map() after .fetch() and pass it a record > mapper ( > http://www.jooq.org/doc/3.7/manual/sql-execution/fetching/recordmapper/), > which is what I'm trying to do, but running into the issue above. I'm > certainly open to more intelligent approaches. > > By the way, I'm going to write up a tutorial on all this once it gets > sorted out and I'm more than happy to contribute documentation if it fits > in anywhere. > That would be wonderful! I'd love to link to it from here: http://www.jooq.org/community -- 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.
