@Override public Result execute( String query ) throws QueryExecutionException { return getGraphDatabaseAPI().execute( query ); }
@Override public Result execute( String query, long timeout, TimeUnit unit ) throws QueryExecutionException { return getGraphDatabaseAPI().execute( query, timeout, unit ); }
@Override public Result execute( String query, Map<String, Object> parameters ) throws QueryExecutionException { return getGraphDatabaseAPI().execute( query, parameters ); }
@Override public Result execute( String query, Map<String,Object> parameters, long timeout, TimeUnit unit ) throws QueryExecutionException { return getGraphDatabaseAPI().execute( query, parameters, timeout, unit ); }
@Test public void shouldNotNotifyOnDynamicPropertyLookupWithNoLabels() { Stream.of( "CYPHER 2.3", "CYPHER 3.1", "CYPHER 3.5" ).forEach( version -> { db().execute( "CREATE INDEX ON :Person(name)" ); db().execute( "Call db.awaitIndexes()" ); shouldNotNotifyInStream( version, "EXPLAIN MATCH (n) WHERE n['key-' + n.name] = 'value' RETURN n" ); } ); }
@Test public void shouldNotNotifyOnDynamicPropertyLookupWithSingleLabelAndNegativePredicate() { Stream.of( "CYPHER 2.3", "CYPHER 3.1", "CYPHER 3.5" ).forEach( version -> { db().execute( "CREATE INDEX ON :Person(name)" ); db().execute( "Call db.awaitIndexes()" ); shouldNotNotifyInStream( version, "EXPLAIN MATCH (n:Person) WHERE n['key-' + n.name] <> 'value' RETURN n" ); } ); }
@Test public void shouldWarnOnUnfulfillableIndexSeekUsingDynamicPropertyAndMultipleIndexedLabels() { Stream.of( "CYPHER 2.3", "CYPHER 3.1", "CYPHER 3.5" ).forEach( version -> { db().execute( "CREATE INDEX ON :Person(name)" ); db().execute( "CREATE INDEX ON :Jedi(weapon)" ); db().execute( "Call db.awaitIndexes()" ); assertNotifications( version + "EXPLAIN MATCH (n:Person:Jedi) WHERE n['key-' + n.name] = 'value' RETURN n", containsItem( dynamicPropertyWarning ) ); } ); }
@Test public void shouldWarnOnDynamicPropertyLookupWithBothStaticAndDynamicProperties() { Stream.of( "CYPHER 2.3", "CYPHER 3.1", "CYPHER 3.5" ).forEach( version -> { db().execute( "CREATE INDEX ON :Person(name)" ); db().execute( "Call db.awaitIndexes()" ); assertNotifications( version + "EXPLAIN MATCH (n:Person) WHERE n.name = 'Tobias' AND n['key-' + n.name] = 'value' RETURN n", containsItem( dynamicPropertyWarning )); } ); }
@Test public void shouldWarnOnUnfulfillableIndexSeekUsingDynamicPropertyAndMultipleLabels() { Stream.of( "CYPHER 3.5" ).forEach( version -> { db().execute( "CREATE INDEX ON :Person(name)" ); db().execute( "Call db.awaitIndexes()" ); assertNotifications( version + "EXPLAIN MATCH (n:Person:Foo) WHERE n['key-' + n.name] = 'value' RETURN n", containsItem( dynamicPropertyWarning ) ); } ); }
@Test public void shouldWarnOnMisspelledProperty() { db().execute("CREATE (n {prop : 42})"); Stream.of( "CYPHER 2.3", "CYPHER 3.1", "CYPHER 3.5" ).forEach( version -> { db().execute( "CREATE (n)-[r:R]->(m)"); assertNotifications(version + "EXPLAIN MATCH (n) WHERE n.propp = 43 RETURN n", containsItem( unknownPropertyKeyWarning ) ); shouldNotNotifyInStream( version, "EXPLAIN MATCH (n) WHERE n.prop = 43 RETURN n" ); }); }
private void createSimpleNodesIndex() { db.execute( format( NODE_CREATE, "nodes", array( LABEL.name() ), array( PROP ) ) ).close(); } }
@Test public void relationshipIndexesMustHaveRelationshipTypes() { db = createDatabase(); expectedException.expect( QueryExecutionException.class ); db.execute( format( RELATIONSHIP_CREATE, "relIndex", array(), array( PROP ) ) ); }
void shouldNotNotifyInStream( String version, String query ) { // when Result result = db().execute( version + query ); // then assertThat( Iterables.asList( result.getNotifications() ), empty() ); Map<String,Object> arguments = result.getExecutionPlanDescription().getArguments(); assertThat( arguments.get( "version" ), equalTo( version ) ); result.close(); }
@Test public void shouldGetErrorWhenUsingCreateUniqueWhenCypherVersionIs3_4() { // expect exception thrown.expect( QueryExecutionException.class ); thrown.expectMessage( "CREATE UNIQUE is no longer supported. You can achieve the same result using MERGE"); // when db().execute( "CYPHER 3.4 MATCH (b) WITH b LIMIT 1 CREATE UNIQUE (b)-[:REL]->()" ); }
@Test public void nodeIndexesMustHaveLabels() { db = createDatabase(); expectedException.expect( QueryExecutionException.class ); db.execute( format( NODE_CREATE, "nodeIndex", array(), array( PROP ) ) ).close(); }
void shouldNotifyInStream( String version, String query, InputPosition pos, NotificationCode code ) { //when Result result = db().execute( version + query ); //then NotificationCode.Notification notification = code.notification( pos ); assertThat( Iterables.asList( result.getNotifications() ), Matchers.hasItems( notification ) ); Map<String,Object> arguments = result.getExecutionPlanDescription().getArguments(); assertThat( arguments.get( "version" ), equalTo( version ) ); result.close(); }
@Test public void deprecatedRulePlanner() { // when Result result = db().execute( "EXPLAIN CYPHER planner=rule RETURN 1" ); // then assertThat( result.getNotifications(), containsItem( deprecatedRulePlanner ) ); result.close(); }
@Test public void deprecatedCompiledRuntime() { // when Result result = db().execute( "EXPLAIN CYPHER runtime=compiled RETURN 1" ); // then assertThat( result.getNotifications(), containsItem( deprecatedCompiledRuntime ) ); result.close(); }
@Test public void shouldNotifyWhenUsingCreateUniqueWhenCypherVersionIsDefault() { // when Result result = db().execute( "MATCH (b) WITH b LIMIT 1 CREATE UNIQUE (b)-[:REL]->()" ); // then assertThat( result.getNotifications(), containsItem( deprecatedCreateUnique ) ); result.close(); }
@Test public void shouldNotifyWhenUsingCreateUniqueWhenCypherVersionIs3_5() { // when Result result = db().execute( "CYPHER 3.5 MATCH (b) WITH b LIMIT 1 CREATE UNIQUE (b)-[:REL]->()" ); InputPosition position = new InputPosition( 36, 1, 37 ); // then assertThat( result.getNotifications(), containsItem( deprecatedCreateUnique ) ); result.close(); }