本文整理匯總了Java中javax.persistence.TypedQuery.getResultList方法的典型用法代碼示例。如果您正苦於以下問題:Java TypedQuery.getResultList方法的具體用法?Java TypedQuery.getResultList怎麽用?Java TypedQuery.getResultList使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.persistence.TypedQuery
的用法示例。
在下文中一共展示了TypedQuery.getResultList方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: searchForUser
import javax.persistence.TypedQuery; //導入方法依賴的package包/類
@Override
public List<UserModel> searchForUser(String search, RealmModel realm, int firstResult, int maxResults) {
TypedQuery<UserEntity> query = em.createNamedQuery("searchForUser", UserEntity.class);
query.setParameter("search", "%" + search.toLowerCase() + "%");
if (firstResult != -1) {
query.setFirstResult(firstResult);
}
if (maxResults != -1) {
query.setMaxResults(maxResults);
}
List<UserEntity> results = query.getResultList();
List<UserModel> users = new LinkedList<>();
for (UserEntity entity : results)
users.add(new UserAdapter(session, realm, model, entity));
return users;
}
示例2: loadAuditLogs
import javax.persistence.TypedQuery; //導入方法依賴的package包/類
/**
* load auditLogs by operationIds and date range, if operationIds is null or
* empty, load auditLogs only by date range
*
* @param operationIds
* @param startTime
* @param endTime
* @return
*/
public List<AuditLog> loadAuditLogs(List<String> operationIds,
long startTime, long endTime) {
TypedQuery<AuditLog> query;
if (operationIds == null || operationIds.isEmpty()) {
query = em.createNamedQuery("AuditLog.findByDateRange",
AuditLog.class);
} else {
query = em.createNamedQuery("AuditLog.findByOperationAndDateRange",
AuditLog.class);
query.setParameter("operationIds", operationIds);
}
query.setParameter("startTime", Long.valueOf(startTime));
query.setParameter("endTime", Long.valueOf(endTime));
return query.getResultList();
}
示例3: getPlayersByPositionAndName
import javax.persistence.TypedQuery; //導入方法依賴的package包/類
public List<PlayerDetails> getPlayersByPositionAndName(String position, String name) {
logger.info("getPlayersByPositionAndName");
List<Player> players = null;
try {
CriteriaQuery<Player> cq = cb.createQuery(Player.class);
if (cq != null) {
Root<Player> player = cq.from(Player.class);
// Get MetaModel from Root
//EntityType<Player> Player_ = player.getModel();
// set the where clause
cq.where(cb.equal(player.get(Player_.position), position),
cb.equal(player.get(Player_.name), name));
cq.select(player).distinct(true);
TypedQuery<Player> q = em.createQuery(cq);
players = q.getResultList();
}
return copyPlayersToDetails(players);
} catch (Exception ex) {
throw new EJBException(ex);
}
}
示例4: getStatusByGuardianId
import javax.persistence.TypedQuery; //導入方法依賴的package包/類
@GET
@Path("id/{guardianId}")
@Produces({"application/xml", "application/json"})
public List<Student> getStatusByGuardianId(@PathParam("guardianId") Long id) {
logger.log(Level.INFO, "Principal is: {0}", ctx.getCallerPrincipal().getName());
CriteriaQuery<Student> cq = cb.createQuery(Student.class);
Root<Student> student = cq.from(Student.class);
Join<Student, Guardian> guardian = student.join(Student_.guardians);
cq.select(student);
cq.where(cb.equal(guardian.get(Guardian_.id), id));
cq.distinct(true);
TypedQuery<Student> q = em.createQuery(cq);
return q.getResultList();
}
示例5: findAllInternal
import javax.persistence.TypedQuery; //導入方法依賴的package包/類
private List<ConfigurationSubscriptionDto> findAllInternal(String mtaId, String appName, String spaceId, String resourceName,
EntityManager manager) {
TypedQuery<ConfigurationSubscriptionDto> query = createQuery(mtaId, appName, spaceId, resourceName, manager);
setQueryParameter(query, ConfigurationSubscriptionDto.FieldNames.SPACE_ID, spaceId);
setQueryParameter(query, ConfigurationSubscriptionDto.FieldNames.APP_NAME, appName);
setQueryParameter(query, ConfigurationSubscriptionDto.FieldNames.RESOURCE_NAME, resourceName);
setQueryParameter(query, ConfigurationSubscriptionDto.FieldNames.MTA_ID, mtaId);
return query.getResultList();
}
示例6: findForEndRace
import javax.persistence.TypedQuery; //導入方法依賴的package包/類
public List<ProductEntity> findForEndRace(String categoryName, String productType, int level) {
TypedQuery<ProductEntity> query = entityManager.createNamedQuery("ProductEntity.findForEndRace", ProductEntity.class);
query.setParameter("categoryName", categoryName);
query.setParameter("productType", productType);
query.setParameter("level", level);
return query.getResultList();
}
示例7: findByPersonaId
import javax.persistence.TypedQuery; //導入方法依賴的package包/類
public List<CarSlotEntity> findByPersonaId(Long personaId) {
PersonaEntity personaEntity = new PersonaEntity();
personaEntity.setPersonaId(personaId);
TypedQuery<CarSlotEntity> query = entityManager.createNamedQuery("CarSlotEntity.findByPersonaId", CarSlotEntity.class);
query.setParameter("persona", personaEntity);
return query.getResultList();
}
示例8: findCode
import javax.persistence.TypedQuery; //導入方法依賴的package包/類
@Override
public ConceptEntity findCode(Coding coding) {
ConceptEntity conceptEntity = null;
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<ConceptEntity> criteria = builder.createQuery(ConceptEntity.class);
Root<ConceptEntity> root = criteria.from(ConceptEntity.class);
List<Predicate> predList = new LinkedList<Predicate>();
List<ConceptEntity> results = new ArrayList<ConceptEntity>();
Join<ConceptEntity,CodeSystemRepository> join = root.join("codeSystemEntity");
log.debug("Looking for code ="+coding.getCode()+" in "+coding.getSystem());
Predicate pcode = builder.equal(root.get("code"), coding.getCode());
predList.add(pcode);
Predicate psystem = builder.equal(join.get("codeSystemUri"), coding.getSystem());
predList.add(psystem);
Predicate[] predArray = new Predicate[predList.size()];
predList.toArray(predArray);
criteria.select(root).where(predArray);
TypedQuery<ConceptEntity> qry = em.createQuery(criteria);
qry.setHint("javax.persistence.cache.storeMode", "REFRESH");
List<ConceptEntity> qryResults = qry.getResultList();
for (ConceptEntity concept : qryResults) {
conceptEntity = concept;
log.debug("Found for code="+coding.getCode()+" ConceptEntity.Id="+conceptEntity.getId());
break;
}
return conceptEntity;
}
示例9: haalPersoonCachesOp
import javax.persistence.TypedQuery; //導入方法依賴的package包/類
/**
* Haalt een lijst van persoon caches op voor een lijst van persoon id's.
* @param ids De id's van de personen.
* @return De lijst van persoon caches.
*/
@Override
public List<PersoonCache> haalPersoonCachesOp(final Set<Long> ids) {
if (ids.isEmpty()) {
return Lists.newArrayList();
}
final String query = "SELECT pc FROM PersoonCache pc WHERE pc.persoon.id IN :ids";
final TypedQuery<PersoonCache> typedQuery = entityManager.createQuery(query, PersoonCache.class);
typedQuery.setParameter("ids", ids);
return typedQuery.getResultList();
}
示例10: getSportsOfPlayer
import javax.persistence.TypedQuery; //導入方法依賴的package包/類
public List<String> getSportsOfPlayer(String playerId) {
logger.info("getSportsOfPlayer");
List<String> sports = new ArrayList<>();
try {
CriteriaQuery<String> cq = cb.createQuery(String.class);
if (cq != null) {
Root<Player> player = cq.from(Player.class);
Join<Player, Team> team = player.join(Player_.teams);
Join<Team, League> league = team.join(Team_.league);
// Get MetaModel from Root
//EntityType<Player> Player_ = player.getModel();
// set the where clause
cq.where(cb.equal(player.get(Player_.id), playerId));
cq.select(league.get(League_.sport)).distinct(true);
TypedQuery<String> q = em.createQuery(cq);
sports = q.getResultList();
}
// Player player = em.find(Player.class, playerId);
// Iterator<Team> i = player.getTeams().iterator();
// while (i.hasNext()) {
// Team team = i.next();
// League league = team.getLeague();
// sports.add(league.getSport());
// }
} catch (Exception ex) {
throw new EJBException(ex);
}
return sports;
}
示例11: findAll
import javax.persistence.TypedQuery; //導入方法依賴的package包/類
protected <T> List<T> findAll(Class clazz) throws DatabaseException {
try {
CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
CriteriaQuery<T> c = cb.createQuery(clazz);
Root<T> root = c.from(clazz);
CriteriaQuery<T> all = c.select(root);
TypedQuery<T> allQuery = getEntityManager().createQuery(all);
return allQuery.getResultList();
} catch (EJBTransactionRolledbackException | PersistenceException e) {
throw new DatabaseException("Could not find entity of class " + clazz.toString() + ", " + e.getMessage());
}
}
示例12: findByEmailAndPassword
import javax.persistence.TypedQuery; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public List<User> findByEmailAndPassword(String email, String password) {
Session session = this.sessionFactory.getCurrentSession();
TypedQuery<User> query = session.getNamedQuery("findByEmailAndPassword");
query.setParameter("email", email);
query.setParameter("password", password);
return query.getResultList();
}
開發者ID:PacktPublishing,項目名稱:Building-Web-Apps-with-Spring-5-and-Angular,代碼行數:10,代碼來源:UserDAOImpl.java
示例13: findByUserId
import javax.persistence.TypedQuery; //導入方法依賴的package包/類
@Override
public List<Session> findByUserId(Long userId) {
TypedQuery<Session> sessionQuery =
entityManager.createNamedQuery(FIND_BY_USER_ID_QUERY, Session.class);
Stream.of(entry("userId", userId), entry("now", nowUtc()))
.collect(Collectors.toMap(Entry::getKey, Entry::getValue))
.forEach(sessionQuery::setParameter);
return sessionQuery.getResultList();
}
示例14: getEventsForCategory
import javax.persistence.TypedQuery; //導入方法依賴的package包/類
public List<Event> getEventsForCategory(String category, Optional<Interval> withIn) {
StringBuilder qs = new StringBuilder("select e from Event e where e.category=:category");
if (withIn.isPresent()) {
qs.append(" and t.lastModifiedTime>:startsAt and t.lastModifiedTime<:endsAt");
}
TypedQuery<Event> q = em.createQuery(qs.toString(), Event.class);
q.setParameter("category", category);
if (withIn.isPresent()) {
Interval intv = withIn.get();
q.setParameter("startsAt", Timestamp.from(intv.getStart().toInstant()));
q.setParameter("endsAt", Timestamp.from(intv.getEnd().toInstant()));
}
return q.getResultList();
}
示例15: findAll
import javax.persistence.TypedQuery; //導入方法依賴的package包/類
@Override
@Transactional
public List<MODEL> findAll() throws BusinessException {
String sql = "from " + persistentClass.getSimpleName() + " order by id";
TypedQuery<MODEL> q = em.createQuery(sql, persistentClass);
return q.getResultList();
}