use of com.google.inject.persist.Transactional in project che by eclipse.
the class JpaProfileDao method doRemove.
@Transactional
protected void doRemove(String userId) {
final EntityManager manager = managerProvider.get();
final ProfileImpl profile = manager.find(ProfileImpl.class, userId);
if (profile != null) {
manager.remove(profile);
manager.flush();
}
}
use of com.google.inject.persist.Transactional in project che by eclipse.
the class JpaProfileDao method doUpdate.
@Transactional
protected void doUpdate(ProfileImpl profile) throws NotFoundException {
final EntityManager manager = managerProvider.get();
if (manager.find(ProfileImpl.class, profile.getUserId()) == null) {
throw new NotFoundException(format("Couldn't update profile, because profile for user with id '%s' doesn't exist", profile.getUserId()));
}
manager.merge(profile);
manager.flush();
}
use of com.google.inject.persist.Transactional in project che by eclipse.
the class JpaUserDao method doRemove.
@Transactional(rollbackOn = { RuntimeException.class, ServerException.class })
protected Optional<UserImpl> doRemove(String id) throws ServerException {
final EntityManager manager = managerProvider.get();
final UserImpl user = manager.find(UserImpl.class, id);
if (user == null) {
return Optional.empty();
}
eventService.publish(new BeforeUserRemovedEvent(user)).propagateException();
manager.remove(user);
manager.flush();
return Optional.of(user);
}
use of com.google.inject.persist.Transactional in project che by eclipse.
the class JpaAccountDao method doUpdate.
@Transactional
protected void doUpdate(AccountImpl update) throws NotFoundException {
final EntityManager manager = managerProvider.get();
final AccountImpl account = manager.find(AccountImpl.class, update.getId());
if (account == null) {
throw new NotFoundException(format("Couldn't update account with id '%s' because it doesn't exist", update.getId()));
}
manager.merge(update);
manager.flush();
}
use of com.google.inject.persist.Transactional in project che by eclipse.
the class JpaAccountDao method getByName.
@Override
@Transactional
public AccountImpl getByName(String name) throws ServerException, NotFoundException {
requireNonNull(name, "Required non-null account name");
final EntityManager manager = managerProvider.get();
try {
return manager.createNamedQuery("Account.getByName", AccountImpl.class).setParameter("name", name).getSingleResult();
} catch (NoResultException e) {
throw new NotFoundException(String.format("Account with name '%s' was not found", name));
} catch (RuntimeException e) {
throw new ServerException(e.getLocalizedMessage(), e);
}
}
Aggregations