com.google.inject.persist.Transactional Java Examples
The following examples show how to use
com.google.inject.persist.Transactional.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JpaSshDao.java From che with Eclipse Public License 2.0 | 6 votes |
@Override @Transactional public List<SshPairImpl> get(String owner, String service) throws ServerException { requireNonNull(owner); requireNonNull(service); try { return managerProvider .get() .createNamedQuery("SshKeyPair.getByOwnerAndService", SshPairImpl.class) .setParameter("owner", owner) .setParameter("service", service) .getResultList(); } catch (RuntimeException e) { throw new ServerException(e.getLocalizedMessage(), e); } }
Example #2
Source File: JpaOrganizationDistributedResourcesDao.java From che with Eclipse Public License 2.0 | 6 votes |
@Override @Transactional public OrganizationDistributedResourcesImpl get(String organizationId) throws NotFoundException, ServerException { requireNonNull(organizationId, "Required non-null organization id"); try { OrganizationDistributedResourcesImpl distributedResources = managerProvider.get().find(OrganizationDistributedResourcesImpl.class, organizationId); if (distributedResources == null) { throw new NotFoundException( "There are no distributed resources for organization with id '" + organizationId + "'."); } return new OrganizationDistributedResourcesImpl(distributedResources); } catch (RuntimeException e) { throw new ServerException(e.getMessage(), e); } }
Example #3
Source File: JpaPreferenceDao.java From che with Eclipse Public License 2.0 | 6 votes |
@Override @Transactional public Map<String, String> getPreferences(String userId, String filter) throws ServerException { requireNonNull(userId); requireNonNull(filter); try { final EntityManager manager = managerProvider.get(); final PreferenceEntity prefs = manager.find(PreferenceEntity.class, userId); if (prefs == null) { return new HashMap<>(); } final Map<String, String> preferences = prefs.getPreferences(); if (!filter.isEmpty()) { final Pattern pattern = Pattern.compile(filter); return preferences .entrySet() .stream() .filter(preference -> pattern.matcher(preference.getKey()).matches()) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } else { return preferences; } } catch (RuntimeException ex) { throw new ServerException(ex.getLocalizedMessage(), ex); } }
Example #4
Source File: JpaMemberDao.java From che with Eclipse Public License 2.0 | 6 votes |
@Override @Transactional public List<MemberImpl> getMemberships(String userId) throws ServerException { requireNonNull(userId, "Required non-null user id"); try { final EntityManager manager = managerProvider.get(); return manager .createNamedQuery("Member.getByUser", MemberImpl.class) .setParameter("userId", userId) .getResultList() .stream() .map(MemberImpl::new) .collect(toList()); } catch (RuntimeException e) { throw new ServerException(e.getLocalizedMessage(), e); } }
Example #5
Source File: JpaSignatureKeyDao.java From che with Eclipse Public License 2.0 | 6 votes |
@Override @Transactional public SignatureKeyPairImpl get(String workspaceId) throws NotFoundException, ServerException { final EntityManager manager = managerProvider.get(); try { return new SignatureKeyPairImpl( manager .createNamedQuery("SignKeyPair.getAll", SignatureKeyPairImpl.class) .setParameter("workspaceId", workspaceId) .getSingleResult()); } catch (NoResultException x) { throw new NotFoundException( format("Signature key pair for workspace '%s' doesn't exist", workspaceId)); } catch (RuntimeException ex) { throw new ServerException(ex.getMessage(), ex); } }
Example #6
Source File: MultiuserJpaWorkspaceDao.java From che with Eclipse Public License 2.0 | 6 votes |
@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); } }
Example #7
Source File: JpaKubernetesMachineCache.java From che with Eclipse Public License 2.0 | 6 votes |
@Transactional protected void doUpdateMachineStatus(String workspaceId, String machineName, MachineStatus status) throws InfrastructureException { EntityManager entityManager = managerProvider.get(); KubernetesMachineImpl machine = entityManager.find(KubernetesMachineImpl.class, new MachineId(workspaceId, machineName)); if (machine == null) { throw new InfrastructureException( format("Machine '%s:%s' was not found", workspaceId, machineName)); } machine.setStatus(status); entityManager.flush(); }
Example #8
Source File: JpaOrganizationDao.java From che with Eclipse Public License 2.0 | 6 votes |
@Override @Transactional public OrganizationImpl getById(String organizationId) throws NotFoundException, ServerException { requireNonNull(organizationId, "Required non-null organization id"); try { final EntityManager manager = managerProvider.get(); OrganizationImpl organization = manager.find(OrganizationImpl.class, organizationId); if (organization == null) { throw new NotFoundException( format("Organization with id '%s' doesn't exist", organizationId)); } return organization; } catch (RuntimeException e) { throw new ServerException(e.getLocalizedMessage(), e); } }
Example #9
Source File: JpaWorkspaceDao.java From che with Eclipse Public License 2.0 | 6 votes |
@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); } }
Example #10
Source File: JpaWorkspaceActivityDao.java From che with Eclipse Public License 2.0 | 6 votes |
@Transactional void doUpdate(boolean optional, String workspaceId, Consumer<WorkspaceActivity> updater) { EntityManager em = managerProvider.get(); WorkspaceActivity activity = em.find(WorkspaceActivity.class, workspaceId); if (activity == null) { if (optional) { return; } activity = new WorkspaceActivity(); activity.setWorkspaceId(workspaceId); updater.accept(activity); em.persist(activity); } else { updater.accept(activity); em.merge(activity); } em.flush(); }
Example #11
Source File: JpaKubernetesRuntimeStateCache.java From che with Eclipse Public License 2.0 | 6 votes |
@Transactional(rollbackOn = {RuntimeException.class, ServerException.class}) protected void doRemove(RuntimeIdentity runtimeIdentity) throws ServerException { EntityManager em = managerProvider.get(); KubernetesRuntimeState runtime = em.find(KubernetesRuntimeState.class, runtimeIdentity.getWorkspaceId()); if (runtime != null) { eventService .publish( new BeforeKubernetesRuntimeStateRemovedEvent(new KubernetesRuntimeState(runtime))) .propagateException(); em.remove(runtime); } }
Example #12
Source File: JpaWorkspaceActivityDao.java From che with Eclipse Public License 2.0 | 6 votes |
@Override @Transactional(rollbackOn = ServerException.class) public long countWorkspacesInStatus(WorkspaceStatus status, long timestamp) throws ServerException { try { String queryName = "WorkspaceActivity.get" + firstUpperCase(status.name()) + "SinceCount"; return managerProvider .get() .createNamedQuery(queryName, Long.class) .setParameter("time", timestamp) .getSingleResult(); } catch (RuntimeException e) { throw new ServerException(e.getMessage(), e); } }
Example #13
Source File: JpaFreeResourcesLimitDao.java From che with Eclipse Public License 2.0 | 6 votes |
@Override @Transactional public Page<FreeResourcesLimitImpl> getAll(int maxItems, int skipCount) throws ServerException { try { final List<FreeResourcesLimitImpl> list = managerProvider .get() .createNamedQuery("FreeResourcesLimit.getAll", FreeResourcesLimitImpl.class) .setMaxResults(maxItems) .setFirstResult(skipCount) .getResultList() .stream() .map(FreeResourcesLimitImpl::new) .collect(Collectors.toList()); return new Page<>(list, skipCount, maxItems, getTotalCount()); } catch (RuntimeException e) { throw new ServerException(e.getMessage(), e); } }
Example #14
Source File: JpaOrganizationDao.java From che with Eclipse Public License 2.0 | 5 votes |
@Transactional protected void doRemove(String organizationId) { final EntityManager manager = managerProvider.get(); final OrganizationImpl organization = manager.find(OrganizationImpl.class, organizationId); if (organization != null) { manager.remove(organization); manager.flush(); } }
Example #15
Source File: KeycloakUserManager.java From che with Eclipse Public License 2.0 | 5 votes |
@Transactional(rollbackOn = {RuntimeException.class, ApiException.class}) protected void doRemove(String id) throws ServerException { UserImpl user; try { user = userDao.getById(id); } catch (NotFoundException ignored) { return; } preferencesDao.remove(id); eventService.publish(new BeforeUserRemovedEvent(user)).propagateException(); userDao.remove(id); }
Example #16
Source File: JpaKubernetesMachineCache.java From che with Eclipse Public License 2.0 | 5 votes |
@Transactional(rollbackOn = {RuntimeException.class, InfrastructureException.class}) protected boolean doUpdateServerStatus( RuntimeIdentity runtimeIdentity, String machineName, String serverName, ServerStatus status) throws InfrastructureException { EntityManager entityManager = managerProvider.get(); KubernetesServerImpl server = getServer(runtimeIdentity, machineName, serverName); if (server.getStatus() != status) { server.setStatus(status); entityManager.flush(); return true; } return false; }
Example #17
Source File: JpaWorkspaceActivityDao.java From che with Eclipse Public License 2.0 | 5 votes |
@Override @Transactional(rollbackOn = ServerException.class) public WorkspaceActivity findActivity(String workspaceId) throws ServerException { try { EntityManager em = managerProvider.get(); return em.find(WorkspaceActivity.class, workspaceId); } catch (RuntimeException x) { throw new ServerException(x.getLocalizedMessage(), x); } }
Example #18
Source File: JpaWorkspaceDao.java From che with Eclipse Public License 2.0 | 5 votes |
@Override @Transactional public WorkspaceImpl get(String id) throws NotFoundException, ServerException { requireNonNull(id, "Required non-null id"); try { final WorkspaceImpl workspace = managerProvider.get().find(WorkspaceImpl.class, id); if (workspace == null) { throw new NotFoundException(format("Workspace with id '%s' doesn't exist", id)); } return new WorkspaceImpl(workspace); } catch (RuntimeException x) { throw new ServerException(x.getLocalizedMessage(), x); } }
Example #19
Source File: JpaKubernetesRuntimeStateCache.java From che with Eclipse Public License 2.0 | 5 votes |
@Transactional(rollbackOn = InfrastructureException.class) @Override public Optional<KubernetesRuntimeState> get(RuntimeIdentity runtimeId) throws InfrastructureException { try { return Optional.ofNullable( managerProvider.get().find(KubernetesRuntimeState.class, runtimeId.getWorkspaceId())); } catch (RuntimeException x) { throw new InfrastructureException(x.getMessage(), x); } }
Example #20
Source File: JpaKubernetesRuntimeStateCache.java From che with Eclipse Public License 2.0 | 5 votes |
@Transactional(rollbackOn = InfrastructureException.class) @Override public Optional<WorkspaceStatus> getStatus(RuntimeIdentity id) throws InfrastructureException { try { Optional<KubernetesRuntimeState> runtimeStateOpt = get(id); return runtimeStateOpt.map(KubernetesRuntimeState::getStatus); } catch (RuntimeException x) { throw new InfrastructureException(x.getMessage(), x); } }
Example #21
Source File: JpaAccountDao.java From che with Eclipse Public License 2.0 | 5 votes |
@Transactional protected void doRemove(String id) { final EntityManager manager = managerProvider.get(); AccountImpl account = manager.find(AccountImpl.class, id); if (account != null) { manager.remove(account); manager.flush(); } }
Example #22
Source File: JpaOrganizationDistributedResourcesDao.java From che with Eclipse Public License 2.0 | 5 votes |
@Override @Transactional public Page<OrganizationDistributedResourcesImpl> getByParent( String organizationId, int maxItems, long skipCount) throws ServerException { requireNonNull(organizationId, "Required non-null organization id"); checkArgument( skipCount <= Integer.MAX_VALUE, "The number of items to skip can't be greater than " + Integer.MAX_VALUE); try { final EntityManager manager = managerProvider.get(); final List<OrganizationDistributedResourcesImpl> distributedResources = manager .createNamedQuery( "OrganizationDistributedResources.getByParent", OrganizationDistributedResourcesImpl.class) .setParameter("parent", organizationId) .setMaxResults(maxItems) .setFirstResult((int) skipCount) .getResultList(); final Long distributedResourcesCount = manager .createNamedQuery("OrganizationDistributedResources.getCountByParent", Long.class) .setParameter("parent", organizationId) .getSingleResult(); return new Page<>( distributedResources .stream() .map(OrganizationDistributedResourcesImpl::new) .collect(Collectors.toList()), skipCount, maxItems, distributedResourcesCount); } catch (RuntimeException e) { throw new ServerException(e.getMessage(), e); } }
Example #23
Source File: JpaMemberDao.java From che with Eclipse Public License 2.0 | 5 votes |
@Override @Transactional public Page<MemberImpl> getMembers(String organizationId, int maxItems, long skipCount) throws ServerException { requireNonNull(organizationId, "Required non-null organization id"); checkArgument( skipCount <= Integer.MAX_VALUE, "The number of items to skip can't be greater than " + Integer.MAX_VALUE); try { final EntityManager manager = managerProvider.get(); final List<MemberImpl> members = manager .createNamedQuery("Member.getByOrganization", MemberImpl.class) .setParameter("organizationId", organizationId) .setMaxResults(maxItems) .setFirstResult((int) skipCount) .getResultList() .stream() .map(MemberImpl::new) .collect(toList()); final Long membersCount = manager .createNamedQuery("Member.getCountByOrganizationId", Long.class) .setParameter("organizationId", organizationId) .getSingleResult(); return new Page<>(members, skipCount, maxItems, membersCount); } catch (RuntimeException e) { throw new ServerException(e.getLocalizedMessage(), e); } }
Example #24
Source File: JpaWorkspaceActivityDao.java From che with Eclipse Public License 2.0 | 5 votes |
@Override @Transactional(rollbackOn = ServerException.class) public Page<String> findInStatusSince( long timestamp, WorkspaceStatus status, int maxItems, long skipCount) throws ServerException { try { String queryName = "WorkspaceActivity.get" + firstUpperCase(status.name()) + "Since"; String countQueryName = queryName + "Count"; long count = managerProvider .get() .createNamedQuery(countQueryName, Long.class) .setParameter("time", timestamp) .getSingleResult(); List<String> data = managerProvider .get() .createNamedQuery(queryName, String.class) .setParameter("time", timestamp) .setFirstResult((int) skipCount) .setMaxResults(maxItems) .getResultList(); return new Page<>(data, skipCount, maxItems, count); } catch (RuntimeException e) { throw new ServerException(e.getMessage(), e); } }
Example #25
Source File: JpaFreeResourcesLimitDao.java From che with Eclipse Public License 2.0 | 5 votes |
@Transactional protected void doRemove(String id) { final EntityManager manager = managerProvider.get(); final FreeResourcesLimitImpl resourcesLimit = manager.find(FreeResourcesLimitImpl.class, id); if (resourcesLimit != null) { manager.remove(resourcesLimit); manager.flush(); } }
Example #26
Source File: JpaOrganizationDao.java From che with Eclipse Public License 2.0 | 5 votes |
@Transactional protected void doUpdate(OrganizationImpl update) throws NotFoundException { final EntityManager manager = managerProvider.get(); if (manager.find(OrganizationImpl.class, update.getId()) == null) { throw new NotFoundException( format( "Couldn't update organization with id '%s' because it doesn't exist", update.getId())); } manager.merge(update); manager.flush(); }
Example #27
Source File: JpaOrganizationDao.java From che with Eclipse Public License 2.0 | 5 votes |
@Override @Transactional public Page<OrganizationImpl> getSuborganizations( String parentQualifiedName, int maxItems, long skipCount) throws ServerException { requireNonNull(parentQualifiedName, "Required non-null parent qualified name"); checkArgument( skipCount <= Integer.MAX_VALUE, "The number of items to skip can't be greater than " + Integer.MAX_VALUE); try { final EntityManager manager = managerProvider.get(); List<OrganizationImpl> result = manager .createNamedQuery("Organization.getSuborganizations", OrganizationImpl.class) .setParameter("qualifiedName", parentQualifiedName + "/%") .setMaxResults(maxItems) .setFirstResult((int) skipCount) .getResultList(); final long suborganizationsCount = manager .createNamedQuery("Organization.getSuborganizationsCount", Long.class) .setParameter("qualifiedName", parentQualifiedName + "/%") .getSingleResult(); return new Page<>(result, skipCount, maxItems, suborganizationsCount); } catch (RuntimeException e) { throw new ServerException(e.getLocalizedMessage(), e); } }
Example #28
Source File: JpaOrganizationDao.java From che with Eclipse Public License 2.0 | 5 votes |
@Override @Transactional public Page<OrganizationImpl> getByParent(String parent, int maxItems, long skipCount) throws ServerException { requireNonNull(parent, "Required non-null parent"); checkArgument( skipCount <= Integer.MAX_VALUE, "The number of items to skip can't be greater than " + Integer.MAX_VALUE); try { final EntityManager manager = managerProvider.get(); final List<OrganizationImpl> result = manager .createNamedQuery("Organization.getByParent", OrganizationImpl.class) .setParameter("parent", parent) .setMaxResults(maxItems) .setFirstResult((int) skipCount) .getResultList(); final Long suborganizationsCount = manager .createNamedQuery("Organization.getByParentCount", Long.class) .setParameter("parent", parent) .getSingleResult(); return new Page<>(result, skipCount, maxItems, suborganizationsCount); } catch (RuntimeException e) { throw new ServerException(e.getLocalizedMessage(), e); } }
Example #29
Source File: JpaFactoryDao.java From che with Eclipse Public License 2.0 | 5 votes |
@Transactional protected void doCreate(FactoryImpl factory) { final EntityManager manager = managerProvider.get(); if (factory.getWorkspace() != null) { factory.getWorkspace().getProjects().forEach(ProjectConfigImpl::prePersistAttributes); } manager.persist(factory); manager.flush(); }
Example #30
Source File: JpaSshDao.java From che with Eclipse Public License 2.0 | 5 votes |
@Transactional protected void doRemove(String owner, String service, String name) throws NotFoundException { EntityManager manager = managerProvider.get(); SshPairImpl entity = manager.find(SshPairImpl.class, new SshPairPrimaryKey(owner, service, name)); if (entity == null) { throw new NotFoundException( format("Ssh pair with service '%s' and name '%s' was not found.", service, name)); } manager.remove(entity); manager.flush(); }