List of usage examples for javax.persistence TypedQuery setParameter
TypedQuery<X> setParameter(int position, Object value);
From source file:com.epam.training.taranovski.web.project.repository.implementation.VacancyRepositoryImplementation.java
@Override public List<VacancySkill> getSkills(Vacancy vacancy) { EntityManager em = entityManagerFactory.createEntityManager(); List<VacancySkill> list = new LinkedList<>(); try {/*from w ww. j a va 2 s. c o m*/ em.getTransaction().begin(); TypedQuery<VacancySkill> query = em.createNamedQuery("VacancySkill.findByVacancy", VacancySkill.class); query.setParameter("vacancy", vacancy); list = query.getResultList(); em.getTransaction().commit(); } catch (RuntimeException e) { Logger.getLogger(VacancyRepositoryImplementation.class.getName()).info(e); } finally { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } em.close(); } return list; }
From source file:ch.puzzle.itc.mobiliar.business.resourcegroup.control.ResourceGroupRepository.java
private List<ResourceGroupEntity> getGroupsForType(String typeParam, Object typeParamValue, List<Integer> myAmw, boolean fetchResources, boolean sorted) { StringBuilder qString = new StringBuilder(); String fetchString = StringUtils.EMPTY; List<ResourceGroupEntity> result; if (fetchResources) { fetchString = "fetch "; }//from w w w . jav a2 s. c o m qString.append("SELECT DISTINCT g FROM ResourceGroupEntity g left join " + fetchString + "g.resources r"); qString.append(" WHERE r.resourceType." + typeParam + "=:typePram"); qString.append(" AND r.name IS NOT :asContainer"); if (!CollectionUtils.isEmpty(myAmw)) { qString.append(" AND g.id in (:myAmw)"); } TypedQuery<ResourceGroupEntity> q = entityManager.createQuery(qString.toString(), ResourceGroupEntity.class); q.setParameter("typePram", typeParamValue); q.setParameter("asContainer", ApplicationServerContainer.APPSERVERCONTAINER.getDisplayName()); if (!CollectionUtils.isEmpty(myAmw)) { q.setParameter("myAmw", myAmw); } result = q.getResultList(); if (sorted) { Collections.sort(result, new Comparator<ResourceGroupEntity>() { @Override public int compare(ResourceGroupEntity group1, ResourceGroupEntity group2) { return group1.getName().toLowerCase().compareTo(group2.getName().toLowerCase()); } }); } return result; }
From source file:io.hops.hopsworks.common.dao.certificates.CertsFacade.java
public List<UserCerts> findUserCertsByUid(String username) { TypedQuery<UserCerts> query = em.createNamedQuery("UserCerts.findByUsername", UserCerts.class); query.setParameter("username", username); try {//from w w w. jav a 2 s. c o m List<UserCerts> res = query.getResultList(); return res; } catch (EntityNotFoundException e) { Logger.getLogger(CertsFacade.class.getName()).log(Level.SEVERE, null, e); } return new ArrayList<>(); }
From source file:com.headissue.pigeon.admin.AdminSurveyHandler.java
public List<SurveyOverviewValue> getAllSurveys() { EntityManager _manager = factory.createEntityManager(); try {// w w w . j av a2 s . c o m TypedQuery<SurveyOverviewValue> q = _manager.createNamedQuery("survey.allSurveyOverview", SurveyOverviewValue.class); q.setParameter("status", SurveyStatus.ENABLED); return JPAUtils.getResultList(q); } finally { _manager.close(); } }
From source file:com.epam.training.taranovski.web.project.repository.implementation.EmployeeRepositoryImplementation.java
@Override public List<Vacancy> getAvailableActiveVacancies(Employee employee) { EntityManager em = entityManagerFactory.createEntityManager(); List<Integer> list = null; List<Vacancy> list1 = null; try {//from w w w .ja va2s . co m em.getTransaction().begin(); Query query = em.createNativeQuery( "select \"ide\" from (select \"UserSkill\".\"employeeId\", \"UserSkill\".\"experience\", \"VacancySkill\".\"vacancyId\" as \"ide\", \"VacancySkill\".\"experience\", \"UserSkill\".\"allSkillsId\" from \"UserSkill\" join \"VacancySkill\" on \"UserSkill\".\"allSkillsId\" = \"VacancySkill\".\"allSkillsId\" where \"UserSkill\".\"employeeId\" = ? and \"UserSkill\".\"experience\" >= \"VacancySkill\".\"experience\") group by \"employeeId\", \"ide\" having count(\"employeeId\") >= (select count(*) from \"VacancySkill\" where \"VacancySkill\".\"vacancyId\" = \"ide\")"); query.setParameter(1, employee.getEmployeeUserId()); list = query.getResultList(); if (list.isEmpty()) { list.add(0); } TypedQuery<Vacancy> query1 = em.createNamedQuery("Vacancy.findActiveVacanciesByIds", Vacancy.class); query1.setParameter("vacancyIdList", list); list1 = query1.getResultList(); em.getTransaction().commit(); } catch (RuntimeException e) { Logger.getLogger(EmployeeRepositoryImplementation.class.getName()).info(e); } finally { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } em.close(); } return list1; }
From source file:io.hops.hopsworks.common.dao.certificates.CertsFacade.java
public List<UserCerts> findUserCertsByProjectId(String projectname) { TypedQuery<UserCerts> query = em.createNamedQuery("UserCerts.findByProjectname", UserCerts.class); query.setParameter("projectname", projectname); try {/*from w ww . j a va 2 s . c o m*/ List<UserCerts> res = query.getResultList(); return res; } catch (EntityNotFoundException e) { Logger.getLogger(CertsFacade.class.getName()).log(Level.SEVERE, null, e); } return new ArrayList<>(); }
From source file:org.openmeetings.app.data.calendar.daos.MeetingMemberDaoImpl.java
public List<MeetingMember> getMeetingMemberByAppointmentId(Long appointmentId) { try {/*w w w . j a va2 s . co m*/ log.debug("getMeetingMemberByAppointmentId: " + appointmentId); String hql = "select app from MeetingMember app " + "WHERE app.deleted <> :deleted " + "AND app.appointment.appointmentId = :appointmentId"; TypedQuery<MeetingMember> query = em.createQuery(hql, MeetingMember.class); query.setParameter("deleted", true); query.setParameter("appointmentId", appointmentId); List<MeetingMember> listmeetingMember = query.getResultList(); return listmeetingMember; } catch (Exception ex2) { log.error("[getMeetingMemberByAppointmentId]: ", ex2); } return null; }
From source file:eu.domibus.ebms3.common.dao.PModeDao.java
@Override public Party getSenderParty(final String pModeKey) { final TypedQuery<Party> query = this.entityManager.createNamedQuery("Party.findByName", Party.class); query.setParameter("NAME", this.getSenderPartyNameFromPModeKey(pModeKey)); return query.getSingleResult(); }
From source file:eu.domibus.ebms3.common.dao.PModeDao.java
@Override public Party getReceiverParty(final String pModeKey) { final TypedQuery<Party> query = this.entityManager.createNamedQuery("Party.findByName", Party.class); query.setParameter("NAME", this.getReceiverPartyNameFromPModeKey(pModeKey)); return query.getSingleResult(); }
From source file:io.hops.hopsworks.common.dao.certificates.CertsFacade.java
public UserCerts findUserCert(String projectName, String username) { TypedQuery<UserCerts> query = em.createNamedQuery("UserCerts.findUserProjectCert", UserCerts.class); query.setParameter("projectname", projectName); query.setParameter("username", username); try {//from w ww.j a va2s . c om UserCerts res = query.getSingleResult(); return res; } catch (NoResultException e) { Logger.getLogger(CertsFacade.class.getName()).log(Level.SEVERE, null, e); } return new UserCerts(); }