Search in sources :

Example 31 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 32 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)

Example 33 with Transactional

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

the class JpaWorkspaceDao method doUpdate.

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

Example 34 with Transactional

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

the class JpaWorkspaceDao method getWorkspaces.

@Override
@Transactional
public List<WorkspaceImpl> getWorkspaces(boolean isTemporary, int skipCount, int maxItems) throws ServerException {
    checkArgument(maxItems >= 0, "The number of items to return can't be negative.");
    checkArgument(skipCount >= 0, "The number of items to skip can't be negative or greater than " + Integer.MAX_VALUE);
    try {
        return managerProvider.get().createNamedQuery("Workspace.getByTemporary", WorkspaceImpl.class).setParameter("temporary", isTemporary).setMaxResults(maxItems).setFirstResult(skipCount).getResultList().stream().map(WorkspaceImpl::new).collect(toList());
    } 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) Transactional(com.google.inject.persist.Transactional)

Example 35 with Transactional

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

the class JpaPreferenceDao method doSetPreference.

@Transactional
protected void doSetPreference(PreferenceEntity prefs) {
    final EntityManager manager = managerProvider.get();
    final PreferenceEntity existing = manager.find(PreferenceEntity.class, prefs.getUserId());
    if (existing != null) {
        manager.merge(prefs);
    } else {
        manager.persist(prefs);
    }
    manager.flush();
}
Also used : EntityManager(javax.persistence.EntityManager) 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