List of usage examples for javax.persistence TypedQuery setParameter
TypedQuery<X> setParameter(int position, Object value);
From source file:org.mitre.oauth2.repository.impl.JpaOAuth2TokenRepository.java
@Override public Set<OAuth2AccessTokenEntity> getAllExpiredAccessTokens() { TypedQuery<OAuth2AccessTokenEntity> query = manager .createNamedQuery(OAuth2AccessTokenEntity.QUERY_EXPIRED_BY_DATE, OAuth2AccessTokenEntity.class); query.setParameter(OAuth2AccessTokenEntity.PARAM_DATE, new Date()); query.setMaxResults(MAXEXPIREDRESULTS); return new LinkedHashSet<>(query.getResultList()); }
From source file:no.dusken.momus.service.ArticleService.java
public List<Article> searchForArticles(ArticleSearchParams params) { long start = System.currentTimeMillis(); ArticleQueryBuilder builder = new ArticleQueryBuilder(params); String queryText = builder.getFullQuery(); Map<String, Object> queryParams = builder.getQueryParams(); TypedQuery<Article> query = entityManager.createQuery(queryText, Article.class); for (Map.Entry<String, Object> e : queryParams.entrySet()) { query.setParameter(e.getKey(), e.getValue()); }/* ww w . j a v a2 s. c om*/ query.setMaxResults(params.getPageSize() + 1); // One extra, so searchpage can see if there is "more pages" query.setFirstResult(params.getStartOfPage()); List<Article> resultList = query.getResultList(); long end = System.currentTimeMillis(); long timeUsed = end - start; logger.debug("Time spent on search: {}ms", timeUsed); if (timeUsed > 800) { logger.warn("Time spent on search high ({}ms), params were: {}", timeUsed, params); } return resultList; }
From source file:org.mitre.oauth2.repository.impl.JpaOAuth2TokenRepository.java
@Override public Set<OAuth2RefreshTokenEntity> getAllExpiredRefreshTokens() { TypedQuery<OAuth2RefreshTokenEntity> query = manager .createNamedQuery(OAuth2RefreshTokenEntity.QUERY_EXPIRED_BY_DATE, OAuth2RefreshTokenEntity.class); query.setParameter(OAuth2RefreshTokenEntity.PARAM_DATE, new Date()); query.setMaxResults(MAXEXPIREDRESULTS); return new LinkedHashSet<>(query.getResultList()); }
From source file:org.mitre.oauth2.repository.impl.JpaOAuth2TokenRepository.java
@Override @Transactional(value = "defaultTransactionManager") public void clearAccessTokensForRefreshToken(OAuth2RefreshTokenEntity refreshToken) { TypedQuery<OAuth2AccessTokenEntity> query = manager .createNamedQuery(OAuth2AccessTokenEntity.QUERY_BY_REFRESH_TOKEN, OAuth2AccessTokenEntity.class); query.setParameter(OAuth2AccessTokenEntity.PARAM_REFERSH_TOKEN, refreshToken); List<OAuth2AccessTokenEntity> accessTokens = query.getResultList(); for (OAuth2AccessTokenEntity accessToken : accessTokens) { removeAccessToken(accessToken);/*from w ww . ja va 2 s .co m*/ } }
From source file:org.mitre.oauth2.repository.impl.JpaOAuth2TokenRepository.java
@Override @Transactional(value = "defaultTransactionManager") public void clearTokensForClient(ClientDetailsEntity client) { TypedQuery<OAuth2AccessTokenEntity> queryA = manager .createNamedQuery(OAuth2AccessTokenEntity.QUERY_BY_CLIENT, OAuth2AccessTokenEntity.class); queryA.setParameter(OAuth2AccessTokenEntity.PARAM_CLIENT, client); List<OAuth2AccessTokenEntity> accessTokens = queryA.getResultList(); for (OAuth2AccessTokenEntity accessToken : accessTokens) { removeAccessToken(accessToken);// w w w . java2 s .c om } TypedQuery<OAuth2RefreshTokenEntity> queryR = manager .createNamedQuery(OAuth2RefreshTokenEntity.QUERY_BY_CLIENT, OAuth2RefreshTokenEntity.class); queryR.setParameter(OAuth2RefreshTokenEntity.PARAM_CLIENT, client); List<OAuth2RefreshTokenEntity> refreshTokens = queryR.getResultList(); for (OAuth2RefreshTokenEntity refreshToken : refreshTokens) { removeRefreshToken(refreshToken); } }
From source file:com.epam.training.taranovski.web.project.repository.implementation.OfferBidRepositoryImplementation.java
@Override public List<Employee> getOffersForVacancy(Vacancy vacancy) { EntityManager em = entityManagerFactory.createEntityManager(); List<Employee> list = new LinkedList<>(); try {//from ww w . j a v a 2 s .co m em.getTransaction().begin(); TypedQuery<Employee> query = em.createNamedQuery("OfferBid.findEmployeeOffersForVacancy", Employee.class); query.setParameter("vacancy", vacancy); list = query.getResultList(); em.getTransaction().commit(); } catch (RuntimeException e) { Logger.getLogger(OfferBidRepositoryImplementation.class.getName()).info(e); } finally { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } em.close(); } return list; }
From source file:net.nan21.dnet.core.presenter.service.asgn.AbstractAsgnService.java
/** * // ww w . ja v a 2 s . c o m * @param selectionId * @param filter * @param params * @param builder * @return * @throws Exception */ public List<M> findLeft(String selectionId, F filter, P params, IQueryBuilder<M, F, P> builder) throws Exception { QueryBuilderWithJpql<M, F, P> bld = (QueryBuilderWithJpql<M, F, P>) builder; bld.addFilterCondition(" e.clientId = :clientId and e." + this.ctx.getLeftPkField() + " not in (select x.itemId from TempAsgnLine x where x.selectionId = :selectionId)"); bld.setFilter(filter); bld.setParams(params); List<M> result = new ArrayList<M>(); TypedQuery<E> q = bld.createQuery(this.getEntityClass()); q.setParameter("clientId", Session.user.get().getClient().getId()); q.setParameter("selectionId", selectionId); List<E> list = q.setFirstResult(bld.getResultStart()).setMaxResults(bld.getResultSize()).getResultList(); for (E e : list) { M m = this.getModelClass().newInstance(); entityToModel(e, m); result.add(m); } return result; }
From source file:net.nan21.dnet.core.presenter.service.asgn.AbstractAsgnService.java
/** * /*from w ww .j a va 2 s . c o m*/ * @param selectionId * @param filter * @param params * @param builder * @return * @throws Exception */ public List<M> findRight(String selectionId, F filter, P params, IQueryBuilder<M, F, P> builder) throws Exception { QueryBuilderWithJpql<M, F, P> bld = (QueryBuilderWithJpql<M, F, P>) builder; bld.addFilterCondition(" e.clientId = :clientId and e." + this.ctx.getLeftPkField() + " in (select x.itemId from TempAsgnLine x where x.selectionId = :selectionId)"); bld.setFilter(filter); bld.setParams(params); List<M> result = new ArrayList<M>(); TypedQuery<E> q = bld.createQuery(this.getEntityClass()); q.setParameter("clientId", Session.user.get().getClient().getId()); q.setParameter("selectionId", selectionId); List<E> list = q.setFirstResult(bld.getResultStart()).setMaxResults(bld.getResultSize()).getResultList(); for (E e : list) { M m = this.getModelClass().newInstance(); entityToModel(e, m); result.add(m); } return result; }
From source file:com.epam.training.taranovski.web.project.repository.implementation.OfferBidRepositoryImplementation.java
@Override public OfferBid getBidByEmployeeAndVacancy(Employee employee, Vacancy vacancy) { EntityManager em = entityManagerFactory.createEntityManager(); OfferBid offer = null;/* w w w .ja va 2s . c o m*/ try { em.getTransaction().begin(); TypedQuery<OfferBid> query = em.createNamedQuery("OfferBid.findBidByEmployeeAndVacancy", OfferBid.class); query.setParameter("employee", employee); query.setParameter("vacancy", vacancy); offer = query.getSingleResult(); em.getTransaction().commit(); } catch (RuntimeException e) { Logger.getLogger(OfferBidRepositoryImplementation.class.getName()).info(e); offer = null; } finally { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } em.close(); } return offer; }
From source file:com.epam.training.taranovski.web.project.repository.implementation.OfferBidRepositoryImplementation.java
@Override public OfferBid getOfferByEmployeeAndVacancy(Employee employee, Vacancy vacancy) { EntityManager em = entityManagerFactory.createEntityManager(); OfferBid offer = null;/*from w w w . j a v a 2 s. co m*/ try { em.getTransaction().begin(); TypedQuery<OfferBid> query = em.createNamedQuery("OfferBid.findOfferByEmployeeAndVacancy", OfferBid.class); query.setParameter("employee", employee); query.setParameter("vacancy", vacancy); offer = query.getSingleResult(); em.getTransaction().commit(); } catch (RuntimeException e) { Logger.getLogger(OfferBidRepositoryImplementation.class.getName()).info(e); offer = null; } finally { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } em.close(); } return offer; }