package com.zte.ums.beas.base.datasource;
import java.util.Properties;
public enum Database implements DataSourceProtocolType {
ORACLE(0, "oracle") {
@Override
public String getUrl(String ip, String port, String dbName) {
return "jdbc:oracle:thin:@" + ip + ":" + port + ":" + dbName;
}
@Override
public String getDriverName() {
return "oracle.jdbc.driver.OracleDriver";
}
},
MYSQL(0, "mysql") {
@Override
public String getUrl(String ip, String port, String dbName) {
return "jdbc:mysql://" + ip + ":" + port + "/" + dbName + "?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull";
}
@Override
public String getDriverName() {
return "com.mysql.jdbc.Driver";
}
},
IMPALA(0, "impala") {
@Override
public String getUrl(String ip, String port, String dbName) {
return "jdbc:hive2://" + ip + ":" + port + "/" + dbName;
}
@Override
public String getDriverName() {
return "org.apache.hive.jdbc.HiveDriver";
}
@Override
public Properties getConnectProperties(String userName, String password, int flag) {
ImpalaAuthType authType = ImpalaAuthType.fromValue(flag);
Properties info = new Properties();
switch (authType) {
case NOAUTH:
info.put("auth", "noSasl");
break;
case KERBEROS:
info.put("auth", password);
break;
case LDAP:
info.put("user", userName);
info.put("password", password);
break;
default:
info.put("auth", "noSasl");
}
return info;
}
},
DB2(0, "db2") {
@Override
public String getUrl(String ip, String port, String dbName) {
return String.format("jdbc:db2://%s:%s/%s", ip, port, dbName);
}
@Override
public String getDriverName() {
return "com.ibm.db2.jcc.DB2Driver";
}
},
SYBASEASE(0, "sybaseASE") {
@Override
public String getUrl(String ip, String port, String dbName) {
return "jdbc:sybase:Tds:" + ip + ":" + port + "/" + dbName;
}
@Override
public String getDriverName() {
return "com.sybase.jdbc3.jdbc.SybDriver";
}
},
SQLSERVER(0, "sqlserver") {
@Override
public String getUrl(String ip, String port, String dbName) {
return "jdbc:sqlserver://" + ip + ":" + port + ";databaseName=" + dbName;
}
@Override
public String getDriverName() {
return "com.microsoft.sqlserver.jdbc.SQLServerDriver";
}
};
private int mark;
private String name;
public int getMark() {
return mark;
}
public String getName() {
return name;
}
private Database(int mark, String name) {
this.mark = mark;
this.name = name;
}
public static Database fromValue(String dbType) {
for (Database e : values()) {
if (e.getName().equalsIgnoreCase(dbType)) {
return e;
}
}
//throw new IllegalArgumentException("Not supported DB type:" + dbType);
return null;
}
public abstract String getUrl(String ip, String port, String dbName);
public abstract String getDriverName();
public Properties getConnectProperties(String userName, String password, int flag) {
Properties info = new Properties();
info.put("user", userName);
info.put("password", password);
return info;
}
@Override
public boolean match(int resourceShareType) {
return resourceShareType == getMark();
}
}