Search in sources :

Example 6 with Filters

use of org.neo4j.ogm.cypher.Filters in project neo4j-ogm by neo4j.

the class RestaurantIntegrationTest method shouldProvideUniqueParameterNamesForFilters.

/**
 * @see issue #137
 */
@Test
public void shouldProvideUniqueParameterNamesForFilters() {
    Restaurant restaurant = new Restaurant();
    restaurant.setName("La Cocina De Flaming Lips");
    session.save(restaurant);
    Restaurant another = new Restaurant();
    another.setName("Antica Pesa");
    session.save(another);
    Filters filters = new Filters();
    Filter firstFilter = new Filter("name", ComparisonOperator.EQUALS, "Foobar");
    firstFilter.setBooleanOperator(BooleanOperator.OR);
    filters.add(firstFilter);
    Filter secondFilter = new Filter("name", ComparisonOperator.EQUALS, "Antica Pesa");
    secondFilter.setBooleanOperator(BooleanOperator.OR);
    filters.add(secondFilter);
    Collection<Restaurant> results = session.loadAll(Restaurant.class, filters);
    assertThat(results.size() >= 1).isTrue();
}
Also used : Restaurant(org.neo4j.ogm.domain.restaurant.Restaurant) Filters(org.neo4j.ogm.cypher.Filters) Filter(org.neo4j.ogm.cypher.Filter) Test(org.junit.Test)

Example 7 with Filters

use of org.neo4j.ogm.cypher.Filters in project neo4j-ogm by neo4j.

the class RestaurantIntegrationTest method shouldFilterByCollectionContaining.

@Test
public void shouldFilterByCollectionContaining() {
    Restaurant sfo = new Restaurant("San Francisco International Airport (SFO)", 72.4);
    sfo.getSpecialities().add("burger");
    sfo.getSpecialities().add("pizza");
    session.save(sfo);
    Restaurant kuroda = new Restaurant("Kuroda", 80.5);
    kuroda.getSpecialities().add("sushi");
    session.save(kuroda);
    Filter f1 = new Filter("specialities", new ContainsAnyComparison(Arrays.asList("burger")));
    Collection<Restaurant> burgers = session.loadAll(Restaurant.class, new Filters(f1));
    assertThat(burgers).hasSize(1);
    assertThat(burgers.iterator().next().getName()).isEqualTo("San Francisco International Airport (SFO)");
    Filter f2 = new Filter("specialities", new ContainsAnyComparison(Arrays.asList("burger", "sushi")));
    Collection<Restaurant> all = session.loadAll(Restaurant.class, new Filters(f2));
    assertThat(all).hasSize(2);
    Filter f3 = new Filter("specialities", new ContainsAnyComparison(Arrays.asList("sushi", "other")));
    Collection<Restaurant> sushi = session.loadAll(Restaurant.class, new Filters(f3));
    assertThat(sushi).hasSize(1);
}
Also used : Restaurant(org.neo4j.ogm.domain.restaurant.Restaurant) Filters(org.neo4j.ogm.cypher.Filters) Filter(org.neo4j.ogm.cypher.Filter) ContainsAnyComparison(org.neo4j.ogm.cypher.function.ContainsAnyComparison) Test(org.junit.Test)

Example 8 with Filters

use of org.neo4j.ogm.cypher.Filters in project neo4j-ogm by neo4j.

the class RestaurantIntegrationTest method shouldFilterByPropertyExists.

/**
 * @see DATAGRAPH-904
 */
@Test
public void shouldFilterByPropertyExists() {
    Restaurant sfo = new Restaurant("San Francisco International Airport (SFO)", 72.4);
    sfo.setLaunchDate(new Date(1000));
    session.save(sfo);
    Restaurant kuroda = new Restaurant("Kuroda", 80.5);
    kuroda.setLaunchDate(new Date(2000));
    session.save(kuroda);
    Filter exists = new Filter("name", ComparisonOperator.EXISTS);
    Collection<Restaurant> results = session.loadAll(Restaurant.class, new Filters().add(exists));
    assertThat(results).isNotNull();
    assertThat(results).hasSize(2);
    Filter notExists = new Filter("name", ComparisonOperator.EXISTS);
    notExists.setNegated(true);
    results = session.loadAll(Restaurant.class, new Filters().add(notExists));
    assertThat(results).isNotNull();
    assertThat(results).isEmpty();
}
Also used : Restaurant(org.neo4j.ogm.domain.restaurant.Restaurant) Filters(org.neo4j.ogm.cypher.Filters) Filter(org.neo4j.ogm.cypher.Filter) Date(java.util.Date) Test(org.junit.Test)

Example 9 with Filters

use of org.neo4j.ogm.cypher.Filters in project neo4j-ogm by neo4j.

the class CineastsIntegrationTest method nestedFilteringCanBeTheOneAndOnlyOredFilter.

@Test
public void nestedFilteringCanBeTheOneAndOnlyOredFilter() {
    Filter filterB = new Filter("name", ComparisonOperator.EQUALS, "Catty");
    filterB.setNestedPath(new Filter.NestedPathSegment("ratings", Rating.class), new Filter.NestedPathSegment("user", User.class), new Filter.NestedPathSegment("pets", Pet.class));
    filterB.setBooleanOperator(BooleanOperator.OR);
    Filters filters = new Filters(filterB);
    Collection<Movie> films = session.loadAll(Movie.class, filters);
    assertThat(films).hasSize(2);
}
Also used : Movie(org.neo4j.ogm.domain.cineasts.annotated.Movie) Filters(org.neo4j.ogm.cypher.Filters) User(org.neo4j.ogm.domain.cineasts.annotated.User) Filter(org.neo4j.ogm.cypher.Filter) Rating(org.neo4j.ogm.domain.cineasts.annotated.Rating) Pet(org.neo4j.ogm.domain.cineasts.annotated.Pet) Test(org.junit.Test)

Example 10 with Filters

use of org.neo4j.ogm.cypher.Filters in project neo4j-ogm by neo4j.

the class NodeQueryStatementsTest method testFindByDifferentNestedPropertiesOred.

// DATAGRAPH-662
@Test(expected = UnsupportedOperationException.class)
public void testFindByDifferentNestedPropertiesOred() {
    Filter planetParam = collidesWithEarthFilter();
    Filter moonParam = orbitsMoonFilter();
    moonParam.setBooleanOperator(BooleanOperator.OR);
    queryStatements.findByType("Asteroid", new Filters().add(planetParam).add(moonParam), 1).getStatement();
}
Also used : Filters(org.neo4j.ogm.cypher.Filters) Filter(org.neo4j.ogm.cypher.Filter) Test(org.junit.Test)

Aggregations

Filters (org.neo4j.ogm.cypher.Filters)82 Filter (org.neo4j.ogm.cypher.Filter)78 Test (org.junit.Test)77 Restaurant (org.neo4j.ogm.domain.restaurant.Restaurant)10 Date (java.util.Date)6 CypherQuery (org.neo4j.ogm.cypher.query.CypherQuery)6 SortOrder (org.neo4j.ogm.cypher.query.SortOrder)4 Rating (org.neo4j.ogm.domain.cineasts.annotated.Rating)3 User (org.neo4j.ogm.domain.cineasts.annotated.User)3 Before (org.junit.Before)2 Pagination (org.neo4j.ogm.cypher.query.Pagination)2 Movie (org.neo4j.ogm.domain.cineasts.annotated.Movie)2 Pet (org.neo4j.ogm.domain.cineasts.annotated.Pet)2 Flight (org.neo4j.ogm.domain.gh851.Flight)2 Map (java.util.Map)1 UnaryOperator (java.util.function.UnaryOperator)1 PropertyValueTransformer (org.neo4j.ogm.cypher.PropertyValueTransformer)1 ContainsAnyComparison (org.neo4j.ogm.cypher.function.ContainsAnyComparison)1 DistanceComparison (org.neo4j.ogm.cypher.function.DistanceComparison)1 DistanceFromPoint (org.neo4j.ogm.cypher.function.DistanceFromPoint)1