use of com.google.inject.persist.Transactional in project che by eclipse.
the class JpaProfileDao method getById.
@Override
@Transactional
public ProfileImpl getById(String userId) throws NotFoundException, ServerException {
requireNonNull(userId, "Required non-null id");
try {
final EntityManager manager = managerProvider.get();
final ProfileImpl profile = manager.find(ProfileImpl.class, userId);
if (profile == null) {
throw new NotFoundException(format("Couldn't find profile for user with id '%s'", userId));
}
manager.refresh(profile);
return profile;
} catch (RuntimeException x) {
throw new ServerException(x.getLocalizedMessage(), x);
}
}
use of com.google.inject.persist.Transactional in project che by eclipse.
the class JpaProfileDao method doCreate.
@Transactional
protected void doCreate(ProfileImpl profile) {
EntityManager manager = managerProvider.get();
manager.persist(profile);
manager.flush();
}
use of com.google.inject.persist.Transactional in project che by eclipse.
the class JpaUserDao method doCreate.
@Transactional(rollbackOn = { RuntimeException.class, ApiException.class })
protected void doCreate(UserImpl user) throws ConflictException, ServerException {
EntityManager manage = managerProvider.get();
manage.persist(user);
manage.flush();
eventService.publish(new PostUserPersistedEvent(new UserImpl(user))).propagateException();
}
use of com.google.inject.persist.Transactional in project che by eclipse.
the class JpaUserDao method doUpdate.
@Transactional
protected void doUpdate(UserImpl update) throws NotFoundException {
final EntityManager manager = managerProvider.get();
final UserImpl user = manager.find(UserImpl.class, update.getId());
if (user == null) {
throw new NotFoundException(format("Couldn't update user with id '%s' because it doesn't exist", update.getId()));
}
final String password = update.getPassword();
if (password != null) {
update.setPassword(encryptor.encrypt(password));
} else {
update.setPassword(user.getPassword());
}
manager.merge(update);
manager.flush();
}
use of com.google.inject.persist.Transactional in project che by eclipse.
the class JpaUserDao method getByAliasAndPassword.
@Override
@Transactional
public UserImpl getByAliasAndPassword(String emailOrName, String password) throws NotFoundException, ServerException {
requireNonNull(emailOrName, "Required non-null email or name");
requireNonNull(password, "Required non-null password");
try {
final UserImpl user = managerProvider.get().createNamedQuery("User.getByAliasAndPassword", UserImpl.class).setParameter("alias", emailOrName).getSingleResult();
if (!encryptor.test(password, user.getPassword())) {
throw new NotFoundException(format("User with email or name '%s' and given password doesn't exist", emailOrName));
}
return erasePassword(user);
} catch (NoResultException x) {
throw new NotFoundException(format("User with email or name '%s' and given password doesn't exist", emailOrName));
} catch (RuntimeException x) {
throw new ServerException(x.getLocalizedMessage(), x);
}
}
Aggregations