List of usage examples for javax.persistence Query getResultList
List getResultList();
From source file:es.ucm.fdi.dalgs.user.repository.UserRepository.java
public User findByUsername(String username) { Query query = em.createQuery("select s from User s where s.username=?1"); query.setParameter(1, username);//from w w w. jav a 2 s .c o m if (query.getResultList().isEmpty()) { logger.error("User not found by username " + username); return null; } return (User) query.getSingleResult(); }
From source file:org.kuali.mobility.push.dao.SenderDaoImpl.java
public List<Sender> findAllSenders() { Query query = entityManager.createQuery("select s from Sender s order by s.name"); return query.getResultList(); }
From source file:com.branded.holdings.qpc.repository.jpa.JpaOwnerRepositoryImpl.java
/** * Important: in the current version of this method, we load Owners with all their Pets and Visits while * we do not need Visits at all and we only need one property from the Pet objects (the 'name' property). * There are some ways to improve it such as: * - creating a Ligtweight class (example here: https://community.jboss.org/wiki/LightweightClass) * - Turning on lazy-loading and using {@link OpenSessionInViewFilter} *///from ww w.ja v a 2 s .c o m @SuppressWarnings("unchecked") public Collection<Owner> findByLastName(String lastName) { // using 'join fetch' because a single query should load both owners and pets // using 'left join fetch' because it might happen that an owner does not have pets yet Query query = this.em.createQuery( "SELECT DISTINCT owner FROM Owner owner left join fetch owner.pets WHERE owner.lastName LIKE :lastName"); query.setParameter("lastName", lastName + "%"); return query.getResultList(); }
From source file:it.scoppelletti.programmerpower.security.DefaultUserManager.java
@Transactional(readOnly = true) public List<User> listUsers() { User user;//from ww w .j a va 2s . c om Query query; List<User> list; list = new ArrayList<User>(); query = myEntityMgr.createQuery("from User order by code"); for (Object item : query.getResultList()) { user = (User) item; list.add(user); } return list; }
From source file:com.panguso.lc.analysis.format.dao.impl.DaoImpl.java
@Override public List<T> find() { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<T> criteriaQuery = cb.createQuery(entityClass); Root<T> customer = criteriaQuery.from(entityClass); criteriaQuery.getRoots().add(customer); Query query = em.createQuery(criteriaQuery); return query.getResultList(); }
From source file:eu.planets_project.tb.impl.persistency.ServiceRecordPersistencyImpl.java
@SuppressWarnings("unchecked") public List<ServiceRecordImpl> getAllServiceRecordsForEndpoint(String endpoint) { Query query = manager.createQuery("from ServiceRecordImpl where endpoint=:endpoint"); query.setParameter("endpoint", endpoint); return (List<ServiceRecordImpl>) query.getResultList(); }
From source file:com.rambird.repository.springdatajpa.JpaOwnerRepositoryImpl.java
@Override @SuppressWarnings("unchecked") public Collection<Owner> findByLastName(String lastName) { // using 'join fetch' because a single query should load both owners and pets // using 'left join fetch' because it might happen that an owner does not have pets yet Query query = this.em.createQuery( "SELECT DISTINCT owner FROM Owner owner left join fetch owner.pets WHERE upper(owner.lastName) LIKE upper(:lastName)"); query.setParameter("lastName", lastName + "%"); return query.getResultList(); }
From source file:es.ucm.fdi.dalgs.degree.repository.DegreeRepository.java
public Degree existByCode(String code) { Query query = em.createQuery("select d from Degree d where d.info.code=?1"); query.setParameter(1, code);/* w w w . j a va 2s .c om*/ if (query.getResultList().isEmpty()) return null; else return (Degree) query.getSingleResult(); }
From source file:org.kuali.mobility.maps.dao.LocationDaoImpl.java
@SuppressWarnings("unchecked") public List<Location> getAllLocations() { Query query = entityManager.createQuery("select loc from Location loc order by loc.locationId"); return query.getResultList(); }
From source file:edu.usu.sdl.opencatalog.service.PersistantServiceImpl.java
public <T> List<T> queryByExample(QueryByExample queryByExample) { StringBuilder queryString = new StringBuilder(); switch (queryByExample.getQueryType()) { case SELECT://from ww w . java 2 s . c om queryString.append("select instance "); break; case COUNT: queryString.append("select count(instance) "); break; case COUNT_DISTINCT: queryString.append("select count(distinct instance) "); break; case UPDATE: queryString.append("update "); break; case DELETE: queryString.append("delete "); break; } queryString.append("from ").append(queryByExample.getExample().getClass().getSimpleName()) .append(" instance "); String whereClause = generateWhereClause(queryByExample.getExample()); if (StringUtils.isNotBlank(whereClause)) { queryString.append("where ").append(whereClause); } Query query = getEntityManger().createQuery(queryString.toString()); mapParameters(query, queryByExample.getExample()); return query.getResultList(); }