Search in sources :

Example 26 with Transactional

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

the class JpaRecipeDao method doCreate.

@Transactional(rollbackOn = { RuntimeException.class, ApiException.class })
protected void doCreate(RecipeImpl recipe) throws ConflictException, ServerException {
    EntityManager manage = managerProvider.get();
    manage.persist(recipe);
    manage.flush();
    eventService.publish(new RecipePersistedEvent(recipe)).propagateException();
}
Also used : EntityManager(javax.persistence.EntityManager) RecipePersistedEvent(org.eclipse.che.api.machine.server.event.RecipePersistedEvent) Transactional(com.google.inject.persist.Transactional)

Example 27 with Transactional

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

the class JpaSnapshotDao method getSnapshot.

@Override
@Transactional
public SnapshotImpl getSnapshot(String workspaceId, String envName, String machineName) throws NotFoundException, SnapshotException {
    requireNonNull(workspaceId, "Required non-null workspace id");
    requireNonNull(envName, "Required non-null environment name");
    requireNonNull(machineName, "Required non-null machine name");
    try {
        return managerProvider.get().createNamedQuery("Snapshot.getByMachine", SnapshotImpl.class).setParameter("workspaceId", workspaceId).setParameter("envName", envName).setParameter("machineName", machineName).getSingleResult();
    } catch (NoResultException x) {
        throw new NotFoundException(format("Snapshot for machine '%s:%s:%s' doesn't exist", workspaceId, envName, machineName));
    } catch (RuntimeException x) {
        throw new SnapshotException(x.getLocalizedMessage(), x);
    }
}
Also used : NotFoundException(org.eclipse.che.api.core.NotFoundException) NoResultException(javax.persistence.NoResultException) SnapshotException(org.eclipse.che.api.machine.server.exception.SnapshotException) Transactional(com.google.inject.persist.Transactional)

Example 28 with Transactional

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

the class JpaSnapshotDao method doReplaceSnapshots.

@Transactional
protected List<SnapshotImpl> doReplaceSnapshots(String workspaceId, String envName, Collection<? extends SnapshotImpl> newSnapshots) {
    final EntityManager manager = managerProvider.get();
    final List<SnapshotImpl> existing = manager.createNamedQuery("Snapshot.findByWorkspaceAndEnvironment", SnapshotImpl.class).setParameter("workspaceId", workspaceId).setParameter("envName", envName).getResultList();
    existing.forEach(manager::remove);
    manager.flush();
    newSnapshots.forEach(manager::persist);
    return existing;
}
Also used : EntityManager(javax.persistence.EntityManager) SnapshotImpl(org.eclipse.che.api.machine.server.model.impl.SnapshotImpl) Transactional(com.google.inject.persist.Transactional)

Example 29 with Transactional

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

the class JpaWorkspaceDao method doRemove.

@Transactional(rollbackOn = { RuntimeException.class, ServerException.class })
protected Optional<WorkspaceImpl> doRemove(String id) throws ServerException {
    final WorkspaceImpl workspace = managerProvider.get().find(WorkspaceImpl.class, id);
    if (workspace == null) {
        return Optional.empty();
    }
    final EntityManager manager = managerProvider.get();
    eventService.publish(new BeforeWorkspaceRemovedEvent(new WorkspaceImpl(workspace))).propagateException();
    manager.remove(workspace);
    manager.flush();
    return Optional.of(workspace);
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) EntityManager(javax.persistence.EntityManager) BeforeWorkspaceRemovedEvent(org.eclipse.che.api.workspace.server.event.BeforeWorkspaceRemovedEvent) Transactional(com.google.inject.persist.Transactional)

Example 30 with Transactional

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

the class JpaWorkspaceDao method doCreate.

@Transactional
protected void doCreate(WorkspaceImpl workspace) {
    if (workspace.getConfig() != null) {
        workspace.getConfig().getProjects().forEach(ProjectConfigImpl::prePersistAttributes);
    }
    EntityManager manager = managerProvider.get();
    manager.persist(workspace);
    manager.flush();
}
Also used : EntityManager(javax.persistence.EntityManager) 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