Search in sources :

Example 6 with Transactional

use of com.google.inject.persist.Transactional in project che by eclipse.

the class JpaStackDao method doCreate.

@Transactional(rollbackOn = { RuntimeException.class, ApiException.class })
protected void doCreate(StackImpl stack) throws ConflictException, ServerException {
    if (stack.getWorkspaceConfig() != null) {
        stack.getWorkspaceConfig().getProjects().forEach(ProjectConfigImpl::prePersistAttributes);
    }
    EntityManager manager = managerProvider.get();
    manager.persist(stack);
    manager.flush();
    eventService.publish(new StackPersistedEvent(stack)).propagateException();
}
Also used : StackPersistedEvent(org.eclipse.che.api.workspace.server.event.StackPersistedEvent) EntityManager(javax.persistence.EntityManager) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl) Transactional(com.google.inject.persist.Transactional)

Example 7 with Transactional

use of com.google.inject.persist.Transactional in project che by eclipse.

the class JpaStackDao method doRemove.

@Transactional(rollbackOn = { RuntimeException.class, ServerException.class })
protected void doRemove(String id) throws ServerException {
    final EntityManager manager = managerProvider.get();
    final StackImpl stack = manager.find(StackImpl.class, id);
    if (stack != null) {
        eventService.publish(new BeforeStackRemovedEvent(new StackImpl(stack))).propagateException();
        manager.remove(stack);
        manager.flush();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) StackImpl(org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl) BeforeStackRemovedEvent(org.eclipse.che.api.workspace.server.event.BeforeStackRemovedEvent) Transactional(com.google.inject.persist.Transactional)

Example 8 with Transactional

use of com.google.inject.persist.Transactional in project che by eclipse.

the class JpaStackDao method doUpdate.

@Transactional
protected StackImpl doUpdate(StackImpl update) throws NotFoundException {
    final EntityManager manager = managerProvider.get();
    if (manager.find(StackImpl.class, update.getId()) == null) {
        throw new NotFoundException(format("Workspace with id '%s' doesn't exist", update.getId()));
    }
    if (update.getWorkspaceConfig() != null) {
        update.getWorkspaceConfig().getProjects().forEach(ProjectConfigImpl::prePersistAttributes);
    }
    StackImpl merged = manager.merge(update);
    manager.flush();
    return merged;
}
Also used : EntityManager(javax.persistence.EntityManager) StackImpl(org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl) NotFoundException(org.eclipse.che.api.core.NotFoundException) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl) Transactional(com.google.inject.persist.Transactional)

Example 9 with Transactional

use of com.google.inject.persist.Transactional in project che by eclipse.

the class JpaWorkspaceDao method get.

@Override
@Transactional
public WorkspaceImpl get(String name, String namespace) throws NotFoundException, ServerException {
    requireNonNull(name, "Required non-null name");
    requireNonNull(namespace, "Required non-null namespace");
    try {
        return new WorkspaceImpl(managerProvider.get().createNamedQuery("Workspace.getByName", WorkspaceImpl.class).setParameter("namespace", namespace).setParameter("name", name).getSingleResult());
    } catch (NoResultException noResEx) {
        throw new NotFoundException(format("Workspace with name '%s' in namespace '%s' doesn't exist", name, namespace));
    } catch (RuntimeException x) {
        throw new ServerException(x.getLocalizedMessage(), x);
    }
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) 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 10 with Transactional

use of com.google.inject.persist.Transactional in project che by eclipse.

the class JpaFactoryDao method doUpdate.

@Transactional
protected FactoryImpl doUpdate(FactoryImpl update) throws NotFoundException {
    final EntityManager manager = managerProvider.get();
    if (manager.find(FactoryImpl.class, update.getId()) == null) {
        throw new NotFoundException(format("Could not update factory with id %s because it doesn't exist", update.getId()));
    }
    if (update.getWorkspace() != null) {
        update.getWorkspace().getProjects().forEach(ProjectConfigImpl::prePersistAttributes);
    }
    FactoryImpl merged = manager.merge(update);
    manager.flush();
    return merged;
}
Also used : EntityManager(javax.persistence.EntityManager) NotFoundException(org.eclipse.che.api.core.NotFoundException) FactoryImpl(org.eclipse.che.api.factory.server.model.impl.FactoryImpl) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl) 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