Search in sources :

Example 51 with Filters

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

the class RestaurantIntegrationTest method shouldFilterByPropertyStartingWith.

/**
 * @see DATAGRAPH-904
 */
@Test
public void shouldFilterByPropertyStartingWith() {
    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.STARTING_WITH, "San Francisco");
    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 52 with Filters

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

the class MusicIntegrationTest method shouldSaveAndRetrieveArtistWithTwoRelationshipTypesToAlbums.

/**
 * @see DATAGRAPH-637
 */
@Test
public void shouldSaveAndRetrieveArtistWithTwoRelationshipTypesToAlbums() {
    Studio emi = new Studio("EMI Studios, London");
    Studio olympic = new Studio("Olympic Studios, London");
    Artist theBeatles = new Artist("The Beatles");
    Artist eric = new Artist("Eric Clapton");
    Album slowhand = new Album("Slowhand");
    Recording slowRecording = new Recording(slowhand, olympic, 1977);
    slowhand.setRecording(slowRecording);
    slowhand.setArtist(eric);
    session.save(slowhand);
    session.clear();
    Album theBeatlesAlbum = new Album("The Beatles");
    Recording pleaseRecording = new Recording(theBeatlesAlbum, emi, 1968);
    theBeatlesAlbum.setRecording(pleaseRecording);
    theBeatles.getAlbums().add(theBeatlesAlbum);
    theBeatlesAlbum.setArtist(theBeatles);
    theBeatlesAlbum.setGuestArtist(eric);
    session.save(theBeatlesAlbum);
    theBeatles = session.loadAll(Artist.class, new Filters().add(new Filter("name", ComparisonOperator.EQUALS, "The Beatles"))).iterator().next();
    assertThat(theBeatles.getName()).isEqualTo("The Beatles");
    assertThat(theBeatles.getAlbums()).hasSize(1);
    assertThat(theBeatles.getAlbums().iterator().next().getName()).isEqualTo("The Beatles");
    assertThat(theBeatles.getAlbums().iterator().next().getRecording().getStudio().getName()).isEqualTo("EMI Studios, London");
    assertThat(theBeatles.getAlbums().iterator().next().getGuestArtist()).isEqualTo(eric);
    // Eric has 2 albums now
    session.clear();
    Artist loadedEric = session.loadAll(Artist.class, new Filters().add(new Filter("name", ComparisonOperator.EQUALS, "Eric Clapton"))).iterator().next();
    assertThat(loadedEric).isNotNull();
    assertThat(loadedEric.getGuestAlbums().iterator().next().getName()).isEqualTo("The Beatles");
    assertThat(loadedEric.getAlbums().iterator().next().getName()).isEqualTo("Slowhand");
}
Also used : Artist(org.neo4j.ogm.domain.music.Artist) Filters(org.neo4j.ogm.cypher.Filters) Filter(org.neo4j.ogm.cypher.Filter) Album(org.neo4j.ogm.domain.music.Album) Recording(org.neo4j.ogm.domain.music.Recording) Studio(org.neo4j.ogm.domain.music.Studio) Test(org.junit.Test)

Example 53 with Filters

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

the class QueryCapabilityTest method deepNestedFiltersOnSameEntitiesButDifferentRelationsShouldWork.

// GH-851
@Test
public void deepNestedFiltersOnSameEntitiesButDifferentRelationsShouldWork() {
    Filters filters = new Filters();
    Filter filter = new Filter("code", ComparisonOperator.EQUALS, "LHR");
    filter.setOwnerEntityType(Flight.class);
    filter.setNestedPath(new Filter.NestedPathSegment("departure", Airport.class));
    filters.and(filter);
    filter = new Filter("code", ComparisonOperator.EQUALS, "LAX");
    filter.setOwnerEntityType(Flight.class);
    filter.setNestedPath(new Filter.NestedPathSegment("arrival", Airport.class));
    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) Airport(org.neo4j.ogm.domain.gh851.Airport) Test(org.junit.Test)

Example 54 with Filters

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

the class RelationshipEntityQuerySortingTest method setUp.

@Before
public void setUp() {
    sortOrder = new SortOrder();
    filters = new Filters();
}
Also used : Filters(org.neo4j.ogm.cypher.Filters) SortOrder(org.neo4j.ogm.cypher.query.SortOrder) Before(org.junit.Before)

Example 55 with Filters

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

the class CountStatementsTest method testCountEdgesWithTypeAndFilters.

@Test
public void testCountEdgesWithTypeAndFilters() throws Exception {
    CypherQuery query = statements.countEdges("INFLUENCE", new Filters().add(new Filter("score", ComparisonOperator.EQUALS, -12.2)));
    assertThat(query.getStatement()).isEqualTo("MATCH (n)-[r0:`INFLUENCE`]->(m) WHERE r0.`score` = $`score_0`  RETURN COUNT(r0)");
    assertThat(query.getParameters().toString()).isEqualTo("{score_0=-12.2}");
}
Also used : Filters(org.neo4j.ogm.cypher.Filters) Filter(org.neo4j.ogm.cypher.Filter) CypherQuery(org.neo4j.ogm.cypher.query.CypherQuery) 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