Search in sources :

Example 1 with Transactional

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();
}
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 2 with Transactional

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);
    }
}
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 3 with Transactional

use of com.google.inject.persist.Transactional 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 4 with Transactional

use of com.google.inject.persist.Transactional 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 5 with Transactional

use of com.google.inject.persist.Transactional 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

Transactional (com.google.inject.persist.Transactional)51 EntityManager (javax.persistence.EntityManager)37 NotFoundException (org.eclipse.che.api.core.NotFoundException)16 ServerException (org.eclipse.che.api.core.ServerException)12 ProjectConfigImpl (org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl)6 UserImpl (org.eclipse.che.api.user.server.model.impl.UserImpl)5 Predicate (com.linkedin.thirdeye.datalayer.util.Predicate)4 NoResultException (javax.persistence.NoResultException)4 RecipeImpl (org.eclipse.che.api.machine.server.recipe.RecipeImpl)4 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)4 Timestamp (java.sql.Timestamp)3 AccountImpl (org.eclipse.che.account.spi.AccountImpl)3 FactoryImpl (org.eclipse.che.api.factory.server.model.impl.FactoryImpl)3 DateTime (org.joda.time.DateTime)3 TaskBean (com.linkedin.thirdeye.datalayer.pojo.TaskBean)2 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 EntityTransaction (javax.persistence.EntityTransaction)2 Query (javax.persistence.Query)2