Search in sources :

Example 1 with Filters

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

the class QueryCapabilityTest method nestedFiltersOnSameEntitiesButDifferentRelationsShouldWork.

// GH-851
@Test
public void nestedFiltersOnSameEntitiesButDifferentRelationsShouldWork() {
    Filters filters = new Filters();
    Filter filter = new Filter("code", ComparisonOperator.EQUALS, "LHR");
    filter.setOwnerEntityType(Flight.class);
    filter.setNestedPropertyType(Airport.class);
    filter.setNestedPropertyName("departure");
    filter.setRelationshipType("DEPARTS");
    filter.setRelationshipDirection(Relationship.OUTGOING);
    filters.and(filter);
    filter = new Filter("code", ComparisonOperator.EQUALS, "LAX");
    filter.setOwnerEntityType(Flight.class);
    filter.setNestedPropertyType(Airport.class);
    filter.setNestedPropertyName("arrival");
    filter.setRelationshipType("ARRIVES");
    filter.setRelationshipDirection(Relationship.OUTGOING);
    filters.and(filter);
    Collection<Flight> flights = session.loadAll(Flight.class, filters);
    assertThat(flights).hasSize(1).first().extracting(Flight::getName).isEqualTo("FL 001");
}
Also used : Filters(org.neo4j.ogm.cypher.Filters) Filter(org.neo4j.ogm.cypher.Filter) Flight(org.neo4j.ogm.domain.gh851.Flight) Test(org.junit.Test)

Example 2 with Filters

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

the class RestaurantIntegrationTest method shouldFilterByPropertyIn.

/**
 * @see DATAGRAPH-904
 */
@Test
public void shouldFilterByPropertyIn() {
    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 filter = new Filter("name", ComparisonOperator.IN, new String[] { "Kuroda", "Foo", "Bar" });
    Collection<Restaurant> results = session.loadAll(Restaurant.class, new Filters().add(filter));
    assertThat(results).isNotNull();
    assertThat(results).hasSize(1);
    assertThat(results.iterator().next().getName()).isEqualTo("Kuroda");
}
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 3 with Filters

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

the class RestaurantIntegrationTest method shouldFilterByPropertyWithConverter.

/**
 * @see DATAGRAPH-904
 */
@Test
public void shouldFilterByPropertyWithConverter() {
    Restaurant kuroda = new Restaurant("Kuroda", 72.4);
    kuroda.setLaunchDate(new Date(1000));
    session.save(kuroda);
    Restaurant cyma = new Restaurant("Cyma", 80.5);
    cyma.setLaunchDate(new Date(2000));
    session.save(cyma);
    Filter launchDateFilter = new Filter("launchDate", ComparisonOperator.LESS_THAN, new Date(1001));
    Collection<Restaurant> results = session.loadAll(Restaurant.class, new Filters().add(launchDateFilter));
    assertThat(results).isNotNull();
    assertThat(results).hasSize(1);
    assertThat(results.iterator().next().getName()).isEqualTo("Kuroda");
    Filter anotherFilter = new Filter("launchDate", ComparisonOperator.EQUALS, new Date(999));
    results = session.loadAll(Restaurant.class, new Filters().add(anotherFilter));
    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 4 with Filters

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

the class RestaurantIntegrationTest method shouldFilterByPropertyContaining.

/**
 * @see DATAGRAPH-904
 */
@Test
public void shouldFilterByPropertyContaining() {
    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 filter = new Filter("name", ComparisonOperator.CONTAINING, "International Airport");
    Collection<Restaurant> results = session.loadAll(Restaurant.class, new Filters().add(filter));
    assertThat(results).isNotNull();
    assertThat(results).hasSize(1);
    assertThat(results.iterator().next().getName()).isEqualTo("San Francisco International Airport (SFO)");
}
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 5 with Filters

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

the class RestaurantIntegrationTest method shouldFilterByPropertyEndingWith.

/**
 * @see DATAGRAPH-904
 */
@Test
public void shouldFilterByPropertyEndingWith() {
    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 filter = new Filter("name", ComparisonOperator.ENDING_WITH, "Airport (SFO)");
    Collection<Restaurant> results = session.loadAll(Restaurant.class, new Filters().add(filter));
    assertThat(results).isNotNull();
    assertThat(results).hasSize(1);
    assertThat(results.iterator().next().getName()).isEqualTo("San Francisco International Airport (SFO)");
}
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)

Aggregations

Filters (org.neo4j.ogm.cypher.Filters)79 Test (org.junit.Test)77 Filter (org.neo4j.ogm.cypher.Filter)77 Restaurant (org.neo4j.ogm.domain.restaurant.Restaurant)10 Date (java.util.Date)6 CypherQuery (org.neo4j.ogm.cypher.query.CypherQuery)6 Rating (org.neo4j.ogm.domain.cineasts.annotated.Rating)3 User (org.neo4j.ogm.domain.cineasts.annotated.User)3 Before (org.junit.Before)2 SortOrder (org.neo4j.ogm.cypher.query.SortOrder)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 FilterFunction (org.neo4j.ogm.cypher.function.FilterFunction)1