Permalink
Browse files

0001723: Unique constraint violation is not logged for tables declare…

…d for conflict detection
  • Loading branch information...
chenson42 committed May 22, 2014
1 parent e3ae299 commit ba33fa2e851d0e10cfacad8ea6663f4d51a24ef0
@@ -45,6 +45,8 @@
protected final static Logger log = LoggerFactory.getLogger(AbstractDatabaseWriter.class);
public static final String CONFLICT_ERROR = "DatabaseWriter.ConflictError";
public static enum LoadStatus {
SUCCESS, CONFLICT
};
@@ -73,7 +75,7 @@
protected IDatabaseWriterConflictResolver conflictResolver;
protected Set<String> missingTables = new HashSet<String>();
protected Set<String> missingTables = new HashSet<String>();
public AbstractDatabaseWriter() {
this(null, null);
@@ -130,6 +132,7 @@ public void write(CsvData data) {
}
protected void write(CsvData data, boolean fallback) {
context.put(CONFLICT_ERROR, null);
if (data.requiresTable() &&
(targetTable == null && data.getDataEventType() != DataEventType.SQL)) {
// if we cross batches and the table isn't specified, then
@@ -220,7 +220,8 @@ protected void attemptToResolve(ResolvedData resolvedData, CsvData data, Abstrac
}
}
} else {
throw new ConflictException(data, writer.getTargetTable(), false, conflict);
throw new ConflictException(data, writer.getTargetTable(), false, conflict,
(Exception) writer.getContext().get(AbstractDatabaseWriter.CONFLICT_ERROR));
}
}
@@ -37,13 +37,17 @@
protected Conflict conflict;
public ConflictException(CsvData data, Table table, boolean fallbackOperationFailed, Conflict conflict) {
super(message(data, table, fallbackOperationFailed));
public ConflictException(CsvData data, Table table, boolean fallbackOperationFailed, Conflict conflict, Exception cause) {
super(message(data, table, fallbackOperationFailed), cause);
this.data = data;
this.table = table;
this.fallbackOperationFailed = fallbackOperationFailed;
this.conflict = conflict;
}
public ConflictException(CsvData data, Table table, boolean fallbackOperationFailed, Conflict conflict) {
this(data, table, fallbackOperationFailed, conflict, null);
}
protected static String message(CsvData data, Table table, boolean fallbackOperationFailed) {
Map<String, String> pks = data.toColumnNameValuePairs(table.getPrimaryKeyColumnNames(),
@@ -60,7 +60,7 @@
protected final static Logger log = LoggerFactory.getLogger(DefaultDatabaseWriter.class);
public static final String CUR_DATA="DatabaseWriter.CurData";
public static final String CUR_DATA = "DatabaseWriter.CurData";
protected IDatabasePlatform platform;
@@ -178,10 +178,11 @@ protected LoadStatus insert(CsvData data) {
} catch (SqlException ex) {
if (platform.getSqlTemplate().isUniqueKeyViolation(ex)) {
if (!platform.getDatabaseInfo().isRequiresSavePointsInTransaction()) {
context.put(CONFLICT_ERROR, ex);
context.put(CUR_DATA,getCurData(transaction));
return LoadStatus.CONFLICT;
} else {
log.warn("Detected a conflict via an exception, but cannot perform conflict resolution because the database in use requires savepoints");
log.info("Detected a conflict via an exception, but cannot perform conflict resolution because the database in use requires savepoints");
throw ex;
}
} else {

0 comments on commit ba33fa2

Please sign in to comment.