|
| 1 | +/* |
| 2 | + * << |
| 3 | + * Davinci |
| 4 | + * == |
| 5 | + * Copyright (C) 2016 - 2019 EDP |
| 6 | + * == |
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | + * you may not use this file except in compliance with the License. |
| 9 | + * You may obtain a copy of the License at |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + * >> |
| 17 | + * |
| 18 | + */ |
| 19 | + |
| 20 | +package me.zhengjie.modules.mnt.util; |
| 21 | + |
| 22 | +import lombok.extern.slf4j.Slf4j; |
| 23 | + |
| 24 | +@Slf4j |
| 25 | +public enum DataTypeEnum { |
| 26 | + |
| 27 | + MYSQL("mysql", "mysql", "com.mysql.jdbc.Driver", "`", "`", "'", "'"), |
| 28 | + |
| 29 | + ORACLE("oracle", "oracle", "oracle.jdbc.driver.OracleDriver", "\"", "\"", "\"", "\""), |
| 30 | + |
| 31 | + SQLSERVER("sqlserver", "sqlserver", "com.microsoft.sqlserver.jdbc.SQLServerDriver", "\"", "\"", "\"", "\""), |
| 32 | + |
| 33 | + H2("h2", "h2", "org.h2.Driver", "`", "`", "\"", "\""), |
| 34 | + |
| 35 | + PHOENIX("phoenix", "hbase phoenix", "org.apache.phoenix.jdbc.PhoenixDriver", "", "", "\"", "\""), |
| 36 | + |
| 37 | + MONGODB("mongo", "mongodb", "mongodb.jdbc.MongoDriver", "`", "`", "\"", "\""), |
| 38 | + |
| 39 | + ELASTICSEARCH("sql4es", "elasticsearch", "nl.anchormen.sql4es.jdbc.ESDriver", "", "", "'", "'"), |
| 40 | + |
| 41 | + PRESTO("presto", "presto", "com.facebook.presto.jdbc.PrestoDriver", "", "", "\"", "\""), |
| 42 | + |
| 43 | + MOONBOX("moonbox", "moonbox", "moonbox.jdbc.MbDriver", "`", "`", "`", "`"), |
| 44 | + |
| 45 | + CASSANDRA("cassandra", "cassandra", "com.github.adejanovski.cassandra.jdbc.CassandraDriver", "", "", "'", "'"), |
| 46 | + |
| 47 | + CLICKHOUSE("clickhouse", "clickhouse", "ru.yandex.clickhouse.ClickHouseDriver", "", "", "\"", "\""), |
| 48 | + |
| 49 | + KYLIN("kylin", "kylin", "org.apache.kylin.jdbc.Driver", "\"", "\"", "\"", "\""), |
| 50 | + |
| 51 | + VERTICA("vertica", "vertica", "com.vertica.jdbc.Driver", "", "", "'", "'"), |
| 52 | + |
| 53 | + HANA("sap", "sap hana", "com.sap.db.jdbc.Driver", "", "", "'", "'"), |
| 54 | + |
| 55 | + IMPALA("impala", "impala", "com.cloudera.impala.jdbc41.Driver", "", "", "'", "'"); |
| 56 | + |
| 57 | + |
| 58 | + private String feature; |
| 59 | + private String desc; |
| 60 | + private String driver; |
| 61 | + private String keywordPrefix; |
| 62 | + private String keywordSuffix; |
| 63 | + private String aliasPrefix; |
| 64 | + private String aliasSuffix; |
| 65 | + |
| 66 | + private static final String jdbcUrlPrefix = "jdbc:"; |
| 67 | + |
| 68 | + DataTypeEnum(String feature, String desc, String driver, String keywordPrefix, String keywordSuffix, String aliasPrefix, String aliasSuffix) { |
| 69 | + this.feature = feature; |
| 70 | + this.desc = desc; |
| 71 | + this.driver = driver; |
| 72 | + this.keywordPrefix = keywordPrefix; |
| 73 | + this.keywordSuffix = keywordSuffix; |
| 74 | + this.aliasPrefix = aliasPrefix; |
| 75 | + this.aliasSuffix = aliasSuffix; |
| 76 | + } |
| 77 | + |
| 78 | + public static DataTypeEnum urlOf(String jdbcUrl) { |
| 79 | + String url = jdbcUrl.toLowerCase().trim(); |
| 80 | + for (DataTypeEnum dataTypeEnum : values()) { |
| 81 | + if (url.startsWith(jdbcUrlPrefix + dataTypeEnum.feature)) { |
| 82 | + try { |
| 83 | + Class<?> aClass = Class.forName(dataTypeEnum.getDriver()); |
| 84 | + if (null == aClass) { |
| 85 | + throw new RuntimeException("Unable to get driver instance for jdbcUrl: " + jdbcUrl); |
| 86 | + } |
| 87 | + } catch (ClassNotFoundException e) { |
| 88 | + throw new RuntimeException("Unable to get driver instance: " + jdbcUrl); |
| 89 | + } |
| 90 | + return dataTypeEnum; |
| 91 | + } |
| 92 | + } |
| 93 | + return null; |
| 94 | + } |
| 95 | + |
| 96 | + public String getFeature() { |
| 97 | + return feature; |
| 98 | + } |
| 99 | + |
| 100 | + public String getDesc() { |
| 101 | + return desc; |
| 102 | + } |
| 103 | + |
| 104 | + public String getDriver() { |
| 105 | + return driver; |
| 106 | + } |
| 107 | + |
| 108 | + public String getKeywordPrefix() { |
| 109 | + return keywordPrefix; |
| 110 | + } |
| 111 | + |
| 112 | + public String getKeywordSuffix() { |
| 113 | + return keywordSuffix; |
| 114 | + } |
| 115 | + |
| 116 | + public String getAliasPrefix() { |
| 117 | + return aliasPrefix; |
| 118 | + } |
| 119 | + |
| 120 | + public String getAliasSuffix() { |
| 121 | + return aliasSuffix; |
| 122 | + } |
| 123 | +} |
0 commit comments