How do I use PGConnectionPoolDataSource with DSL.using(...)?

Visto 88 veces
Saltar al primer mensaje no leído

Chris A

no leída,
24 ago 2022, 12:29:1324/8/22
a jOOQ User Group
For reference, MysqlConnectionPoolDataSource works with DSL.using() but PGConnectionPoolDataSource does not.

A quick look seems like MysqlConnectionPoolDataSource inherits from DataSource and CommonDataSource and PGConnectionPoolDataSource only from CommonDataSource.

Maybe DSL.using() should accept CommonDataSource instead of DataSource?


In either case, is there a good way to use the 3 argument DSL.using() that accepts Settings with PGConnectionPoolDataSource?



Lukas Eder

no leída,
25 ago 2022, 2:53:1125/8/22
a jOOQ User Group
Hi Chris,

Thanks for your message. Indeed, we could support that out of the box. We don't yet. I've created a feature request for this:

It's not really too hard to support it on your end, by implementing a ConnectionProvider and supplying jOOQ's DefaultConfiguration with that. Just correctly implement the acquire()/release() lifecycle, and you're all set.

I hope this helps,
Lukas

--
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 jooq-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jooq-user/99855e4d-8a02-4265-af36-f38bd71d3dcdn%40googlegroups.com.

Lukas Eder

no leída,
25 ago 2022, 2:57:0025/8/22
a jOOQ User Group
Of course, you could also just use a third party, such as Hikari, to handle the pooling for you, rather than using the JDBC driver's:

vahid Saber

no leída,
2 mar 2023, 7:09:302/3/23
a jOOQ User Group
Hi Lukas,
Can you elaborate why we should use a third party library instead of PGConnectionPoolDataSource ? Are they used for different purposes?
I have heard nice things about HikariCP and I have used it before. But I am still unable to enumerate the answers for this valid question.
I know 
PGPoolingDataSource (not PGConnectionPoolDataSource) is deprecated, and I have seen its short argument in pgjdbc. But, does that also apply to PGConnectionPoolDataSource?

Vahid

Lukas Eder

no leída,
2 mar 2023, 7:18:242/3/23
a jooq...@googlegroups.com
Sure, just read all the things e.g. HikariCP does:

Now, check out the source code of PGConnectionPoolDataSource:

Specifically, getConnection:

  public Connection getConnection(@Nullable String user, @Nullable String password)
      throws SQLException {
    try {
      Connection con = DriverManager.getConnection(getUrl(), user, password);
      if (LOGGER.isLoggable(Level.FINE)) {
        LOGGER.log(Level.FINE, "Created a {0} for {1} at {2}",
            new Object[] {getDescription(), user, getUrl()});
      }
      return con;
    } catch (SQLException e) {
      LOGGER.log(Level.FINE, "Failed to create a {0} for {1} at {2}: {3}",
          new Object[] {getDescription(), user, getUrl(), e});
      throw e;
    }
  }

You will immediately see that it is not an actual ConnectionPool.

Now, there's the deprecated PGPoolingDataSource, which says:
Don't use this if your server/middleware vendor provides a connection pooling implementation which interfaces with the PostgreSQL ConnectionPoolDataSource implementation

So, with this information, I'm positive you can make an informed decision about what to do?

Anyway. None of this is jOOQ specific. You'll do the same thing if you're using jOOQ, Hibernate, JDBC directly, MyBatis, or whatever.

Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos