use of com.cubrid.common.ui.cubrid.table.dialog.imp.event.ImportDataSuccessEvent in project cubrid-manager by CUBRID.
the class AbsImportRunnable method commit.
/**
*
* Commit the data
*
*
* @param monitor IProgressMonitor
* @param currentRow int
* @throws SQLException The exception
*/
protected void commit(List<ImportRowData> rowList) throws SQLException {
if (pStmt == null) {
return;
}
try {
pStmt.executeBatch();
QueryUtil.commit(conn);
handleEvent(new ImportDataSuccessEvent(tableName, rowList.size()));
LOGGER.debug("Committed : " + rowList.size());
} catch (SQLException ex) {
QueryUtil.rollback(conn);
ImportDataFailedEvent failedEvt = new ImportDataFailedEvent(tableName, rowList.size(), "", ex.getMessage());
handleEvent(failedEvt);
LOGGER.debug("Failed : " + rowList.size());
writeErrorLog(rowList);
} finally {
rowList.clear();
try {
pStmt.clearBatch();
} catch (SQLException e) {
LOGGER.error(e.getMessage());
processSQLException(e);
}
}
}
use of com.cubrid.common.ui.cubrid.table.dialog.imp.event.ImportDataSuccessEvent in project cubrid-manager by CUBRID.
the class ImportFromSQLRunnable method commit.
/**
* Commit the data
*
* @param importDataEventHandler IImportDataEventHandler
* @param rowList List<RowData>
*/
protected void commit(List<ImportRowData> rowList) {
// FIXME move this logic to core module
if (stmt == null || conn == null) {
return;
}
String sql = "";
int importCount = 0;
long currentRunCount = 0;
int totalWorkedSize = 0;
List<ImportRowData> batchDataList = new ArrayList<ImportRowData>();
for (ImportRowData rowData : rowList) {
batchDataList.add(rowData);
sql = rowData.getSql();
try {
importCount++;
currentRunCount++;
totalWorkedSize += rowData.getWorkSize();
stmt.execute(sql);
if (importCount % commitCount == 0) {
QueryUtil.commit(conn);
ImportDataSuccessEvent successEvt = new ImportDataSuccessEvent(fileName, importCount);
successEvt.setWorkedSize(totalWorkedSize);
handleEvent(successEvt);
LOGGER.debug("Committed : currentRunCount={}, commitCount={}", currentRunCount, importCount);
importCount = 0;
totalWorkedSize = 0;
batchDataList.clear();
}
} catch (Exception e) {
for (ImportRowData batchData : batchDataList) {
String tempSql = batchData.getSql();
String errMessage = Messages.msgFailedByRollback;
if (StringUtil.isEqual(tempSql, sql)) {
errMessage = e.getMessage();
}
ImportDataFailedEvent failedEvt = new ImportDataFailedEvent(fileName, 1, tempSql, errMessage);
failedEvt.setWorkedSize(batchData.getWorkSize());
handleEvent(failedEvt);
writeErrorLog(batchData);
}
QueryUtil.rollback(conn);
LOGGER.debug("Execute SQL from SQL file sql : {}, error message: {}", sql, e);
importCount = 0;
totalWorkedSize = 0;
batchDataList.clear();
}
}
if (importCount > 0) {
QueryUtil.commit(conn);
ImportDataSuccessEvent successEvt = new ImportDataSuccessEvent(fileName, importCount);
successEvt.setWorkedSize(totalWorkedSize);
handleEvent(successEvt);
LOGGER.debug("Committed : currentRunCount={}, commitCount={}", currentRunCount, importCount);
importCount = 0;
totalWorkedSize = 0;
batchDataList.clear();
}
}
Aggregations