List of usage examples for javax.persistence Query setParameter
Query setParameter(int position, Object value);
From source file:be.fedict.eid.applet.beta.SessionContextManagerBean.java
@SuppressWarnings("unchecked") public int getSessionContextId(String httpSessionId) { LOG.debug("get context Id for HTTP session Id: " + httpSessionId); Query query = this.entityManager .createQuery("FROM SessionContextEntity AS sc WHERE sc.httpSessionId = :httpSessionId"); query.setParameter("httpSessionId", httpSessionId); List<SessionContextEntity> sessionContextList = query.getResultList(); if (sessionContextList.isEmpty()) { HttpServletRequest httpServletRequest; try {//from ww w . jav a2s .c o m httpServletRequest = (HttpServletRequest) PolicyContext .getContext("javax.servlet.http.HttpServletRequest"); } catch (PolicyContextException e) { throw new RuntimeException("JACC error: " + e.getMessage()); } String userAgent = httpServletRequest.getHeader("user-agent"); LOG.debug("user agent: " + userAgent); SessionContextEntity sessionContextEntity = new SessionContextEntity(httpSessionId, userAgent); this.entityManager.persist(sessionContextEntity); int contextId = sessionContextEntity.getContextId(); LOG.debug("new context Id: " + contextId); return contextId; } /* * An existing HTTP session will come from the same user agent. */ SessionContextEntity sessionContextEntity = sessionContextList.get(0); int contextId = sessionContextEntity.getContextId(); LOG.debug("existing context Id: " + contextId); return contextId; }
From source file:org.kuali.mobility.push.dao.PreferenceDaoImpl.java
public List<Preference> findPreferencesByUsername(String username) { Query query = entityManager.createQuery("select p from Preference p where p.username = :username"); query.setParameter("username", username); return query.getResultList(); }
From source file:org.messic.server.datamodel.jpaimpl.DAOJPAGenre.java
@Override @Transactional/*from w w w. ja v a2s . c o m*/ public MDOGenre getByName(String username, String genreName) { Query query = entityManager .createQuery("from MDOGenre as a where (a.owner.login = :userName) AND (a.name = :genreName)"); query.setParameter("genreName", genreName); query.setParameter("userName", username); @SuppressWarnings("unchecked") List<MDOGenre> results = query.getResultList(); if (results != null && results.size() > 0) { return results.get(0); } return null; }
From source file:com.headissue.pigeon.service.AdminSurveyService.java
void mergeQuestion(Survey _survey, SurveyValue _value, EntityManager _manager) { List<Question> _items = new ArrayList<Question>(_survey.getQuestions()); int _orderBy = 0; Question q = null;//from ww w .ja va 2 s .c o m for (QuestionValue qv : _value.getQuestions()) { if (!_items.isEmpty()) { q = beanService.copy(_items.remove(0), qv, QUESTION_PROPERTIES); q.setOrderBy(++_orderBy); LogUtils.debug(log, "recycle question %s: '%s'", q.getId(), q.getText()); } else { q = beanService.copy(Question.class, qv, QUESTION_PROPERTIES); _survey.addQuestion(q, ++_orderBy); LogUtils.debug(log, "add a new question: '%s'", q.getText()); } mergeQuestionText(q, qv, _manager); } if (!_items.isEmpty()) { for (Question qq : _items) { LogUtils.debug(log, "remove question %s", qq.getId()); Query query = _manager.createNamedQuery("answer.deleteAnswerByQuestion"); query.setParameter("question", qq); query.executeUpdate(); _survey.getQuestions().remove(qq); } } }
From source file:com.expressui.core.dao.security.PermissionDao.java
/** * Finds permissions for a given role, entity type and field. * * @param role the role to query//from w w w . ja v a 2 s. c o m * @param entityType the entity type to query * @param field the field to query * @return found permissions */ public List<Permission> findByRoleEntityTypeAndField(Role role, String entityType, String field) { Query query = getEntityManager().createQuery("SELECT p FROM Permission p WHERE p.role = :role" + " AND p.targetType = :entityType AND p.field = :field"); query.setParameter("role", role); query.setParameter("entityType", entityType); query.setParameter("field", field); query.setFlushMode(FlushModeType.COMMIT); return query.getResultList(); }
From source file:es.ucm.fdi.dalgs.module.repository.ModuleRepository.java
public Module getModule(Long id, Long id_degree) { Degree degree = em.getReference(Degree.class, id_degree); Query query = em.createQuery("select m from Module m where m.id=?1 and m.degree=?2 "); query.setParameter(1, id); query.setParameter(2, degree);//from w ww . ja va 2 s .c om if (query.getResultList().isEmpty()) return null; return (Module) query.getSingleResult(); }
From source file:org.messic.server.datamodel.jpaimpl.DAOJPAGenre.java
/** * @TODO limit to the valid genres for the user? *//*from www. jav a 2s .c o m*/ @Override @Transactional public List<MDOGenre> findSimilarGenre(String genreName, String username) { Query query = entityManager .createQuery("from MDOGenre as a where (a.owner.login = :userName) AND (a.name LIKE :genreName)"); query.setParameter("genreName", "%" + genreName + "%"); query.setParameter("userName", username); @SuppressWarnings("unchecked") List<MDOGenre> results = query.getResultList(); return results; }
From source file:org.messic.server.datamodel.jpaimpl.DAOJPAGenre.java
@Override @Transactional//from w w w. j a v a 2 s .c o m public MDOGenre getGenre(String username, String genreName) { Query query = entityManager .createQuery("from MDOGenre as a where (a.owner.login = :userName) AND (a.name = :genreName)"); query.setParameter("genreName", "'" + genreName + "'"); query.setParameter("userName", username); @SuppressWarnings("unchecked") List<MDOGenre> results = query.getResultList(); if (results != null && results.size() > 0) { return results.get(0); } else { return null; } }
From source file:org.messic.server.datamodel.jpaimpl.DAOJPASong.java
@Override @Transactional/*from w w w . j a v a 2 s. co m*/ public List<MDOSong> getAll(String username) { Query query = entityManager.createQuery("from MDOSong as a where (a.owner.login = :userName)"); query.setParameter("userName", username); @SuppressWarnings("unchecked") List<MDOSong> results = query.getResultList(); return results; }
From source file:org.messic.server.datamodel.jpaimpl.DAOJPAAuthor.java
@Override @Transactional/*w w w . j a v a2s . co m*/ public MDOAuthor get(String username, long authorSid) { Query query = entityManager .createQuery("from MDOAuthor as a where (a.owner.login = :userName) AND (a.sid = :authorSid)"); query.setParameter("userName", username); query.setParameter("authorSid", authorSid); @SuppressWarnings("unchecked") List<MDOAuthor> results = query.getResultList(); if (results != null && results.size() > 0) { return results.get(0); } return null; }