setReadOnly

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

setReadOnly

Björn Raupach
Hi there,

is there way to set setReadOnly on the connection? Ideally as an attribute in the statement in the Mapper XML file. Then we could cherry pick which statements are eligible for reading from the slave and which are not. So before the statement is executed, actually before a transaction happens, set setReadOnly(true), run the statement and then set setReadOnly(false). Since Connections are usually pooled it makes no sense to toggle readOnly for a longer scope.

Background: As far as I understand we can distribute load among our master mysql and his slaves (lol), but we need to set the setReadOnly(true) on the connection.

Any ideas?

kind regards
Björn

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: setReadOnly

Björn Raupach
Ok, guess I am the only one. lol.

Lets say I implement this. PR possible? Anyone else thinks this is a nice feature to add?

On Wednesday, May 16, 2018 at 4:25:40 PM UTC+2, Björn Raupach wrote:
Hi there,

is there way to set setReadOnly on the connection? Ideally as an attribute in the statement in the Mapper XML file. Then we could cherry pick which statements are eligible for reading from the slave and which are not. So before the statement is executed, actually before a transaction happens, set setReadOnly(true), run the statement and then set setReadOnly(false). Since Connections are usually pooled it makes no sense to toggle readOnly for a longer scope.

Background: As far as I understand we can distribute load among our master mysql and his slaves (lol), but we need to set the setReadOnly(true) on the connection.

Any ideas?

kind regards
Björn

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re[2]: setReadOnly

Guy Rouillier-2
Both SqlSession and SqlSessionManager have a getConnection() method; you can then setReadOnly() on the returned Connection (standard JDBC method, nothing to do with MyBatis.)  This doesn't seem very secure, though.  If you really want to enforce readonly, you'd be better off creating a account in the database that only has SELECT privilege, and then creating a connection pool using those credentials.

--
Guy Rouillier

------ Original Message ------
From: "'Björn Raupach' via mybatis-user" <[hidden email]>
To: "mybatis-user" <[hidden email]>
Sent: 5/28/2018 3:38:30 AM
Subject: Re: setReadOnly

Ok, guess I am the only one. lol.

Lets say I implement this. PR possible? Anyone else thinks this is a nice feature to add?

On Wednesday, May 16, 2018 at 4:25:40 PM UTC+2, Björn Raupach wrote:
Hi there,

is there way to set setReadOnly on the connection? Ideally as an attribute in the statement in the Mapper XML file. Then we could cherry pick which statements are eligible for reading from the slave and which are not. So before the statement is executed, actually before a transaction happens, set setReadOnly(true), run the statement and then set setReadOnly(false). Since Connections are usually pooled it makes no sense to toggle readOnly for a longer scope.

Background: As far as I understand we can distribute load among our master mysql and his slaves (lol), but we need to set the setReadOnly(true) on the connection.

Any ideas?

kind regards
Björn

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: setReadOnly

Björn Raupach
Hi Guy,

thanks for getting in touch. It is not about security. Just a way to distribute load. From my understanding the cluster sends connection with the readOnly set to a slave instead of the master.

True, getConnection from SqlSession is simple enough. Just have to make sure I set it back to false in the finally block. That should work for now. I just thought this is maybe a common pattern. Guess not.

Björn

On 29. May 2018, at 07:19, Guy Rouillier <[hidden email]> wrote:

Both SqlSession and SqlSessionManager have a getConnection() method; you can then setReadOnly() on the returned Connection (standard JDBC method, nothing to do with MyBatis.)  This doesn't seem very secure, though.  If you really want to enforce readonly, you'd be better off creating a account in the database that only has SELECT privilege, and then creating a connection pool using those credentials.

--
Guy Rouillier

------ Original Message ------
From: "'Björn Raupach' via mybatis-user" <[hidden email]>
To: "mybatis-user" <[hidden email]>
Sent: 5/28/2018 3:38:30 AM
Subject: Re: setReadOnly

Ok, guess I am the only one. lol.

Lets say I implement this. PR possible? Anyone else thinks this is a nice feature to add?

On Wednesday, May 16, 2018 at 4:25:40 PM UTC+2, Björn Raupach wrote:
Hi there,

is there way to set setReadOnly on the connection? Ideally as an attribute in the statement in the Mapper XML file. Then we could cherry pick which statements are eligible for reading from the slave and which are not. So before the statement is executed, actually before a transaction happens, set setReadOnly(true), run the statement and then set setReadOnly(false). Since Connections are usually pooled it makes no sense to toggle readOnly for a longer scope.

Background: As far as I understand we can distribute load among our master mysql and his slaves (lol), but we need to set the setReadOnly(true) on the connection.

Any ideas?

kind regards
Björn


-- 
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.