Search in sources :

Example 6 with MetaData

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

the class OperateSystemDBImpl method createSysDb.

/**
	 * (non-Javadoc)
	 * @see net.heartsome.cat.database.SystemDBOperator#createSysDb()
	 */
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 7 with MetaData

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

the class OperateDBImpl method checkDbExistOnServer.

@Override
public boolean checkDbExistOnServer() {
    Connection conn = null;
    PreparedStatement stmt = null;
    ResultSet rs = null;
    try {
        MetaData data = (MetaData) metaData.clone();
        data.setDatabaseName(Constants.HSSYSDB);
        String url = Utils.replaceParams(dbConfig.getDbURL(), data);
        String driver = dbConfig.getDriver();
        Properties prop = Utils.replaceParams(dbConfig.getConfigProperty(), data);
        conn = getConnection(driver, url, prop);
        String getDbList = "SELECT DBNAME, QUALITY, USERS FROM HSCATSYSDB WHERE DBNAME=?";
        stmt = conn.prepareStatement(getDbList);
        stmt.setString(1, metaData.getDatabaseName());
        rs = stmt.executeQuery();
        if (rs.next()) {
            return true;
        } else {
            return false;
        }
    } catch (CloneNotSupportedException e) {
        logger.error("", e);
    } catch (ClassNotFoundException e) {
        logger.error("", e);
    } catch (SQLException e) {
        logger.error("", e);
    } finally {
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                logger.warn("", e);
            }
        }
        freeConnection(stmt, conn);
    }
    return true;
}
Also used : SQLException(java.sql.SQLException) MetaData(net.heartsome.cat.common.bean.MetaData) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Properties(java.util.Properties)

Example 8 with MetaData

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

the class OperateDBImpl method checkSysDb.

/**
	 * 检查系统库是否已经创建
	 * @return true 已创建, false 没有创建
	 */
@Override
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);
        stmt = conn.createStatement();
        stmt.execute("SELECT DBNAME, QUALITY, USERS FROM HSCATSYSDB");
    } catch (ClassNotFoundException e) {
        logger.warn(Messages.getString("oracle.OperateDBImpl.logger1"), e);
        return false;
    } catch (SQLException e) {
        return false;
    } finally {
        freeConnection(stmt, conn);
    }
    return true;
}
Also used : SQLException(java.sql.SQLException) MetaData(net.heartsome.cat.common.bean.MetaData) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) Properties(java.util.Properties)

Example 9 with MetaData

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

the class OperateSystemDBImpl method checkSysDb.

@Override
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;
    ResultSet rs = 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);
        stmt = conn.createStatement();
        rs = stmt.executeQuery("SELECT DBNAME, QUALITY, USERS FROM HSCATSYSDB");
    } catch (ClassNotFoundException e) {
        logger.warn(Messages.getString("hsql.OperateSystemDBImpl.logger1"), e);
        return false;
    } catch (SQLException e) {
        // 系统表不存在则创建系统表
        List<String> createTables = dbConfig.getCreateSysTables();
        try {
            createDB(createTables, data);
            return true;
        } catch (SQLException e1) {
            logger.error(Messages.getString("hsql.OperateSystemDBImpl.logger2"), e);
            return false;
        }
    } finally {
        try {
            if (stmt != null) {
                stmt.executeUpdate("SHUTDOWN;");
            }
        } catch (SQLException e) {
        //				logger.error("", e);
        }
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                logger.error("", e);
            }
        }
        freeConnection(stmt, conn);
    }
    return true;
}
Also used : SQLException(java.sql.SQLException) MetaData(net.heartsome.cat.common.bean.MetaData) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) List(java.util.List) Properties(java.util.Properties)

Example 10 with MetaData

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

the class OperateSystemDBImpl method getSysDbNames.

@Override
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 {
        Statement _stmt = null;
        try {
            _stmt = conn.createStatement();
            _stmt.executeUpdate("SHUTDOWN;");
        } catch (SQLException e) {
            logger.error("", e);
        } finally {
            if (stmt != null) {
                try {
                    _stmt.close();
                } catch (SQLException e) {
                    logger.warn("", e);
                }
            }
        }
        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) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) 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