Skip to content

Commit

Permalink
preload mysql driver(may fix issues in some cases)
Browse files Browse the repository at this point in the history
  • Loading branch information
caoli5288 committed Nov 25, 2020
1 parent aca650b commit aa2fe8c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/mengcraft/simpleorm/EbeanHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ DataSource newDataSource() {
HikariDataSource source = new HikariDataSource();
source.setPoolName(name);
source.setConnectionTimeout(5_000);
source.setJdbcUrl(IDatabaseDriver.validAndLoad(url));
source.setJdbcUrl(IDatabaseDriver.filter(url));
source.setUsername(user);
source.setPassword(password);
source.setAutoCommit(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private void load() {
}
}

public static String validAndLoad(String jdbc) {
public static String filter(String jdbc) {
URI uri = URI.create(jdbc);
if (!Objects.equals(uri.getScheme(), "jdbc")) {
throw new IllegalArgumentException(jdbc + " is not valid jdbc url");
Expand All @@ -48,6 +48,7 @@ public static class Registry {
static {
register(new H2Driver());
register(new PostgreDriver());
register(new MySqlDriver());
}

private static void register(IDatabaseDriver driver) {
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/com/mengcraft/simpleorm/driver/MySqlDriver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.mengcraft.simpleorm.driver;

public class MySqlDriver extends IDatabaseDriver {

@Override
protected String clazz() {
return "com.mysql.jdbc.Driver";
}

@Override
protected String protocol() {
return "mysql";
}

@Override
protected String description() {
return "mysql:mysql-connector-java:jar:5.1.49";
}
}

0 comments on commit aa2fe8c

Please sign in to comment.