private JPADriftFile getDriftFile(String sha256, List<JPADriftFile> emptyDriftFiles, boolean addToList) {
if (null == sha256 || "0".equals(sha256)) {
return null;
}
JPADriftFile result = entityManager.find(JPADriftFile.class, sha256);
// if the JPADriftFile is not yet in the db then persist it, and mark it requested if content is to be fetched
// note - by immediately setting the initial status to REQUESTED we avoid a future update and a
// potential deadlock scenario where the REQUESTED and LOADED status updates can happen simultaneously
if (null == result) {
JPADriftFile driftFile = new JPADriftFile(sha256);
if (addToList) {
driftFile.setStatus(DriftFileStatus.REQUESTED);
}
result = persistDriftFile(driftFile);
if (addToList) {
emptyDriftFiles.add(result);
}