Search in sources :

Example 41 with Filters

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

the class NodeQueryStatementsTest method testFindByNestedPropertiesOnTheSameEntityOredNotFollowingEachOtherDirectly.

// Would be something like findByMoonSomethingAndFindByPlanetXOrFindByPlanetY
@Test
public void testFindByNestedPropertiesOnTheSameEntityOredNotFollowingEachOtherDirectly() {
    Filter planetParam = collidesWithEarthFilter();
    Filter planetParam2 = collidesWithMarsFilter();
    planetParam2.setBooleanOperator(BooleanOperator.OR);
    Filter moonParam = orbitsMoonFilter();
    moonParam.setBooleanOperator(BooleanOperator.AND);
    assertThat(queryStatements.findByType("Asteroid", new Filters().add(planetParam).add(moonParam).add(planetParam2), 1).getStatement()).isEqualTo("MATCH (n:`Asteroid`) MATCH (m0:`Planet`) WHERE m0.`name` = $`collidesWith_name_0` OR m0.`name` = $`collidesWith_name_2` " + "MATCH (m1:`Moon`) WHERE m1.`name` = $`moon_name_1` MATCH (n)-[:`COLLIDES`]->(m0) " + "MATCH (n)<-[:`ORBITS`]-(m1) WITH DISTINCT n MATCH p=(n)-[*0..1]-(m) RETURN p, ID(n)");
}
Also used : Filters(org.neo4j.ogm.cypher.Filters) Filter(org.neo4j.ogm.cypher.Filter) Test(org.junit.Test)

Example 42 with Filters

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

the class NodeQueryStatementsTest method testFindByPropertyIsNull.

@Test
public void testFindByPropertyIsNull() {
    Filter isNull = new Filter("score", ComparisonOperator.IS_NULL, null);
    String statement = queryStatements.findByType("Restaurant", new Filters().add(isNull), 3).getStatement();
    assertThat(statement).isEqualTo("MATCH (n:`Restaurant`) WHERE n.`score` IS NULL WITH n MATCH p=(n)-[*0..3]-(m) RETURN p, ID(n)");
    Filter isNotNull = new Filter("score", ComparisonOperator.IS_NULL, null);
    isNotNull.setNegated(true);
    statement = queryStatements.findByType("Restaurant", new Filters().add(isNotNull), 3).getStatement();
    assertThat(statement).isEqualTo("MATCH (n:`Restaurant`) WHERE NOT(n.`score` IS NULL ) WITH n MATCH p=(n)-[*0..3]-(m) RETURN p, ID(n)");
}
Also used : Filters(org.neo4j.ogm.cypher.Filters) Filter(org.neo4j.ogm.cypher.Filter) Test(org.junit.Test)

Example 43 with Filters

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

the class NodeQueryStatementsTest method testFindByMultipleAndPropertiesGreaterThan.

// DATAGRAPH-629
@Test
public void testFindByMultipleAndPropertiesGreaterThan() {
    Filter nameParam = new Filter("name", ComparisonOperator.EQUALS, "AST-1");
    Filter diameterParam = new Filter("diameter", ComparisonOperator.GREATER_THAN, 60);
    diameterParam.setBooleanOperator(BooleanOperator.AND);
    assertThat(queryStatements.findByType("Asteroid", new Filters().add(nameParam).add(diameterParam), 2).getStatement()).isEqualTo("MATCH (n:`Asteroid`) WHERE n.`name` = $`name_0` AND n.`diameter` > $`diameter_1` WITH n MATCH p=(n)-[*0..2]-(m) RETURN p, ID(n)");
}
Also used : Filters(org.neo4j.ogm.cypher.Filters) Filter(org.neo4j.ogm.cypher.Filter) Test(org.junit.Test)

Example 44 with Filters

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

the class NodeQueryStatementsTest method testFindByMultipleAndPropertiesWithMissingBooleanOperator.

// GH-73
@Test(expected = MissingOperatorException.class)
public void testFindByMultipleAndPropertiesWithMissingBooleanOperator() {
    Filter nameParam = new Filter("name", ComparisonOperator.EQUALS, "AST-1");
    Filter diameterParam = new Filter("diameter", ComparisonOperator.LESS_THAN, 60);
    queryStatements.findByType("Asteroid", new Filters().add(nameParam).add(diameterParam), 2).getStatement();
}
Also used : Filters(org.neo4j.ogm.cypher.Filters) Filter(org.neo4j.ogm.cypher.Filter) Test(org.junit.Test)

Example 45 with Filters

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

the class NodeQueryStatementsTest method testFindByChainedOredProperties.

// DATAGRAPH-445
@Test
public void testFindByChainedOredProperties() {
    Filter planetParam = new Filter("name", ComparisonOperator.EQUALS, "Earth");
    Filter moonParam = new Filter("name", ComparisonOperator.EQUALS, "Moon");
    assertThat(queryStatements.findByType("Asteroid", new Filters().add(planetParam).or(moonParam), 1).getStatement()).isEqualTo("MATCH (n:`Asteroid`) WHERE n.`name` = $`name_0` " + "OR n.`name` = $`name_1` WITH n MATCH p=(n)-[*0..1]-(m) RETURN p, ID(n)");
}
Also used : Filters(org.neo4j.ogm.cypher.Filters) Filter(org.neo4j.ogm.cypher.Filter) 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