use of javax.persistence.EntityManager 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 javax.persistence.EntityManager 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);
}
}
use of javax.persistence.EntityManager in project che by eclipse.
the class JpaRecipeDao method doUpdate.
@Transactional
protected RecipeImpl doUpdate(RecipeImpl update) throws NotFoundException {
final EntityManager manager = managerProvider.get();
if (manager.find(RecipeImpl.class, update.getId()) == null) {
throw new NotFoundException(format("Could not update recipe with id %s because it doesn't exist", update.getId()));
}
RecipeImpl merged = manager.merge(update);
manager.flush();
return merged;
}
use of javax.persistence.EntityManager in project che by eclipse.
the class JpaRecipeDao method getById.
@Override
@Transactional
public RecipeImpl getById(String id) throws NotFoundException, ServerException {
requireNonNull(id);
try {
final EntityManager manager = managerProvider.get();
final RecipeImpl recipe = manager.find(RecipeImpl.class, id);
if (recipe == null) {
throw new NotFoundException(format("Recipe with id '%s' doesn't exist", id));
}
return recipe;
} catch (RuntimeException ex) {
throw new ServerException(ex.getLocalizedMessage(), ex);
}
}
use of javax.persistence.EntityManager in project che by eclipse.
the class JpaRecipeDao method doRemove.
@Transactional(rollbackOn = { RuntimeException.class, ServerException.class })
protected void doRemove(String id) throws ServerException {
final EntityManager manager = managerProvider.get();
final RecipeImpl recipe = manager.find(RecipeImpl.class, id);
if (recipe != null) {
eventService.publish(new BeforeRecipeRemovedEvent(new RecipeImpl(recipe))).propagateException();
manager.remove(recipe);
manager.flush();
}
}
Aggregations