Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions api/src/org/labkey/api/data/DbScope.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.labkey.api.util.GUID;
import org.labkey.api.util.MemTracker;
import org.labkey.api.util.TestContext;
import org.labkey.api.util.UnexpectedException;
import org.labkey.data.xml.TablesDocument;
import org.springframework.dao.DeadlockLoserDataAccessException;

Expand Down Expand Up @@ -636,6 +637,11 @@ public <T extends Throwable> void rethrow(Class<T> clazz) throws T
if (clazz.isAssignableFrom(getCause().getClass()))
throw (T)getCause();
}

public <T extends Throwable> void throwRuntimeException() throws RuntimeException
{
throw UnexpectedException.wrap(getCause());
}
}

/** Won't retry if we're already in a transaction
Expand Down
61 changes: 36 additions & 25 deletions query/src/org/labkey/query/controllers/QueryController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2375,33 +2375,44 @@ public boolean handlePost(QueryForm form, BindException errors) throws Exception
}

DbSchema dbSchema = table.getSchema();
dbSchema.getScope().executeWithRetry(tx ->
try
{
try
{
updateService.deleteRows(getUser(), getContainer(), keyValues, null, null);
}
catch (SQLException x)
{
if (!RuntimeSQLException.isConstraintException(x))
throw new RuntimeSQLException(x);
errors.reject(ERROR_MSG, getMessage(table.getSchema().getSqlDialect(), x));
}
catch (DataIntegrityViolationException | OptimisticConflictException e)
dbSchema.getScope().executeWithRetry(tx ->
{
errors.reject(ERROR_MSG, e.getMessage());
}
catch (BatchValidationException x)
{
x.addToErrors(errors);
}
catch (Exception x)
{
errors.reject(ERROR_MSG, null == x.getMessage() ? x.toString() : x.getMessage());
ExceptionUtil.logExceptionToMothership(getViewContext().getRequest(), x);
}
return !errors.hasErrors();
});
try
{
updateService.deleteRows(getUser(), getContainer(), keyValues, null, null);
}
catch (SQLException x)
{
if (!RuntimeSQLException.isConstraintException(x))
throw new RuntimeSQLException(x);
errors.reject(ERROR_MSG, getMessage(table.getSchema().getSqlDialect(), x));
}
catch (DataIntegrityViolationException | OptimisticConflictException e)
{
errors.reject(ERROR_MSG, e.getMessage());
}
catch (BatchValidationException x)
{
x.addToErrors(errors);
}
catch (Exception x)
{
errors.reject(ERROR_MSG, null == x.getMessage() ? x.toString() : x.getMessage());
ExceptionUtil.logExceptionToMothership(getViewContext().getRequest(), x);
}
// need to throw here to avoid committing tx
if (errors.hasErrors())
throw new DbScope.RetryException(errors);
return true;
});
}
catch (DbScope.RetryException x)
{
if (x.getCause() != errors)
x.throwRuntimeException();
}
return !errors.hasErrors();
}

Expand Down