• enum


    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();
    }
    }

  • 相关阅读:
    WPF多线程问题
    SQL 使用经验
    [转]express 路由控制--next
    [转]浅谈Web缓存
    [转]一份优秀的前端开发工程师简历是怎么样的?
    http
    [转]HTTP详解(1)-工作原理
    [转]使用Flexible实现手淘H5页面的终端适配
    [转]理解$watch ,$apply 和 $digest --- 理解数据绑定过程
    GMT时间
  • 原文地址:https://www.cnblogs.com/hyp5490-/p/6376636.html
Copyright © 2020-2023  润新知