@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 ); } }
public static NodeValue[] nodes( long... ids ) { return Arrays.stream( ids ) .mapToObj( id -> nodeValue( id, stringArray( "L" ), emptyMap() ) ) .toArray( NodeValue[]::new ); }
@Test public void startTransactionWithCustomTimeout() { when( request.getHeader( HttpHeaderUtils.MAX_EXECUTION_TIME_HEADER ) ) .thenReturn( String.valueOf( CUSTOM_TRANSACTION_TIMEOUT ) ); CypherExecutor cypherExecutor = new CypherExecutor( database, logProvider ); cypherExecutor.start(); cypherExecutor.createTransactionContext( QUERY, VirtualValues.emptyMap(), request ); verify( databaseQueryService ).beginTransaction( KernelTransaction.Type.implicit, AUTH_DISABLED, CUSTOM_TRANSACTION_TIMEOUT, TimeUnit.MILLISECONDS ); logProvider.assertNoLoggingOccurred(); }
@Test public void startDefaultTransactionIfTimeoutIsNegative() { when( request.getHeader( HttpHeaderUtils.MAX_EXECUTION_TIME_HEADER ) ) .thenReturn( "-2" ); CypherExecutor cypherExecutor = new CypherExecutor( database, logProvider ); cypherExecutor.start(); cypherExecutor.createTransactionContext( QUERY, VirtualValues.emptyMap(), request ); verify( databaseQueryService ).beginTransaction( KernelTransaction.Type.implicit, AUTH_DISABLED ); logProvider.assertNoLoggingOccurred(); }
@Test public void startDefaultTransactionWhenHeaderHasIncorrectValue() { when( request.getHeader( HttpHeaderUtils.MAX_EXECUTION_TIME_HEADER ) ) .thenReturn( "not a number" ); CypherExecutor cypherExecutor = new CypherExecutor( database, logProvider ); cypherExecutor.start(); cypherExecutor.createTransactionContext( QUERY, VirtualValues.emptyMap(), request ); verify( databaseQueryService ).beginTransaction( KernelTransaction.Type.implicit, AUTH_DISABLED ); logProvider.assertContainsMessageContaining( "Fail to parse `max-execution-time` header with value: 'not a " + "number'. Should be a positive number." ); }
@Test void shouldAllowNoTransactionTimeout() throws Exception { assertNull( parseTransactionTimeout( emptyMap() ) ); }
public static RelationshipValue[] relationships( long... ids ) { return Arrays.stream( ids ) .mapToObj( id -> relationshipValue( id, node( 0L ), node( 1L ), stringValue( "T" ), emptyMap() ) ) .toArray( RelationshipValue[]::new ); } }
public static NodeValue node( long id, String... labels ) { TextValue[] labelValues = new TextValue[labels.length]; for ( int i = 0; i < labels.length; i++ ) { labelValues[i] = stringValue( labels[i] ); } return nodeValue( id, stringArray( labels ), emptyMap() ); }
@Test void shouldAllowNoTransactionMetadata() throws Exception { assertNull( parseTransactionMetadata( emptyMap() ) ); }
public static RelationshipValue rel( long id, long start, long end ) { return relationshipValue( id, node( start ), node( end ), stringValue( "T" ), emptyMap() ); }
@Test public void startDefaultTransaction() { CypherExecutor cypherExecutor = new CypherExecutor( database, logProvider ); cypherExecutor.start(); cypherExecutor.createTransactionContext( QUERY, VirtualValues.emptyMap(), request ); verify( databaseQueryService ).beginTransaction( KernelTransaction.Type.implicit, AUTH_DISABLED ); logProvider.assertNoLoggingOccurred(); }
private List<LockOperationRecord> traceQueryLocks( String query, LockOperationListener... listeners ) throws QueryExecutionKernelException { GraphDatabaseQueryService graph = databaseRule.resolveDependency( GraphDatabaseQueryService.class ); QueryExecutionEngine executionEngine = databaseRule.resolveDependency( QueryExecutionEngine.class ); try ( InternalTransaction tx = graph .beginTransaction( KernelTransaction.Type.implicit, LoginContext.AUTH_DISABLED ) ) { TransactionalContextWrapper context = new TransactionalContextWrapper( createTransactionContext( graph, tx, query ), listeners ); executionEngine.executeQuery( query, VirtualValues.emptyMap(), context ); return new ArrayList<>( context.recordingLocks.getLockOperationRecords() ); } }
private static Stream<AnyValue> parameters() NodeValue node1 = nodeValue( 1, stringArray(), emptyMap() ); NodeValue node2 = nodeValue( 2, stringArray(), emptyMap() ); NodeValue node3 = nodeValue( 3, stringArray(), emptyMap() ); RelationshipValue relationship1 = relationshipValue( 100, node1, node2, stringValue( "ONE" ), emptyMap() ); RelationshipValue relationship2 = relationshipValue( 200, node2, node2, stringValue( "TWO" ), emptyMap() ); return Stream.of( node1,
shouldWrite( VirtualValues.path( new NodeValue[]{nodeValue( 20L, stringArray( "L" ), emptyMap() ), nodeValue( 40L, stringArray( "L" ), emptyMap() )}, new RelationshipValue[]{ relationshipValue( 100L, nodeValue( 40L, stringArray( "L" ), emptyMap() ), nodeValue( 20L, stringArray( "L" ), emptyMap() ), stringValue( "T" ), emptyMap() )} ), writePath( new NodeValue[]{nodeValue( 20L, stringArray( "L" ), emptyMap() ), nodeValue( 40L, stringArray( "L" ), emptyMap() )}, new RelationshipValue[]{ relationshipValue( 100L, nodeValue( 40L, stringArray( "L" ), emptyMap() ), nodeValue( 20L, stringArray( "L" ), emptyMap() ), stringValue( "T" ), emptyMap() )} ) ), ), shouldWrite( relationshipValue( 1337L, nodeValue( 42L, stringArray( "L" ), emptyMap() ), nodeValue( 43L, stringArray( "L" ), emptyMap() ), stringValue( "T" ), map( new String[]{"foo"}, new AnyValue[]{stringValue( "foo" )} ) ),
@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 ); } }