use of org.jumpmind.db.sql.SqlException in project symmetric-ds by JumpMind.
the class DbFill method updateRandomRecord.
private void updateRandomRecord(ISqlTransaction tran, Table table) {
DmlStatement updStatement = createUpdateDmlStatement(table);
Row row = createRandomUpdateValues(tran, updStatement, table);
Object[] values = new Object[table.getColumnCount()];
int i = 0;
for (Column column : table.getColumns()) {
if (!column.isPrimaryKey()) {
values[i++] = row.get(column.getName());
}
}
for (Column column : table.getPrimaryKeyColumns()) {
values[i++] = row.get(column.getName());
}
try {
tran.prepareAndExecute(updStatement.getSql(), values);
} catch (SqlException ex) {
log.info("Failed to update {}: {}", table.getName(), ex.getMessage());
if (continueOnError) {
if (debug) {
logRow(row);
log.info("", ex);
}
} else {
throw ex;
}
}
}
use of org.jumpmind.db.sql.SqlException in project symmetric-ds by JumpMind.
the class DefaultDatabaseWriter method logFailureDetails.
@Override
protected void logFailureDetails(Throwable e, CsvData data, boolean logLastDmlDetails) {
StringBuilder failureMessage = new StringBuilder();
failureMessage.append("Failed to process ");
failureMessage.append(data.getDataEventType().toString().toLowerCase());
failureMessage.append(" event in batch ");
failureMessage.append(batch.getBatchId());
failureMessage.append(".\n");
if (logLastDmlDetails && this.currentDmlStatement != null) {
failureMessage.append("Failed sql was: ");
failureMessage.append(this.currentDmlStatement.getSql());
failureMessage.append("\n");
}
if (logLastDmlDetails && this.currentDmlValues != null) {
failureMessage.append("Failed sql parameters: ");
failureMessage.append(StringUtils.abbreviate(Arrays.toString(currentDmlValues), CsvData.MAX_DATA_SIZE_TO_PRINT_TO_LOG));
failureMessage.append("\n");
failureMessage.append("Failed sql parameters types: ");
failureMessage.append(Arrays.toString(this.currentDmlStatement.getTypes()));
failureMessage.append("\n");
}
if (logLastDmlDetails && e instanceof SqlException && e.getCause() instanceof SQLException) {
SQLException se = (SQLException) e.getCause();
failureMessage.append("Failed sql state and code: ").append(se.getSQLState());
failureMessage.append(" (").append(se.getErrorCode()).append(")");
failureMessage.append("\n");
}
data.writeCsvDataDetails(failureMessage);
log.info(failureMessage.toString(), e);
}
use of org.jumpmind.db.sql.SqlException in project symmetric-ds by JumpMind.
the class AbstractDatabaseWriter method write.
public void write(CsvData data) {
context.remove(AbstractDatabaseWriter.CONFLICT_ERROR);
/* If the startTable has been called and the targetTable is required then check
* to see if the writer has been configured to ignore this data event
*/
if (sourceTable != null && targetTable == null && data.requiresTable() && (writerSettings.isIgnoreMissingTables() || batch.getBatchId() == IoConstants.IGNORE_TABLES_BATCH)) {
String qualifiedName = sourceTable.getFullyQualifiedTableName();
if (!missingTables.contains(qualifiedName)) {
log.warn("Did not find the {} table in the target database", qualifiedName);
missingTables.add(qualifiedName);
}
} else {
context.put(CONFLICT_ERROR, null);
if (data.requiresTable() && sourceTable != null && targetTable == null && data.getDataEventType() != DataEventType.SQL) {
Table lastTable = context.getLastParsedTable();
if (lastTable != null && lastTable.getFullyQualifiedTableNameLowerCase().equals(sourceTable.getFullyQualifiedTableNameLowerCase())) {
// if we cross batches and the table isn't specified, then
// use the last table we used
start(lastTable);
}
}
if (targetTable != null || !data.requiresTable() || (targetTable == null && data.getDataEventType() == DataEventType.SQL)) {
try {
statistics.get(batch).increment(DataWriterStatisticConstants.STATEMENTCOUNT);
statistics.get(batch).increment(DataWriterStatisticConstants.LINENUMBER);
if (filterBefore(data)) {
LoadStatus loadStatus = LoadStatus.SUCCESS;
switch(data.getDataEventType()) {
case UPDATE:
loadStatus = update(data, writerSettings.isApplyChangesOnly(), true);
break;
case INSERT:
loadStatus = insert(data);
break;
case DELETE:
loadStatus = delete(data, true);
break;
case BSH:
script(data);
break;
case SQL:
sql(data);
break;
case CREATE:
create(data);
break;
default:
break;
}
if (loadStatus == LoadStatus.CONFLICT) {
if (conflictResolver != null) {
conflictResolver.needsResolved(this, data, loadStatus);
} else {
throw new ConflictException(data, targetTable, false, writerSettings.pickConflict(targetTable, batch), (Exception) context.get(AbstractDatabaseWriter.CONFLICT_ERROR));
}
}
uncommittedCount++;
lastData = data;
filterAfter(data);
checkForEarlyCommit();
}
} catch (IgnoreBatchException ex) {
rollback();
throw ex;
} catch (RuntimeException ex) {
if (filterError(data, ex)) {
if (!(ex instanceof SqlException)) {
/*
* SQL exceptions should have already been logged
*/
logFailureDetails(ex, data, false);
}
throw ex;
} else {
uncommittedCount++;
statistics.get(batch).increment(DataWriterStatisticConstants.IGNORECOUNT);
checkForEarlyCommit();
}
}
} else {
if (sourceTable != null) {
// still unknown throw an exception
throw new SqlException(String.format("Could not find the target table %s", sourceTable.getFullyQualifiedTableName()));
} else {
throw new SqlException("The target table was not specified");
}
}
}
}
use of org.jumpmind.db.sql.SqlException in project symmetric-ds by JumpMind.
the class FirebirdDatabasePlatform method getCreateSymTriggerPermission.
@Override
public PermissionResult getCreateSymTriggerPermission() {
String delimiter = getDatabaseInfo().getDelimiterToken();
delimiter = delimiter != null ? delimiter : "";
String triggerSql = "CREATE TRIGGER TEST_TRIGGER FOR " + delimiter + PERMISSION_TEST_TABLE_NAME + delimiter + " AFTER UPDATE AS BEGIN END";
PermissionResult result = new PermissionResult(PermissionType.CREATE_TRIGGER, Status.FAIL);
try {
getSqlTemplate().update(triggerSql);
result.setStatus(Status.PASS);
} catch (SqlException e) {
result.setException(e);
result.setSolution("Grant CREATE TRIGGER permission or TRIGGER permission");
}
return result;
}
use of org.jumpmind.db.sql.SqlException in project symmetric-ds by JumpMind.
the class HsqlDb2DatabasePlatform method getCreateSymTriggerPermission.
@Override
public PermissionResult getCreateSymTriggerPermission() {
String delimiter = getDatabaseInfo().getDelimiterToken();
delimiter = delimiter != null ? delimiter : "";
String triggerSql = "CREATE TRIGGER TEST_TRIGGER AFTER UPDATE ON " + delimiter + PERMISSION_TEST_TABLE_NAME + delimiter + " FOR EACH ROW INSERT INTO " + delimiter + PERMISSION_TEST_TABLE_NAME + delimiter + " VALUES(NULL,NULL)";
PermissionResult result = new PermissionResult(PermissionType.CREATE_TRIGGER, Status.FAIL);
try {
getSqlTemplate().update(triggerSql);
result.setStatus(Status.PASS);
} catch (SqlException e) {
result.setException(e);
result.setSolution("Grant CREATE TRIGGER permission or TRIGGER permission");
}
return result;
}
Aggregations