Java Code Examples for org.mongodb.morphia.query.Query#or()

The following examples show how to use org.mongodb.morphia.query.Query#or() . 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: DynamicBuildRepository.java    From DotCi with MIT License 6 votes vote down vote up
public <T extends DbBackedBuild> Iterable<T> getCurrentUserBuilds(final DbBackedProject project, final int i, final Result result) {
    Query<DbBackedBuild> query = getQuery(project)
        .limit(i)
        .order("-number");

    query.or(
        query.criteria("actions.causes.user").equal(Jenkins.getAuthentication().getName()),
        query.criteria("actions.causes.pusher").equal(Jenkins.getAuthentication().getName())
    );

    if (result != null) {
        query = query.filter("result", result.toString());
    }
    final List<DbBackedBuild> builds = query.asList();

    for (final DbBackedBuild build : builds) {
        associateProject(project, build);
    }

    return (Iterable<T>) builds;
}
 
Example 2
Source File: JobMetric.java    From DotCi with MIT License 5 votes vote down vote up
private Query<DynamicBuild> filterBranch(final Query<DynamicBuild> query) {
    final String branch = getBranch();
    if ("All".equals(branch)) {
        return query;
    }
    if ("Mine".equals(branch)) {
        query.or(
            query.criteria("actions.causes.user").equal(Jenkins.getAuthentication().getName()),
            query.criteria("actions.causes.pusher").equal(Jenkins.getAuthentication().getName())
        );
        return query;
    }

    return getDynamicBuildRepository().filterExpression(branch, query);
}
 
Example 3
Source File: DynamicBuildRepository.java    From DotCi with MIT License 5 votes vote down vote up
private Query<DynamicBuild> getDynamicBuildsForUser(final String user, final int numberOfBuilds) {
    final Query<DynamicBuild> query = getDatastore().createQuery(DynamicBuild.class)
        .limit(numberOfBuilds)
        .disableValidation()
        .order("-timestamp")
        .field("className").equal("com.groupon.jenkins.dynamic.build.DynamicBuild");

    query.or(
        query.criteria("actions.causes.user").equal(user),
        query.criteria("actions.causes.pusher").equal(user)
    );
    return query;
}
 
Example 4
Source File: MongoExperimentsStore.java    From alchemy with MIT License 4 votes vote down vote up
@Override
public Iterable<Experiment> find(Filter filter, Experiment.BuilderFactory factory) {

    final Query<ExperimentEntity> query = ds.find(ExperimentEntity.class);

    if (filter.getFilter() != null) {
        query.or(
            query.criteria("name").containsIgnoreCase(filter.getFilter()),
            query.criteria("description").containsIgnoreCase(filter.getFilter())
        );
    }

    final Ordering ordering = filter.getOrdering();
    if (ordering != null && !ordering.isEmpty()) {
        final StringBuilder orderingString = new StringBuilder();
        for (Entry<Field, Direction> entry : ordering.getFields().entrySet()) {
            final String field = ExperimentEntity.getFieldName(entry.getKey());

            if (orderingString.length() > 0) {
                orderingString.append(',');
            }

            if (entry.getValue() == Direction.DESCENDING) {
                orderingString.append('-');
            }

            orderingString.append(field);
        }

        query.order(orderingString.toString());
    }

    if (filter.getOffset() != null) {
        query.offset(filter.getOffset());
    }

    if (filter.getLimit() != null) {
        query.limit(filter.getLimit());
    }

    return new ExperimentIterable(query.iterator(), factory);
}