Search in sources :

Example 11 with Filter

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

the class RestaurantIntegrationTest method shouldQueryByDistanceUsingFilter.

@Test
public void shouldQueryByDistanceUsingFilter() {
    Restaurant restaurant = new Restaurant("San Francisco International Airport (SFO)", new Location(37.61649, -122.38681), 94128);
    session.save(restaurant);
    session.clear();
    Filter filter = new Filter(new DistanceComparison(new DistanceFromPoint(37.61649, -122.38681, 1000 * 1000.0)), ComparisonOperator.LESS_THAN);
    Collection<Restaurant> found = session.loadAll(Restaurant.class, filter);
    assertThat(found).isNotNull();
    assertThat(found.size() >= 1).isTrue();
}
Also used : Restaurant(org.neo4j.ogm.domain.restaurant.Restaurant) DistanceComparison(org.neo4j.ogm.cypher.function.DistanceComparison) DistanceFromPoint(org.neo4j.ogm.cypher.function.DistanceFromPoint) Filter(org.neo4j.ogm.cypher.Filter) Location(org.neo4j.ogm.domain.restaurant.Location) Test(org.junit.Test)

Example 12 with Filter

use of org.neo4j.ogm.cypher.Filter 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 13 with Filter

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

the class SocialIntegrationTest method shouldSaveIncomingKnownMortals.

/**
 * @see DATAGRAPH-594
 */
@Test
public void shouldSaveIncomingKnownMortals() {
    Mortal mortalA = new Mortal("A");
    Mortal mortalB = new Mortal("B");
    Mortal mortalC = new Mortal("C");
    Mortal mortalD = new Mortal("D");
    mortalA.getKnownBy().add(mortalB);
    mortalA.getKnownBy().add(mortalC);
    mortalD.getKnownBy().add(mortalA);
    session.save(mortalA);
    session.save(mortalB);
    session.save(mortalC);
    session.save(mortalD);
    session.clear();
    mortalA = session.loadAll(Mortal.class, new Filter("name", ComparisonOperator.EQUALS, "A")).iterator().next();
    assertThat(mortalA).isNotNull();
    assertThat(mortalA.getKnownBy()).hasSize(2);
    mortalB = session.loadAll(Mortal.class, new Filter("name", ComparisonOperator.EQUALS, "B")).iterator().next();
    assertThat(mortalB).isNotNull();
    assertThat(mortalB.getKnownBy()).isEmpty();
    mortalC = session.loadAll(Mortal.class, new Filter("name", ComparisonOperator.EQUALS, "C")).iterator().next();
    assertThat(mortalC).isNotNull();
    assertThat(mortalC.getKnownBy()).isEmpty();
    mortalD = session.loadAll(Mortal.class, new Filter("name", ComparisonOperator.EQUALS, "D")).iterator().next();
    assertThat(mortalD).isNotNull();
    assertThat(mortalD.getKnownBy()).hasSize(1);
    assertThat(mortalD.getKnownBy().iterator().next().getName()).isEqualTo("A");
}
Also used : Filter(org.neo4j.ogm.cypher.Filter) Mortal(org.neo4j.ogm.domain.social.Mortal) Test(org.junit.Test)

Example 14 with Filter

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

the class SocialIntegrationTest method shouldFetchOnlyPeopleILike.

/**
 * @see DATAGRAPH-594
 */
@Test
public void shouldFetchOnlyPeopleILike() {
    session.query("create (p1:Person {name:'A'}) create (p2:Person {name:'B'}) create (p3:Person {name:'C'})" + " create (p4:Person {name:'D'}) create (p1)-[:LIKES]->(p2) create (p1)-[:LIKES]->(p3) create (p4)-[:LIKES]->(p1)", Collections.EMPTY_MAP);
    Person personA = session.loadAll(Person.class, new Filter("name", ComparisonOperator.EQUALS, "A")).iterator().next();
    assertThat(personA).isNotNull();
    assertThat(personA.getPeopleILike()).hasSize(2);
    Person personD = session.loadAll(Person.class, new Filter("name", ComparisonOperator.EQUALS, "D")).iterator().next();
    assertThat(personD).isNotNull();
    assertThat(personD.getPeopleILike()).hasSize(1);
    assertThat(personD.getPeopleILike().get(0)).isEqualTo(personA);
}
Also used : Filter(org.neo4j.ogm.cypher.Filter) Person(org.neo4j.ogm.domain.social.Person) Test(org.junit.Test)

Example 15 with Filter

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

the class SocialIntegrationTest method shouldSaveUndirectedFriendsInBothDirections.

/**
 * @see DATAGRAPH-594
 */
@Test
public void shouldSaveUndirectedFriendsInBothDirections() {
    Person userA = new Person("A");
    Person userB = new Person("B");
    userA.getPeopleILike().add(userB);
    userB.getPeopleILike().add(userA);
    session.save(userA);
    session.clear();
    userA = session.loadAll(Person.class, new Filter("name", ComparisonOperator.EQUALS, "A")).iterator().next();
    assertThat(userA).isNotNull();
    assertThat(userA.getPeopleILike()).hasSize(1);
    session.clear();
    userB = session.loadAll(Person.class, new Filter("name", ComparisonOperator.EQUALS, "B")).iterator().next();
    assertThat(userB).isNotNull();
    assertThat(userB.getPeopleILike()).hasSize(1);
}
Also used : Filter(org.neo4j.ogm.cypher.Filter) Person(org.neo4j.ogm.domain.social.Person) Test(org.junit.Test)

Aggregations

Filter (org.neo4j.ogm.cypher.Filter)155 Test (org.junit.Test)146 Filters (org.neo4j.ogm.cypher.Filters)78 User (org.neo4j.ogm.domain.cineasts.annotated.User)19 Rating (org.neo4j.ogm.domain.cineasts.annotated.Rating)18 Movie (org.neo4j.ogm.domain.cineasts.annotated.Movie)17 Restaurant (org.neo4j.ogm.domain.restaurant.Restaurant)12 Date (java.util.Date)10 Session (org.neo4j.ogm.session.Session)10 DistanceFromNativePoint (org.neo4j.ogm.cypher.function.DistanceFromNativePoint)8 SomethingSpatial (org.neo4j.ogm.persistence.types.nativetypes.SomethingSpatial)8 HashSet (java.util.HashSet)7 CypherQuery (org.neo4j.ogm.cypher.query.CypherQuery)7 GroupMember (org.neo4j.ogm.domain.gh824.GroupMember)7 ArrayList (java.util.ArrayList)4 Actor (org.neo4j.ogm.domain.cineasts.annotated.Actor)4 User (org.neo4j.ogm.domain.gh824.User)4 UserGroup (org.neo4j.ogm.domain.gh824.UserGroup)4 Studio (org.neo4j.ogm.domain.music.Studio)4 Collections (java.util.Collections)2