Search in sources :

Example 11 with MetaData

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

the class OperateSystemDBImpl method createSysDb.

/**
	 * 创建系统库
	 * @return
	 * @throws SQLException
	 */
public int createSysDb() throws SQLException {
    MetaData data = null;
    try {
        data = (MetaData) metaData.clone();
        data.setDatabaseName(Constants.HSSYSDB);
    } catch (CloneNotSupportedException e) {
        logger.warn("", e);
        return Constants.FAILURE;
    }
    List<String> createTables = dbConfig.getCreateSysTables();
    return createDB(createTables, data);
}
Also used : MetaData(net.heartsome.cat.common.bean.MetaData)

Example 12 with MetaData

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

the class SystemDBOperator method createSysDb.

/**
	 * 创建系统库
	 * @return
	 * @throws SQLException
	 */
public int createSysDb() throws SQLException {
    MetaData data = null;
    try {
        data = (MetaData) metaData.clone();
        data.setDatabaseName(Constants.HSSYSDB);
    } catch (CloneNotSupportedException e) {
        logger.warn("", e);
        return Constants.FAILURE;
    }
    String createDb = Utils.replaceParams(dbConfig.getCreateSysDb(), data);
    List<String> createTables = dbConfig.getCreateSysTables();
    return createDB(createDb, createTables, data);
}
Also used : MetaData(net.heartsome.cat.common.bean.MetaData)

Example 13 with MetaData

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

the class SystemDBOperator method addSysDb.

/**
	 * 插入系统库
	 * @param dbName
	 *            数据库名称
	 * @param quality
	 *            是否优化
	 */
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);
    Properties prop = Utils.replaceParams(dbConfig.getConfigProperty(), data);
    Connection conn = null;
    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) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Properties(java.util.Properties)

Example 14 with MetaData

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

the class SystemDBOperator method checkSysDb.

/**
	 * 检查系统库是否已经创建
	 * @return true 已创建, false 没有创建
	 */
public boolean checkSysDb() {
    MetaData data = null;
    try {
        data = (MetaData) metaData.clone();
        data.setDatabaseName(Constants.HSSYSDB);
    } catch (CloneNotSupportedException e) {
        logger.warn("", e);
        return false;
    }
    Connection conn = null;
    Statement stmt = null;
    String driver = dbConfig.getDriver();
    String url = Utils.replaceParams(dbConfig.getDbURL(), data);
    Properties prop = Utils.replaceParams(dbConfig.getConfigProperty(), data);
    try {
        conn = getConnection(driver, url, prop);
    } catch (ClassNotFoundException e) {
        logger.warn(Messages.getString("database.SystemDBOperator.logger3"), e);
        return false;
    } catch (SQLException e) {
        logger.warn("", e);
        return false;
    } finally {
        freeConnection(stmt, conn);
    }
    return true;
}
Also used : SQLException(java.sql.SQLException) MetaData(net.heartsome.cat.common.bean.MetaData) Statement(java.sql.Statement) PreparedStatement(java.sql.PreparedStatement) Connection(java.sql.Connection) Properties(java.util.Properties)

Example 15 with MetaData

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

the class SystemDBOperator method checkDbExistOnServer.

/**
	 * 检查数据库在当前服务器上是否已经存在,而非在R8系统中已经存在<br>
	 * @return true已经存在.false不存在
	 */
public boolean checkDbExistOnServer() {
    Connection conn = null;
    MetaData data = null;
    try {
        data = (MetaData) metaData.clone();
    } catch (CloneNotSupportedException e) {
        logger.warn("", e);
        return false;
    }
    try {
        String url = Utils.replaceParams(dbConfig.getDbURL(), data);
        String driver = dbConfig.getDriver();
        Properties prop = Utils.replaceParams(dbConfig.getConfigProperty(), data);
        conn = getConnection(driver, url, prop);
    } catch (ClassNotFoundException e) {
        logger.error(Messages.getString("database.SystemDBOperator.logger1"), e);
        return false;
    } catch (SQLException e) {
        // Just check ,so don't need record the exception
        return false;
    } finally {
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                logger.warn("", e);
            }
        }
    }
    return true;
}
Also used : SQLException(java.sql.SQLException) MetaData(net.heartsome.cat.common.bean.MetaData) Connection(java.sql.Connection) Properties(java.util.Properties)

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