public void _save() { if (!em().contains(this)) { em().persist(this); PlayPlugin.postEvent("JPASupport.objectPersisted", this); } avoidCascadeSaveLoops.set(new HashSet<JPABase>()); try { saveAndCascade(true); } finally { avoidCascadeSaveLoops.get().clear(); } try { em().flush(); } catch (PersistenceException e) { if (e.getCause() instanceof GenericJDBCException) { throw new PersistenceException(((GenericJDBCException) e.getCause()).getSQL(), e); } else { throw e; } } avoidCascadeSaveLoops.set(new HashSet<JPABase>()); try { saveAndCascade(false); } finally { avoidCascadeSaveLoops.get().clear(); } }
public void _delete() { try { avoidCascadeSaveLoops.set(new HashSet<JPABase>()); try { saveAndCascade(true); } finally { avoidCascadeSaveLoops.get().clear(); } em().remove(this); try { em().flush(); } catch (PersistenceException e) { if (e.getCause() instanceof GenericJDBCException) { throw new PersistenceException(((GenericJDBCException) e.getCause()).getSQL(), e); } else { throw e; } } avoidCascadeSaveLoops.set(new HashSet<JPABase>()); try { saveAndCascade(false); } finally { avoidCascadeSaveLoops.get().clear(); } PlayPlugin.postEvent("JPASupport.objectDeleted", this); } catch (PersistenceException e) { throw e; } catch (Throwable e) { throw new RuntimeException(e); } }
private void addResource( Accessions accession, IdentifierType resourceId, DomainImportController controller, String accesionNumber, int recordNumber) throws ImportException { if (resourceId != null) { String resourceId1; String resourceId2 = null; String resourceId3 = null; String resourceId4 = null; if (resourceId.getComposite() != null) { resourceId1 = StringHelper.trimToLength( resourceId.getComposite(), ATFieldInfo.checkFieldLength( Resources.class, Resources.PROPERTYNAME_RESOURCE_IDENTIFIER_1)); } else { resourceId1 = resourceId.getPart1(); resourceId2 = resourceId.getPart2(); resourceId3 = resourceId.getPart3(); resourceId4 = resourceId.getPart4(); } ResourcesDAO resourceDao = new ResourcesDAO(); Resources resource; if (resourceCreation.equalsIgnoreCase(AccessionImportXmlHandler.RESOURCE_CREATION_NONE)) { resource = resourceDao.lookupResource( resourceId1, resourceId2, resourceId3, resourceId4, false, repository); } else { resource = resourceDao.lookupResource( resourceId1, resourceId2, resourceId3, resourceId4, true, repository); } if (resourceDao.getNewRecordCreated() && resourceCreation.equalsIgnoreCase(AccessionImportXmlHandler.RESOURCE_CREATION_FULL)) { try { resource = (Resources) resourceDao.findByPrimaryKeyLongSession(resource.getIdentifier()); resource.populateResourceFromAccession(accession); resourceDao.updateLongSession(resource); } catch (LookupException e) { throw new ImportException( "Error creating resource: " + resourceId + ", " + e.getMessage(), e); } catch (PersistenceException e) { throw new ImportException( "Error creating resource: " + resourceId + ", " + e.getMessage(), e); } catch (DuplicateLinkException e) { throw new ImportException( "Error creating resource: duplicate link" + resourceId + ", " + e.getMessage(), e); } } if (resource != null) { AccessionsResources accessionResource = new AccessionsResources(resource, accession); accession.addAccessionsResources(accessionResource); } } else { if (!resourceCreation.equalsIgnoreCase(AccessionImportXmlHandler.RESOURCE_CREATION_NONE)) { controller.addLineToImportLog( "Record # " + recordNumber + " - " + accesionNumber + " has no resource id so no resource record was created"); } } }