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();
}
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);
}
}
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;
}
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);
}
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();
}
Aggregations