List of usage examples for javax.persistence EntityManager createNamedQuery
public Query createNamedQuery(String name);
Query
for executing a named query (in the Java Persistence query language or in native SQL). From source file:in.bookmylab.jpa.JpaDAO.java
/** * @param spmId //from ww w . j a v a 2s . c o m * @return */ public SpmLabBooking getSpmByBookingId(Long bookingId) { EntityManager em = emf.createEntityManager(); SpmLabBooking spm = null; try { Query q = em.createNamedQuery("SpmLabBooking.findByBookingId"); spm = (SpmLabBooking) q.setParameter("bookingId", bookingId).getSingleResult(); } finally { em.close(); } return spm; }
From source file:in.bookmylab.jpa.JpaDAO.java
/** * @param xrdId // ww w. j a v a2 s.c o m * @return */ public XrdLabBooking getXrdBooking(Long xrdId) { EntityManager em = emf.createEntityManager(); XrdLabBooking xrd = null; try { Query q = em.createNamedQuery("XrdLabBooking.findById"); xrd = (XrdLabBooking) q.setParameter("xrdId", xrdId).getSingleResult(); } finally { em.close(); } return xrd; }
From source file:in.bookmylab.jpa.JpaDAO.java
/** * @param xrdId //from w ww . j a va2s .com * @return */ public XrdLabBooking getXrdByBookingId(Long bookingId) { EntityManager em = emf.createEntityManager(); XrdLabBooking xrd = null; try { Query q = em.createNamedQuery("XrdLabBooking.findByBookingId"); xrd = (XrdLabBooking) q.setParameter("bookingId", bookingId).getSingleResult(); } finally { em.close(); } return xrd; }
From source file:org.apache.falcon.state.store.jdbc.JDBCStateStore.java
@Override public Collection<Entity> getEntities(EntityState.STATE state) throws StateStoreException { EntityManager entityManager = getEntityManager(); Query q = entityManager.createNamedQuery(PersistenceConstants.GET_ENTITY_FOR_STATE); q.setParameter("state", state.toString()); List result = q.getResultList(); entityManager.close();//from w w w . j av a 2s .co m return BeanMapperUtil.convertToEntities(result); }
From source file:org.opencastproject.comments.events.persistence.EventCommentDatabaseServiceImpl.java
@Override @SuppressWarnings("unchecked") public List<Comment> getComments(String eventId) throws EventCommentDatabaseException { EntityManager em = emf.createEntityManager(); try {//ww w .jav a 2 s. com Query q = em.createNamedQuery("EventComment.findByEvent"); q.setParameter("eventId", eventId); q.setParameter("org", securityService.getOrganization().getId()); List<Comment> comments = Monadics.mlist(q.getResultList()).map(new Function<CommentDto, Comment>() { @Override public Comment apply(CommentDto a) { return a.toComment(userDirectoryService); } }).sort(new Comparator<Comment>() { @Override public int compare(Comment c1, Comment c2) { boolean v1 = c1.isResolvedStatus(); boolean v2 = c2.isResolvedStatus(); return (v1 ^ v2) ? ((v1 ^ false) ? 1 : -1) : 0; } }).value(); return new ArrayList<Comment>(comments); } catch (Exception e) { logger.error("Could not retreive comments for event {}: {}", eventId, ExceptionUtils.getStackTrace(e)); throw new EventCommentDatabaseException(e); } finally { if (em != null) em.close(); } }
From source file:org.apache.falcon.state.store.jdbc.JDBCStateStore.java
private EntityBean getEntityBean(EntityID id) { EntityManager entityManager = getEntityManager(); Query q = entityManager.createNamedQuery(PersistenceConstants.GET_ENTITY); q.setParameter("id", id.getKey()); List result = q.getResultList(); entityManager.close();/*from w ww . j av a2s. c om*/ if (result.isEmpty()) { return null; } return ((EntityBean) result.get(0)); }
From source file:org.apache.falcon.state.store.jdbc.JDBCStateStore.java
@Override public Collection<EntityState> getAllEntities() throws StateStoreException { EntityManager entityManager = getEntityManager(); Query q = entityManager.createNamedQuery(PersistenceConstants.GET_ENTITIES); List result = q.getResultList(); entityManager.close();//from w w w . ja v a 2 s . com try { return BeanMapperUtil.convertToEntityState(result); } catch (IOException e) { throw new StateStoreException(e); } }
From source file:org.opencastproject.comments.events.persistence.EventCommentDatabaseServiceImpl.java
/** * Gets an event comment, using the current organizational context. * * @param eventId/*from w w w .jav a 2 s. co m*/ * the event identifier * @param commentId * the comment identifier * @param em * an open entity manager * @return the event comment entity, or null if not found */ private EventCommentDto getEventComment(String eventId, long commentId, EntityManager em) { String orgId = securityService.getOrganization().getId(); Query q = em.createNamedQuery("EventComment.findByCommentId"); q.setParameter("eventId", eventId); q.setParameter("commentId", commentId); q.setParameter("org", orgId); try { return (EventCommentDto) q.getSingleResult(); } catch (NoResultException e) { return null; } }
From source file:org.apache.falcon.state.store.jdbc.JDBCStateStore.java
@Override public Map<InstanceState.STATE, Long> getExecutionInstanceSummary(Entity entity, String cluster, DateTime start, DateTime end) throws StateStoreException { String entityKey = new EntityClusterID(entity, cluster).getEntityID().getKey(); EntityManager entityManager = getEntityManager(); Query q = entityManager.createNamedQuery(PersistenceConstants.GET_INSTANCE_SUMMARY_BY_STATE_WITH_RANGE); q.setParameter("entityId", entityKey); q.setParameter("cluster", cluster); q.setParameter("startTime", new Timestamp(start.getMillis())); q.setParameter("endTime", new Timestamp(end.getMillis())); List result = q.getResultList(); entityManager.close();/*from w w w .j a va 2 s. c o m*/ return BeanMapperUtil.getInstanceStateSummary(result); }
From source file:org.apache.falcon.state.store.jdbc.JDBCStateStore.java
private InstanceState getExecutionInstanceByKey(ID instanceKey) throws StateStoreException { EntityManager entityManager = getEntityManager(); Query q = entityManager.createNamedQuery(PersistenceConstants.GET_INSTANCE); q.setParameter("id", instanceKey.toString()); List result = q.getResultList(); entityManager.close();/*from w w w.ja v a 2 s . c o m*/ if (result.isEmpty()) { return null; } try { InstanceBean instanceBean = (InstanceBean) (result.get(0)); return BeanMapperUtil.convertToInstanceState(instanceBean); } catch (IOException e) { throw new StateStoreException(e); } }