Search in sources :

Example 11 with SortOrder

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

the class CineastsRelationshipEntityTest method testFilterOnRelatedNode.

@Test
public void testFilterOnRelatedNode() throws Exception {
    User frantisek = new User();
    frantisek.setName("Frantisek");
    frantisek.setLogin("frantisek");
    User michal = new User();
    michal.setName("Michal");
    michal.setLogin("michal");
    User ottoH = new User();
    ottoH.setName("Otto");
    ottoH.setLogin("otto");
    User ottoB = new User();
    ottoB.setName("Otto von Bismarc");
    ottoB.setLogin("ottob");
    frantisek.addFriends(ottoH, ottoB);
    session.save(frantisek);
    michal.addFriends(ottoH, ottoB);
    session.save(michal);
    // name contains ' '
    Filter filter = new Filter("name", ComparisonOperator.CONTAINING, "Otto");
    filter.setNestedPropertyName("friends");
    filter.setNestedPropertyType(User.class);
    SortOrder sortOrder = new SortOrder();
    sortOrder.add("name");
    Collection<User> users = session.loadAll(User.class, filter, sortOrder, new Pagination(0, 2));
    assertThat(users).hasSize(2);
}
Also used : Pagination(org.neo4j.ogm.cypher.query.Pagination) User(org.neo4j.ogm.domain.cineasts.annotated.User) Filter(org.neo4j.ogm.cypher.Filter) SortOrder(org.neo4j.ogm.cypher.query.SortOrder) Test(org.junit.Test)

Example 12 with SortOrder

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

the class SatelliteIntegrationTest method shouldReturnProgramsSortedByRefDesc.

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

Example 13 with SortOrder

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

the class SatelliteIntegrationTest method shouldLoadActiveSatellitesByPropertySorted.

@Test
public void shouldLoadActiveSatellitesByPropertySorted() {
    Collection<Satellite> satellites = session.loadAll(Satellite.class, new Filter("manned", ComparisonOperator.EQUALS, "Y"), 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 : Filter(org.neo4j.ogm.cypher.Filter) Satellite(org.neo4j.ogm.domain.satellites.Satellite) SortOrder(org.neo4j.ogm.cypher.query.SortOrder) Test(org.junit.Test)

Example 14 with SortOrder

use of org.neo4j.ogm.cypher.query.SortOrder 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 15 with SortOrder

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

the class RelationshipEntityQuerySortingTest method testDefaultMultipleSortOrders.

@Test
public void testDefaultMultipleSortOrders() {
    String cypher = "MATCH ()-[r0:`ORBITS`]-()  WITH DISTINCT(r0) as r0,startnode(r0) AS n, " + "endnode(r0) AS m ORDER BY r0.distance,r0.aphelion " + "MATCH p1 = (n)-[*0..3]-() WITH r0, COLLECT(DISTINCT p1) AS startPaths, m " + "MATCH p2 = (m)-[*0..3]-() WITH r0, startPaths, COLLECT(DISTINCT p2) AS endPaths " + "WITH r0,startPaths + endPaths  AS paths UNWIND paths AS p RETURN DISTINCT p, ID(r0)";
    PagingAndSortingQuery orbitsQuery = query.findByType("ORBITS", 3);
    check(cypher, orbitsQuery.setSortOrder(sortOrder.add("distance", "aphelion")).getStatement());
    check(cypher, orbitsQuery.setSortOrder(new SortOrder("distance", "aphelion")).getStatement());
    check(cypher, orbitsQuery.setSortOrder(new SortOrder().asc("distance", "aphelion")).getStatement());
}
Also used : SortOrder(org.neo4j.ogm.cypher.query.SortOrder) PagingAndSortingQuery(org.neo4j.ogm.cypher.query.PagingAndSortingQuery) Test(org.junit.Test)

Aggregations

SortOrder (org.neo4j.ogm.cypher.query.SortOrder)19 Test (org.junit.Test)13 Filters (org.neo4j.ogm.cypher.Filters)4 Pagination (org.neo4j.ogm.cypher.query.Pagination)4 PagingAndSortingQuery (org.neo4j.ogm.cypher.query.PagingAndSortingQuery)3 Before (org.junit.Before)2 Filter (org.neo4j.ogm.cypher.Filter)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