Skip to content

Commit

Permalink
added option to throw on write errors
Browse files Browse the repository at this point in the history
  • Loading branch information
albogdano committed Jun 29, 2018
1 parent 43b490d commit 8d067c9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import static com.erudika.para.persistence.AWSDynamoUtils.isSharedAppid;
import static com.erudika.para.persistence.AWSDynamoUtils.readPageFromSharedTable;
import static com.erudika.para.persistence.AWSDynamoUtils.readPageFromTable;
import static com.erudika.para.persistence.AWSDynamoUtils.throwIfNecessary;
import static com.erudika.para.persistence.AWSDynamoUtils.toRow;
import com.erudika.para.utils.Config;
import com.erudika.para.utils.Pager;
Expand Down Expand Up @@ -179,6 +180,7 @@ private String createRow(String key, String appid, Map<String, AttributeValue> r
client().putItem(putItemRequest);
} catch (Exception e) {
logger.error("Could not write row to DB - appid={}, key={}", appid, key, e);
throwIfNecessary(e);
}
return key;
}
Expand Down Expand Up @@ -228,6 +230,7 @@ private boolean updateRow(String key, String appid, Map<String, AttributeValue>
logger.warn("Item not updated. Versions don't match. Appid={}, key={}.", appid, key);
} catch (Exception e) {
logger.error("Could not update row in DB - appid={}, key={}", appid, key, e);
throwIfNecessary(e);
}
return false;
}
Expand Down Expand Up @@ -260,6 +263,7 @@ private void deleteRow(String key, String appid) {
client().deleteItem(delItemRequest);
} catch (Exception e) {
logger.error("Could not delete row from DB - appid={}, key={}", appid, key, e);
throwIfNecessary(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ protected static void batchWrite(Map<String, List<WriteRequest>> items) {
}
} catch (Exception e) {
logger.error(null, e);
throwIfNecessary(e);
}
}

Expand Down Expand Up @@ -629,4 +630,10 @@ private static String keyPrefix(String appIdentifier) {
return StringUtils.join(StringUtils.trim(appIdentifier), "_");
}

protected static void throwIfNecessary(Throwable t) {
if (t != null && Config.getConfigBoolean("fail_on_write_errors", false)) {
throw new RuntimeException("DAO write operation failed!", t);
}
}

}

0 comments on commit 8d067c9

Please sign in to comment.