Search in sources :

Example 6 with EntityManager

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();
}
Also used : EntityManager(javax.persistence.EntityManager) AccountImpl(org.eclipse.che.account.spi.AccountImpl) NotFoundException(org.eclipse.che.api.core.NotFoundException) Transactional(com.google.inject.persist.Transactional)

Example 7 with EntityManager

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);
    }
}
Also used : EntityManager(javax.persistence.EntityManager) ServerException(org.eclipse.che.api.core.ServerException) NotFoundException(org.eclipse.che.api.core.NotFoundException) NoResultException(javax.persistence.NoResultException) Transactional(com.google.inject.persist.Transactional)

Example 8 with EntityManager

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;
}
Also used : EntityManager(javax.persistence.EntityManager) RecipeImpl(org.eclipse.che.api.machine.server.recipe.RecipeImpl) NotFoundException(org.eclipse.che.api.core.NotFoundException) Transactional(com.google.inject.persist.Transactional)

Example 9 with EntityManager

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);
    }
}
Also used : EntityManager(javax.persistence.EntityManager) ServerException(org.eclipse.che.api.core.ServerException) RecipeImpl(org.eclipse.che.api.machine.server.recipe.RecipeImpl) NotFoundException(org.eclipse.che.api.core.NotFoundException) Transactional(com.google.inject.persist.Transactional)

Example 10 with EntityManager

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();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) RecipeImpl(org.eclipse.che.api.machine.server.recipe.RecipeImpl) BeforeRecipeRemovedEvent(org.eclipse.che.api.machine.server.event.BeforeRecipeRemovedEvent) Transactional(com.google.inject.persist.Transactional)

Aggregations

EntityManager (javax.persistence.EntityManager)1395 Test (org.junit.Test)876 Priority (org.hibernate.envers.test.Priority)249 Query (javax.persistence.Query)200 TestForIssue (org.hibernate.testing.TestForIssue)97 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)87 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)79 List (java.util.List)69 NoResultException (javax.persistence.NoResultException)65 AbstractMetamodelSpecificTest (org.hibernate.jpa.test.metamodel.AbstractMetamodelSpecificTest)63 EntityManagerFactory (javax.persistence.EntityManagerFactory)56 HashMap (java.util.HashMap)50 StrTestEntity (org.hibernate.envers.test.entities.StrTestEntity)50 ArrayList (java.util.ArrayList)41 PersistenceException (javax.persistence.PersistenceException)40 EntityNotFoundException (javax.persistence.EntityNotFoundException)39 Transactional (com.google.inject.persist.Transactional)38 EntityTransaction (javax.persistence.EntityTransaction)36 Item (org.hibernate.jpa.test.Item)36 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)34