⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dictionary.java

📁 信息发布 发布系统 动态的菜单 和 信息统计
💻 JAVA
字号:
package com.xuntian.material.sql;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.xuntian.material.data.dao.Transaction;
import com.xuntian.material.data.idao.TransactionManager;
import com.xuntian.material.exception.ConnectPoolException;
import com.xuntian.material.util.LogUtil;

public final class Dictionary {
    public static String DICT_GROUP_SUB_COMPANY = "-1";

    public static String DICT_GROUP_ITEM_DEPARTMENT = "-2";

    public static String DICT_GROUP_MATERIAL_DEPARTMENT = "-3";

    public static String TABLE = "mat_dictionary";

    public static String COLUMN_ID = "dict_id";

    public static String COLUMN_TABLE = "dict_table";

    public static String COLUMN_COLUMN = "dict_column";

    public static String COLUMN_CODE = "dict_code";

    public static String COLUMN_NAME = "dict_name";

    private static Map<String, Map<Integer, String>> dictMap = new HashMap<String, Map<Integer, String>>();

    private static String SELECT_DICTIONARY_SQL = "SELECT " + COLUMN_TABLE
            + ", " + COLUMN_COLUMN + ", " + COLUMN_CODE + ", " + COLUMN_NAME
            + " FROM " + TABLE;

    private static Dictionary dictionary = new Dictionary();

    public static final List<String> getSelectYearOptions() {
        List<String> year = new ArrayList<String>(51);
        for (int i = 2004; i <= 2020; i++) {
            year.add(String.valueOf(i));
        }
        return year;
    }

    public static final List<String> getSelectMonthOptions() {
        List<String> month = new ArrayList<String>(12);
        for (int i = 1; i <= 12; i++) {
            month.add(i < 10 ? "0" + i : String.valueOf(i));
        }
        return month;
    }

    private Dictionary() {
        try {
            init();
        } catch (ConnectPoolException cpe) {
            LogUtil.getLogger(Dictionary.class)
                    .error("connecion pool is error");
        } catch (SQLException e) {
            LogUtil.getLogger(Dictionary.class).error(
                    "iterator the SELECT_DICTIONARY_SQL result error");
        }
    }

    public static final Dictionary getInstance() {
        return dictionary;
    }

    public Map<Integer, String> getDictionary(String table, String column) {
        return dictMap.get(table + "." + column);
    }

    private void init() throws ConnectPoolException, SQLException {
        TransactionManager trans = Transaction.getInstance();
        ResultSet rs = trans.executeQuery(SELECT_DICTIONARY_SQL);
        String key = "", name = "";
        int code = 0;
        Map<Integer, String> dict;
        while (rs.next()) {
            key = rs.getString(COLUMN_TABLE) + "."
                    + rs.getString(COLUMN_COLUMN);
            dict = dictMap.get(key);
            if (dict == null) {
                dict = new HashMap<Integer, String>();
                dictMap.put(key, dict);
            }
            code = rs.getInt(COLUMN_CODE);
            name = rs.getString(COLUMN_NAME);
            dict.put(new Integer(code), name);
        }
        rs.close();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -