Search in sources :

Example 66 with Filter

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

the class RelationshipQueryStatementsTest method testFindByPropertiesWithDifferentComparisonOperatorsAnded.

// DATAGRAPH-632
@Test
public void testFindByPropertiesWithDifferentComparisonOperatorsAnded() {
    Filter distance = new Filter("distance", ComparisonOperator.LESS_THAN, 60.2);
    Filter time = new Filter("time", ComparisonOperator.EQUALS, 3600);
    time.setBooleanOperator(BooleanOperator.AND);
    assertThat(query.findByType("ORBITS", new Filters().add(distance, time), 4).getStatement()).isEqualTo("MATCH (n)-[r0:`ORBITS`]->(m) WHERE r0.`distance` < $`distance_0` AND r0.`time` = $`time_1`  " + "WITH DISTINCT(r0) as r0,startnode(r0) AS n, endnode(r0) AS m MATCH p1 = (n)-[*0..4]-() " + "WITH r0, COLLECT(DISTINCT p1) AS startPaths, m MATCH p2 = (m)-[*0..4]-() " + "WITH r0, startPaths, COLLECT(DISTINCT p2) AS endPaths " + "WITH r0,startPaths + endPaths  AS paths UNWIND paths AS p RETURN DISTINCT p, ID(r0)");
}
Also used : Filters(org.neo4j.ogm.cypher.Filters) Filter(org.neo4j.ogm.cypher.Filter) Test(org.junit.Test)

Example 67 with Filter

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

the class RelationshipQueryStatementsTest method testFindByNestedPropertyIncoming.

// DATAGRAPH-632
@Test
public void testFindByNestedPropertyIncoming() {
    Filter planetFilter = new Filter("name", ComparisonOperator.EQUALS, "Earth");
    planetFilter.setNestedPropertyName("world");
    planetFilter.setNestedEntityTypeLabel("Planet");
    planetFilter.setRelationshipType("ORBITS");
    planetFilter.setRelationshipDirection(Relationship.Direction.INCOMING);
    assertThat(query.findByType("ORBITS", new Filters().add(planetFilter), 4).getStatement()).isEqualTo("MATCH (m:`Planet`) WHERE m.`name` = $`world_name_0` MATCH (n)<-[r0:`ORBITS`]-(m)  " + "WITH DISTINCT(r0) as r0,startnode(r0) AS n, endnode(r0) AS m MATCH p1 = (n)-[*0..4]-() " + "WITH r0, COLLECT(DISTINCT p1) AS startPaths, m " + "MATCH p2 = (m)-[*0..4]-() WITH r0, startPaths, COLLECT(DISTINCT p2) AS endPaths " + "WITH r0,startPaths + endPaths  AS paths UNWIND paths AS p RETURN DISTINCT p, ID(r0)");
}
Also used : Filters(org.neo4j.ogm.cypher.Filters) Filter(org.neo4j.ogm.cypher.Filter) Test(org.junit.Test)

Example 68 with Filter

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

the class ConcurrentSessionTest method multipleThreadsResultsGetMixedUp.

@Test
public void multipleThreadsResultsGetMixedUp() throws Exception {
    World world1 = new World("world 1", 1);
    Session session = sessionFactory.openSession();
    session.save(world1, 0);
    World world2 = new World("world 2", 2);
    session.save(world2, 0);
    int iterations = 1000;
    ExecutorService service = Executors.newFixedThreadPool(2);
    final CountDownLatch countDownLatch = new CountDownLatch(iterations * 2);
    for (int i = 0; i < iterations; i++) {
        service.execute(() -> {
            Session session1 = sessionFactory.openSession();
            World world = session1.loadAll(World.class, new Filter("name", ComparisonOperator.EQUALS, "world 1")).iterator().next();
            if (!"world 1".equals(world.getName())) {
                failed = true;
            }
            countDownLatch.countDown();
        });
        service.execute(() -> {
            Session session2 = sessionFactory.openSession();
            World world = session2.loadAll(World.class, new Filter("name", ComparisonOperator.EQUALS, "world 2")).iterator().next();
            if (!"world 2".equals(world.getName())) {
                failed = true;
            }
            countDownLatch.countDown();
        });
    }
    countDownLatch.await();
    assertThat(failed).isFalse();
}
Also used : Filter(org.neo4j.ogm.cypher.Filter) ExecutorService(java.util.concurrent.ExecutorService) World(org.neo4j.ogm.domain.concurrency.World) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 69 with Filter

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

the class DistanceComparisonTestBase method filterForCartesianPoint3d.

@Test
public void filterForCartesianPoint3d() {
    Session session = sessionFactory.openSession();
    SomethingSpatial spatial = new SomethingSpatial();
    CartesianPoint3d point = new CartesianPoint3d(1, 2, 3);
    spatial.setCartesianPoint3d(point);
    session.save(spatial);
    DistanceFromNativePoint distanceFromNativePoint = new DistanceFromNativePoint(new CartesianPoint3d(2, 2, 3), 2);
    Filter filter = new Filter("cartesianPoint3d", distanceComparisonFor(distanceFromNativePoint));
    filter.setOwnerEntityType(SomethingSpatial.class);
    Collection<SomethingSpatial> somethingSpatials = session.loadAll(SomethingSpatial.class, filter);
    assertThat(somethingSpatials).hasSize(1);
}
Also used : CartesianPoint3d(org.neo4j.ogm.types.spatial.CartesianPoint3d) Filter(org.neo4j.ogm.cypher.Filter) SomethingSpatial(org.neo4j.ogm.persistence.types.nativetypes.SomethingSpatial) DistanceFromNativePoint(org.neo4j.ogm.cypher.function.DistanceFromNativePoint) Session(org.neo4j.ogm.session.Session) Test(org.junit.Test)

Example 70 with Filter

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

the class DistanceComparisonTestBase method filterForGeographicPoint3d.

@Test
public void filterForGeographicPoint3d() {
    Session session = sessionFactory.openSession();
    SomethingSpatial spatial = new SomethingSpatial();
    GeographicPoint3d centralStationLocation = new GeographicPoint3d(55.6093093, 13.0004377, -5);
    spatial.setGeographicPoint3d(centralStationLocation);
    session.save(spatial);
    GeographicPoint3d office = new GeographicPoint3d(55.611851, 12.9949028, 15);
    DistanceFromNativePoint distanceFromNativePoint = new DistanceFromNativePoint(office, 448.9591);
    Filter filter = new Filter("geographicPoint3d", distanceComparisonFor(distanceFromNativePoint));
    filter.setOwnerEntityType(SomethingSpatial.class);
    Collection<SomethingSpatial> somethingSpatials = session.loadAll(SomethingSpatial.class, filter);
    assertThat(somethingSpatials).hasSize(1);
}
Also used : Filter(org.neo4j.ogm.cypher.Filter) GeographicPoint3d(org.neo4j.ogm.types.spatial.GeographicPoint3d) SomethingSpatial(org.neo4j.ogm.persistence.types.nativetypes.SomethingSpatial) DistanceFromNativePoint(org.neo4j.ogm.cypher.function.DistanceFromNativePoint) Session(org.neo4j.ogm.session.Session) 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