本文整理汇总了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();
}