List of usage examples for javax.persistence NoResultException NoResultException
public NoResultException()
NoResultException
exception with null
as its detail message. From source file:cc.kune.wave.server.search.CustomPerUserWaveViewHandlerImpl.java
@Override @KuneTransactional// w w w. j a v a 2 s . c om public Multimap<WaveId, WaveletId> retrievePerUserWaveView(final ParticipantId participantId) { final String address = participantId.getAddress(); LOG.debug("Retrive waves view of user " + address); final Multimap<WaveId, WaveletId> userWavesViewMap = HashMultimap.create(); try { final ParticipantEntity participantEntity = participantEntityManager.find(address); if (participantEntity != null) { for (final WaveEntity wave : participantEntity.getWaves()) { userWavesViewMap.put(WaveId.deserialise(wave.getWaveId()), WaveletId.deserialise(wave.getWaveletId())); } } else { throw new NoResultException(); } } catch (final javax.persistence.NoResultException e) { logNotFound(participantId); } return userWavesViewMap; }
From source file:org.batoo.jpa.core.impl.nativeQuery.NativeQuery.java
/** * {@inheritDoc}/*from www .ja va 2s .c o m*/ * */ @Override public Object getSingleResult() { final List<?> resultList = this.getResultList(); if (resultList.size() > 1) { throw new NonUniqueResultException(); } if (resultList.size() == 0) { throw new NoResultException(); } return resultList.get(0); }
From source file:com.enioka.jqm.api.HibernateClient.java
@Override public void cancelJob(int idJob) { EntityManager em = null;/*from w w w . jav a 2s . c o m*/ JobInstance ji = null; try { em = getEm(); em.getTransaction().begin(); ji = em.find(JobInstance.class, idJob, LockModeType.PESSIMISTIC_WRITE); if (ji.getState().equals(State.SUBMITTED)) { ji.setState(State.CANCELLED); } else { throw new NoResultException(); } em.getTransaction().commit(); } catch (NoResultException e) { closeQuietly(em); throw new JqmClientException( "the job is already running, has already finished or never existed to begin with"); } try { em.getTransaction().begin(); History h = new History(); h.setId(ji.getId()); h.setJd(ji.getJd()); h.setApplicationName(ji.getJd().getApplicationName()); h.setSessionId(ji.getSessionID()); h.setQueue(ji.getQueue()); h.setQueueName(ji.getQueue().getName()); h.setEnqueueDate(ji.getCreationDate()); h.setUserName(ji.getUserName()); h.setEmail(ji.getEmail()); h.setParentJobId(ji.getParentId()); h.setApplication(ji.getApplication()); h.setModule(ji.getModule()); h.setKeyword1(ji.getKeyword1()); h.setKeyword2(ji.getKeyword2()); h.setKeyword3(ji.getKeyword3()); h.setProgress(ji.getProgress()); h.setStatus(State.CANCELLED); h.setNode(ji.getNode()); if (ji.getNode() != null) { h.setNodeName(ji.getNode().getName()); } em.persist(h); em.createQuery("DELETE FROM JobInstance WHERE id = :i").setParameter("i", ji.getId()).executeUpdate(); em.getTransaction().commit(); } catch (Exception e) { throw new JqmClientException("could not cancel job instance", e); } finally { closeQuietly(em); } }
From source file:com.enioka.jqm.api.HibernateClient.java
@Override public void setJobQueue(int idJob, int idQueue) { EntityManager em = null;//from w w w . ja v a 2 s . c o m JobInstance ji = null; Queue q = null; try { em = getEm(); q = em.find(Queue.class, idQueue); } catch (NoResultException e) { closeQuietly(em); throw new JqmClientException("Queue does not exist"); } catch (Exception e) { closeQuietly(em); throw new JqmClientException("Cannot retrieve queue", e); } try { em.getTransaction().begin(); ji = em.find(JobInstance.class, idJob, LockModeType.PESSIMISTIC_WRITE); if (ji == null || !ji.getState().equals(State.SUBMITTED)) { throw new NoResultException(); } ji.setQueue(q); em.getTransaction().commit(); } catch (NoResultException e) { throw new JqmClientException("Job instance does not exist or has already started"); } catch (Exception e) { throw new JqmClientException("could not change the queue of a job (internal error)", e); } finally { closeQuietly(em); } }
From source file:org.batoo.jpa.core.impl.criteria.QueryImpl.java
/** * {@inheritDoc}/*from w ww.j a v a 2s . c om*/ * */ @Override public X getSingleResult() { final List<X> resultList = this.getResultList(); if (resultList.size() > 1) { throw new NonUniqueResultException(); } if (resultList.size() == 0) { throw new NoResultException(); } return resultList.get(0); }
From source file:org.opencastproject.serviceregistry.impl.ServiceRegistryJpaImpl.java
/** * Internal method to update a job, throwing unwrapped JPA exceptions. * /* ww w. jav a 2 s . c o m*/ * @param em * the current entity manager * @param job * the job to update * @return the updated job * @throws PersistenceException * if there is an exception thrown while persisting the job via JPA * @throws IllegalArgumentException */ protected Job updateInternal(EntityManager em, Job job) throws PersistenceException { EntityTransaction tx = em.getTransaction(); try { tx.begin(); JobJpaImpl fromDb; fromDb = em.find(JobJpaImpl.class, job.getId()); if (fromDb == null) { throw new NoResultException(); } update(fromDb, (JaxbJob) job); em.merge(fromDb); tx.commit(); ((JaxbJob) job).setVersion(fromDb.getVersion()); setJobUri(job); return job; } catch (PersistenceException e) { if (tx.isActive()) { tx.rollback(); } throw e; } }
From source file:org.opencastproject.serviceregistry.impl.ServiceRegistryJpaImpl.java
/** * Internal method to update the service registration state, throwing unwrapped JPA exceptions. * /*ww w .j ava2s . c o m*/ * @param em * the current entity manager * @param registration * the service registration to update * @return the updated service registration * @throws PersistenceException * if there is an exception thrown while persisting the job via JPA * @throws IllegalArgumentException */ private ServiceRegistration updateServiceState(EntityManager em, ServiceRegistrationJpaImpl registration) throws PersistenceException { EntityTransaction tx = em.getTransaction(); try { tx.begin(); ServiceRegistrationJpaImpl fromDb; fromDb = em.find(ServiceRegistrationJpaImpl.class, registration.getId()); if (fromDb == null) { throw new NoResultException(); } fromDb.setServiceState(registration.getServiceState()); fromDb.setStateChanged(registration.getStateChanged()); fromDb.setWarningStateTrigger(registration.getWarningStateTrigger()); fromDb.setErrorStateTrigger(registration.getErrorStateTrigger()); tx.commit(); servicesStatistics.updateService(registration); return registration; } catch (PersistenceException e) { if (tx.isActive()) { tx.rollback(); } throw e; } }