Search in sources :

Example 36 with MetaData

use of net.heartsome.cat.common.bean.MetaData in project translationstudio8 by heartsome.

the class OperateSystemDBImpl method addSysDb.

public void addSysDb(String dbName, String quality, int type) {
    MetaData data = null;
    try {
        data = (MetaData) metaData.clone();
        data.setDatabaseName(Constants.HSSYSDB);
    } catch (CloneNotSupportedException e) {
        LOGGER.warn("", e);
        return;
    }
    String driver = dbConfig.getDriver();
    String url = Utils.replaceParams(dbConfig.getDbURL(), data);
    url = url.replace("__FILE_SEPARATOR__", File.separator);
    Properties prop = Utils.replaceParams(dbConfig.getConfigProperty(), data);
    PreparedStatement stmt = null;
    try {
        conn = getConnection(driver, url, prop);
        String insertDb = Utils.replaceParams(dbConfig.getInsertSysDb(), data);
        stmt = conn.prepareStatement(insertDb);
        stmt.setString(1, dbName);
        stmt.setString(2, quality);
        stmt.setInt(3, type);
        stmt.execute();
    } catch (ClassNotFoundException e) {
        LOGGER.warn("", e);
    } catch (SQLException e) {
        LOGGER.warn("", e);
    } finally {
        freeConnection(stmt, conn);
    }
}
Also used : SQLException(java.sql.SQLException) MetaData(net.heartsome.cat.common.bean.MetaData) PreparedStatement(java.sql.PreparedStatement) Properties(java.util.Properties)

Example 37 with MetaData

use of net.heartsome.cat.common.bean.MetaData in project translationstudio8 by heartsome.

the class TmDbManagerDialog method searchCurrServerDatabase.

private List<DatabaseManagerDbListBean> searchCurrServerDatabase(SystemDBOperator sysDbOp, DatabaseModelBean currServer) {
    List<DatabaseManagerDbListBean> temp = new ArrayList<DatabaseManagerDbListBean>();
    // 检查是否创建了系统库
    if (!sysDbOp.checkSysDb()) {
        // MessageDialog.openInformation(getShell(), "提示信息",
        // "当前服务器上没有创建任何库");
        setLastSelectedServer(null);
        return null;
    }
    // 检查是否创建了库
    List<String> dbNames = sysDbOp.getSysDbNames(Constants.DB_TYPE_TM);
    if (dbNames.size() == 0) {
        // MessageDialog.openInformation(getShell(), "提示信息",
        // "当前服务器上没有创建任何库");
        setLastSelectedServer(null);
        return null;
    }
    // 获取数据库相关资料,封装了库名称和语言
    MetaData metaData = currServer.toDbMetaData();
    DBOperator dbop = DatabaseService.getDBOperator(metaData);
    for (int i = 0; i < dbNames.size(); i++) {
        DatabaseManagerDbListBean bean = new DatabaseManagerDbListBean();
        String dbName = dbNames.get(i);
        bean.setIndex(i + 1 + "");
        bean.setDbName(dbName);
        metaData.setDatabaseName(dbName);
        dbop.setMetaData(metaData);
        String lang = "";
        try {
            dbop.start();
            List<String> langs = dbop.getLanguages();
            for (int j = 0; j < langs.size(); j++) {
                lang += langs.get(j);
                if (j != langs.size() - 1) {
                    lang += ", ";
                }
            }
        } catch (Exception e1) {
            logger.error("", e1);
            continue;
        } finally {
            try {
                if (dbop != null) {
                    dbop.end();
                }
            } catch (SQLException e) {
                logger.error("", e);
            }
        }
        if (lang.equals("")) {
            bean.setLangs(Messages.getString("dialog.TmDbManagerDialog.msg10"));
        } else {
            bean.setLangs(lang);
        }
        temp.add(bean);
    }
    return temp;
}
Also used : SQLException(java.sql.SQLException) DatabaseManagerDbListBean(net.heartsome.cat.database.ui.bean.DatabaseManagerDbListBean) MetaData(net.heartsome.cat.common.bean.MetaData) ArrayList(java.util.ArrayList) SystemDBOperator(net.heartsome.cat.database.SystemDBOperator) DBOperator(net.heartsome.cat.database.DBOperator) Point(org.eclipse.swt.graphics.Point) SQLException(java.sql.SQLException)

Example 38 with MetaData

use of net.heartsome.cat.common.bean.MetaData in project translationstudio8 by heartsome.

the class DatabaseService method getSystemSuportDbMetaData.

/**
	 * 获取系统支持数据库的元数据
	 * @return ;
	 */
public static Map<String, MetaData> getSystemSuportDbMetaData() {
    Map<String, MetaData> map = new HashMap<String, MetaData>();
    List<SystemDBOperator> sysDbOp = getSystemDbOperaterList();
    for (int i = 0; i < sysDbOp.size(); i++) {
        SystemDBOperator dbOp = sysDbOp.get(i);
        map.put(dbOp.getMetaData().getDbType(), dbOp.getMetaData());
    }
    return map;
}
Also used : SystemDBOperator(net.heartsome.cat.database.SystemDBOperator) HashMap(java.util.HashMap) MetaData(net.heartsome.cat.common.bean.MetaData)

Example 39 with MetaData

use of net.heartsome.cat.common.bean.MetaData in project translationstudio8 by heartsome.

the class SystemDBOperator method getSysDbNames.

/**
	 * 得到系统库中的存储的数据库名称
	 * @return
	 * @throws SQLException
	 */
public List<String> getSysDbNames(int type) {
    MetaData data = null;
    try {
        data = (MetaData) metaData.clone();
        data.setDatabaseName(Constants.HSSYSDB);
    } catch (CloneNotSupportedException e) {
        logger.warn("", e);
        return null;
    }
    String driver = dbConfig.getDriver();
    String url = Utils.replaceParams(dbConfig.getDbURL(), data);
    Properties prop = Utils.replaceParams(dbConfig.getConfigProperty(), data);
    Connection conn = null;
    PreparedStatement stmt = null;
    ResultSet rs = null;
    List<String> result = new ArrayList<String>();
    try {
        conn = getConnection(driver, url, prop);
        String sql = dbConfig.getSysDbList();
        stmt = conn.prepareStatement(sql);
        stmt.setInt(1, type);
        rs = stmt.executeQuery();
        while (rs.next()) {
            result.add(rs.getString("DBNAME"));
        }
    } catch (ClassNotFoundException e) {
        logger.warn("", e);
    } catch (SQLException e) {
        logger.warn("", e);
    } finally {
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                logger.warn("", e);
            }
        }
        freeConnection(stmt, conn);
    }
    return result;
}
Also used : SQLException(java.sql.SQLException) MetaData(net.heartsome.cat.common.bean.MetaData) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) Properties(java.util.Properties)

Example 40 with MetaData

use of net.heartsome.cat.common.bean.MetaData in project translationstudio8 by heartsome.

the class DatabaseService method getSysDbOperateByMetaData.

/**
	 * 通过数据库元数据库获取数据库连接,主要取数据库类型
	 * @param metaData
	 * @return ;
	 */
public static SystemDBOperator getSysDbOperateByMetaData(MetaData metaData) {
    @SuppressWarnings({ "rawtypes", "unchecked" }) ServiceTracker tracker = new ServiceTracker(Activator.context, DBServiceProvider.class.getName(), null);
    tracker.open();
    try {
        Object[] services = tracker.getServices();
        for (Object i : services) {
            DBServiceProvider serviceProvider = (DBServiceProvider) i;
            SystemDBOperator temp = serviceProvider.getOperateDBInstance();
            if (temp == null) {
                continue;
            }
            MetaData tempMetaData = temp.getMetaData();
            if (tempMetaData.getDbType().equals(metaData.getDbType())) {
                tempMetaData.setDatabaseName(metaData.getDatabaseName());
                tempMetaData.setDataPath(metaData.getDataPath());
                tempMetaData.setInstance(metaData.getInstance());
                tempMetaData.setPassword(metaData.getPassword());
                tempMetaData.setPort(metaData.getPort());
                tempMetaData.setServerName(metaData.getServerName());
                tempMetaData.setTB(metaData.isTB());
                tempMetaData.setTM(metaData.isTM());
                tempMetaData.setUserName(metaData.getUserName());
                return temp;
            }
        }
    } finally {
        tracker.close();
    }
    return null;
}
Also used : DBServiceProvider(net.heartsome.cat.database.DBServiceProvider) SystemDBOperator(net.heartsome.cat.database.SystemDBOperator) ServiceTracker(org.osgi.util.tracker.ServiceTracker) MetaData(net.heartsome.cat.common.bean.MetaData)

Aggregations

MetaData (net.heartsome.cat.common.bean.MetaData)40 SQLException (java.sql.SQLException)21 ArrayList (java.util.ArrayList)14 Properties (java.util.Properties)13 Connection (java.sql.Connection)11 PreparedStatement (java.sql.PreparedStatement)11 DatabaseModelBean (net.heartsome.cat.common.bean.DatabaseModelBean)8 DBOperator (net.heartsome.cat.database.DBOperator)8 Statement (java.sql.Statement)6 ResultSet (java.sql.ResultSet)5 HashMap (java.util.HashMap)5 LinkedHashMap (java.util.LinkedHashMap)5 Entry (java.util.Map.Entry)5 Point (org.eclipse.swt.graphics.Point)5 MenuItem (org.eclipse.swt.widgets.MenuItem)5 List (java.util.List)4 SystemDBOperator (net.heartsome.cat.database.SystemDBOperator)4 File (java.io.File)2 HashSet (java.util.HashSet)2 IdentityHashMap (java.util.IdentityHashMap)2