Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 1 addition & 28 deletions framework/src/play/db/DBPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,9 @@ private boolean changed() {
String name = m.group("name");
String host = m.group("host");
String parameters = m.group("parameters");

Map<String, String> paramMap = new HashMap<>();
paramMap.put("useUnicode", "yes");
paramMap.put("characterEncoding", "UTF-8");
paramMap.put("connectionCollation", "utf8_general_ci");
addParameters(paramMap, parameters);

dbConfig.put("db.driver", "com.mysql.jdbc.Driver");
dbConfig.put("db.url", "jdbc:mysql://" + (host == null ? "localhost" : host) + "/" + name + "?" + toQueryString(paramMap));
dbConfig.put("db.url", "jdbc:mysql://" + (host == null ? "localhost" : host) + "/" + name + "?" + parameters);
if (user != null) {
dbConfig.put("db.user", user);
}
Expand Down Expand Up @@ -251,28 +245,7 @@ private boolean changed() {
}
return false;
}

private static void addParameters(Map<String, String> paramsMap, String urlQuery) {
if (!StringUtils.isBlank(urlQuery)) {
String[] params = urlQuery.split("[\\&]");
for (String param : params) {
String[] parts = param.split("[=]");
if (parts.length > 0 && !StringUtils.isBlank(parts[0])) {
paramsMap.put(parts[0], parts.length > 1 ? StringUtils.stripToNull(parts[1]) : null);
}
}
}
}

private static String toQueryString(Map<String, String> paramMap) {
StringBuilder builder = new StringBuilder();
for (Map.Entry<String, String> entry : paramMap.entrySet()) {
if (builder.length() > 0) builder.append("&");
builder.append(entry.getKey()).append("=").append(entry.getValue() != null ? entry.getValue() : "");
}
return builder.toString();
}

/**
* Needed because DriverManager will not load a driver ouside of the system classloader
*/
Expand Down