I have a Java application that connects to our Amazon RDS MySQL via Spring AWS JDBC module to use readonly replicas for read only transactions. I use NamedParameterJdbcTemplate to execute INSERT INTO... ON DUPLICATE KEY UPDATE ... command. In MySQL JDBC driver there is a small bug that when executing the following code:
int rowsChanged = jdbcTemplate.update(INSERT_OR_UPDATE_SQL, params);
It returns incorrect value in rowsChanged. To overcome this issue I need to add useAffectedRows=true
in JDBC URL. For the pure MySQL and regular Datasource definition this works perfectly. But Spring AWS JDBC implementation hides the real JDBC URL generation. I tried to override MapBasedDatabasePlatformSupport class and in its getDatabaseUrlForDatabase method, and when generating the URI I hardcoded useAffectedRows=true
in the URI class constructor query parameter. Before I put it on the AWS, I'd like to verify that my solution is correct.
So my question is: Am I doing the right thing? If not, what is a better/the best way to do it in Spring AWS JDBC?
Thanks in advance, Alex
Aucun commentaire:
Enregistrer un commentaire