Connection re-use with MySql withConnection API

65 views
Skip to first unread message

Chandramouli Rangarajan

unread,
Mar 30, 2021, 1:49:04 PM3/30/21
to ve...@googlegroups.com
Hello, I'm using the vertx MySql (non-jdbc) client with the withConnection() API. 
I was wondering if there's a way to figure out if the connection obtained from withConnection is a newly established connection, or an existing one.

Currently, the underlying connection is always wrapped in a new MySqlConnectionImpl object even if the underlying "conn" is the same, and there is no way to determine the above. 

Is it possible to add a "isReused" or a similar API to achieve this? (alternatively, is there a way to do it currently).

Thanks a lot for your support


--
--Chandramouli

Julien Viet

unread,
Mar 31, 2021, 3:25:35 AM3/31/21
to vert.x
Hi,

what is your use case ? perform some initialization of the connection ?

Julien

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/CAJWMOKpjQAz29V_%3DHx2v5cnR6TNNOGb2A87qrkaS-VnH-Uxaqw%40mail.gmail.com.

Chandra R.

unread,
Mar 31, 2021, 1:30:54 PM3/31/21
to vert.x
Hi, there are a couple of use-cases.
1) To maintain some metadata/state per connection (which will be discarded on connection close by supplying a closeHandler).
2) To keep track of how many new connections are created v/s re-used on the client

The primary reason why this came up is the following:
I'm trying to set some session/connection parameters with a mysql backend, which would have traditionally been done by supplying "sessionVariables" query parameter
as part of jdbcUrlParams. Since I'm not able to do this with the MySqlClient, the alternative is to use withConnection, and then send a "SET" before performing every query on that connection.
In order to avoid doing this, one approach is that I maintain some state per connection in the application, and only send the "SET" command if the connection is a newly established one.
I realized later that I can also use the state to keep track of new v/s re-used connections etc.

Julien Viet

unread,
Apr 1, 2021, 3:50:32 AM4/1/21
to vert.x
we are currently working on the new connection pool for SQL client and we shall provide a connection initializer that would allow one to perform an action before the connection is inserted in the pool after it has been created.

how does that sound to you ?

Chandramouli Rangarajan

unread,
Apr 4, 2021, 3:09:30 PM4/4/21
to ve...@googlegroups.com
Thank you, that sounds good. Also, is
there any plan to support mysql connection parameters (similar to jdbc url params)?

You received this message because you are subscribed to a topic in the Google Groups "vert.x" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vertx/Zvxl_KMFb9M/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vertx+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/CA%2BH-X4964qX9Q-6FRWK0fm%3D9uDKLLAn2tCPfEHgfB0N2oLcYKQ%40mail.gmail.com.
--
--Chandramouli
Reply all
Reply to author
Forward
0 new messages