List of usage examples for javax.persistence Query setParameter
Query setParameter(int position, Object value);
From source file:com.mothsoft.alexis.dao.UserDaoImpl.java
private void purgeStaleTokens(User user, Long millisAgeAllowed) { final Date oldestPermissible = new Date(System.currentTimeMillis() - millisAgeAllowed); final Query query = this.em.createQuery( "DELETE FROM UserApiToken token WHERE token.user.id = :userId AND token.lastUsed < :oldestDate"); query.setParameter("userId", user.getId()); query.setParameter("oldestDate", oldestPermissible); int purged = query.executeUpdate(); logger.debug("Purged " + purged + " stale API tokens for user: " + user.getUsername()); }
From source file:de.voolk.marbles.persistence.services.PageService.java
@Override public Page findPageByUserAndId(IUser user, int id) { Query query = getEntityManager().createNamedQuery("page:byUserAndId"); query.setParameter("user", user); query.setParameter("id", id); return (Page) query.getSingleResult(); }
From source file:net.urlgrey.mythpodcaster.dao.MythRecordingsDAOImpl.java
@SuppressWarnings("unchecked") @Override/*from w ww. j a v a 2 s. c o m*/ @Transactional(readOnly = true) public RecordedSeries findRecordedSeries(String seriesId, int numberOfMostRecentRecordings) { final Query namedQuery = entityManager.createNamedQuery("MYTH_RECORDINGS.findRecordedSeries"); namedQuery.setParameter("seriesId", seriesId); final List<RecordedSeries> seriesResultsList = namedQuery.getResultList(); if (seriesResultsList != null && seriesResultsList.size() == 1) { final Query seriesProgramsQuery = entityManager .createNamedQuery("MYTH_RECORDINGS.findRecordedProgramsForSeries"); seriesProgramsQuery.setParameter("seriesId", seriesId); seriesProgramsQuery.setMaxResults(numberOfMostRecentRecordings); final RecordedSeries series = seriesResultsList.get(0); series.setRecordedPrograms(seriesProgramsQuery.getResultList()); return series; } return null; }
From source file:com.expedia.seiso.domain.service.search.QueryFactory.java
private void setParameters(Query jpaQuery, List<String> parameterNames, Set<String> searchTokens) { int parameterIndex = 0; for (String searchToken : searchTokens) { jpaQuery.setParameter(parameterNames.get(parameterIndex++), searchToken); }//from w w w. j a va2 s. co m }
From source file:com.telefonica.euro_iaas.paasmanager.dao.impl.SubNetworkInstanceDaoJpaImpl.java
private SubNetworkInstance findByNetworkInstanceName(String name, String vdc, String region) throws EntityNotFoundException { Query query = getEntityManager().createQuery( "select p from SubNetworkInstance p where p.name = :name and p.vdc = :vdc and p.region = :region"); query.setParameter("name", name); query.setParameter("vdc", vdc); query.setParameter("region", region); SubNetworkInstance subNetworkInstance = null; try {/*from ww w.ja v a 2 s .c o m*/ subNetworkInstance = (SubNetworkInstance) query.getSingleResult(); } catch (NoResultException e) { String message = " No subNetworkInstance found in the database with id: " + name + " Exception: " + e.getMessage(); throw new EntityNotFoundException(NetworkInstance.class, "name", name); } return subNetworkInstance; }
From source file:org.kuali.mobility.emergencyinfo.dao.EmergencyInfoDaoImpl.java
public EmergencyInfo findEmergencyInfoById(Long id) { Query query = entityManager .createQuery("select ei from MaintEmergencyInfo ei where ei.emergencyInfoId = :id"); query.setParameter("id", id); try {// w w w .j a v a2 s .c o m return (EmergencyInfo) query.getSingleResult(); } catch (NoResultException e) { return null; } }
From source file:org.messic.server.datamodel.jpaimpl.DAOJPAGenre.java
@Override @Transactional/*from w w w . j a va 2 s . c om*/ public List<MDOGenre> getRandomGenre(String username, int number) { Query query = entityManager .createQuery("from MDOGenre as a where (1=1 AND a.owner.login= :userName) order by rand()"); query.setParameter("userName", username); query.setMaxResults(5); @SuppressWarnings("unchecked") List<MDOGenre> results = query.getResultList(); return results; }
From source file:be.fedict.eid.pkira.blm.model.contracts.ContractRepositoryBean.java
private void addQueryParameters(String userRrn, CertificatesFilter certificatesFilter, Query query) { query.setParameter("nationalRegisterNumber", userRrn); query.setParameter("registrationStatus", RegistrationStatus.APPROVED); if (certificatesFilter.getCertificateDomainId() != null) query.setParameter("certificateDomainId", certificatesFilter.getCertificateDomainId()); if (isNotBlank(certificatesFilter.getDistinguishedName())) query.setParameter("distinguishedName", certificatesFilter.getDistinguishedName()); if (isNotBlank(certificatesFilter.getIssuer())) query.setParameter("issuer", certificatesFilter.getIssuer()); if (isNotBlank(certificatesFilter.getSerialNumber())) { BigInteger serialNumber;/*from w w w . jav a 2 s.c o m*/ try { serialNumber = new BigInteger(certificatesFilter.getSerialNumber()); } catch (NumberFormatException e) { serialNumber = BigInteger.ZERO; } query.setParameter("serialNumber", serialNumber); } if (certificatesFilter.getCertificateType() != null) { query.setParameter("certificateType", certificatesFilter.getCertificateType()); } if (certificatesFilter.getValidityStartFrom() != null) query.setParameter("validityStartFrom", certificatesFilter.getValidityStartFrom()); if (certificatesFilter.getValidityStartTo() != null) query.setParameter("validityStartTo", certificatesFilter.getValidityStartTo()); if (certificatesFilter.getValidityEndFrom() != null) query.setParameter("validityEndFrom", certificatesFilter.getValidityEndFrom()); if (certificatesFilter.getValidityEndTo() != null) query.setParameter("validityEndTo", certificatesFilter.getValidityEndTo()); }
From source file:de.jaxenter.eesummit.caroline.backend.impl.UserServiceImpl.java
@Override public CaroLineUser login(String loginId, String password) { Validate.notNull(loginId);// w w w . ja v a 2s . c o m Validate.notNull(password); String pwdHash = getPasswordHash(password); Query q = em.createQuery( "select u from CaroLineUser as u " + "where u.loginId = :loginId and u.loginHash = :loginHash", CaroLineUser.class); q.setParameter("loginId", loginId); q.setParameter("loginHash", pwdHash); CaroLineUser usr = null; try { usr = (CaroLineUser) q.getSingleResult(); } catch (NoResultException nre) { return null; } return usr; }
From source file:com.impetus.kwitter.service.TwitterService.java
@Override public List<Tweet> findTweetByDevice(String deviceName) { Query q = em.createQuery("select u.tweets.device from User u where u.tweets.device =:device"); q.setParameter("device", deviceName); List<Tweet> tweets = q.getResultList(); return tweets; }