List of usage examples for javax.persistence TypedQuery setParameter
TypedQuery<X> setParameter(int position, Object value);
From source file:eu.domibus.ebms3.common.dao.PModeDao.java
protected String findPartyName(final List<PartyId> partyIds) throws EbMS3Exception { Identifier identifier;//from w ww .ja va2 s . c o m for (final PartyId partyId : partyIds) { try { String type = partyId.getType(); if (type == null || type.isEmpty()) { //PartyId must be an URI try { //noinspection ResultOfMethodCallIgnored URI.create(partyId.getValue()); //if not an URI an IllegalArgumentException will be thrown type = ""; } catch (final IllegalArgumentException e) { final EbMS3Exception ex = new EbMS3Exception(EbMS3Exception.EbMS3ErrorCode.EBMS_0003, e, null); ex.setErrorDetail("PartyId " + partyId.getValue() + " is not a valid URI [CORE] 5.2.2.3"); throw ex; } } final TypedQuery<Identifier> identifierQuery = this.entityManager .createNamedQuery("Identifier.findByTypeAndPartyId", Identifier.class); identifierQuery.setParameter("PARTY_ID", partyId.getValue()); identifierQuery.setParameter("PARTY_ID_TYPE", type); identifier = identifierQuery.getSingleResult(); final TypedQuery<String> query = this.entityManager.createNamedQuery("Party.findPartyByIdentifier", String.class); query.setParameter("PARTY_IDENTIFIER", identifier); return query.getSingleResult(); } catch (final NoResultException e) { PModeDao.LOG.debug("", e); // Its ok to not know all identifiers, we just have to know one } } throw new EbMS3Exception(EbMS3Exception.EbMS3ErrorCode.EBMS_0003, "No matching party found", null, null, null); }
From source file:org.cleverbus.core.common.dao.MessageDaoJpaImpl.java
@Override public int getCountMessages(MsgStateEnum state, Integer interval) { Date lastUpdateTime = null;/*from w w w. j a va 2s . c o m*/ String jSql = "SELECT COUNT(m) " + "FROM " + Message.class.getName() + " m " + "WHERE m.state = '" + state.name() + "'"; if (interval != null) { lastUpdateTime = DateUtils.addSeconds(new Date(), -interval); jSql += " AND m.lastUpdateTimestamp >= :lastUpdateTime"; } TypedQuery<Number> q = em.createQuery(jSql, Number.class); if (lastUpdateTime != null) { q.setParameter("lastUpdateTime", new Timestamp(lastUpdateTime.getTime())); } return q.getSingleResult().intValue(); }
From source file:com.github.fharms.camel.route.CamelEntityManagerTestRouteTest.java
private Dog findDogByPetName(String petname) { TypedQuery<Dog> typedQuery = em.createQuery("select d from Dog d where d.petName = :petname", Dog.class); typedQuery.setParameter("petname", petname); Dog result = null;/*from w w w . j a v a 2s. c o m*/ try { result = typedQuery.getSingleResult(); } catch (Exception e) { result = null; } return result; }
From source file:org.mitre.oauth2.repository.impl.JpaOAuth2TokenRepository.java
@Override public OAuth2AccessTokenEntity getAccessTokenByValue(String accessTokenValue) { try {/*from ww w. j a v a 2s . co m*/ JWT jwt = JWTParser.parse(accessTokenValue); TypedQuery<OAuth2AccessTokenEntity> query = manager .createNamedQuery(OAuth2AccessTokenEntity.QUERY_BY_TOKEN_VALUE, OAuth2AccessTokenEntity.class); query.setParameter(OAuth2AccessTokenEntity.PARAM_TOKEN_VALUE, jwt); return JpaUtil.getSingleResult(query.getResultList()); } catch (ParseException e) { return null; } }
From source file:org.mitre.oauth2.repository.impl.JpaOAuth2TokenRepository.java
@Override public OAuth2RefreshTokenEntity getRefreshTokenByValue(String refreshTokenValue) { try {/*from w w w .j av a 2 s. c om*/ JWT jwt = JWTParser.parse(refreshTokenValue); TypedQuery<OAuth2RefreshTokenEntity> query = manager.createNamedQuery( OAuth2RefreshTokenEntity.QUERY_BY_TOKEN_VALUE, OAuth2RefreshTokenEntity.class); query.setParameter(OAuth2RefreshTokenEntity.PARAM_TOKEN_VALUE, jwt); return JpaUtil.getSingleResult(query.getResultList()); } catch (ParseException e) { return null; } }
From source file:com.netflix.genie.core.jpa.services.JpaJobSearchServiceImpl.java
/** * {@inheritDoc}/*from w w w .java 2 s . c o m*/ */ @Override public JobStatus getJobStatus(@NotBlank final String id) throws GenieException { log.debug("Called with id {}", id); final TypedQuery<JobStatus> query = entityManager.createNamedQuery(JobEntity.QUERY_GET_STATUS_BY_ID, JobStatus.class); query.setParameter("id", id); try { return query.getSingleResult(); } catch (NoResultException e) { throw new GenieNotFoundException("No job with id " + id + " exists."); } }
From source file:it.polimi.meteocal.ejb.HandleAuthFacebookImpl.java
@Override public boolean doLoginFacebook(String faceCode) { if (faceCode != null && !"".equals(faceCode)) { String redirectUrl = URL_BASE + "/MeteoCal-web/loginFacebook.xhtml"; String newUrl = "https://graph.facebook.com/oauth/access_token?client_id=" + APP_ID + "&redirect_uri=" + redirectUrl + "&client_secret=" + APPSECRET + "&code=" + faceCode; LOGGER.log(Level.INFO, "URL FB: " + newUrl); CloseableHttpClient httpclient = HttpClientBuilder.create().build(); try {/*from www. j a v a 2s . c om*/ HttpGet httpget = new HttpGet(newUrl); ResponseHandler<String> responseHandler = new BasicResponseHandler(); String responseBody = httpclient.execute(httpget, responseHandler); LOGGER.log(Level.INFO, "Response Body: " + responseBody); accessToken = StringUtils.removeStart(responseBody, "access_token="); int i = accessToken.indexOf("&"); accessToken = accessToken.substring(0, i); LOGGER.log(Level.INFO, "AccessToken: " + accessToken); facebookClient = new DefaultFacebookClient(accessToken, APPSECRET, Version.VERSION_2_5); com.restfb.types.User userFB = facebookClient.fetchObject("me", com.restfb.types.User.class); if (!AuthUtil.isUserLogged()) { // Save the new data of the user User utente; TypedQuery<User> q = em.createNamedQuery(User.FIND_BY_FACEBOOK_ID, User.class); q.setParameter("facebookId", userFB.getId()); TypedQuery<User> q2 = em.createNamedQuery(User.FIND_BY_EMAIL, User.class); q2.setParameter("email", userFB.getEmail()); if (q.getResultList().isEmpty() && q2.getResultList().isEmpty()) { // The userFB isn't in the system utente = setupNewUser(userFB); em.persist(utente); em.flush(); em.refresh(utente); } else if (!q.getResultList().isEmpty()) { // The User is already in the system with fb LOGGER.log(Level.INFO, "User already registered with Facebook"); utente = q.getResultList().get(0); if (utente.getFacebookToken().equals(accessToken)) { LOGGER.log(Level.INFO, "Facebook token no needed change"); } else { LOGGER.log(Level.INFO, "Facebook token updated"); utente.setFacebookToken(accessToken); em.merge(utente); em.flush(); } } else { LOGGER.log(Level.INFO, "User already registered with classic method"); utente = q2.getResultList().get(0); //TODO merge informazioni da facebook mancanti em.merge(utente); em.flush(); } // Make the session for the user AuthUtil.makeUserSession(utente.getId()); } else { // User already logged in the system User utente = em.find(User.class, AuthUtil.getUserID()); TypedQuery<User> q = em.createNamedQuery(User.FIND_BY_FACEBOOK_ID, User.class); q.setParameter("facebookId", userFB.getId()); if (q.getResultList().isEmpty()) { // The user account isn't already present in the db so set the new FB data utente.setFacebookId(userFB.getId()); utente.setFacebookToken(accessToken); em.merge(utente); em.flush(); } else { // User account already in the system LOGGER.log(Level.INFO, "User already registered with Facebook"); User oldUser = q.getResultList().get(0); if (!Objects.equals(utente.getId(), oldUser.getId())) { // Need to merge the two account utente = HandleUserImpl.mergeUserAccount(utente, oldUser); // set the new facebook data utente.setFacebookId(userFB.getId()); utente.setFacebookToken(accessToken); em.merge(utente); em.flush(); // Transfer all the data that can block the old user remove HandleUserImpl.mergeOldUserNewUser(em, utente, oldUser); em.remove(oldUser); em.flush(); } } } } catch (ClientProtocolException e) { LOGGER.log(Level.ERROR, e); } catch (IOException e) { LOGGER.log(Level.ERROR, e); } finally { try { httpclient.close(); } catch (IOException e) { LOGGER.log(Level.WARN, e); } } } return true; }
From source file:com.healthcit.cacure.dao.FormDao.java
public Collection<FormLibraryForm> findLibraryForms(String query) { TypedQuery<FormLibraryForm> q = this.em.createQuery( "FROM FormLibraryForm form WHERE form.name LIKE :qString ORDER BY form.ord ASC", FormLibraryForm.class); q.setParameter("qString", "%" + query + "%"); return q.getResultList(); }
From source file:com.netflix.genie.core.jpa.services.JpaJobSearchServiceImpl.java
/** * {@inheritDoc}/*ww w .jav a 2 s. co m*/ */ @Override public List<String> getAllHostsWithActiveJobs() { log.debug("Called"); final TypedQuery<String> query = entityManager .createNamedQuery(JobExecutionEntity.QUERY_FIND_HOSTS_BY_STATUS, String.class); query.setParameter("statuses", JobStatus.getActiveStatuses()); return query.getResultList(); }
From source file:org.openmeetings.app.data.file.dao.FileExplorerItemDaoImpl.java
public List<FileExplorerItem> getFileExplorerItemsByRoomAndOwner(Long room_id, Long ownerId) { log.debug(".getFileExplorerItemsByRoomAndOwner() started"); try {/*from w w w .j a v a 2 s . com*/ String hql = "SELECT c FROM FileExplorerItem c " + "WHERE c.deleted <> :deleted " + "AND c.room_id = :room_id " + "AND c.ownerId = :ownerId " + "ORDER BY c.isFolder DESC, c.fileName "; TypedQuery<FileExplorerItem> query = em.createQuery(hql, FileExplorerItem.class); query.setParameter("deleted", "true"); query.setParameter("room_id", room_id); query.setParameter("ownerId", ownerId); List<FileExplorerItem> fileExplorerList = query.getResultList(); return fileExplorerList; } catch (Exception ex2) { log.error("[getFileExplorerItemsByRoomAndOwner]: ", ex2); } return null; }