|
23 | 23 | * @author Mark Pollack |
24 | 24 | */ |
25 | 25 | public class MySqlJdbcUrlCreator extends AbstractJdbcUrlCreator { |
26 | | - public static final String MYSQL_SCHEME = "mysql"; |
27 | | - public static final String MARIADB_SCHEME = "mariadb"; |
28 | | - public static final String[] MYSQL_SCHEMES = new String[]{MYSQL_SCHEME, MARIADB_SCHEME}; |
29 | | - public static final String MYSQL_TAG = "mysql"; |
30 | | - public static final String MARIADB_TAG = "mariadb"; |
31 | | - public static final String[] MYSQL_TAGS = new String[]{MYSQL_TAG, MARIADB_TAG}; |
32 | | - public static final String MYSQL_LABEL = "mysql"; |
33 | | - public static final String MARIADB_LABEL = "mariadb"; |
34 | | - public static final String[] MYSQL_LABELS = new String[]{MYSQL_LABEL, MARIADB_LABEL}; |
35 | | - public static final String MYSQL_DRIVER_CLASS_NAME = "com.mysql.cj.jdbc.Driver"; |
36 | | - public static final String MARIADB_DRIVER_CLASS_NAME = "org.mariadb.jdbc.Driver"; |
| 26 | + public static final String MYSQL_SCHEME = "mysql"; |
| 27 | + public static final String MARIADB_SCHEME = "mariadb"; |
| 28 | + public static final String[] MYSQL_SCHEMES = new String[]{MYSQL_SCHEME, MARIADB_SCHEME}; |
| 29 | + public static final String MYSQL_TAG = "mysql"; |
| 30 | + public static final String MARIADB_TAG = "mariadb"; |
| 31 | + public static final String[] MYSQL_TAGS = new String[]{MYSQL_TAG, MARIADB_TAG}; |
| 32 | + public static final String MYSQL_LABEL = "mysql"; |
| 33 | + public static final String MARIADB_LABEL = "mariadb"; |
| 34 | + public static final String[] MYSQL_LABELS = new String[]{MYSQL_LABEL, MARIADB_LABEL}; |
| 35 | + public static final String MYSQL_DRIVER_CLASS_NAME = "com.mysql.cj.jdbc.Driver"; |
| 36 | + public static final String MARIADB_DRIVER_CLASS_NAME = "org.mariadb.jdbc.Driver"; |
37 | 37 |
|
38 | | - @Override |
39 | | - public boolean isDatabaseService(CfService cfService) { |
40 | | - return jdbcUrlMatchesScheme(cfService, MYSQL_SCHEMES) |
41 | | - || cfService.existsByTagIgnoreCase(MYSQL_TAGS) |
42 | | - || cfService.existsByLabelStartsWith(MYSQL_LABELS) |
43 | | - || cfService.existsByUriSchemeStartsWith(MYSQL_SCHEMES) |
44 | | - || cfService.existsByCredentialsContainsUriField(MYSQL_SCHEMES); |
45 | | - } |
| 38 | + @Override |
| 39 | + public boolean isDatabaseService(CfService cfService) { |
| 40 | + return jdbcUrlMatchesScheme(cfService, MYSQL_SCHEMES) |
| 41 | + || cfService.existsByTagIgnoreCase(MYSQL_TAGS) |
| 42 | + || cfService.existsByLabelStartsWith(MYSQL_LABELS) |
| 43 | + || cfService.existsByUriSchemeStartsWith(MYSQL_SCHEMES) |
| 44 | + || cfService.existsByCredentialsContainsUriField(MYSQL_SCHEMES); |
| 45 | + } |
46 | 46 |
|
47 | | - private boolean isMariaDbService(CfService cfService) { |
48 | | - return jdbcUrlMatchesScheme(cfService, MARIADB_SCHEME) |
49 | | - || cfService.existsByTagIgnoreCase(MARIADB_TAG) |
50 | | - || cfService.existsByLabelStartsWith(MARIADB_LABEL) |
51 | | - || cfService.existsByUriSchemeStartsWith(MARIADB_SCHEME) |
52 | | - || cfService.existsByCredentialsContainsUriField(MARIADB_SCHEME); |
53 | | - } |
| 47 | + private boolean isMariaDbService(CfService cfService) { |
| 48 | + return jdbcUrlMatchesScheme(cfService, MARIADB_SCHEME) |
| 49 | + || cfService.existsByTagIgnoreCase(MARIADB_TAG) |
| 50 | + || cfService.existsByLabelStartsWith(MARIADB_LABEL) |
| 51 | + || cfService.existsByUriSchemeStartsWith(MARIADB_SCHEME) |
| 52 | + || cfService.existsByCredentialsContainsUriField(MARIADB_SCHEME); |
| 53 | + } |
54 | 54 |
|
55 | | - @Override |
56 | | - public String getDriverClassName() { |
57 | | - String driverClassNameToUse; |
58 | | - try { |
59 | | - driverClassNameToUse = MARIADB_DRIVER_CLASS_NAME; |
60 | | - Class.forName(driverClassNameToUse, false, getClass().getClassLoader()); |
61 | | - } |
62 | | - catch (ClassNotFoundException e) { |
63 | | - try { |
64 | | - driverClassNameToUse = MYSQL_DRIVER_CLASS_NAME; |
65 | | - Class.forName(driverClassNameToUse, false, getClass().getClassLoader()); |
66 | | - } |
67 | | - catch (ClassNotFoundException e2) { |
68 | | - return null; |
69 | | - } |
70 | | - } |
71 | | - return driverClassNameToUse; |
72 | | - } |
| 55 | + @Override |
| 56 | + public String getDriverClassName() { |
| 57 | + String driverClassNameToUse; |
| 58 | + try { |
| 59 | + driverClassNameToUse = MARIADB_DRIVER_CLASS_NAME; |
| 60 | + Class.forName(driverClassNameToUse, false, getClass().getClassLoader()); |
| 61 | + } |
| 62 | + catch (ClassNotFoundException e) { |
| 63 | + try { |
| 64 | + driverClassNameToUse = MYSQL_DRIVER_CLASS_NAME; |
| 65 | + Class.forName(driverClassNameToUse, false, getClass().getClassLoader()); |
| 66 | + } |
| 67 | + catch (ClassNotFoundException e2) { |
| 68 | + return null; |
| 69 | + } |
| 70 | + } |
| 71 | + return driverClassNameToUse; |
| 72 | + } |
73 | 73 |
|
74 | | - @Override |
75 | | - public String createJdbcUrl(CfService cfService) { |
76 | | - CfCredentials cfCredentials = cfService.getCredentials(); |
77 | | - String jdbcUrl = (String) cfCredentials.getMap().get("jdbcUrl"); |
78 | | - if (jdbcUrl == null) { |
79 | | - jdbcUrl = buildJdbcUrlFromUriField(cfCredentials); |
80 | | - } |
81 | | - if (isMariaDbService(cfService) && getDriverClassName().equals(MARIADB_DRIVER_CLASS_NAME)) { |
82 | | - jdbcUrl = jdbcUrl.replaceFirst("^(jdbc:mysql)", "jdbc:mariadb"); |
83 | | - } |
84 | | - return jdbcUrl; |
85 | | - } |
| 74 | + @Override |
| 75 | + public String createJdbcUrl(CfService cfService) { |
| 76 | + CfCredentials cfCredentials = cfService.getCredentials(); |
| 77 | + String jdbcUrl = (String) cfCredentials.getMap().get("jdbcUrl"); |
| 78 | + if (jdbcUrl == null) { |
| 79 | + jdbcUrl = buildJdbcUrlFromUriField(cfCredentials); |
| 80 | + } |
| 81 | + if (isMariaDbService(cfService) && getDriverClassName().equals(MARIADB_DRIVER_CLASS_NAME)) { |
| 82 | + jdbcUrl = jdbcUrl.replaceFirst("^(jdbc:mysql)", "jdbc:mariadb"); |
| 83 | + } |
| 84 | + return jdbcUrl; |
| 85 | + } |
86 | 86 |
|
87 | | - @Override |
88 | | - public String buildJdbcUrlFromUriField(CfCredentials cfCredentials) { |
89 | | - UriInfo uriInfo = cfCredentials.getUriInfo(MYSQL_SCHEME); |
90 | | - return String.format("%s%s://%s%s/%s%s%s", JDBC_PREFIX, MYSQL_SCHEME, |
91 | | - uriInfo.getHost(), uriInfo.formatPort(), uriInfo.getPath(), |
92 | | - uriInfo.formatUserNameAndPasswordQuery(), uriInfo.formatQuery()); |
93 | | - } |
| 87 | + @Override |
| 88 | + public String buildJdbcUrlFromUriField(CfCredentials cfCredentials) { |
| 89 | + UriInfo uriInfo = cfCredentials.getUriInfo(MYSQL_SCHEME); |
| 90 | + return String.format("%s%s://%s%s/%s%s%s", JDBC_PREFIX, MYSQL_SCHEME, |
| 91 | + uriInfo.getHost(), uriInfo.formatPort(), uriInfo.getPath(), |
| 92 | + uriInfo.formatUserNameAndPasswordQuery(), uriInfo.formatQuery()); |
| 93 | + } |
94 | 94 | } |
0 commit comments