Hey Lukas, thanks for the reply!

I've already implemented JOOQ with HikariCP and i'm loving it! Just a few 
concerns and guidance on a few things. Would love your input to see if i'm 
doing this the right and efficient way.

This is the original method:

private static void loadUser(Client c) {
    ArrayList<LoginUser> players = new ArrayList<>(c.getCharacterSlots());

       final String sql = "SELECT `id` FROM `characters` WHERE `accountid` 
= ? AND `world` = ?";
        try (
                Connection con = Database.connection(); // JDBC
                PreparedStatement ps = con.prepareStatement(sql);) {
            ps.setInt(1, c.getAccountId());
            ps.setInt(2, c.getWorld());
            try (ResultSet rs = ps.executeQuery();) {
                while (rs.next()) {
                    players.add(LoginUser.load(c, rs.getInt(1)));
                }
            }

        // .... further source code
        } catch (SQLException ex) {
            LOG.log(Level.WARNING, "Could not load characters of account " + 
c.getAccountId(), ex);
        } finally {
            con.dispose(con, ps, rs);
        }
}


And this is my attempted conversion:

private static void loadUser(Client c) {
    ArrayList<LoginUser> players = new ArrayList<>(c.getCharacterSlots());

    final DataSource ds = connection(); // hikari connection pool
    final DSLContext ctx = DSL.using(ds, SQLDialect.MYSQL_8_0);

    for (Record record : ctx.select().from(CHARACTERS)
            .where(CHARACTERS.ACCOUNTID.contains(c.getAccountId()))
            .and(CHARACTERS.WORLD.contains(c.getWorld()))
            .fetch())
    {
            players.add(LoginUser.load(c, record.get(CHARACTERS.ID)));
    }
    //... further source code
}



Does this look right and efficient or Is there a better way to do this?

My 2nd concern is, about try/catch and closing connections. As you can see 
in the first example, I'm using try catch blocks AND i'm also manually 
closing all the open statements. In the 2nd example, if I don't include a 
try/catch would it still close the opened connections?
I think I was looking at one of your tutorials on github and saw something 
similar. Furthermore, is a try/catch/closing statements needed for other 
queries as well? (update, delete, etc) or does JOOQ handle those too?

Those are all the concerns I have for now haha, thanks a bunch!!!

On Monday, April 30, 2018 at 3:33:19 AM UTC-4, Lukas Eder wrote:
>
> Hello,
>
> I'll comment inline.
>
> 2018-04-28 8:44 GMT+02:00 xragons <[email protected] <javascript:>>:
>
>> Hello, I've been reading a lot of about JOOQ as well as hibernate and was 
>> wondering if I could get some information on whether JOOQ can do what my 
>> current application is doing with the regular MySQL JDCB.
>>
>
> Yes, everything you're doing with JDBC can be done with jOOQ.
>
> So would I be able to achieve all this efficiently with JOOQ?
>>
>
> Yes
>  
>
>> Would it be best in this case to use both JOOQ and Hibernate? Or would 
>> sticking with JOOQ be suffice enough for my needs based on the code above.
>>
>
> Your code can be migrated very easily to jOOQ as your code is SQL centric 
> and so is jOOQ (this is mostly the case with JDBC based applications). The 
> main differences between JDBC and jOOQ are listed here:
> https://www.jooq.org/doc/latest/manual/sql-execution/comparison-with-jdbc
>
> The most immediate effect is that your code will be a bit less verbose and 
> type safe.
>
> From what I've seen, Hibernate could also be an option, but would require 
> quite a bit of refactoring. If you've never used Hibernate, you'll have to 
> invest a bit of time in getting it right as well, or your performance might 
> degrade at first.
>  
>
>> Can JOOQ work with netbeans?
>>
>
> I don't see why not.
>  
>
>> I want to be able to easily write quries as well and I from what I read 
>> JOOQ does this well. The transition will be tough
>>
>
> I really don't think there's anything tough about transitioning from 
> JDBC-based applications to jOOQ based ones. It's a routine piece of work.
>
> Thanks a lot for those who made it down here! I appreciate it. Really hope 
>> posting code on this post isn't against the rules or something, 
>>
>
> There are no such rules :) Be our guest and welcome to the 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.

Reply via email to