Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
allow postgres users to enable or disable savepoints
  • Loading branch information
erilong committed Mar 24, 2010
1 parent a9b4bc9 commit 577296b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
Expand Up @@ -79,6 +79,7 @@ private ParameterConstants() {
public final static String DATA_LOADER_TIME_BETWEEN_ACK_RETRIES = "time.between.ack.retries.ms";
public final static String DATA_LOADER_NO_KEYS_IN_UPDATE = "dont.include.keys.in.update.statement";
public final static String DATA_LOADER_ENABLE_FALLBACK_UPDATE = "dataloader.enable.fallback.update";
public final static String DATA_LOADER_ENABLE_FALLBACK_SAVEPOINT = "dataloader.enable.fallback.savepoint";
public final static String DATA_LOADER_ENABLE_FALLBACK_INSERT = "dataloader.enable.fallback.insert";
public final static String DATA_LOADER_ALLOW_MISSING_DELETE = "dataloader.allow.missing.delete";
public final static String DATA_LOADER_MAX_ROWS_BEFORE_COMMIT = "dataloader.max.rows.before.commit";
Expand Down
Expand Up @@ -257,10 +257,14 @@ protected int insert(String[] tokens) {

if (continueToLoad) {
boolean enableFallbackUpdate = parameterService.is(ParameterConstants.DATA_LOADER_ENABLE_FALLBACK_UPDATE);
boolean enableFallbackSavepoint = parameterService.is(ParameterConstants.DATA_LOADER_ENABLE_FALLBACK_SAVEPOINT);
Object savepoint = null;
try {
stats.startTimer();
if (enableFallbackUpdate && dbDialect.requiresSavepointForFallback()) {
if (context.getTableTemplate().count(context, parseKeys(tokens, 1)) > 0) {
if (enableFallbackSavepoint) {
savepoint = dbDialect.createSavepointForFallback();
} else if (context.getTableTemplate().count(context, parseKeys(tokens, 1)) > 0) {
throw new DataIntegrityViolationException("Row already exists");
}
}
Expand All @@ -269,6 +273,7 @@ protected int insert(String[] tokens) {
// TODO: modify sql-error-codes.xml for unique constraint vs
// foreign key
if (enableFallbackUpdate) {
dbDialect.rollbackToSavepoint(savepoint);
if (log.isDebugEnabled()) {
log.debug("LoaderInsertingFailedUpdating", context.getTableName(), ArrayUtils.toString(tokens));
}
Expand Down
6 changes: 6 additions & 0 deletions symmetric/src/main/resources/symmetric-default.properties
Expand Up @@ -263,6 +263,12 @@ dataextractor.old.data.enable=true
# This property can be overridden in the database
dataloader.enable.fallback.update=true

# For dialects that roll back on integrity errors, enabled the use of savepoints
# before inserts, otherwise it will try to select the row by primary key.
#
# This property can be overridden in the database
dataloader.enable.fallback.savepoint=true

# Turn on/off fallback to insert statements after a failed
# update
#
Expand Down

0 comments on commit 577296b

Please sign in to comment.