@@ -18,7 +18,7 @@ public final class JdbcUtil {
1818
1919 private static final org .slf4j .Logger logger = LoggerFactory .getLogger (JdbcUtil .class );
2020
21- protected static final Pattern jdbcUrlPattern = Pattern .compile ("jdbc:([^:]+):" );
21+ protected static final Pattern jdbcUrlPattern = Pattern .compile ("jdbc:([^:]+):(([^:]+)?:)? " );
2222
2323 public static Connection getConnection (DataSource dataSource ) {
2424 try {
@@ -77,8 +77,8 @@ public static void close(ResultSet resultSet) {
7777 public static String inferDialectName (String url ) {
7878 return match (
7979 url ,
80- name -> {
81- switch (name ) {
80+ names -> {
81+ switch (names . getFirst () ) {
8282 case "h2" :
8383 return "h2" ;
8484 case "hsqldb" :
@@ -105,15 +105,18 @@ public static String inferDialectName(String url) {
105105 public static String inferDriverClassName (String url ) {
106106 return match (
107107 url ,
108- name -> {
109- switch (name ) {
108+ names -> {
109+ switch (names . getFirst () ) {
110110 case "h2" :
111111 return "org.h2.Driver" ;
112112 case "hsqldb" :
113113 return "org.hsqldb.jdbc.JDBCDriver" ;
114114 case "sqlite" :
115115 return "org.sqlite.JDBC" ;
116116 case "mysql" :
117+ if ("aws" .equals (names .getSecond ())) {
118+ return "software.aws.rds.jdbc.mysql.Driver" ;
119+ }
117120 return "com.mysql.cj.jdbc.Driver" ;
118121 case "mariadb" :
119122 return "org.mariadb.jdbc.Driver" ;
@@ -131,14 +134,15 @@ public static String inferDriverClassName(String url) {
131134 });
132135 }
133136
134- protected static <R > R match (String url , Function <String , R > mapper ) {
137+ protected static <R > R match (String url , Function <Pair < String , String > , R > mapper ) {
135138 if (url == null ) {
136139 throw new CodeGenNullPointerException ("url" );
137140 }
138141 Matcher matcher = jdbcUrlPattern .matcher (url );
139142 if (matcher .lookingAt ()) {
140- String name = matcher .group (1 );
141- return mapper .apply (name );
143+ String first = matcher .group (1 );
144+ String second = matcher .group (3 );
145+ return mapper .apply (new Pair <>(first , second ));
142146 }
143147 return null ;
144148 }
0 commit comments