List of usage examples for javax.persistence TypedQuery setParameter
TypedQuery<X> setParameter(int position, Object value);
From source file:com.clustercontrol.infra.util.QueryUtil.java
public static boolean isInfraFileReferredByFileTransferModuleInfoEntity(String fileId) { HinemosEntityManager em = new JpaTransactionManager().getEntityManager(); TypedQuery<FileTransferModuleInfo> query = em.createNamedQuery("FileTransferModuleInfoEntity.findByFileId", FileTransferModuleInfo.class); query.setParameter("fileId", fileId); query.setMaxResults(1);//w ww . j av a 2 s. c om return !query.getResultList().isEmpty(); }
From source file:fr.univrouen.poste.domain.PosteCandidature.java
public static TypedQuery<PosteCandidature> findPosteCandidaturesByCandidatAndByDateEndCandidatGreaterThan( User candidat, Date date) { EntityManager em = entityManager();/*from w ww. j a va2 s . c om*/ String jpaQuery = "SELECT o FROM PosteCandidature AS o WHERE o.candidat = :candidat and o.poste.dateEndSignupCandidat > :date"; TypedQuery<PosteCandidature> q = em.createQuery(jpaQuery, PosteCandidature.class); q.setParameter("candidat", candidat); q.setParameter("date", date); return q; }
From source file:fr.univrouen.poste.domain.PosteCandidature.java
public static TypedQuery<PosteCandidature> findPosteCandidaturesByCandidatAndByDateEndCandidatGreaterThanAndNoAuditionnableOrByDateEndCandidatAuditionnableGreaterThanAndAuditionnable( User candidat, Date date) { EntityManager em = entityManager();//from w w w . j a v a 2 s. c o m String jpaQuery = "SELECT o FROM PosteCandidature AS o WHERE o.candidat = :candidat and (o.poste.dateEndSignupCandidat > :date and o.auditionnable = FALSE or o.poste.dateEndCandidatAuditionnable > :date and o.auditionnable = TRUE)"; TypedQuery<PosteCandidature> q = em.createQuery(jpaQuery, PosteCandidature.class); q.setParameter("candidat", candidat); q.setParameter("date", date); return q; }
From source file:net.triptech.metahive.model.SubmittedField.java
/** * Find the submitted fields for the supplied parameters. * * @param def the def//from ww w .j a v a 2 s .com * @param primaryId the primary id * @param secondaryId the secondary id * @param tertiaryId the tertiary id * @return the list */ public static List<SubmittedField> findSubmittedFields(final Definition def, final String primaryId, final String secondaryId, final String tertiaryId) { if (def == null) { throw new IllegalArgumentException("A valid defintion is required"); } if (StringUtils.isBlank(primaryId)) { throw new IllegalArgumentException("The primaryId argument is required"); } Map<String, Object> variables = new HashMap<String, Object>(); StringBuilder sql = new StringBuilder(); sql.append("SELECT s FROM SubmittedField AS s JOIN s.definition d"); sql.append(" JOIN s.submission sub WHERE d.id = :definitionId"); variables.put("definitionId", def.getId()); sql.append(" AND LOWER(s.primaryRecordId) = LOWER(:primaryRecordId)"); variables.put("primaryRecordId", primaryId); if (def.getApplicability() == Applicability.RECORD_SECONDARY) { if (StringUtils.isNotBlank(secondaryId)) { sql.append(" AND LOWER(s.secondaryRecordId) = LOWER(:secondaryRecordId)"); variables.put("secondaryRecordId", secondaryId); } else { sql.append(" AND (s.secondaryRecordId IS NULL"); sql.append(" OR s.secondaryRecordId = '')"); } } if (def.getApplicability() == Applicability.RECORD_TERTIARY) { if (StringUtils.isNotBlank(tertiaryId)) { sql.append(" AND LOWER(s.tertiaryRecordId) = LOWER(:tertiaryRecordId)"); variables.put("tertiaryRecordId", tertiaryId); } else { sql.append(" AND (s.tertiaryRecordId IS NULL"); sql.append(" OR s.tertiaryRecordId = '')"); } } sql.append(" ORDER BY sub.created"); TypedQuery<SubmittedField> q = entityManager().createQuery(sql.toString(), SubmittedField.class); for (String key : variables.keySet()) { q.setParameter(key, variables.get(key)); } return q.getResultList(); }
From source file:fr.univrouen.poste.domain.PosteCandidature.java
public static TypedQuery<PosteCandidature> findPosteCandidaturesRecevableByPostes(Set<PosteAPourvoir> postes, Boolean auditionnable, String sortFieldName, String sortOrder) { if (postes == null) throw new IllegalArgumentException("The postes argument is required"); String jpaQuery = "SELECT o FROM PosteCandidature AS o WHERE o.poste IN :postes AND o.recevable = TRUE"; if (auditionnable != null) { jpaQuery = jpaQuery + " AND o.auditionnable = :auditionnable"; }/*from w ww . j av a 2 s .c o m*/ if (fieldNames4OrderClauseFilter.contains(sortFieldName)) { jpaQuery = jpaQuery + " ORDER BY " + sortFieldName; if ("ASC".equalsIgnoreCase(sortOrder) || "DESC".equalsIgnoreCase(sortOrder)) { jpaQuery = jpaQuery + " " + sortOrder; } } TypedQuery<PosteCandidature> q = entityManager().createQuery(jpaQuery, PosteCandidature.class); q.setParameter("postes", postes); if (auditionnable != null) { q.setParameter("auditionnable", auditionnable); } return q; }
From source file:com.clustercontrol.accesscontrol.util.QueryUtil.java
public static List<ObjectPrivilegeInfo> getAllObjectPrivilegeByFilter(String objectType, String objectId, String roleId, String objectPrivilege) { HinemosEntityManager em = new JpaTransactionManager().getEntityManager(); StringBuffer sbJpql = new StringBuffer(); sbJpql.append("SELECT a FROM ObjectPrivilegeInfo a WHERE true = true"); if (objectType != null && !"".equals(objectType)) { sbJpql.append(" AND a.id.objectType = :objectType"); }/* w ww .j a va2 s.com*/ if (objectId != null && !"".equals(objectId)) { sbJpql.append(" AND a.id.objectId = :objectId"); } if (roleId != null && !"".equals(roleId)) { sbJpql.append(" AND a.id.roleId = :roleId"); } if (objectPrivilege != null && !"".equals(objectPrivilege)) { sbJpql.append(" AND a.id.objectPrivilege = :objectPrivilege"); } TypedQuery<ObjectPrivilegeInfo> typedQuery = em.createQuery(sbJpql.toString(), ObjectPrivilegeInfo.class); if (objectType != null && !"".equals(objectType)) { typedQuery = typedQuery.setParameter("objectType", objectType); } if (objectId != null && !"".equals(objectId)) { typedQuery = typedQuery.setParameter("objectId", objectId); } if (roleId != null && !"".equals(roleId)) { typedQuery = typedQuery.setParameter("roleId", roleId); } if (objectPrivilege != null && !"".equals(objectPrivilege)) { typedQuery = typedQuery.setParameter("objectPrivilege", objectPrivilege); } return typedQuery.getResultList(); }
From source file:fr.univrouen.poste.domain.PosteCandidature.java
public static Long countFindPosteCandidaturesByPostesAndCandidatsAndRecevableAndAuditionnableAndModification( List<PosteAPourvoir> postes, List<User> candidats, List<ReviewStatusTypes> reviewStatus, Boolean recevable, Boolean auditionnable, Boolean modification) { EntityManager em = entityManager();// www . j a va 2s . com String jpaQuery = "SELECT COUNT(o) FROM PosteCandidature AS o WHERE"; if (postes != null) { jpaQuery = jpaQuery + " o.poste IN :postes AND"; } if (candidats != null) { jpaQuery = jpaQuery + " o.candidat IN :candidats AND"; } if (reviewStatus != null) { jpaQuery = jpaQuery + " o.managerReview.reviewStatus IN :reviewStatus AND"; } if (recevable != null) { jpaQuery = jpaQuery + " o.recevable = :recevable AND"; } if (auditionnable != null) { jpaQuery = jpaQuery + " o.auditionnable = :auditionnable AND"; } if (modification != null) { if (modification) { jpaQuery = jpaQuery + " o.modification IS NOT NULL AND"; } else { jpaQuery = jpaQuery + " o.modification IS NULL AND"; } } jpaQuery = jpaQuery + " 1=1"; TypedQuery q = em.createQuery(jpaQuery, Long.class); if (postes != null) { q.setParameter("postes", postes); } if (candidats != null) { q.setParameter("candidats", candidats); } if (reviewStatus != null) { q.setParameter("reviewStatus", reviewStatus); } if (recevable != null) { q.setParameter("recevable", recevable); } if (auditionnable != null) { q.setParameter("auditionnable", auditionnable); } return ((Long) q.getSingleResult()); }
From source file:fr.univrouen.poste.domain.User.java
public static List<User> findUsersByEmailAddresses(List<String> emails) { if (emails == null) throw new IllegalArgumentException("The emails argument is required"); TypedQuery<User> q = entityManager().createQuery( "SELECT o FROM User o WHERE o.emailAddress IN :emails ORDER BY o.emailAddress asc", User.class); q.setParameter("emails", emails); return q.getResultList(); }
From source file:fr.univrouen.poste.domain.PosteCandidature.java
public static TypedQuery<PosteCandidature> findPostesCandidaturesByPostesAndCandidatAndRecevableAndAuditionnableAndModification( List<PosteAPourvoir> postes, List<User> candidats, List<ReviewStatusTypes> reviewStatus, Boolean recevable, Boolean auditionnable, Boolean modification, String sortFieldName, String sortOrder) {/*from ww w . j a v a 2 s . c om*/ EntityManager em = entityManager(); String jpaQuery = "SELECT o FROM PosteCandidature AS o WHERE"; if (postes != null) { jpaQuery = jpaQuery + " o.poste IN :postes AND"; } if (candidats != null) { jpaQuery = jpaQuery + " o.candidat IN :candidats AND"; } if (reviewStatus != null) { jpaQuery = jpaQuery + " o.managerReview.reviewStatus IN :reviewStatus AND"; } if (recevable != null) { jpaQuery = jpaQuery + " o.recevable = :recevable AND"; } if (auditionnable != null) { jpaQuery = jpaQuery + " o.auditionnable = :auditionnable AND"; } if (modification != null) { if (modification) { jpaQuery = jpaQuery + " o.modification IS NOT NULL AND"; } else { jpaQuery = jpaQuery + " o.modification IS NULL AND"; } } jpaQuery = jpaQuery + " 1=1"; if (fieldNames4OrderClauseFilter.contains(sortFieldName)) { jpaQuery = jpaQuery + " ORDER BY " + sortFieldName; if ("ASC".equalsIgnoreCase(sortOrder) || "DESC".equalsIgnoreCase(sortOrder)) { jpaQuery = jpaQuery + " " + sortOrder; } } TypedQuery<PosteCandidature> q = em.createQuery(jpaQuery, PosteCandidature.class); if (postes != null) { q.setParameter("postes", postes); } if (candidats != null) { q.setParameter("candidats", candidats); } if (reviewStatus != null) { q.setParameter("reviewStatus", reviewStatus); } if (recevable != null) { q.setParameter("recevable", recevable); } if (auditionnable != null) { q.setParameter("auditionnable", auditionnable); } return q; }
From source file:mobile.service.core.ClientLogService.java
/** * ?ClientLog/* www . j a v a 2 s . co m*/ * * @param pageIndex ?1 * @param pageSize ?? * @param from ?? * @return */ public static MobilePage<ClientLog> getPage(int pageIndex, int pageSize, String from) { String contentHql = " from MobileClientLog where 1=1 "; if (StringUtils.isNotBlank(from)) { contentHql += " and device = :device "; } String countHql = " select count(id) " + contentHql; contentHql = contentHql + " order by id desc "; TypedQuery<Long> countTypedQuery = JPA.em().createQuery(countHql, Long.class); TypedQuery<MobileClientLog> contentTypedQuery = JPA.em().createQuery(contentHql, MobileClientLog.class) .setFirstResult((pageIndex - 1) * pageSize).setMaxResults(pageSize); if (StringUtils.isNotBlank(from)) { countTypedQuery.setParameter("device", from); contentTypedQuery.setParameter("device", from); } Long count = countTypedQuery.getSingleResult(); List<MobileClientLog> contentList = contentTypedQuery.getResultList(); List<ClientLog> voList = new ArrayList<ClientLog>(); if (CollectionUtils.isNotEmpty(contentList)) { for (MobileClientLog po : contentList) { voList.add(ClientLog.create(po)); } } MobilePage<ClientLog> page = new MobilePage<ClientLog>(count, voList); return page; }