List of usage examples for javax.persistence Query getSingleResult
Object getSingleResult();
From source file:org.venice.piazza.common.hibernate.dao.job.JobDaoImpl.java
public Page<JobEntity> getJobListForUserAndStatus(String status, String userName, Pagination pagination) { // Query/*from w w w . j a va 2s . c o m*/ String queryString = String.format(USERNAME_AND_STATUS_JOB_QUERY, Direction.fromString(pagination.getOrder())); Query query = entityManager.createNativeQuery(queryString, JobEntity.class); query.setParameter(1, userName); query.setParameter(2, status); query.setParameter(3, pagination.getSortBy()); query.setParameter(4, pagination.getPerPage()); query.setParameter(5, pagination.getPage() * pagination.getPerPage()); List<JobEntity> results = query.getResultList(); // Count query = entityManager.createNativeQuery(USERNAME_AND_STATUS_JOB_QUERY_COUNT); query.setParameter(1, userName); query.setParameter(2, status); long count = ((BigInteger) query.getSingleResult()).longValue(); return new PageImpl<JobEntity>(results, null, count); }
From source file:org.asqatasun.entity.dao.audit.ContentDAOImpl.java
@Override public Long findNumberOfSSPFromWebResource(WebResource webResource, int httpStatusCode) { if (webResource != null) { StringBuilder strb = new StringBuilder(); strb.append(SELECT_DISTINCT_SSP); strb.append(SSPImpl.class.getName()); strb.append(" s"); strb.append(JOIN_WR);/*from w w w .j a v a2s . c o m*/ if (webResource instanceof Page) { strb.append(" WHERE w.id=:idWebResource"); } else if (webResource instanceof Site) { strb.append(" WHERE w.parent.id=:idWebResource"); } if (httpStatusCode != -1) { strb.append(HTTP_STATUS_CONDITION); } else { strb.append(" AND s.httpStatusCode!=:httpStatusCode"); } Query query = entityManager.createQuery(strb.toString()); query.setParameter(ID_WEB_RESOURCE_KEY, webResource.getId()); query.setParameter(HTTP_STATUS_CODE_KEY, httpStatusCode); return (Long) query.getSingleResult(); } else { return (long) 0; } }
From source file:org.venice.piazza.common.hibernate.dao.deployment.DeploymentDaoImpl.java
public Page<DeploymentEntity> getDeploymentListByDeploymentId(String keyword, Pagination pagination) { // Query// w w w. ja v a2 s. co m String queryString = String.format(KEYWORD_DEPLOYMENT_ID_QUERY, Direction.fromString(pagination.getOrder())); Query query = entityManager.createNativeQuery(queryString, DeploymentEntity.class); query.setParameter(1, String.format(WILDCARD_STRING_QUERY, keyword)); query.setParameter(2, pagination.getSortBy()); query.setParameter(3, pagination.getPerPage()); query.setParameter(4, pagination.getPage() * pagination.getPerPage()); List<DeploymentEntity> results = query.getResultList(); // Count query = entityManager.createNativeQuery(KEYWORD_DEPLOYMENT_ID_QUERY_COUNT); query.setParameter(1, String.format(WILDCARD_STRING_QUERY, keyword)); long count = ((BigInteger) query.getSingleResult()).longValue(); return new PageImpl<DeploymentEntity>(results, null, count); }
From source file:org.venice.piazza.common.hibernate.dao.service.ServiceDaoImpl.java
public Page<ServiceEntity> getServiceListByUser(String userName, Pagination pagination) { // Query//w ww .ja va 2s.c o m String queryString = String.format(USERNAME_SERVICE_QUERY, Direction.fromString(pagination.getOrder())); Query query = entityManager.createNativeQuery(queryString, ServiceEntity.class); query.setParameter(1, String.format(WILDCARD_STRING_QUERY, userName)); query.setParameter(2, pagination.getSortBy()); query.setParameter(3, pagination.getPerPage()); query.setParameter(4, pagination.getPage() * pagination.getPerPage()); List<ServiceEntity> results = query.getResultList(); // Count query = entityManager.createNativeQuery(USERNAME_SERVICE_QUERY_COUNT); query.setParameter(1, String.format(WILDCARD_STRING_QUERY, userName)); long count = ((BigInteger) query.getSingleResult()).longValue(); return new PageImpl<ServiceEntity>(results, null, count); }
From source file:org.venice.piazza.common.hibernate.dao.deployment.DeploymentDaoImpl.java
public Page<DeploymentEntity> getDeploymentListByCapabilitiesUrl(String keyword, Pagination pagination) { // Query/*from w w w.jav a 2 s.co m*/ String queryString = String.format(KEYWORD_CAPABILITIES_URL_QUERY, Direction.fromString(pagination.getOrder())); Query query = entityManager.createNativeQuery(queryString, DeploymentEntity.class); query.setParameter(1, String.format(WILDCARD_STRING_QUERY, keyword)); query.setParameter(2, pagination.getSortBy()); query.setParameter(3, pagination.getPerPage()); query.setParameter(4, pagination.getPage() * pagination.getPerPage()); List<DeploymentEntity> results = query.getResultList(); // Count query = entityManager.createNativeQuery(KEYWORD_CAPABILITIES_URL_QUERY_COUNT); query.setParameter(1, String.format(WILDCARD_STRING_QUERY, keyword)); long count = ((BigInteger) query.getSingleResult()).longValue(); return new PageImpl<DeploymentEntity>(results, null, count); }
From source file:com.doculibre.constellio.services.RecordServicesImpl.java
@Override public int count(ConnectorInstance connectorInstance) { int attempts = 0; while (true) { try {/* www .j a va 2s .c om*/ String ql = "SELECT COUNT(r.id) FROM Record r WHERE r.connectorInstance = :connectorInstance"; Query query = this.getEntityManager().createQuery(ql); query.setParameter("connectorInstance", connectorInstance); return ((Number) query.getSingleResult()).intValue(); } catch (PessimisticLockException e) { attempts++; if (attempts > 100) { throw e; } } } }
From source file:com.expressui.core.dao.GenericDao.java
/** * Finds a single entity that is "owned" by a given user, for example a user profile or preferences. * * @param entityType the type of entity/*w ww . j a va 2 s .c om*/ * @param user the user to query * @param <T> type of entity * @return found entity, null if none found */ public <T> T findUserOwnedEntity(Class<? extends T> entityType, User user) { Assert.PROGRAMMING.isTrue(UserOwnedEntity.class.isAssignableFrom(entityType), "This entityType " + entityType + " must implement " + UserOwnedEntity.class.getName()); Query query = getEntityManager() .createQuery("SELECT e FROM " + entityType.getSimpleName() + " e where e.user = :user"); query.setParameter("user", user); try { return (T) query.getSingleResult(); } catch (NoResultException e) { return null; } }
From source file:com.openmeap.model.ModelServiceImpl.java
@Override public ApplicationVersion findAppVersionByNameAndId(String appName, String identifier) { Query q = entityManager.createQuery("select distinct av " + "from ApplicationVersion av " + "inner join fetch av.application a " + "where av.identifier=:identifier " + "and a.name=:name"); q.setParameter("name", appName); q.setParameter("identifier", identifier); try {//from ww w . j a v a2s.c o m ApplicationVersion ver = (ApplicationVersion) q.getSingleResult(); return ver; } catch (NoResultException nre) { return null; } }
From source file:eu.forgestore.ws.impl.FStoreJpaController.java
public Product readProductByUUID(String uuid) { EntityManager entityManager = entityManagerFactory.createEntityManager(); Query q = entityManager.createQuery("SELECT m FROM Product m WHERE m.uuid='" + uuid + "'"); return (q.getResultList().size() == 0) ? null : (Product) q.getSingleResult(); }
From source file:eu.forgestore.ws.impl.FStoreJpaController.java
public FStoreUser readFStoreUserByEmail(String email) { EntityManager entityManager = entityManagerFactory.createEntityManager(); Query q = entityManager.createQuery("SELECT m FROM FStoreUser m WHERE m.email='" + email + "'"); return (q.getResultList().size() == 0) ? null : (FStoreUser) q.getSingleResult(); }