本文整理匯總了Java中javax.persistence.criteria.Root類的典型用法代碼示例。如果您正苦於以下問題:Java Root類的具體用法?Java Root怎麽用?Java Root使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Root類屬於javax.persistence.criteria包,在下文中一共展示了Root類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: toPredicate
import javax.persistence.criteria.Root; //導入依賴的package包/類
@Override
public Predicate toPredicate(Root<TestSuite> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
Predicate result = null;
if (StringUtils.isNotEmpty(filter.getSuite())) {
result = criteriaBuilder.like(criteriaBuilder.lower(root.get(SUITE_PROPERTY)),
buildLikeValue(filter.getSuite()));
}
return result;
}
示例2: getPlayersBySport
import javax.persistence.criteria.Root; //導入依賴的package包/類
public List<PlayerDetails> getPlayersBySport(String sport) {
logger.info("getPlayersByLeagueId");
List<Player> players = null;
try {
CriteriaQuery<Player> cq = cb.createQuery(Player.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(league.get(League_.sport), sport));
cq.select(player).distinct(true);
TypedQuery<Player> q = em.createQuery(cq);
players = q.getResultList();
}
return copyPlayersToDetails(players);
} catch (Exception ex) {
throw new EJBException(ex);
}
}
示例3: byKeyword
import javax.persistence.criteria.Root; //導入依賴的package包/類
public static Specification<User> byKeyword(String keyword, String role, String active){
return (Root<User> root, CriteriaQuery<?> query, CriteriaBuilder cb) -> {
List<Predicate> predicates = new ArrayList<>();
if (StringUtils.hasText(keyword)) {
predicates.add(
cb.or(
cb.like(root.get(User_.email), "%" + keyword + "%"),
cb.like(root.get(User_.username), "%" + keyword + "%")
));
}
if (StringUtils.hasText(role) && !"ALL".equals(role)) {
ListJoin<User, String> roleJoin = root.join(User_.roles);
predicates.add(cb.equal(roleJoin, role));
}
if (StringUtils.hasText(active)) {
predicates.add(cb.equal(root.get(User_.active), Boolean.valueOf(active)));
}
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
};
}
示例4: filterByKeywordAndStatus
import javax.persistence.criteria.Root; //導入依賴的package包/類
public static Specification<Post> filterByKeywordAndStatus(
final String keyword,//
final Post.Status status) {
return (Root<Post> root, CriteriaQuery<?> query, CriteriaBuilder cb) -> {
List<Predicate> predicates = new ArrayList<>();
if (StringUtils.hasText(keyword)) {
predicates.add(
cb.or(
cb.like(root.get(Post_.title), "%" + keyword + "%"),
cb.like(root.get(Post_.content), "%" + keyword + "%")
)
);
}
if (status != null) {
predicates.add(cb.equal(root.get(Post_.status), status));
}
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
};
}
示例5: findDeploymentSpecByVirtualSystemProjectAndRegion
import javax.persistence.criteria.Root; //導入依賴的package包/類
public static DeploymentSpec findDeploymentSpecByVirtualSystemProjectAndRegion(EntityManager em, VirtualSystem vs,
String projectId, String region) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<DeploymentSpec> query = cb.createQuery(DeploymentSpec.class);
Root<DeploymentSpec> root = query.from(DeploymentSpec.class);
query = query.select(root)
.where(cb.equal(root.get("projectId"), projectId),
cb.equal(root.get("region"), region),
cb.equal(root.get("virtualSystem"), vs));
try {
return em.createQuery(query).getSingleResult();
} catch (NoResultException nre) {
return null;
}
}
示例6: search
import javax.persistence.criteria.Root; //導入依賴的package包/類
@Override
public Page search(QueryCriteria criteria, Pageable pageable) {
CriteriaBuilder builder = this.entityManager.getCriteriaBuilder();
CriteriaQuery<Long> countCriteria = builder.createQuery(Long.class);
Root<T> countRoot = countCriteria.from(this.domainClass);
long total = this.entityManager.createQuery(
countCriteria.select(builder.count(countRoot))
.where(toPredicates(criteria, countRoot, builder))
).getSingleResult();
CriteriaQuery<T> pageCriteria = builder.createQuery(this.domainClass);
Root<T> pageRoot = pageCriteria.from(this.domainClass);
List<T> list = this.entityManager.createQuery(
pageCriteria.select(pageRoot)
.where(toPredicates(criteria, pageRoot, builder))
.orderBy(toOrders(pageable.getSort(), pageRoot, builder))
).setFirstResult(pageable.getOffset())
.setMaxResults(pageable.getPageSize())
.getResultList();
return new PageImpl<>(new ArrayList<>(list), pageable, total);
}
示例7: toPredicate
import javax.persistence.criteria.Root; //導入依賴的package包/類
@Override
public Predicate toPredicate(Root<TestRun> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
Predicate result = null;
if (!CollectionUtils.isEmpty(filter.getBuilds())) {
result = criteriaBuilder.in(root.get(BUILD_PROPERTY)).value(filter.getBuilds());
}
if (!CollectionUtils.isEmpty(filter.getTestSuites())) {
result = and(criteriaBuilder, result,
criteriaBuilder.in(root.get("testSuite").get("id")).value(filter.getTestSuites()));
}
if (!CollectionUtils.isEmpty(filter.getGit())) {
result = and(criteriaBuilder, result,
criteriaBuilder.or(
criteriaBuilder.in(root.get("gitHash")).value(filter.getGit()),
criteriaBuilder.in(root.get("gitBranch")).value(filter.getGit())
));
}
result = and(criteriaBuilder, result, criteriaBuilder.isNotNull(root.get("testSuite")));
return result;
}
示例8: applySpecificationToQueryCriteria
import javax.persistence.criteria.Root; //導入依賴的package包/類
/**
* Spec op query doen.
* @param spec spec
* @param query query
* @param <S> query type
* @return root
*/
protected final <S> Root<T> applySpecificationToQueryCriteria(final Specification<T> spec, final CriteriaQuery<S> query) {
Assert.notNull(query, "Query mag niet null zijn.");
final Root<T> root = query.from(getDomainClass());
if (spec == null) {
return root;
}
final CriteriaBuilder builder = em.getCriteriaBuilder();
final Predicate predicate = spec.toPredicate(root, query, builder);
if (predicate != null) {
query.where(predicate);
}
return root;
}
示例9: getPredicateGlobalSearch
import javax.persistence.criteria.Root; //導入依賴的package包/類
private Predicate getPredicateGlobalSearch(final Root<T> root, final CriteriaQuery<?> query, final CriteriaBuilder cb,
Predicate predicate) {
// check whether a global filter value exists
final String globalFilterValue = input.getSearch().getValue();
if (globalFilterValue != null && globalFilterValue.trim().length() > 0) {
LOGGER.fine("filtre global: {"+ globalFilterValue+"}");
Predicate matchOneColumnPredicate = cb.disjunction();
// add a 'WHERE .. LIKE' clause on each searchable column
for (final DatatableColumn column : input.getColumns()) {
if (column.getSearchable()) {
LOGGER.log(Level.FINE, "filtre global pour colonne: {}", column);
final Expression<String> expression = DatatableHelper.getExpression(root, column.getData(), String.class);
matchOneColumnPredicate = cb.or(matchOneColumnPredicate,
cb.like(cb.lower(expression), getLikeFilterValue(globalFilterValue), ESCAPE_CHAR));
}
}
predicate = cb.and(predicate, matchOneColumnPredicate);
}
return predicate;
}
示例10: findRecentRegionProductTypeFrom
import javax.persistence.criteria.Root; //導入依賴的package包/類
@GET
@Produces({"application/xml", "application/json"})
@Path("/recent/region/producttype/{regionName}/{productTypeId}/{orderLineId}")
public List<LiveSalesList> findRecentRegionProductTypeFrom(@PathParam("regionName") String regionName, @PathParam("productTypeId") Integer productTypeId, @PathParam("orderLineId") Integer orderLineId) {
CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
javax.persistence.criteria.CriteriaQuery cq = cb.createQuery();
Root<LiveSalesList> liveSalesList = cq.from(LiveSalesList.class);
cq.select(liveSalesList);
cq.where(cb.and(
cb.equal(liveSalesList.get(LiveSalesList_.productTypeId), productTypeId),
cb.equal(liveSalesList.get(LiveSalesList_.region), regionName),
cb.gt(liveSalesList.get(LiveSalesList_.orderLineId), orderLineId)
));
Query q = getEntityManager().createQuery(cq);
q.setMaxResults(500);
return q.getResultList();
}
示例11: createQuery
import javax.persistence.criteria.Root; //導入依賴的package包/類
private TypedQuery<ContextExtension> createQuery(String processId, String name, EntityManager manager) {
CriteriaBuilder builder = manager.getCriteriaBuilder();
CriteriaQuery<ContextExtension> query = builder.createQuery(ContextExtension.class);
Root<ContextExtension> root = query.from(ContextExtension.class);
List<Predicate> predicates = new ArrayList<>();
if (processId != null) {
predicates.add(builder.equal(root.get(ContextExtension.FieldNames.PROCESS_ID),
builder.parameter(String.class, ContextExtension.FieldNames.PROCESS_ID)));
}
if (name != null) {
predicates.add(builder.equal(root.get(ContextExtension.FieldNames.NAME),
builder.parameter(String.class, ContextExtension.FieldNames.NAME)));
}
return manager.createQuery(query.select(root).where(predicates.toArray(new Predicate[0])));
}
示例12: findRecentProductTypeFrom
import javax.persistence.criteria.Root; //導入依賴的package包/類
@GET
@Produces({"application/xml", "application/json"})
@Path("/recent/producttype/{id}/{orderLineId}")
public List<LiveSalesList> findRecentProductTypeFrom(@PathParam("id") Integer productTypeId, @PathParam("orderLineId") Integer orderLineId) {
CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
javax.persistence.criteria.CriteriaQuery cq = cb.createQuery();
Root<LiveSalesList> liveSalesList = cq.from(LiveSalesList.class);
cq.select(liveSalesList);
cq.where(cb.and(
cb.equal(liveSalesList.get(LiveSalesList_.productTypeId), productTypeId),
cb.gt(liveSalesList.get(LiveSalesList_.orderLineId), orderLineId)
));
Query q = getEntityManager().createQuery(cq);
q.setMaxResults(500);
return q.getResultList();
}
示例13: aggregate
import javax.persistence.criteria.Root; //導入依賴的package包/類
private <S> S aggregate(CriteriaBuilder builder, CriteriaQuery<S> query, Root<E> root, Specification<E> spec, List<Selection<?>> selectionList, LockModeType lockMode) {
if (selectionList != null) {
Predicate predicate = spec.toPredicate(root, query, builder);
if (predicate != null) {
query.where(predicate);
}
query.multiselect(selectionList);
return (S) em.createQuery(query).setLockMode(lockMode).getSingleResult();
}
return null;
}
示例14: getUser
import javax.persistence.criteria.Root; //導入依賴的package包/類
public static User getUser(String username) {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("userData");
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
tx.begin();
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<User> q = cb.createQuery(User.class);
Root<User> c = q.from(User.class);
q.select(c).where(cb.equal(c.get("username"), username));
TypedQuery<User> query = em.createQuery(q);
List<User> users = query.getResultList();
em.close();
LOGGER.info("found " + users.size() + " users with username " + username);
if (users.size() == 1)
return users.get(0);
else
return null;
}
示例15: getExpression
import javax.persistence.criteria.Root; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public static <T, N extends Number> Expression<N> getExpression(CriteriaBuilder cb, Root<T> root, String input) {
StringTokenizer tokenizer = new StringTokenizer(input, "+-*/", true);
Expression<N> expr = getPath(root, tokenizer.nextToken());
if (tokenizer.hasMoreTokens()) {
String op = tokenizer.nextToken();
String name = tokenizer.nextToken();
Expression<N> expr2 = getPath(root, name);
if ("+".equals(op)) {
expr = cb.sum(expr, expr2);
} else if ("-".equals(op)) {
expr = cb.diff(expr, expr2);
} else if ("*".equals(op)) {
expr = cb.prod(expr, expr2);
} else if ("/".equals(op)) {
expr = (Expression<N>) cb.quot(expr, expr2);
}
}
return expr;
}