Search in sources :

Example 1 with SortOrder

use of org.neo4j.ogm.cypher.query.SortOrder in project neo4j-ogm by neo4j.

the class SatelliteIntegrationTest method shouldReturnSatellitesSortedByRefAsc.

@Test
public void shouldReturnSatellitesSortedByRefAsc() {
    Collection<Satellite> satellites = session.loadAll(Satellite.class, new SortOrder().add("ref"));
    Iterator<Satellite> iter = satellites.iterator();
    Satellite first = iter.next();
    while (iter.hasNext()) {
        Satellite next = iter.next();
        assertThat(first.getRef().compareTo(next.getRef()) < 0).isTrue();
        first = next;
    }
}
Also used : Satellite(org.neo4j.ogm.domain.satellites.Satellite) SortOrder(org.neo4j.ogm.cypher.query.SortOrder) Test(org.junit.Test)

Example 2 with SortOrder

use of org.neo4j.ogm.cypher.query.SortOrder in project neo4j-ogm by neo4j.

the class MusicIntegrationTest method shouldSortByDomainPropertyName.

/**
 * @see Issue 191
 */
@Test
public void shouldSortByDomainPropertyName() {
    Studio emi = new Studio("EMI Studios, London");
    Studio olympic = new Studio("Olympic Studios, London");
    session.save(emi);
    session.save(olympic);
    session.clear();
    SortOrder name = new SortOrder().add("name");
    Collection<Studio> studios1 = session.loadAll(Studio.class, name);
    Collection<Studio> studios2 = session.loadAll(Studio.class, name);
    assertThat(studios1.iterator().next().getName()).isEqualTo("EMI Studios, London");
    assertThat(studios2.iterator().next().getName()).isEqualTo("EMI Studios, London");
    studios1 = session.loadAll(Studio.class, new SortOrder().add(SortOrder.Direction.DESC, "name"));
    assertThat(studios1.iterator().next().getName()).isEqualTo("Olympic Studios, London");
}
Also used : SortOrder(org.neo4j.ogm.cypher.query.SortOrder) Studio(org.neo4j.ogm.domain.music.Studio) Test(org.junit.Test)

Example 3 with SortOrder

use of org.neo4j.ogm.cypher.query.SortOrder in project neo4j-ogm by neo4j.

the class CineastsRelationshipEntityTest method shouldSortRatings.

@Test
public void shouldSortRatings() {
    Movie movie = new Movie("Pulp Fiction", 1994);
    session.save(movie);
    User michal = new User();
    michal.setName("Michal");
    michal.setLogin("bachmania");
    Rating awesome = new Rating();
    awesome.setMovie(movie);
    awesome.setUser(michal);
    awesome.setStars(5);
    michal.setRatings(Collections.singleton(awesome));
    session.save(michal);
    // Add a rating from luanne for the same movie
    User luanne = new User();
    luanne.setName("luanne");
    luanne.setLogin("luanne");
    luanne.setPassword("luanne");
    Rating rating = new Rating();
    rating.setMovie(movie);
    rating.setUser(luanne);
    rating.setStars(3);
    luanne.setRatings(Collections.singleton(rating));
    session.save(luanne);
    session.clear();
    Collection<Rating> ratings = session.loadAll(Rating.class, new SortOrder().add(SortOrder.Direction.ASC, "stars"));
    assertThat(ratings).isNotNull();
    int i = 0;
    for (Rating r : ratings) {
        if (i++ == 0) {
            assertThat(r.getStars()).isEqualTo(3);
        } else {
            assertThat(r.getStars()).isEqualTo(5);
        }
    }
}
Also used : Movie(org.neo4j.ogm.domain.cineasts.annotated.Movie) User(org.neo4j.ogm.domain.cineasts.annotated.User) Rating(org.neo4j.ogm.domain.cineasts.annotated.Rating) SortOrder(org.neo4j.ogm.cypher.query.SortOrder) Test(org.junit.Test)

Example 4 with SortOrder

use of org.neo4j.ogm.cypher.query.SortOrder in project neo4j-ogm by neo4j.

the class LoadCapabilityTest method loadAllShouldRespectEntityType.

// DATAGRAPH-707
@Test
public void loadAllShouldRespectEntityType() {
    Collection<Artist> artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId));
    assertThat(artists).hasSize(1);
    assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
    Collection<Album> albums = session.loadAll(Album.class, Collections.singletonList(beatlesId));
    assertThat(albums).isEmpty();
    artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), 0);
    assertThat(artists).hasSize(1);
    assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
    albums = session.loadAll(Album.class, Collections.singletonList(beatlesId), 0);
    assertThat(albums).isEmpty();
    artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), new SortOrder().add("name"));
    assertThat(artists).hasSize(1);
    assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
    albums = session.loadAll(Album.class, Collections.singletonList(beatlesId), new SortOrder().add("name"));
    assertThat(albums).isEmpty();
    artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), new SortOrder().add("name"), 0);
    assertThat(artists).hasSize(1);
    assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
    albums = session.loadAll(Album.class, Collections.singletonList(beatlesId), new SortOrder().add("name"), 0);
    assertThat(albums).isEmpty();
    artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), new Pagination(0, 5));
    assertThat(artists).hasSize(1);
    assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
    albums = session.loadAll(Album.class, Collections.singletonList(beatlesId), new Pagination(0, 5));
    assertThat(albums).isEmpty();
    artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), new Pagination(0, 5), 0);
    assertThat(artists).hasSize(1);
    assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
    albums = session.loadAll(Album.class, Collections.singletonList(beatlesId), new Pagination(0, 5), 0);
    assertThat(albums).isEmpty();
    artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), new SortOrder().add("name"), new Pagination(0, 5));
    assertThat(artists).hasSize(1);
    assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
    albums = session.loadAll(Album.class, Collections.singletonList(beatlesId), new SortOrder().add("name"), new Pagination(0, 5));
    assertThat(albums).isEmpty();
    artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), new SortOrder().add("name"), new Pagination(0, 5), 0);
    assertThat(artists).hasSize(1);
    assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
    Artist bonJovi = new Artist("Bon Jovi");
    session.save(bonJovi);
    artists = session.loadAll(Artist.class, Arrays.asList(beatlesId, pleaseId, bonJovi.getId()), new SortOrder().add("name"), new Pagination(0, 5), 0);
    assertThat(artists).hasSize(2);
    artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), new SortOrder().add("name"), new Pagination(0, 5), 0);
    assertThat(artists).hasSize(1);
    assertThat(artists.iterator().next().getName()).isEqualTo(// make sure Bon Jovi isn't returned as well
    "The Beatles");
    albums = session.loadAll(Album.class, Collections.singletonList(beatlesId), new SortOrder().add("name"), new Pagination(0, 5), 0);
    assertThat(albums).isEmpty();
}
Also used : Artist(org.neo4j.ogm.domain.music.Artist) Pagination(org.neo4j.ogm.cypher.query.Pagination) Album(org.neo4j.ogm.domain.music.Album) SortOrder(org.neo4j.ogm.cypher.query.SortOrder) Test(org.junit.Test)

Example 5 with SortOrder

use of org.neo4j.ogm.cypher.query.SortOrder in project neo4j-ogm by neo4j.

the class LoadCapabilityTest method shouldKeepOrder.

// GH-368
@Test
public void shouldKeepOrder() {
    User anna = new User("noone@nowhere.com", "Anna", "Doe");
    User bob = new User("noone@nowhere.com", "Bob", "Doe");
    User charlie = new User("noone@nowhere.com", "Charlie", "Doe");
    session.save(charlie);
    session.save(anna);
    session.save(bob);
    anna.setFriends(Collections.singleton(charlie));
    session.save(anna);
    Collection<User> allUsers = session.loadAll(User.class, new SortOrder().add("lastName").add("firstName"), 1);
    assertThat(allUsers).extracting(User::getFirstName).containsExactly("Anna", "Bob", "Charlie");
}
Also used : User(org.neo4j.ogm.domain.gh368.User) SortOrder(org.neo4j.ogm.cypher.query.SortOrder) Test(org.junit.Test)

Aggregations

SortOrder (org.neo4j.ogm.cypher.query.SortOrder)16 Test (org.junit.Test)13 PagingAndSortingQuery (org.neo4j.ogm.cypher.query.PagingAndSortingQuery)3 Before (org.junit.Before)2 Filter (org.neo4j.ogm.cypher.Filter)2 Filters (org.neo4j.ogm.cypher.Filters)2 Pagination (org.neo4j.ogm.cypher.query.Pagination)2 User (org.neo4j.ogm.domain.cineasts.annotated.User)2 Artist (org.neo4j.ogm.domain.music.Artist)2 Satellite (org.neo4j.ogm.domain.satellites.Satellite)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 GraphRowListModelMapper (org.neo4j.ogm.context.GraphRowListModelMapper)1 GraphRowModelMapper (org.neo4j.ogm.context.GraphRowModelMapper)1 DefaultGraphModelRequest (org.neo4j.ogm.cypher.query.DefaultGraphModelRequest)1 DefaultGraphRowListModelRequest (org.neo4j.ogm.cypher.query.DefaultGraphRowListModelRequest)1 Movie (org.neo4j.ogm.domain.cineasts.annotated.Movie)1 Rating (org.neo4j.ogm.domain.cineasts.annotated.Rating)1 User (org.neo4j.ogm.domain.gh368.User)1 Album (org.neo4j.ogm.domain.music.Album)1