List of usage examples for javax.persistence TypedQuery setParameter
TypedQuery<X> setParameter(int position, Object value);
From source file:org.openmeetings.app.data.file.dao.FileExplorerItemDaoImpl.java
public FileExplorerItem[] getFileExplorerItemsByParent(Long parentFileExplorerItemId) { log.debug(".getFileExplorerItemsByParent() started"); try {/*from w w w . j av a 2 s. c o m*/ String hql = "SELECT c FROM FileExplorerItem c " + "WHERE c.deleted <> :deleted " + "AND c.parentFileExplorerItemId = :parentFileExplorerItemId " + "ORDER BY c.isFolder DESC, c.fileName "; TypedQuery<FileExplorerItem> query = em.createQuery(hql, FileExplorerItem.class); query.setParameter("deleted", "true"); query.setParameter("parentFileExplorerItemId", parentFileExplorerItemId); FileExplorerItem[] fileExplorerList = query.getResultList().toArray(new FileExplorerItem[0]); return fileExplorerList; } catch (Exception ex2) { log.error("[getFileExplorerRootItemsByOwner]: ", ex2); } return null; }
From source file:org.openmeetings.app.data.file.dao.FileExplorerItemDaoImpl.java
public FileExplorerItem[] getFileExplorerItemsByOwner(Long ownerId, Long parentFileExplorerItemId) { log.debug(".getFileExplorerItemsByOwner() started"); try {// w ww . j a v a 2 s . c o m String hql = "SELECT c FROM FileExplorerItem c " + "WHERE c.deleted <> :deleted " + "AND c.ownerId = :ownerId " + "AND c.parentFileExplorerItemId = :parentFileExplorerItemId " + "ORDER BY c.isFolder DESC, c.fileName "; TypedQuery<FileExplorerItem> query = em.createQuery(hql, FileExplorerItem.class); query.setParameter("deleted", "true"); query.setParameter("ownerId", ownerId); query.setParameter("parentFileExplorerItemId", parentFileExplorerItemId); FileExplorerItem[] fileExplorerList = query.getResultList().toArray(new FileExplorerItem[0]); return fileExplorerList; } catch (Exception ex2) { log.error("[getFileExplorerRootItemsByOwner]: ", ex2); } return null; }
From source file:org.noorganization.instalist.server.api.CategoriesResourceTest.java
@Test public void testPostCategory() throws Exception { final String url = "/groups/%d/categories"; UUID uuid = UUID.randomUUID(); Response wrongTokenResponse = target(String.format(url, mGroup.getId())).request() .header(HttpHeaders.AUTHORIZATION, "X-Token wrongToken") .post(Entity.json(new CategoryInfo().withUUID(uuid).withName("cat3"))); assertEquals(401, wrongTokenResponse.getStatus()); Response wrongGroupResponse = target(String.format(url, mNotAccessibleGroup.getId())).request() .header(HttpHeaders.AUTHORIZATION, "X-Token " + mToken) .post(Entity.json(new CategoryInfo().withUUID(uuid).withName("cat3"))); assertEquals(401, wrongGroupResponse.getStatus()); Response invalidCatResponse = target(String.format(url, mGroup.getId())).request() .header(HttpHeaders.AUTHORIZATION, "X-Token " + mToken) .post(Entity.json(new CategoryInfo().withUUID(uuid))); assertEquals(400, invalidCatResponse.getStatus()); Response conflictCatResponse = target(String.format(url, mGroup.getId())).request() .header(HttpHeaders.AUTHORIZATION, "X-Token " + mToken) .post(Entity.json(new CategoryInfo().withUUID(mCategory.getUUID()).withName("cat3"))); assertEquals(409, conflictCatResponse.getStatus()); mManager.refresh(mCategory);/* ww w.ja v a 2 s. c o m*/ assertEquals("cat1", mCategory.getName()); Response validCatResponse = target(String.format(url, mGroup.getId())).request() .header(HttpHeaders.AUTHORIZATION, "X-Token " + mToken) .post(Entity.json(new CategoryInfo().withUUID(uuid).withName("cat3"))); assertEquals(201, validCatResponse.getStatus()); TypedQuery<Category> savedCatQuery = mManager.createQuery( "select c from Category c where " + "c.UUID = :uuid and c.group = :groupid", Category.class); savedCatQuery.setParameter("uuid", uuid); savedCatQuery.setParameter("groupid", mGroup); List<Category> savedCats = savedCatQuery.getResultList(); assertEquals(1, savedCats.size()); assertEquals("cat3", savedCats.get(0).getName()); }
From source file:org.openmeetings.app.data.file.dao.FileExplorerItemDaoImpl.java
public FileExplorerItem[] getFileExplorerItemsByRoom(Long room_id, Long parentFileExplorerItemId) { log.debug("getFileExplorerItemsByRoom room_id :: " + room_id); try {//ww w. j a va 2s.c om String hql = "SELECT c FROM FileExplorerItem c " + "WHERE c.deleted <> :deleted " + "AND c.room_id = :room_id " + "AND c.ownerId IS NULL " + "AND c.parentFileExplorerItemId = :parentFileExplorerItemId " + "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("parentFileExplorerItemId", parentFileExplorerItemId); FileExplorerItem[] fileExplorerList = query.getResultList().toArray(new FileExplorerItem[0]); return fileExplorerList; } catch (Exception ex2) { log.error("[getFileExplorerRootItemsByRoom]: ", ex2); } return null; }
From source file:org.openmeetings.app.data.file.dao.FileExplorerItemDaoImpl.java
public FileExplorerItem getFileExplorerItemsById(Long fileExplorerItemId) { //log.debug(".getFileExplorerItemsById() started"); try {/*from www . j av a2s . c om*/ String hql = "SELECT c FROM FileExplorerItem c " + "WHERE c.fileExplorerItemId = :fileExplorerItemId"; TypedQuery<FileExplorerItem> query = em.createQuery(hql, FileExplorerItem.class); query.setParameter("fileExplorerItemId", fileExplorerItemId); FileExplorerItem fileExplorerList = null; try { fileExplorerList = query.getSingleResult(); } catch (NoResultException ex) { } return fileExplorerList; } catch (Exception ex2) { log.error("[getFileExplorerItemsById]: ", ex2); } return null; }
From source file:com.music.dao.PieceDao.java
public PieceEvaluation getEvaluation(long pieceId, Long userId, String ip) { TypedQuery<PieceEvaluation> query; if (userId != null) { query = getEntityManager().createQuery( "SELECT ev FROM PieceEvaluation ev where ev.piece.id=:pieceId AND ev.user.id=:userId", PieceEvaluation.class); query.setParameter("userId", userId); } else {//from ww w .j a va2s .c o m query = getEntityManager().createQuery( "SELECT ev FROM PieceEvaluation ev where ev.piece.id=:pieceId AND ev.ip=:ip", PieceEvaluation.class); query.setParameter("ip", ip); } query.setParameter("pieceId", pieceId); try { return query.getSingleResult(); } catch (NoResultException ex) { return null; } }
From source file:org.openmeetings.app.data.file.dao.FileExplorerItemDaoImpl.java
public FileExplorerItem getFileExplorerItemsByExternalIdAndType(Long externalFileId, String externalType) { log.debug(".getFileExplorerItemsByExternalIdAndType() started"); try {//from w ww . ja v a 2 s . c om String hql = "SELECT c FROM FileExplorerItem c " + "WHERE c.externalFileId = :externalFileId " + "AND c.externalType LIKE :externalType"; TypedQuery<FileExplorerItem> query = em.createQuery(hql, FileExplorerItem.class); query.setParameter("externalFileId", externalFileId); query.setParameter("externalType", externalType); FileExplorerItem fileExplorerList = null; try { fileExplorerList = query.getSingleResult(); } catch (NoResultException ex) { } return fileExplorerList; } catch (Exception ex2) { log.error("[getFileExplorerItemsByExternalIdAndType]: ", ex2); } return null; }
From source file:com.netflix.genie.core.jpa.services.JpaJobSearchServiceImpl.java
/** * {@inheritDoc}/*from ww w.j av a 2s.com*/ */ @Override public Set<Job> getAllActiveJobsOnHost(@NotBlank final String hostName) { log.debug("Called with hostname {}", hostName); final TypedQuery<JobEntity> query = entityManager .createNamedQuery(JobExecutionEntity.QUERY_FIND_BY_STATUS_HOST, JobEntity.class); query.setParameter("statuses", JobStatus.getActiveStatuses()); query.setParameter("hostName", hostName); return query.getResultList().stream().map(JobEntity::getDTO).collect(Collectors.toSet()); }
From source file:com.ilkgunel.hastaneotomasyonu.service.AvailableAppointmentsService.java
public List<Uygunrandevular> getAllAvaliableAppointments(String hospitalName, String clinic, String clicPlace) { int hospitalid = 0; for (Hastaneler h : hospitalsService.getHospitalResults()) { if (h.getHastaneadi().equals(hospitalName)) { hospitalid = h.getId();/*from w ww . j a v a2 s.c o m*/ break; } } int clinicId = 0; for (Klinikler k : clinicService.getClinicResults()) { if (k.getKlinikadi().equals(clinic)) { clinicId = k.getId(); break; } } TypedQuery<Uygunrandevular> query = em.createQuery( "SELECT u FROM Uygunrandevular AS u WHERE u.hastaneid=:hospitalid AND u.klinikid=:clinicid AND u.klinikyeri=:clinicplace " + "AND u.tarih = (select min(uu.tarih) from Uygunrandevular uu where uu.doktorid = u.doktorid)", Uygunrandevular.class); query.setParameter("hospitalid", hospitalid); query.setParameter("clinicid", clinicId); query.setParameter("clinicplace", clicPlace); availableAppointments = query.getResultList(); return availableAppointments; }
From source file:com.music.dao.PieceDao.java
@SuppressWarnings("rawtypes") public Map<Piece, Integer> getTopRecentPieces(int page, int pageSize, DateTime minusWeeks) { TypedQuery<List> query = getEntityManager().createQuery( "SELECT new list(ev.piece, COUNT(ev) AS cnt) FROM PieceEvaluation ev WHERE ev.dateTime > :threshold AND ev.piece.likes > 0 GROUP BY ev.piece ORDER BY cnt DESC, ev.dateTime DESC", List.class); query.setParameter("threshold", minusWeeks); query.setFirstResult(page * pageSize); query.setMaxResults(pageSize);//from w w w . ja v a 2s. co m Map<Piece, Integer> result = new LinkedHashMap<>(); for (List<?> list : query.getResultList()) { result.put((Piece) list.get(0), ((Long) list.get(1)).intValue()); } return result; }