本文整理匯總了Java中javax.persistence.criteria.CriteriaQuery.from方法的典型用法代碼示例。如果您正苦於以下問題:Java CriteriaQuery.from方法的具體用法?Java CriteriaQuery.from怎麽用?Java CriteriaQuery.from使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.persistence.criteria.CriteriaQuery
的用法示例。
在下文中一共展示了CriteriaQuery.from方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getAllRasterPoints
import javax.persistence.criteria.CriteriaQuery; //導入方法依賴的package包/類
@Override
public List<RasterPoint> getAllRasterPoints() {
// set up potentially long running transaction!
try {
// TODO refactor out
ut.setTransactionTimeout(2000);
ut.begin();
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<RasterPoint> c = cb.createQuery(RasterPoint.class);
Root<RasterPoint> root = c.from(RasterPoint.class);
CriteriaQuery<RasterPoint> all = c.select(root);
TypedQuery<RasterPoint> allQuery = entityManager.createQuery(all);
List<RasterPoint> resultList = allQuery.getResultList();
ut.commit();
return resultList;
} catch (Exception e) {
//throw new DatabaseException("Could not load raster from database! Reason: " + e.getMessage());
log.error("Could not load raster from database! Reason: {}", e.getMessage());
return Collections.emptyList();
}
}
示例2: findPoliciesById
import javax.persistence.criteria.CriteriaQuery; //導入方法依賴的package包/類
/**
* Verifies if the request contains valid policies supported by security manager available on the OSC.
* If the request contains one or more invalid policies, throw an exception.
*/
// TODO Larkins: Improve the method not to do the validation
public static Set<Policy> findPoliciesById(EntityManager em, Set<Long> ids, ApplianceManagerConnector mc)
throws VmidcBrokerValidationException, Exception {
Set<Policy> policies = new HashSet<>();
Set<String> invalidPolicies = new HashSet<>();
for (Long id : ids) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Policy> query = cb.createQuery(Policy.class);
Root<Policy> root = query.from(Policy.class);
query = query.select(root).where(cb.equal(root.get("id"), id),
cb.equal(root.join("applianceManagerConnector").get("id"), mc.getId()));
try {
Policy policy = em.createQuery(query).getSingleResult();
policies.add(policy);
} catch (NoResultException nre) {
invalidPolicies.add(id.toString());
}
}
if (invalidPolicies.size() > 0) {
throw new VmidcBrokerValidationException(
"Invalid Request. Request contains invalid policies: " + String.join(", ", invalidPolicies));
}
return policies;
}
示例3: getPlayersNotOnTeam
import javax.persistence.criteria.CriteriaQuery; //導入方法依賴的package包/類
public List<PlayerDetails> getPlayersNotOnTeam() {
logger.info("getPlayersNotOnTeam");
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.isNull(player.get(Player_.team)));
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: search
import javax.persistence.criteria.CriteriaQuery; //導入方法依賴的package包/類
@Override
public Optional<SearchResponse> search(final ServiceUser user,
final SearchRequest request){
final String dataSourceUuid = request.getQuery().getDataSource().getUuid();
try (final Session session = database.openSession()) {
final CriteriaBuilder cb = session.getCriteriaBuilder();
final CriteriaQuery<Tuple> cq = cb.createTupleQuery();
final Root<T> root = cq.from(this.dtoClass);
cq.multiselect(this.fields.stream()
.map(f -> root.get(f.getName()))
.collect(Collectors.toList()));
final Predicate requestPredicate = getPredicate(cb, root, request.getQuery().getExpression());
final Predicate dataSourcePredicate = cb.equal(root.get(QueryableEntity.DATA_SOURCE_UUID), dataSourceUuid);
cq.where(cb.and(requestPredicate, dataSourcePredicate));
final List<Tuple> tuples = session.createQuery(cq).getResultList();
final SearchResponse searchResponse = projectResults(request, tuples);
return Optional.of(searchResponse);
}
}
示例5: getGuardianByEmail
import javax.persistence.criteria.CriteriaQuery; //導入方法依賴的package包/類
@GET
@Path("/guardian/{guardianEmail}")
@Produces({"application/xml", "application/json"})
@RolesAllowed({"Guardian", "Administrator"})
public Guardian getGuardianByEmail(@PathParam("guardianEmail") String email) {
logger.log(Level.INFO, "Principal is: {0}", ctx.getCallerPrincipal().getName());
CriteriaQuery<Guardian> cq = cb.createQuery(Guardian.class);
Root<Guardian> guardian = cq.from(Guardian.class);
cq.select(guardian);
cq.where(cb.equal(guardian.get(Guardian_.email), email));
cq.distinct(true);
TypedQuery<Guardian> q = em.createQuery(cq);
return q.getSingleResult();
}
示例6: readByName
import javax.persistence.criteria.CriteriaQuery; //導入方法依賴的package包/類
public UserDataSet readByName(String name) {
CriteriaBuilder builder = session.getCriteriaBuilder();
CriteriaQuery<UserDataSet> criteria = builder.createQuery(UserDataSet.class);
Root<UserDataSet> from = criteria.from(UserDataSet.class);
criteria.where(builder.equal(from.get("name"), name));
Query<UserDataSet> query = session.createQuery(criteria);
return query.uniqueResult();
}
示例7: stream
import javax.persistence.criteria.CriteriaQuery; //導入方法依賴的package包/類
public Stream<T> stream() {
CriteriaBuilder cb = this.entityManager().getCriteriaBuilder();
CriteriaQuery<T> q = cb.createQuery(entityClass());
Root<T> c = q.from(entityClass());
return entityManager().createQuery(q).getResultStream();
}
示例8: findAllByFieldIn
import javax.persistence.criteria.CriteriaQuery; //導入方法依賴的package包/類
@Override
public List<T> findAllByFieldIn(String Field, Iterable<?> values) {
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<T> query = cb.createQuery(getDomainClass());
Root<T> e = query.from(getDomainClass());
query.where(cb.in(e.get(Field)).value(values));
return entityManager.createQuery(query).getResultList();
}
示例9: getUncompletedJobs
import javax.persistence.criteria.CriteriaQuery; //導入方法依賴的package包/類
public List<JobRecord> getUncompletedJobs(EntityManager em) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<JobRecord> query = cb.createQuery(JobRecord.class);
Root<JobRecord> from = query.from(JobRecord.class);
query = query.select(from)
.where(cb.notEqual(from.get("state"), COMPLETED));
return em.createQuery(query).getResultList();
}
示例10: getQuery
import javax.persistence.criteria.CriteriaQuery; //導入方法依賴的package包/類
private CriteriaQuery<User> getQuery(User po) {
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<User> query = cb.createQuery(User.class);
Root<User> root = query.from(User.class);
query.select(root);
query.where(cb.and(getPredicates(cb, root, po)));
return query;
}
示例11: getTodaysSession
import javax.persistence.criteria.CriteriaQuery; //導入方法依賴的package包/類
public TutoringSession getTodaysSession() {
// get today's date and trim the time information
Calendar today = Calendar.getInstance();
CalendarUtil.stripTime(today);
// find today's session
SimpleDateFormat formatter = new SimpleDateFormat("E, MMM d, yyyy");
logger.log(Level.INFO, "Finding tutoring session for {0}", formatter.format(today.getTime()));
CriteriaQuery<TutoringSession> cq = cb.createQuery(TutoringSession.class);
Root<TutoringSession> tutoringSession = cq.from(TutoringSession.class);
cq.select(tutoringSession);
cq.where(cb.equal(tutoringSession.get(TutoringSession_.sessionDate), today));
cq.distinct(true);
TypedQuery<TutoringSession> q = em.createQuery(cq);
TutoringSession session;
try {
session = q.getSingleResult();
logger.info("Found session for today.");
} catch (NoResultException e) {
logger.info("Today's session not found. Creating a new session.");
session = new TutoringSession();
em.persist(session);
}
return session;
}
示例12: findAll
import javax.persistence.criteria.CriteriaQuery; //導入方法依賴的package包/類
/**
* 分頁查詢
* @param domainClass 領域類(實體類)
* @param pageable 分頁信息
* @param <T> 領域類(實體類)範型
* @return 分頁結果信息
*/
public static <T> Page<T> findAll(Class<T> domainClass, Pageable pageable) {
EntityManager em = getEntityManager(domainClass);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<T> cq = cb.createQuery(domainClass);
cq.from(domainClass);
return findAll(cq, pageable);
}
示例13: validarUsuario
import javax.persistence.criteria.CriteriaQuery; //導入方法依賴的package包/類
public Pessoa validarUsuario(String log, String pass){
final CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
final CriteriaQuery<Pessoa> cquery = cb.createQuery(Pessoa.class);
final Root<Pessoa> root = cquery.from(Pessoa.class);
final List<Predicate> condicoes = new ArrayList<Predicate>();
condicoes.add(cb.equal(root.get("login"), log));
condicoes.add(cb.equal(root.get("senha"), pass));
cquery.select(root).where(condicoes.toArray(new Predicate[]{}));
Pessoa pessoa = null;
try{
pessoa = getEntityManager().createQuery(cquery).getSingleResult();
for(Menu m : pessoa.getPerfil().getMenus()) {
m.getItens().size();
}
} catch (Exception e) {
e.printStackTrace();
}
return pessoa;
}
示例14: executeCountQuery
import javax.persistence.criteria.CriteriaQuery; //導入方法依賴的package包/類
private long executeCountQuery(QueryWrapper queryWrapper) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Long> query = cb.createQuery(Long.class);
Root<T> root = query.from(entityClass);
query.select(cb.count(root));
queryWrapper.wrap(root, query, cb, false);
TypedQuery<Long> typedQuery = em.createQuery(query);
long total = 0;
for (long value : typedQuery.getResultList()) {
total += value;
}
return total;
}
示例15: findSystem
import javax.persistence.criteria.CriteriaQuery; //導入方法依賴的package包/類
@Override
@Transactional
public SystemEntity findSystem(String system) {
CriteriaBuilder builder = em.getCriteriaBuilder();
SystemEntity systemEntity = null;
CriteriaQuery<SystemEntity> criteria = builder.createQuery(SystemEntity.class);
Root<SystemEntity> root = criteria.from(SystemEntity.class);
List<Predicate> predList = new LinkedList<Predicate>();
log.debug("Looking for System = " + system);
Predicate p = builder.equal(root.<String>get("codeSystemUri"),system);
predList.add(p);
Predicate[] predArray = new Predicate[predList.size()];
predList.toArray(predArray);
if (predList.size()>0)
{
log.debug("Found System "+system);
criteria.select(root).where(predArray);
List<SystemEntity> qryResults = em.createQuery(criteria).getResultList();
for (SystemEntity cme : qryResults) {
systemEntity = cme;
break;
}
}
if (systemEntity == null) {
log.info("Not found. Adding SystemEntity = "+system);
systemEntity = new SystemEntity();
systemEntity.setUri(system);
em.persist(systemEntity);
}
return systemEntity;
}