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