Search in sources :

Example 81 with Filter

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

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

Example 83 with Filter

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

the class NodeQueryBuilder method build.

public FilteredQuery build() {
    if (!built) {
        int i = 0;
        for (Filter filter : filters) {
            if (i != 0 && filter.getBooleanOperator().equals(BooleanOperator.NONE)) {
                throw new MissingOperatorException("BooleanOperator missing for filter with property name " + filter.getPropertyName() + ". Only the first filter may not specify the BooleanOperator.");
            }
            if (filter.isNested()) {
                appendNestedFilter(filter);
                hasRelationshipMatch = true;
            } else if (filter.isDeepNested()) {
                appendDeepNestedFilter(filter);
                hasRelationshipMatch = true;
            } else if (principalClause != null) {
                // If the filter is not nested, it belongs to the node we're returning
                principalClause().append(filter);
            }
            parameters.putAll(filter.parameters());
            i++;
        }
        built = true;
    }
    return new FilteredQuery(toCypher(), parameters);
}
Also used : MissingOperatorException(org.neo4j.ogm.exception.core.MissingOperatorException) Filter(org.neo4j.ogm.cypher.Filter)

Example 84 with Filter

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

the class BasicDriverTest method shouldLoadByProperty.

@Test
public void shouldLoadByProperty() {
    User user = new User("Bilbo Baggins");
    session.save(user);
    session.clear();
    User userByProperty = session.loadAll(User.class, new Filter("name", ComparisonOperator.EQUALS, "Bilbo Baggins")).iterator().next();
    assertThat(userByProperty).isNotNull();
}
Also used : User(org.neo4j.ogm.domain.social.User) Filter(org.neo4j.ogm.cypher.Filter) Test(org.junit.Test)

Example 85 with Filter

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

the class CypherContextTest method shouldDeregisterRelationshipEntities.

// GH-576
@Test
public void shouldDeregisterRelationshipEntities() {
    Collection<DataItem> dataItems;
    FormulaItem formulaItem;
    Filter filter = new Filter("nodeId", ComparisonOperator.EQUALS, "m1");
    dataItems = session.loadAll(DataItem.class, filter);
    assertThat(dataItems).hasSize(1);
    formulaItem = (FormulaItem) dataItems.iterator().next();
    assertThat(formulaItem.getVariables()).hasSize(3);
    Predicate<Variable> isVariableAWithDataItemM2 = v -> v.getVariable().equals("A") && v.getDataItem().getNodeId().equals("m2");
    formulaItem.getVariables().removeIf(isVariableAWithDataItemM2);
    assertThat(formulaItem.getVariables()).hasSize(2);
    session.save(formulaItem);
    dataItems = session.loadAll(DataItem.class, filter);
    assertThat(dataItems).hasSize(1);
    formulaItem = (FormulaItem) dataItems.iterator().next();
    assertThat(formulaItem.getVariables()).hasSize(2);
}
Also used : IntStream(java.util.stream.IntStream) Session(org.neo4j.ogm.session.Session) BeforeClass(org.junit.BeforeClass) Variable(org.neo4j.ogm.domain.gh576.Variable) Predicate(java.util.function.Predicate) Collection(java.util.Collection) ComparisonOperator(org.neo4j.ogm.cypher.ComparisonOperator) RunWith(org.junit.runner.RunWith) FormulaItem(org.neo4j.ogm.domain.gh576.FormulaItem) IOException(java.io.IOException) Test(org.junit.Test) Filter(org.neo4j.ogm.cypher.Filter) TestUtils(org.neo4j.ogm.testutil.TestUtils) DataItem(org.neo4j.ogm.domain.gh576.DataItem) Collectors(java.util.stream.Collectors) List(java.util.List) After(org.junit.After) Assertions(org.assertj.core.api.Assertions) SessionFactory(org.neo4j.ogm.session.SessionFactory) TestContainersTestBase(org.neo4j.ogm.testutil.TestContainersTestBase) Collections(java.util.Collections) Parameterized(org.junit.runners.Parameterized) Before(org.junit.Before) FormulaItem(org.neo4j.ogm.domain.gh576.FormulaItem) Variable(org.neo4j.ogm.domain.gh576.Variable) DataItem(org.neo4j.ogm.domain.gh576.DataItem) Filter(org.neo4j.ogm.cypher.Filter) 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