private Future executeInThread( final String query ) { return executorService.submit( () -> db.execute( query ).resultAsString() ); } }
private Future executeInThread( final String query ) { return executorService.submit( () -> db.execute( query ).resultAsString() ); } }
@Override public String listTransactions() { String res; try ( Transaction tx = graphDatabaseAPI.beginTx() ) { res = graphDatabaseAPI.execute( "CALL dbms.listTransactions()" ).resultAsString(); tx.success(); } catch ( QueryExecutionException e ) { res = "dbms.listTransactions() is not available"; } return res; }
private void executeInThread( final String query, Map<String,Object> params ) { executorService.execute( () -> { try { db.execute( query, params ).resultAsString(); } catch ( Exception e ) { hasFailed.set( true ); } } ); } }
@Override public Pair<String, String> evaluate( String script ) { if ( StringUtils.EMPTY.equals( script.trim() ) ) { return Pair.of( StringUtils.EMPTY, null ); } String resultString; try { TransactionalContext tc = cypherExecutor.createTransactionContext( script, emptyMap(), request ); ExecutionEngine engine = cypherExecutor.getExecutionEngine(); Result result = engine.executeQuery( script, emptyMap(), tc ); resultString = result.resultAsString(); } catch ( SyntaxException error ) { resultString = error.getMessage(); } catch ( Exception exception ) { log.error( "Unknown error executing cypher query", exception ); resultString = "Error: " + exception.getClass().getSimpleName() + " - " + exception.getMessage(); } return Pair.of( resultString, null ); } }
@Test public void eagerResultToString() { Result result = database.execute( "MATCH (n) RETURN n.c, n.d" ); assertEquals( 1, testCursorContext.getAdditionalAttempts() ); String resultString = result.resultAsString(); assertTrue( resultString.contains( "n.c, n.d" ) ); assertTrue( resultString.contains( "d, a" ) ); assertTrue( resultString.contains( "y, k" ) ); }
private static void addNode( GraphDatabaseService db ) { if ( USE_CYPHER ) { Result result = db.execute( "create (:Person {name: 'Sneaky Steve'})" ); System.out.println( result.resultAsString() ); } else { try ( Transaction tx = db.beginTx() ) { db.createNode( label( "Person" ) ).setProperty( "name", "Sneaky Steve" ); tx.success(); } } }
@Test public void eagerResultWriteAsStringToStream() { Result result = database.execute( "MATCH (n) RETURN n.c" ); assertEquals( 1, testCursorContext.getAdditionalAttempts() ); assertEquals( result.resultAsString(), printToStream( result ) ); }
@Test public void shouldGiveCorrectPositionWhetherFromCacheOrNot() { // Given String cachedQuery = "MATCH (a:L1) RETURN a"; String nonCachedQuery = "MATCH (a:L2) RETURN a"; //make sure we cache the query GraphDatabaseAPI db = db(); int limit = db.getDependencyResolver().resolveDependency( Config.class ) .get( GraphDatabaseSettings.cypher_expression_recompilation_limit ); for ( int i = 0; i < limit + 1; i++ ) { db.execute( cachedQuery ).resultAsString(); } // When Notification cachedNotification = Iterables.asList( db.execute( "EXPLAIN " + cachedQuery ).getNotifications() ).get( 0 ); Notification nonCachedNotication = Iterables.asList( db.execute( "EXPLAIN " + nonCachedQuery ).getNotifications() ).get( 0 ); // Then assertThat( cachedNotification.getPosition(), equalTo( new InputPosition( 17, 1, 18 ) ) ); assertThat( nonCachedNotication.getPosition(), equalTo( new InputPosition( 17, 1, 18 ) ) ); } }
@Test @Ignore public void overrideSingleCallStatement() throws Exception { db.execute("call apoc.custom.asProcedure('answer','RETURN 42 as answer')"); TestUtil.testCall(db, "call custom.answer() yield row return row", (row) -> assertEquals(42L, ((Map)row.get("row")).get("answer"))); String clearCaches = db.execute("call dbms.clearQueryCaches()").resultAsString(); System.out.println(clearCaches); db.execute("call apoc.custom.asProcedure('answer','RETURN 43 as answer')"); TestUtil.testCall(db, "call custom.answer() yield row return row", (row) -> assertEquals(43L, ((Map)row.get("row")).get("answer"))); } @Test
@Test public void testFilterIntoCollection() { testResult(db, "call apoc.load.xml('file:src/test/resources/xml/books.xml') yield value as catalog\n" + " UNWIND catalog._children as book\n" + " RETURN book.id, [attr IN book._children WHERE attr._type IN ['author','title'] | [attr._type, attr._text]] as pairs" , result -> { assertEquals("+----------------------------------------------------------------------------------------------------------------+\n" + "| book.id | pairs |\n" + "+----------------------------------------------------------------------------------------------------------------+\n" + "| \"bk101\" | [[\"author\",\"Gambardella, Matthew\"],[\"author\",\"Arciniegas, Fabio\"],[\"title\",\"XML Developer's Guide\"]] |\n" + "| \"bk102\" | [[\"author\",\"Ralls, Kim\"],[\"title\",\"Midnight Rain\"]] |\n" + "| \"bk103\" | [[\"author\",\"Corets, Eva\"],[\"title\",\"Maeve Ascendant\"]] |\n" + "| \"bk104\" | [[\"author\",\"Corets, Eva\"],[\"title\",\"Oberon's Legacy\"]] |\n" + "| \"bk105\" | [[\"author\",\"Corets, Eva\"],[\"title\",\"The Sundered Grail\"]] |\n" + "| \"bk106\" | [[\"author\",\"Randall, Cynthia\"],[\"title\",\"Lover Birds\"]] |\n" + "| \"bk107\" | [[\"author\",\"Thurman, Paula\"],[\"title\",\"Splish Splash\"]] |\n" + "| \"bk108\" | [[\"author\",\"Knorr, Stefan\"],[\"title\",\"Creepy Crawlies\"]] |\n" + "| \"bk109\" | [[\"author\",\"Kress, Peter\"],[\"title\",\"Paradox Lost\"]] |\n" + "| \"bk110\" | [[\"author\",\"O'Brien, Tim\"],[\"title\",\"Microsoft .NET: The Programming Bible\"]] |\n" + "| \"bk111\" | [[\"author\",\"O'Brien, Tim\"],[\"title\",\"MSXML3: A Comprehensive Guide\"]] |\n" + "| \"bk112\" | [[\"author\",\"Galos, Mike\"],[\"title\",\"Visual Studio 7: A Comprehensive Guide\"]] |\n" + "+----------------------------------------------------------------------------------------------------------------+\n" + "12 rows\n", result.resultAsString()); }); }
@Test public void testSubmitStatement() throws Exception { String callList = "CALL apoc.periodic.list()"; // force pre-caching the queryplan System.out.println("call list" + db.execute(callList).resultAsString()); assertFalse(db.execute(callList).hasNext()); testCall(db, "CALL apoc.periodic.submit('foo','create (:Foo)')", (row) -> { assertEquals("foo", row.get("name")); assertEquals(false, row.get("done")); assertEquals(false, row.get("cancelled")); assertEquals(0L, row.get("delay")); assertEquals(0L, row.get("rate")); }); long count = tryReadCount(50, "MATCH (:Foo) RETURN COUNT(*) AS count", 1L); assertThat(String.format("Expected %d, got %d ", 1L, count), count, equalTo(1L)); testCall(db, callList, (r) -> assertEquals(true, r.get("done"))); }
@Test public void testReturnCollectionElements() { testResult(db, "call apoc.load.xml('file:src/test/resources/xml/books.xml') yield value as catalog\n"+ "UNWIND catalog._children as book\n" + "WITH book.id as id, [attr IN book._children WHERE attr._type IN ['author','title'] | attr._text] as pairs\n" + "RETURN id, pairs[0] as author, pairs[1] as title" , result -> { assertEquals("+-----------------------------------------------------------------------------+\n" + "| id | author | title |\n" + "+-----------------------------------------------------------------------------+\n" + "| \"bk101\" | \"Gambardella, Matthew\" | \"Arciniegas, Fabio\" |\n" + "| \"bk102\" | \"Ralls, Kim\" | \"Midnight Rain\" |\n" + "| \"bk103\" | \"Corets, Eva\" | \"Maeve Ascendant\" |\n" + "| \"bk104\" | \"Corets, Eva\" | \"Oberon's Legacy\" |\n" + "| \"bk105\" | \"Corets, Eva\" | \"The Sundered Grail\" |\n" + "| \"bk106\" | \"Randall, Cynthia\" | \"Lover Birds\" |\n" + "| \"bk107\" | \"Thurman, Paula\" | \"Splish Splash\" |\n" + "| \"bk108\" | \"Knorr, Stefan\" | \"Creepy Crawlies\" |\n" + "| \"bk109\" | \"Kress, Peter\" | \"Paradox Lost\" |\n" + "| \"bk110\" | \"O'Brien, Tim\" | \"Microsoft .NET: The Programming Bible\" |\n" + "| \"bk111\" | \"O'Brien, Tim\" | \"MSXML3: A Comprehensive Guide\" |\n" + "| \"bk112\" | \"Galos, Mike\" | \"Visual Studio 7: A Comprehensive Guide\" |\n" + "+-----------------------------------------------------------------------------+\n" + "12 rows\n", result.resultAsString()); }); }
@Override public String listTransactions() { String res; try ( Transaction tx = graphDatabaseAPI.beginTx() ) { res = graphDatabaseAPI.execute( "CALL dbms.listTransactions()" ).resultAsString(); tx.success(); } catch ( QueryExecutionException e ) { res = "dbms.listTransactions() is not available"; } return res; }
return cypherUtil.execute(replacedStartCurie).resultAsString();
@Override public Pair<String, String> evaluate( String script ) { if ( StringUtils.EMPTY.equals( script.trim() ) ) { return Pair.of( StringUtils.EMPTY, null ); } String resultString; try { TransactionalContext tc = cypherExecutor.createTransactionContext( script, emptyMap(), request ); ExecutionEngine engine = cypherExecutor.getExecutionEngine(); Result result = engine.executeQuery( script, emptyMap(), tc ); resultString = result.resultAsString(); } catch ( SyntaxException error ) { resultString = error.getMessage(); } catch ( Exception exception ) { log.error( "Unknown error executing cypher query", exception ); resultString = "Error: " + exception.getClass().getSimpleName() + " - " + exception.getMessage(); } return Pair.of( resultString, null ); } }
@Test public void testColumnAreInTheRightOrder() throws Exception { createTenNodes(); String q = "match (one), (two), (three), (four), (five), (six), (seven), (eight), (nine), (ten) " + "where id(one) = 1 and id(two) = 2 and id(three) = 3 and id(four) = 4 and id(five) = 5 " + "and id(six) = 6 and id(seven) = 7 and id(eight) = 8 and id(nine) = 9 and id(ten) = 10 " + "return one, two, three, four, five, six, seven, eight, nine, ten"; Result result = db.execute( q ); assertThat( result.resultAsString(), matchesPattern( "one.*two.*three.*four.*five.*six.*seven.*eight.*nine.*ten" ) ); }
fw.append( "\nResulting in:\n\n" ); fw.append( AsciiDocGenerator.dumpToSeparateFileWithType( new File( DOCS_TARGET ), "intro.result", createQueryResultSnippet( graphdb.execute( query ).resultAsString() ) ) ); fw.append( "\nResulting in:\n\n" ); fw.append( AsciiDocGenerator.dumpToSeparateFileWithType( new File( DOCS_TARGET ), "intro.result", createQueryResultSnippet( graphdb.execute( query ).resultAsString() ) ) ); fw.close();
gen.get().addSnippet( "query1", createCypherSnippet( query ) ); String result = db.execute( query ) .resultAsString(); assertTrue( result.contains("File1") ); gen.get() gen.get().addSnippet( "query2", createCypherSnippet( query ) ); result = db.execute( query ) .resultAsString(); assertTrue( result.contains("File1") ); assertTrue( result.contains("User1") ); gen.get().addSnippet( "query3", createCypherSnippet( query ) ); result = db.execute( query ) .resultAsString(); assertTrue( result.contains("File1") ); assertTrue( result.contains("File2") );
resultString = db.execute( "match (n {name: 'my node'}) return n, n.name" ).resultAsString();