use of gov.usgs.cida.coastalhazards.exception.CycleIntroductionException in project coastal-hazards by USGS-CIDA.
the class ItemManager method persist.
public synchronized String persist(Item item) throws CycleIntroductionException {
String id;
EntityTransaction transaction = em.getTransaction();
try {
transaction.begin();
persistItem(item);
id = item.getId();
transaction.commit();
} catch (Exception ex) {
log.debug("Exception during save", ex);
if (transaction.isActive()) {
transaction.rollback();
}
id = null;
if (ex instanceof CycleIntroductionException) {
throw ex;
}
}
fixEnabledStatus();
return id;
}
use of gov.usgs.cida.coastalhazards.exception.CycleIntroductionException in project coastal-hazards by USGS-CIDA.
the class ItemManager method persistAll.
public synchronized boolean persistAll(List<Item> items) throws CycleIntroductionException {
boolean worked = false;
EntityTransaction transaction = em.getTransaction();
try {
transaction.begin();
for (Item item : items) {
persistItem(item);
}
transaction.commit();
worked = true;
} catch (Exception ex) {
log.debug("Exception during save", ex);
if (transaction.isActive()) {
transaction.rollback();
}
if (ex instanceof CycleIntroductionException) {
throw ex;
}
}
fixEnabledStatus();
return worked;
}
use of gov.usgs.cida.coastalhazards.exception.CycleIntroductionException in project coastal-hazards by USGS-CIDA.
the class ItemManager method mergeAll.
public synchronized boolean mergeAll(List<Item> items) throws CycleIntroductionException {
boolean worked = false;
EntityTransaction transaction = em.getTransaction();
try {
transaction.begin();
for (Item item : items) {
mergeItem(item);
}
transaction.commit();
worked = true;
} catch (Exception ex) {
log.debug("Exception during save", ex);
if (transaction.isActive()) {
transaction.rollback();
}
if (ex instanceof CycleIntroductionException) {
throw ex;
}
}
fixEnabledStatus();
return worked;
}
use of gov.usgs.cida.coastalhazards.exception.CycleIntroductionException in project coastal-hazards by USGS-CIDA.
the class ItemManager method merge.
public synchronized String merge(Item item) throws CycleIntroductionException {
String id;
EntityTransaction transaction = em.getTransaction();
try {
// Update old ancestor chain
mergeAll(updateAncestors(item));
transaction.begin();
id = mergeItem(item);
transaction.commit();
fixEnabledStatus();
// update new ancestor chain
mergeAll(updateAncestors(item));
} catch (Exception ex) {
log.debug("Transaction failed on merge", ex);
if (transaction.isActive()) {
transaction.rollback();
}
id = null;
}
return id;
}
use of gov.usgs.cida.coastalhazards.exception.CycleIntroductionException in project coastal-hazards by USGS-CIDA.
the class ItemManager method mergeItem.
private synchronized String mergeItem(Item item) {
String id;
try (DataDomainManager dm = new DataDomainManager()) {
if (anyCycles(item)) {
throw new CycleIntroductionException();
}
List<Item> children = item.getChildren();
List<Item> replaceList = new LinkedList<>();
if (children != null) {
for (Item child : children) {
replaceList.add(load(child.getId()));
}
item.setChildren(replaceList);
}
em.merge(item);
id = item.getId();
// Clear the upstream data domains if this item has a domain
if (dm.load(id) != null) {
List<Item> domainsToDelete = findVisibleAncestors(item);
for (Item toDelete : domainsToDelete) {
dm.deleteDomainForItem(toDelete);
}
}
} catch (Exception e) {
log.error("Failed to save item: " + item.getId() + " | Error: " + e.getMessage());
id = null;
}
return id;
}
Aggregations