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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations