VIVO-1478 mysql driver throws exception (#69)

* VIVO-1478 Add time zone to the MySQL URL, to avoid an InvalidConnectionAttributeOption. 
* Go with proven driver version, rather than the most recent.
This commit is contained in:
Jim Blake 2018-05-04 10:44:43 -04:00 committed by Ben
parent efe8f265dc
commit b406f99fec
3 changed files with 51 additions and 39 deletions

View file

@ -52,6 +52,10 @@ public class SDBConnectionSmokeTests {
+ PROPERTY_DB_URL + "'"); + PROPERTY_DB_URL + "'");
return; return;
} }
// Get the full URL, with options.
url = SDBDataSource.getJdbcUrl(props);
String username = props.getProperty(PROPERTY_DB_USERNAME); String username = props.getProperty(PROPERTY_DB_USERNAME);
if (username == null || username.isEmpty()) { if (username == null || username.isEmpty()) {
ss.fatal("runtime.properties does not contain a value for '" ss.fatal("runtime.properties does not contain a value for '"

View file

@ -2,8 +2,6 @@
package edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb; package edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb;
import java.beans.PropertyVetoException;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -51,7 +49,7 @@ public class SDBDataSource {
public BasicDataSource getDataSource() { public BasicDataSource getDataSource() {
BasicDataSource cpds = new BasicDataSource(); BasicDataSource cpds = new BasicDataSource();
cpds.setDriverClassName(getDbDriverClassName()); cpds.setDriverClassName(getDbDriverClassName());
cpds.setUrl(getJdbcUrl()); cpds.setUrl(getJdbcUrl(configProps));
cpds.setUsername(configProps.getProperty(PROPERTY_DB_USERNAME)); cpds.setUsername(configProps.getProperty(PROPERTY_DB_USERNAME));
cpds.setPassword(configProps.getProperty(PROPERTY_DB_PASSWORD)); cpds.setPassword(configProps.getProperty(PROPERTY_DB_PASSWORD));
cpds.setMaxTotal(getMaxActive()); cpds.setMaxTotal(getMaxActive());
@ -75,41 +73,6 @@ public class SDBDataSource {
DEFAULT_DRIVER_CLASS); DEFAULT_DRIVER_CLASS);
} }
private String getDbType() {
return configProps.getProperty(PROPERTY_DB_TYPE, DEFAULT_TYPE);
}
private String getJdbcUrl() {
String url = configProps.getProperty(PROPERTY_DB_URL);
// Ensure that MySQL handles unicode properly, else all kinds of
// horrible nastiness ensues.
if (DEFAULT_TYPE.equals(getDbType())) {
if (!url.contains("?")) {
url += "?useUnicode=yes&characterEncoding=utf8&nullNamePatternMatchesAll=true&cachePrepStmts=true&useServerPrepStmts=true";
} else {
String urlLwr = url.toLowerCase();
if (!urlLwr.contains("useunicode")) {
url += "&useUnicode=yes";
}
if (!urlLwr.contains("characterencoding")) {
url += "&characterEncoding=utf8";
}
if (!urlLwr.contains("nullnamepatternmatchesall")) {
url += "&nullNamePatternMatchesAll=true";
}
if (!urlLwr.contains("cacheprepstmts")) {
url += "&cachePrepStmts=true";
}
if (!urlLwr.contains("useserverprepstmts")) {
url += "&useServerPrepStmts=true";
}
}
}
return url;
}
private String getValidationQuery() { private String getValidationQuery() {
return configProps.getProperty(PROPERTY_DB_VALIDATION_QUERY, return configProps.getProperty(PROPERTY_DB_VALIDATION_QUERY,
DEFAULT_VALIDATION_QUERY); DEFAULT_VALIDATION_QUERY);
@ -167,4 +130,49 @@ public class SDBDataSource {
return defaultValue; return defaultValue;
} }
} }
/**
* Get the JDBC URL, perhaps with special MySQL options.
*
* This must be static and package-accessible so SDBConnectionSmokeTests can
* use the same options.
*/
static String getJdbcUrl(ConfigurationProperties props) {
String url = props.getProperty(PROPERTY_DB_URL);
// Ensure that MySQL handles unicode properly, else all kinds of
// horrible nastiness ensues. Also, set some other handy options.
if (DEFAULT_TYPE.equals(getDbType(props))) {
if (!url.contains("?")) {
url += "?useUnicode=yes&characterEncoding=utf8&nullNamePatternMatchesAll=true&cachePrepStmts=true&useServerPrepStmts=true&serverTimezone=UTC";
} else {
String urlLwr = url.toLowerCase();
if (!urlLwr.contains("useunicode")) {
url += "&useUnicode=yes";
}
if (!urlLwr.contains("characterencoding")) {
url += "&characterEncoding=utf8";
}
if (!urlLwr.contains("nullnamepatternmatchesall")) {
url += "&nullNamePatternMatchesAll=true";
}
if (!urlLwr.contains("cacheprepstmts")) {
url += "&cachePrepStmts=true";
}
if (!urlLwr.contains("useserverprepstmts")) {
url += "&useServerPrepStmts=true";
}
if (!urlLwr.contains("servertimezone")) {
url += "&serverTimezone=UTC";
}
}
}
return url;
}
private static String getDbType(ConfigurationProperties props) {
return props.getProperty(PROPERTY_DB_TYPE, DEFAULT_TYPE);
}
} }

View file

@ -114,7 +114,7 @@
<dependency> <dependency>
<groupId>mysql</groupId> <groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId> <artifactId>mysql-connector-java</artifactId>
<version>6.0.6</version> <version>5.1.46</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.sf.jga</groupId> <groupId>net.sf.jga</groupId>