package com.engine.organization.util.db;


import com.engine.organization.exception.OrganizationRunTimeException;
import weaver.conn.RecordSet;

public enum DBType implements DBOperateAdapter {
    MYSQL("mysql") {
        @Override
        public String like(String some) {
            return "like '%" + some + "%'";
        }

        @Override
        public String concat(String some) {
            return "concat(','," + some + ",',')";
        }
    },
    SQLSERVER("sqlserver") {
        @Override
        public String like(String some) {
            return "like '%" + some + "%'";
        }

        @Override
        public String concat(String some) {
            return "','+" + some + "+','";
        }
    },
    ORACLE("oracle") {
        @Override
        public String like(String some) {
            return "'%'||" + some + "||'%'";
        }

        @Override
        public String concat(String some) {
            return "',' ||" + some + "|| ','";
        }
    };

    private String dbtype;

    DBType(String dbtype) {
        this.dbtype = dbtype;
    }

    public static DBType get(String dbtype) {
        for (DBType t : DBType.values()) {
            if (t.dbtype.equalsIgnoreCase(dbtype)) {
                return t;
            }
        }
        throw new OrganizationRunTimeException("不支持的数据库类型");
    }

    public static boolean isOracle() {
        return DBType.get(new RecordSet().getDBType()).equals(DBType.ORACLE);
    }


}
