List of usage examples for javax.persistence Query getSingleResult
Object getSingleResult();
From source file:com.assetmanager.service.auth.PersistentTokenRepositoryImpl.java
/** * Updates the token given the series, token value, and last used date. * * @param series the series//from ww w .j av a2s. com * @param tokenValue the token value * @param lastUsed the last used date */ @Override @Transactional public final void updateToken(final String series, final String tokenValue, final Date lastUsed) { final Query query = entityManager.createQuery("SELECT p FROM PersistentLogin p WHERE series = :series"); query.setParameter("series", series); final PersistentLogin persistentLogin = (PersistentLogin) query.getSingleResult(); persistentLogin.setToken(tokenValue); persistentLogin.setLastUsed(lastUsed); entityManager.persist(persistentLogin); }
From source file:es.ucm.fdi.dalgs.degree.repository.DegreeRepository.java
public Degree existByCode(String code) { Query query = em.createQuery("select d from Degree d where d.info.code=?1"); query.setParameter(1, code);/*from w w w . ja va 2s .c om*/ if (query.getResultList().isEmpty()) return null; else return (Degree) query.getSingleResult(); }
From source file:com.doculibre.constellio.services.FeaturedLinkServicesImpl.java
@Override public FeaturedLink suggest(String text, RecordCollection collection) { FeaturedLink suggestion;//from w ww . j a v a2s . c om EntityManager entityManager = ConstellioPersistenceContext.getCurrentEntityManager(); String analyzedText; try { analyzedText = AnalyzerUtils.analyze(text, collection); } catch (Exception e) { analyzedText = null; } if (StringUtils.isNotBlank(analyzedText)) { StringBuffer sql = new StringBuffer(); sql.append("SELECT FL.id FROM FeaturedLink FL, FeaturedLink_KeywordsAnalyzed FLK, RecordCollection RC"); sql.append(" WHERE FLK.FeaturedLink_id=FL.id AND FL.RecordCollection_id=RC.id"); sql.append(" AND RC.id=? AND FLK.keyword=?"); Query sqlQuery = entityManager.createNativeQuery(sql.toString()); sqlQuery.setMaxResults(1); sqlQuery.setParameter(1, collection.getId()); sqlQuery.setParameter(2, analyzedText); try { BigInteger featuredLinkId = (BigInteger) sqlQuery.getSingleResult(); suggestion = get(featuredLinkId.longValue()); } catch (NoResultException e) { suggestion = null; } } else { suggestion = null; } return suggestion; }
From source file:com.assetmanager.service.auth.PersistentTokenRepositoryImpl.java
/** * Creates a new remember me token.//from w w w .j a v a 2s. c o m * * @param token the remember me token */ @Override @Transactional public final void createNewToken(final PersistentRememberMeToken token) { final Query query = entityManager.createQuery("SELECT u FROM UserAccount u WHERE username = :username"); query.setParameter("username", token.getUsername()); final UserAccount user = (UserAccount) query.getSingleResult(); if (user.getPersistentUser() == null) { user.setPersistentUser(new PersistentUser(user.getKey(), token.getUsername())); } if (user.getPersistentUser().getPersistentLogins() == null) { user.getPersistentUser().setPersistentLogins(new ArrayList<PersistentLogin>()); } user.getPersistentUser().getPersistentLogins() .add(createPersistentLogin(user.getPersistentUser().getKey(), token)); entityManager.persist(user); memcacheService.put(user.getUsername(), user, Expiration.byDeltaSeconds(DEFAULT_EXPIRATION)); }
From source file:com.healthcit.cacure.dao.FormDao.java
public BaseForm getById(Long id) { BaseForm form = null;//w w w . j a v a 2 s.c o m Query query = em.createQuery("from BaseForm fe where id = :Id"); query.setParameter("Id", id); return (BaseForm) query.getSingleResult(); }
From source file:honeypot.services.WepawetServiceImpl.java
/** * {@inheritDoc}// w w w.j av a 2s . c om * @see honeypot.services.WepawetService#getStatus() */ @Transactional public Status getStatus() { Status status = new Status(); // Errors Query query = entityManager.createQuery("SELECT COUNT(e.id) FROM WepawetError e"); status.setErrors((Long) query.getSingleResult()); // Processing query = entityManager.createQuery("SELECT COUNT(p.id) FROM WepawetProcessing p"); status.setProcessing((Long) query.getSingleResult()); // Results query = entityManager.createQuery("SELECT COUNT(r.id) FROM WepawetResult r"); status.setResults((Long) query.getSingleResult()); return status; }
From source file:org.kuali.mobility.maps.dao.LocationDaoImpl.java
public MapsGroup getMapsGroupByCode(String groupCode) { try {/*from www .ja va 2 s. c o m*/ Query query = entityManager .createQuery("select group from MapsGroup group where group.groupCode = :code"); query.setParameter("code", groupCode); return (MapsGroup) query.getSingleResult(); } catch (NoResultException e) { return null; } }
From source file:com.cimpoint.mes.server.repositories.TransitionAttributesRepository.java
public ETransitionAttributes findTransitionAttributes(long objectId, MESConstants.Object.Type objectType) { try {/* www . j a va 2s . c o m*/ Query qry = entityManager .createQuery("select o from " + ETransitionAttributes.class.getName() + " o where o.objectId = ?1 AND o.objectType = ?2") .setParameter(1, objectId).setParameter(2, objectType); ETransitionAttributes e = (ETransitionAttributes) qry.getSingleResult(); return e; } catch (NoResultException ex) { return null; } catch (Exception ex) { ex.printStackTrace(); return null; } }
From source file:org.syncope.core.persistence.dao.impl.MembershipDAOImpl.java
@Override public Membership find(final SyncopeUser user, final SyncopeRole role) { Query query = entityManager.createQuery( "SELECT e FROM Membership e " + "WHERE e.syncopeUser = :user AND e.syncopeRole = :role"); query.setParameter("user", user); query.setParameter("role", role); Membership result = null;/*from w w w. ja v a 2 s . co m*/ try { result = (Membership) query.getSingleResult(); } catch (NoResultException e) { if (LOG.isDebugEnabled()) { LOG.debug("No membership was found for user " + user + " and role " + role); } } return result; }
From source file:gwap.rest.User.java
@GET @Path("/{id:[A-Za-z0-9][A-Za-z0-9]*}") public Response getUser(@PathParam("id") String deviceId) { Query query = entityManager.createNamedQuery("person.byDeviceId"); query.setParameter("deviceId", deviceId); Person person = (Person) query.getSingleResult(); JSONObject userObject = getUserStatistics(deviceId, person); return Response.ok(userObject.toString(), MediaType.APPLICATION_JSON).build(); }