0
votes

I'm using Slick and Play together with the play-slick plugin and I'm having trouble figuring out if I can use the com.mysql.jdbc.ReplicationDriver with them. I want to use the master/slave features of that driver. When using Slick only, it seems to be as easy as passing in the driver as an argument to the "forUrl" method, but play-slick creates its connections differently. I've gone through the source to try and figure out what's happening but I've come up empty. Does anybody know if this can be done?

PS: This is what my configuration currently looks like:

db.default.url="jdbc:mysql:replication://master,slave/production?autoReconnectForPools=true&roundRobinLoadBalance=true&loadBalanceBlacklistTimeout=1000&readOnly=true"
db.default.driver=com.mysql.jdbc.ReplicationDriver
db.default.slickdriver=scala.slick.driver.MySQLDriver
db.default.user=root
db.default.password=""

When I looked through the Slick source its drivers just seemed to define how to structure data and queries and didn't include anything about actually connecting, so I kind of assumed I'd be able to tell play-slick to use that driver for slick and the replication driver for JDBC

Update: So it turns out the above configuration actually does seem to use the proper driver, the problem is I need to apply Connection.readOnly(true) for each database operation that occurs as explained here. I'm not sure how Play manages its connections, is there a way that I can do this?

Update 2 So I found the spot in the play framework's source where it gets JDBC connections but I'm not sure how to go about adding anything to that process. Would I have to fork the whole framework to accomplish this or is there a more sane way to do it?

1

1 Answers

0
votes

You may be able to extend Slick's MySQLDriver and override createSession of the contained val Database to always call readOnly on a connection. It may be a bit tricky if you are not used to nested traits in Scala and potential init order problems. Feel free to submit a PR to Slick that avoids them for your use case if necessary.