javax.persistence.criteria.Path Java Examples

The following examples show how to use javax.persistence.criteria.Path. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ItemFactory.java    From o2oa with GNU Affero General Public License v3.0 7 votes vote down vote up
public List<Item> listWithJobWithPathWithAfterLocation(String job, Integer index, String... paths)
		throws Exception {
	EntityManager em = this.entityManagerContainer().get(Item.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Item> cq = cb.createQuery(Item.class);
	Root<Item> root = cq.from(Item.class);
	Predicate p = cb.equal(root.get(Item_.bundle), job);
	p = cb.and(p, cb.equal(root.get(Item_.itemCategory), ItemCategory.pp));
	for (int i = 0; ((i < (paths.length - 1)) && (i < 8)); i++) {
		p = cb.and(p, cb.equal(root.get("path" + i), paths[i]));
	}
	Path<Integer> locationPath = root.get("path" + (paths.length - 1) + "Location");
	p = cb.and(p, cb.greaterThan(locationPath, index));
	cq.select(root).where(p);
	List<Item> list = em.createQuery(cq).getResultList();
	return list;
}
 
Example #2
Source File: RSQLUtility.java    From hawkbit with Eclipse Public License 1.0 7 votes vote down vote up
private Predicate getEqualToPredicate(final Object transformedValue, final Path<Object> fieldPath) {
    if (transformedValue instanceof String) {
        if (StringUtils.isEmpty(transformedValue)) {
            return cb.or(cb.isNull(pathOfString(fieldPath)), cb.equal(pathOfString(fieldPath), ""));
        }

        final String sqlValue = toSQL((String) transformedValue);
        return cb.like(cb.upper(pathOfString(fieldPath)), sqlValue, ESCAPE_CHAR);
    }

    if (transformedValue == null) {
        return cb.isNull(pathOfString(fieldPath));
    }

    return cb.equal(fieldPath, transformedValue);
}
 
Example #3
Source File: ActionFilterAttribute.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private List<NameValueCountPair> listProcessPair(Business business, EffectivePerson effectivePerson,
		Predicate predicate) throws Exception {
	EntityManager em = business.entityManagerContainer().get(Review.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Tuple> cq = cb.createQuery(Tuple.class);
	Root<Review> root = cq.from(Review.class);
	Path<String> pathProcess = root.get(Review_.process);
	Path<String> pathProcessName = root.get(Review_.processName);
	cq.multiselect(pathProcess, pathProcessName, cb.count(root)).where(predicate).groupBy(pathProcess);
	List<Tuple> os = em.createQuery(cq).getResultList();
	List<NameValueCountPair> list = new ArrayList<>();
	NameValueCountPair pair = null;
	for (Tuple o : os) {
		pair = new NameValueCountPair();
		pair.setName(o.get(pathProcessName));
		pair.setValue(o.get(pathProcess));
		pair.setCount(o.get(2, Long.class));
		list.add(pair);
	}
	list = list.stream().sorted((o1, o2) -> Objects.toString(o1.getName()).compareTo(o2.getName().toString()))
			.collect(Collectors.toList());
	return list;
}
 
Example #4
Source File: V2Count.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private List<NameValueCountPair> groupByProcess(Business business, Predicate predicate) throws Exception {
	EntityManager em = business.entityManagerContainer().get(TaskCompleted.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Tuple> cq = cb.createQuery(Tuple.class);
	Root<TaskCompleted> root = cq.from(TaskCompleted.class);
	Path<String> pathProcess = root.get(TaskCompleted_.process);
	Path<String> pathProcessName = root.get(TaskCompleted_.processName);
	cq.multiselect(pathProcess, pathProcessName, cb.count(root)).where(predicate).groupBy(pathProcess);
	List<Tuple> os = em.createQuery(cq).getResultList();
	List<NameValueCountPair> list = new ArrayList<>();
	NameValueCountPair pair = null;
	for (Tuple o : os) {
		pair = new NameValueCountPair();
		pair.setName(o.get(pathProcessName));
		pair.setValue(o.get(pathProcess));
		pair.setCount(o.get(2, Long.class));
		list.add(pair);
	}
	return list.stream().sorted(Comparator.comparing(NameValueCountPair::getCount).reversed())
			.collect(Collectors.toList());
}
 
Example #5
Source File: RSQLPredicateProducerTest.java    From pnc with Apache License 2.0 6 votes vote down vote up
@Test
public void testCriteriaPredicate() {
    org.jboss.pnc.spi.datastore.repositories.api.Predicate<BuildRecord> criteriaPredicate = producer
            .getCriteriaPredicate(BuildRecord.class, "id==4");

    CriteriaBuilder cb = mock(CriteriaBuilder.class);
    Root<BuildRecord> root = mock(Root.class);
    Path<Integer> idPath = mock(Path.class);

    when(root.get(BuildRecord_.id)).thenReturn(idPath);
    Mockito.doReturn(Integer.class).when(idPath).getJavaType();

    criteriaPredicate.apply(root, null, cb);

    Mockito.verify(cb).equal(idPath, 4);
}
 
Example #6
Source File: BaseAction.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private List<ApplicationDictItem> listWithApplicationDictWithPathWithAfterLocation(Business business,
		String applicationDict, Integer index, String... paths) throws Exception {
	EntityManager em = business.entityManagerContainer().get(ApplicationDictItem.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<ApplicationDictItem> cq = cb.createQuery(ApplicationDictItem.class);
	Root<ApplicationDictItem> root = cq.from(ApplicationDictItem.class);
	Predicate p = cb.equal(root.get(ApplicationDictItem_.bundle), applicationDict);
	for (int i = 0; ((i < (paths.length - 1)) && (i < 8)); i++) {
		p = cb.and(p, cb.equal(root.get("path" + i), paths[i]));
	}
	Path<Integer> locationPath = root.get("path" + (paths.length - 1) + "Location");
	p = cb.and(p, cb.greaterThan(locationPath, index));
	cq.select(root).where(p);
	List<ApplicationDictItem> list = em.createQuery(cq).getResultList();
	return list;
}
 
Example #7
Source File: RSQLUtility.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
private Path<?> getJoinFieldPath(final Path<?> fieldPath, final String fieldNameSplit) {
    if (fieldPath instanceof PluralJoin) {
        final Join<Object, ?> join = (Join<Object, ?>) fieldPath;
        final From<?, Object> joinParent = join.getParent();
        final Optional<Join<Object, Object>> currentJoinOfType = findCurrentJoinOfType(join.getJavaType());
        if (currentJoinOfType.isPresent() && isOrLevel) {
            // remove the additional join and use the existing one
            joinParent.getJoins().remove(join);
            return currentJoinOfType.get();
        } else {
            final Join<Object, Object> newJoin = joinParent.join(fieldNameSplit, JoinType.LEFT);
            addCurrentJoin(newJoin);
            return newJoin;
        }
    }
    return fieldPath;
}
 
Example #8
Source File: V2Count.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private List<NameValueCountPair> groupByStartTimeMonth(Business business, Predicate predicate) throws Exception {
	EntityManager em = business.entityManagerContainer().get(Task.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Tuple> cq = cb.createQuery(Tuple.class);
	Root<Task> root = cq.from(Task.class);
	Path<String> pathStartTimeMonth = root.get(Task_.startTimeMonth);
	cq.multiselect(pathStartTimeMonth, cb.count(root)).where(predicate).groupBy(pathStartTimeMonth);
	List<Tuple> os = em.createQuery(cq).getResultList();
	List<NameValueCountPair> list = new ArrayList<>();
	NameValueCountPair pair = null;
	for (Tuple o : os) {
		pair = new NameValueCountPair();
		pair.setName(o.get(pathStartTimeMonth));
		pair.setValue(o.get(pathStartTimeMonth));
		pair.setCount(o.get(1, Long.class));
		list.add(pair);
	}
	return list.stream()
			.sorted((o1, o2) -> Objects.toString(o2.getName(), "").compareTo(Objects.toString(o1.getName(), "")))
			.collect(Collectors.toList());
}
 
Example #9
Source File: BusinessObjectDefinitionDaoImpl.java    From herd with Apache License 2.0 6 votes vote down vote up
@Override
public List<BusinessObjectDefinitionEntity> getMostRecentBusinessObjectDefinitions(int numberOfResults)
{
    // Create the criteria builder and a tuple style criteria query.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<BusinessObjectDefinitionEntity> criteria = builder.createQuery(BusinessObjectDefinitionEntity.class);

    // The criteria root is the business object definition.
    Root<BusinessObjectDefinitionEntity> businessObjectDefinitionEntityRoot = criteria.from(BusinessObjectDefinitionEntity.class);

    // Get the columns.
    Path<Timestamp> businessObjectDefinitionUpdatedOnColumn = businessObjectDefinitionEntityRoot.get(BusinessObjectDefinitionEntity_.updatedOn);

    // Select the business object definitions and order descending by the updated on column
    criteria.select(businessObjectDefinitionEntityRoot).orderBy(builder.desc(businessObjectDefinitionUpdatedOnColumn));

    return entityManager.createQuery(criteria).setMaxResults(numberOfResults).getResultList();
}
 
Example #10
Source File: CommandPredicatesTest.java    From genie with Apache License 2.0 6 votes vote down vote up
@Test
void testFindEmptyStatuses() {
    CommandPredicates.find(this.root, this.cq, this.cb, NAME, USER_NAME, Sets.newHashSet(), TAGS);

    Mockito
        .verify(this.cb, Mockito.times(1))
        .equal(this.root.get(CommandEntity_.name), NAME);
    Mockito
        .verify(this.cb, Mockito.times(1))
        .equal(this.root.get(CommandEntity_.user), USER_NAME);
    for (final String status : STATUSES) {
        Mockito.verify(this.cb, Mockito.never()).equal(this.root.get(CommandEntity_.status), status);
    }
    Mockito.verify(this.root, Mockito.times(1)).join(CommandEntity_.tags);
    Mockito.verify(this.tagEntityJoin, Mockito.times(1)).in(TAGS);
    Mockito.verify(this.cq, Mockito.times(1)).groupBy(Mockito.any(Path.class));
    Mockito.verify(this.cq, Mockito.times(1)).having(Mockito.any(Predicate.class));
}
 
Example #11
Source File: V2Count.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private List<NameValueCountPair> groupByStartTimeMonth(Business business, Predicate predicate) throws Exception {
	EntityManager em = business.entityManagerContainer().get(Read.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Tuple> cq = cb.createQuery(Tuple.class);
	Root<Read> root = cq.from(Read.class);
	Path<String> pathStartTimeMonth = root.get(Read_.startTimeMonth);
	cq.multiselect(pathStartTimeMonth, cb.count(root)).where(predicate).groupBy(pathStartTimeMonth);
	List<Tuple> os = em.createQuery(cq).getResultList();
	List<NameValueCountPair> list = new ArrayList<>();
	NameValueCountPair pair = null;
	for (Tuple o : os) {
		pair = new NameValueCountPair();
		pair.setName(o.get(pathStartTimeMonth));
		pair.setValue(o.get(pathStartTimeMonth));
		pair.setCount(o.get(1, Long.class));
		list.add(pair);
	}
	return list.stream()
			.sorted((o1, o2) -> Objects.toString(o2.getName(), "").compareTo(Objects.toString(o1.getName(), "")))
			.collect(Collectors.toList());
}
 
Example #12
Source File: ActionFilterAttribute.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private List<NameValueCountPair> listApplicationPair(Business business, EffectivePerson effectivePerson,
		Predicate predicate) throws Exception {
	EntityManager em = business.entityManagerContainer().get(Review.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Tuple> cq = cb.createQuery(Tuple.class);
	Root<Review> root = cq.from(Review.class);
	Path<String> pathApplication = root.get(Review_.application);
	Path<String> pathApplicationName = root.get(Review_.applicationName);
	cq.multiselect(pathApplication, pathApplicationName, cb.count(root)).where(predicate).groupBy(pathApplication);
	List<Tuple> os = em.createQuery(cq).getResultList();
	List<NameValueCountPair> list = new ArrayList<>();
	NameValueCountPair pair = null;
	for (Tuple o : os) {
		pair = new NameValueCountPair();
		pair.setName(o.get(pathApplicationName));
		pair.setValue(o.get(pathApplication));
		pair.setCount(o.get(2, Long.class));
		list.add(pair);
	}
	list = list.stream().sorted((o1, o2) -> Objects.toString(o1.getName()).compareTo(o2.getName().toString()))
			.collect(Collectors.toList());
	return list;
}
 
Example #13
Source File: V2Count.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private List<NameValueCountPair> groupByStartTimeMonth(Business business, Predicate predicate) throws Exception {
	EntityManager em = business.entityManagerContainer().get(Review.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Tuple> cq = cb.createQuery(Tuple.class);
	Root<Review> root = cq.from(Review.class);
	Path<String> pathStartTimeMonth = root.get(Review_.startTimeMonth);
	cq.multiselect(pathStartTimeMonth, cb.count(root)).where(predicate).groupBy(pathStartTimeMonth);
	List<Tuple> os = em.createQuery(cq).getResultList();
	List<NameValueCountPair> list = new ArrayList<>();
	NameValueCountPair pair = null;
	for (Tuple o : os) {
		pair = new NameValueCountPair();
		pair.setName(o.get(pathStartTimeMonth));
		pair.setValue(o.get(pathStartTimeMonth));
		pair.setCount(o.get(1, Long.class));
		list.add(pair);
	}
	return list.stream()
			.sorted((o1, o2) -> Objects.toString(o2.getName(), "").compareTo(Objects.toString(o1.getName(), "")))
			.collect(Collectors.toList());
}
 
Example #14
Source File: V2Count.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private List<NameValueCountPair> groupByCreatorUnit(Business business, Predicate predicate) throws Exception {
	EntityManager em = business.entityManagerContainer().get(Read.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Tuple> cq = cb.createQuery(Tuple.class);
	Root<Read> root = cq.from(Read.class);
	Path<String> pathCreatorUnit = root.get(Read_.creatorUnit);
	cq.multiselect(pathCreatorUnit, cb.count(root)).where(predicate).groupBy(pathCreatorUnit);
	List<Tuple> os = em.createQuery(cq).getResultList();
	List<NameValueCountPair> list = new ArrayList<>();
	NameValueCountPair pair = null;
	for (Tuple o : os) {
		pair = new NameValueCountPair();
		pair.setName(o.get(pathCreatorUnit));
		pair.setValue(o.get(pathCreatorUnit));
		pair.setCount(o.get(1, Long.class));
		list.add(pair);
	}
	return list.stream().sorted(Comparator.comparing(NameValueCountPair::getCount).reversed())
			.collect(Collectors.toList());
}
 
Example #15
Source File: TagDaoImpl.java    From herd with Apache License 2.0 6 votes vote down vote up
@Override
public List<TagEntity> getMostRecentTags(int numberOfResults)
{
    // Create the criteria builder and a tuple style criteria query.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<TagEntity> criteria = builder.createQuery(TagEntity.class);

    // The criteria root is the tag.
    Root<TagEntity> tagEntityRoot = criteria.from(TagEntity.class);

    // Get the columns.
    Path<Timestamp> tagUpdatedOnColumn = tagEntityRoot.get(TagEntity_.updatedOn);

    // Select the tags and order descending by the updated on column
    criteria.select(tagEntityRoot).orderBy(builder.desc(tagUpdatedOnColumn));

    return entityManager.createQuery(criteria).setMaxResults(numberOfResults).getResultList();
}
 
Example #16
Source File: NumberCriteria.java    From onedev with MIT License 6 votes vote down vote up
@Override
public Predicate getPredicate(Root<PullRequest> root, CriteriaBuilder builder) {
	Path<Long> attribute = root.get(PullRequest.PROP_NUMBER);
	Predicate numberPredicate;
	
	if (operator == PullRequestQueryLexer.Is)
		numberPredicate = builder.equal(attribute, number.getNumber());
	else if (operator == PullRequestQueryLexer.IsGreaterThan)
		numberPredicate = builder.greaterThan(attribute, number.getNumber());
	else
		numberPredicate = builder.lessThan(attribute, number.getNumber());
	
	return builder.and(
			builder.equal(root.get(PullRequest.PROP_TARGET_PROJECT), number.getProject()),
			numberPredicate);
}
 
Example #17
Source File: TupleTest.java    From high-performance-java-persistence with Apache License 2.0 6 votes vote down vote up
@Test
public void testTuple() {
    doInJPA(entityManager -> {
        CriteriaBuilder cb = entityManager.getCriteriaBuilder();
        CriteriaQuery<Tuple> cq = cb.createTupleQuery();

        Root<BlogEntityProvider.Post> postRoot = cq.from(BlogEntityProvider.Post.class);
        Path<Long> idPath = postRoot.get("id");
        Path<String> titlePath = postRoot.get("title");
        cq.multiselect(idPath, titlePath);

        List<Tuple> resultList = entityManager.createQuery(cq).getResultList();

        for (Tuple tuple : resultList) {
            Long id = tuple.get(idPath);
            String title = tuple.get(titlePath);
        }
    });
}
 
Example #18
Source File: V2Count.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private List<NameValueCountPair> groupByApplication(Business business, Predicate predicate) throws Exception {
	EntityManager em = business.entityManagerContainer().get(Read.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Tuple> cq = cb.createQuery(Tuple.class);
	Root<Read> root = cq.from(Read.class);
	Path<String> pathApplication = root.get(Read_.application);
	Path<String> pathApplicationName = root.get(Read_.applicationName);
	cq.multiselect(pathApplication, pathApplicationName, cb.count(root)).where(predicate).groupBy(pathApplication);
	List<Tuple> os = em.createQuery(cq).getResultList();
	List<NameValueCountPair> list = new ArrayList<>();
	NameValueCountPair pair = null;
	for (Tuple o : os) {
		pair = new NameValueCountPair();
		pair.setName(o.get(pathApplicationName));
		pair.setValue(o.get(pathApplication));
		pair.setCount(o.get(2, Long.class));
		list.add(pair);
	}
	return list.stream().sorted(Comparator.comparing(NameValueCountPair::getCount).reversed())
			.collect(Collectors.toList());
}
 
Example #19
Source File: RSQLUtility.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private Predicate mapToMapPredicate(final ComparisonNode node, final Path<Object> fieldPath,
        final A enumField) {
    if (!enumField.isMap()) {
        return null;
    }

    final String[] graph = getSubAttributesFrom(node.getSelector());

    final String keyValue = graph[graph.length - 1];
    if (fieldPath instanceof MapJoin) {
        // Currently we support only string key .So below cast is safe.
        return cb.equal(cb.upper((Expression<String>) (((MapJoin<?, ?, ?>) fieldPath).key())),
                keyValue.toUpperCase());
    }

    final String keyFieldName = enumField.getSubEntityMapTuple().map(Entry::getKey)
            .orElseThrow(() -> new UnsupportedOperationException(
                    "For the fields, defined as Map, only Map java type or tuple in the form of SimpleImmutableEntry are allowed. Neither of those could be found!"));

    return cb.equal(cb.upper(fieldPath.get(keyFieldName)), keyValue.toUpperCase());
}
 
Example #20
Source File: MCRJobQueue.java    From mycore with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @param action
 * @param params
 *
 * @return the query for the given parameters
 * */
private <T> T buildQuery(Class<? extends MCRJobAction> action, Map<String, String> params,
    Function<TypedQuery<MCRJob>, T> consumer) {
    EntityManager em = MCREntityManagerProvider.getCurrentEntityManager();
    CriteriaBuilder cb = em.getCriteriaBuilder();

    CriteriaQuery<MCRJob> query = cb.createQuery(MCRJob.class);
    Root<MCRJob> jobRoot = query.from(MCRJob.class);
    query.select(jobRoot);

    params.keySet().forEach(key -> {
        MapJoin<MCRJob, String, String> parameterJoin = jobRoot.join(MCRJob_.parameters, JoinType.INNER);
        Path<String> keyPath = parameterJoin.key();
        Path<String> valuePath = parameterJoin.value();
        parameterJoin.on(cb.equal(keyPath, key), cb.equal(valuePath, params.get(key)));
    });

    query.where(cb.equal(jobRoot.get(MCRJob_.action), action));
    T result = consumer.apply(em.createQuery(query));
    clearPreFetch();
    return result;
}
 
Example #21
Source File: ApplicationDictItemFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
public List<ApplicationDictItem> listWithApplicationDictWithPathWithAfterLocation(String applicationDict,
		Integer index, String... paths) throws Exception {
	EntityManager em = this.entityManagerContainer().get(ApplicationDictItem.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<ApplicationDictItem> cq = cb.createQuery(ApplicationDictItem.class);
	Root<ApplicationDictItem> root = cq.from(ApplicationDictItem.class);
	Predicate p = cb.equal(root.get(ApplicationDictItem_.bundle), applicationDict);
	for (int i = 0; ((i < (paths.length - 1)) && (i < 8)); i++) {
		p = cb.and(p, cb.equal(root.get("path" + i), paths[i]));
	}
	Path<Integer> locationPath = root.get("path" + (paths.length - 1) + "Location");
	p = cb.and(p, cb.greaterThan(locationPath, index));
	cq.select(root).where(p);
	List<ApplicationDictItem> list = em.createQuery(cq).getResultList();
	return list;
}
 
Example #22
Source File: AbstractNotificationRegistrationDao.java    From herd with Apache License 2.0 6 votes vote down vote up
/**
 * Gets a list of notification registration keys from the list of tuples that contain notification registration name and namespace columns.
 *
 * @param tuples the list tof tuples that contain notification registration name and namespace columns
 * @param notificationRegistrationNamespaceColumn the column that contains the namespace of the notification registration
 * @param notificationRegistrationNameColumn the column that contains the name of the notification registration
 *
 * @return the list of notification registration keys
 */
protected List<NotificationRegistrationKey> getNotificationRegistrationKeys(List<Tuple> tuples, Path<String> notificationRegistrationNamespaceColumn,
    Path<String> notificationRegistrationNameColumn)
{
    List<NotificationRegistrationKey> notificationRegistrationKeys = new ArrayList<>();

    // Populate the "keys" objects from the returned tuples (i.e. 1 tuple for each row).
    for (Tuple tuple : tuples)
    {
        NotificationRegistrationKey notificationRegistrationKey = new NotificationRegistrationKey();
        notificationRegistrationKeys.add(notificationRegistrationKey);
        notificationRegistrationKey.setNamespace(tuple.get(notificationRegistrationNamespaceColumn));
        notificationRegistrationKey.setNotificationName(tuple.get(notificationRegistrationNameColumn));
    }

    return notificationRegistrationKeys;
}
 
Example #23
Source File: RSQLProducerImpl.java    From pnc with Apache License 2.0 5 votes vote down vote up
private <DB extends GenericEntity<?>> Predicate<DB> getEntityPredicate(Node rootNode, Class<DB> type) {
    return (root, query, cb) -> {
        RSQLNodeTraveller<javax.persistence.criteria.Predicate> visitor = new EntityRSQLNodeTraveller(
                root,
                cb,
                new BiFunction<From<?, DB>, RSQLSelectorPath, Path>() {
                    @Override
                    public Path apply(From<?, DB> from, RSQLSelectorPath selector) {
                        return mapper.toPath(type, from, selector);
                    }
                });
        return rootNode.accept(visitor);
    };
}
 
Example #24
Source File: FixedIssueCriteria.java    From onedev with MIT License 5 votes vote down vote up
@Override
public Predicate getPredicate(Root<Build> root, CriteriaBuilder builder) {
	Path<Long> attribute = root.get(Build.PROP_ID);
	Project project = issue.getProject();
	Collection<ObjectId> fixCommits = getCommitInfoManager().getFixCommits(project, issue.getNumber());
	Collection<String> descendents = new HashSet<>();
	for (ObjectId each: getCommitInfoManager().getDescendants(project, fixCommits))
		descendents.add(each.name());
	BuildManager buildManager = OneDev.getInstance(BuildManager.class);
	Collection<Long> inBuildIds = buildManager.filterIds(project.getId(), descendents);
	return builder.and(
			builder.equal(root.get(Build.PROP_PROJECT), issue.getProject()),
			inManyValues(builder, attribute, inBuildIds, buildManager.getIdsByProject(project.getId())));
}
 
Example #25
Source File: ConditionTest.java    From activejpa with Apache License 2.0 5 votes vote down vote up
@BeforeMethod
public void setup() {
	builder = mock(CriteriaBuilder.class);
	path = mock(Path.class);
	when(path.getJavaType()).thenReturn(String.class);
	expression = mock(ParameterExpression.class);
	root = mock(Root.class);
	query = mock(Query.class);
	Parameter param = mock(Parameter.class);
	when(param.getParameterType()).thenReturn(String.class);
	when(query.getParameter(anyString())).thenReturn(param);
	
}
 
Example #26
Source File: NumericFieldCriteria.java    From onedev with MIT License 5 votes vote down vote up
@Override
protected Predicate getValuePredicate(Join<?, ?> field, CriteriaBuilder builder) {
	Path<Integer> attribute = field.get(IssueField.PROP_ORDINAL);
	if (operator == IssueQueryLexer.Is)
		return builder.equal(attribute, value);
	else if (operator == IssueQueryLexer.IsGreaterThan)
		return builder.greaterThan(attribute, value);
	else
		return builder.lessThan(attribute, value);
}
 
Example #27
Source File: HasFailedBuildsCriteria.java    From onedev with MIT License 5 votes vote down vote up
@Override
public Predicate getPredicate(Root<PullRequest> root, CriteriaBuilder builder) {
	Join<?, ?> join = root
			.join(PullRequest.PROP_VERIFICATIONS, JoinType.LEFT)
			.join(PullRequestVerification.PROP_BUILD, JoinType.INNER);
	Path<?> status = join.get(Build.STATUS);
	
	join.on(builder.or(
			builder.equal(status, Build.Status.FAILED), 
			builder.equal(status, Build.Status.CANCELLED), 
			builder.equal(status, Build.Status.TIMED_OUT)));
	return join.isNotNull();
}
 
Example #28
Source File: CommentCriteria.java    From onedev with MIT License 5 votes vote down vote up
@Override
public Predicate getPredicate(Root<PullRequest> root, CriteriaBuilder builder) {
	Join<?, ?> join = root.join(PullRequest.PROP_COMMENTS, JoinType.LEFT);
	Path<String> attribute = join.get(PullRequestComment.PROP_CONTENT);
	join.on(builder.like(builder.lower(attribute), "%" + value.toLowerCase() + "%"));
	return join.isNotNull();
}
 
Example #29
Source File: ApprovedByMeCriteria.java    From onedev with MIT License 5 votes vote down vote up
@Override
public Predicate getPredicate(Root<PullRequest> root, CriteriaBuilder builder) {
	if (User.get() != null) {
		Join<?, ?> join = root.join(PullRequest.PROP_REVIEWS, JoinType.LEFT);
		Path<?> userPath = EntityQuery.getPath(join, PullRequestReview.PROP_USER);
		Path<?> approvedPath = EntityQuery.getPath(join, PullRequestReview.PROP_RESULT + "." + ReviewResult.PROP_APPROVED);
		join.on(builder.and(
				builder.equal(userPath, User.get()), 
				builder.equal(approvedPath, true)));
		return join.isNotNull();
	} else {
		throw new OneException("Please login to perform this query");
	}
}
 
Example #30
Source File: WorkDataHelper.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
private List<Item> load() throws Exception {
	EntityManager em = emc.get(Item.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Item> cq = cb.createQuery(Item.class);
	Root<Item> root = cq.from(Item.class);
	Path<String> path = root.get(Item.bundle_FIELDNAME);
	Predicate p = cb.equal(path, this.job);
	p = cb.and(p, cb.equal(root.get(Item_.itemCategory), ItemCategory.pp));
	List<Item> list = em.createQuery(cq.where(p)).getResultList();
	return list;
}