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); } }
/** * Updates user profile with new values and adds a picture to user profile if one is selected. * * @param user <code>AppUser</code> type value of user * @param password <code>String</code> type value of user password * @param name <code>String</code> type value of user name * @param lastname <code>String</code> type value of user lastname * @param phone <code>String</code> type value of user phone * @param profileImage <code>Image</code> type value of user profile image * @return <code>boolean</code> type value true if user profile was successfully updated, false if * not */ public static boolean updateUserProfile( AppUser user, String password, String name, String lastname, String phone, Image profileImage) { if (user != null) { try { user.firstname = name; user.lastname = lastname; user.password = password; user.hashPass(); user.phoneNumber = phone; if (profileImage != null) { user.profileImg = profileImage; } user.update(); return true; } catch (PersistenceException e) { ErrorLogger.createNewErrorLogger("Failed to update user profile.", e.getMessage()); return false; } } return false; }
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(); } }
/** * Tests accuracy of <code>PersistenceException(String)</code> constructor.<br> * The detail error message should be properly set. */ @Test public void testCtor1() { PersistenceException exception = new PersistenceException(DETAIL_MESSAGE); // Verify that there is a detail message assertNotNull("Should have message.", exception.getMessage()); assertEquals( "Detailed error message should be identical.", DETAIL_MESSAGE, exception.getMessage()); }
/** * Deletes specific user from database, user is foundby provided email. * * @param email <code>String</code> type alue of email * @return <code>boolean</code> type value true if user is successfully deleted, false if not */ public static boolean deleteUser(String email) { AppUser user = AppUser.getUserByEmail(email); if (user != null) { try { user.delete(); return true; } catch (PersistenceException e) { ErrorLogger.createNewErrorLogger("Failed to delete user.", e.getMessage()); return false; } } return false; }
/** * Tests accuracy of <code>PersistenceException(String, ExceptionData)</code> constructor.<br> * The detail error message and the exception data should be properly set. */ @Test public void testCtor3() { PersistenceException exception = new PersistenceException(DETAIL_MESSAGE, EXCEPTION_DATA); // Verify that there is a detail message assertNotNull("Should have message.", exception.getMessage()); assertEquals( "Detailed error message with cause should be properly set.", DETAIL_MESSAGE, exception.getMessage()); // Verify that the exception data is correctly set. assertNotNull("Application code should not null.", exception.getApplicationCode()); assertEquals("Exception data is not set.", APPLICATION_CODE, exception.getApplicationCode()); }
/** * Tests accuracy of <code>PersistenceException(String, Throwable)</code> constructor.<br> * The detail error message and the original cause of error should be properly set. */ @Test public void testCtor2() { PersistenceException exception = new PersistenceException(DETAIL_MESSAGE, CAUSE); // Verify that there is a detail message assertNotNull("Should have message.", exception.getMessage()); assertEquals( "Detailed error message with cause should be properly set.", DETAIL_MESSAGE, exception.getMessage()); // Verify that there is a cause assertNotNull("Should have cause.", exception.getCause()); assertSame("Cause should be identical.", CAUSE, exception.getCause()); }
public static void saveLog(String detail) { Log log = new Log(); Person person = MailManagementSystemUI.person; log.setUsername(person.getUsername()); log.setRole(person.getRole().getName()); log.setActionDate(new Date()); log.setDetail(detail); EntityManager entityManager = initialDataLoader.em; if (!entityManager.getTransaction().isActive()) entityManager.getTransaction().begin(); try { entityManager.persist(log); entityManager.getTransaction().commit(); } catch (PersistenceException e) { System.out.println(e.getMessage()); entityManager.getTransaction().rollback(); } }
@Override public void printStackTrace(PrintWriter s) { super.printStackTrace(s); for (Map.Entry<Object, Throwable> e : exceptions.entrySet()) { s.println("Exception occured while trying to update/refresh the object " + e.getKey()); e.getValue().printStackTrace(s); } }
@Override public void printStackTrace() { super.printStackTrace(); Logger logger = Logger.getLogger(CollectionPersistenceException.class.getName()); for (Map.Entry<Object, Throwable> e : exceptions.entrySet()) { logger.log( Level.WARNING, "Exception occured while trying to update/refresh the object " + e.getKey(), e.getValue()); } }
/** * Changes role of user, new role is taken from html selection box. User is found with provided * email. * * @param email <code>String</code> type value of user email * @param role <code>String</code> type value of new user role * @return <code>boolean</code> type value true if user is successfully updated, false if not */ public static boolean changeUserRole(String email, String role) { AppUser user = AppUser.getUserByEmail(email); if (user != null) { if ("buyer".equals(role)) { user.userAccessLevel = UserAccessLevel.BUYER; } else if ("seller".equals(role)) { user.userAccessLevel = UserAccessLevel.SELLER; } else if ("hotelmanager".equals(role)) { user.userAccessLevel = UserAccessLevel.HOTEL_MANAGER; } try { user.update(); return true; } catch (PersistenceException e) { ErrorLogger.createNewErrorLogger("Failed to change user role.", e.getMessage()); return false; } } return false; }
/** * Saves new user to database, user is checked for being null value, depending on userType, seller * doesn't have to authenticate email address. * * @param user <code>AppUser</code> type value of user * @param userType <code>String</code> type value of user type * @return <code>boolean</code> type value if user is successfully saved to database, false if not */ public static boolean saveNewUser(AppUser user, String userType) { if (user != null) { user.hashPass(); user.token = UUID.randomUUID().toString(); user.androidToken = UUID.randomUUID().toString(); if (Constants.USER_SELLER.equals(userType)) { user.userAccessLevel = UserAccessLevel.SELLER; user.validated = Constants.VALIDATED_USER; } try { user.save(); return true; } catch (PersistenceException e) { ErrorLogger.createNewErrorLogger( "Failed to save user. Possible duplicate email entry.", e.getMessage()); return false; } } return false; }
public static boolean activateForgottenPassword(String email) { AppUser user = AppUser.getUserByEmail(email); if (user != null) { try { user.forgottenPassToken = UUID.randomUUID().toString(); user.update(); // Sending Email To user String host = Play.application().configuration().getString("url") + "user/forgotyourpassword/" + user.forgottenPassToken; String cancelRequest = Play.application().configuration().getString("url") + "user/cancelpasswordchangerequest/" + user.forgottenPassToken; MailHelper.send(user.email, host, Constants.CHANGE_PASSWORD, cancelRequest, null, null); return true; } catch (PersistenceException e) { ErrorLogger.createNewErrorLogger("Failed to set password reset token.", e.getMessage()); return false; } } return false; }
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"); } } }