@Override public void close() { statement.close(); }
@Override public void close() { statement.close(); }
@Override public void close() { if ( statement != null ) { statement.close(); statement = null; } }
@Test public void closeStatementOnClose() { KernelTransaction kernelTransaction = mock( KernelTransaction.class ); Statement statement = mock( Statement.class ); when( kernelTransaction.acquireStatement() ).thenReturn( statement ); //noinspection EmptyTryBlock try ( IndexProcedures ignored = new IndexProcedures( kernelTransaction, null ) ) { } verify( statement ).close(); } }
@Override public void cleanForReuse() { // close the old statement reference after the statement has been "upgraded" // to either a schema data or a schema statement, so that the locks are "handed over". statement.queryRegistration().unregisterExecutingQuery( executingQuery ); statement.close(); statement = txBridge.get(); statement.queryRegistration().registerExecutingQuery( executingQuery ); }
@Test public void shouldCloseStatementIfExceptionIsThrownDbPropertyKeys() { // Given RuntimeException runtimeException = new RuntimeException(); when( tokens.propertyKeyGetAllTokens() ).thenThrow( runtimeException ); // When try { call( "db.propertyKeys" ); fail( "Procedure call should have failed" ); } catch ( Exception e ) { assertThat( e.getCause(), is( runtimeException ) ); // expected } // Then verify( statement ).close(); }
@Test public void shouldCloseStatementIfExceptionIsThrownDbLabels() { // Given RuntimeException runtimeException = new RuntimeException(); when( tokens.labelsGetAllTokens() ).thenThrow( runtimeException ); // When try { call( "db.labels" ); fail( "Procedure call should have failed" ); } catch ( Exception e ) { assertThat( e.getCause(), is( runtimeException ) ); // expected } // Then verify( statement ).close(); }
@Test public void shouldCloseStatementIfExceptionIsThrownDbRelationshipTypes() { // Given RuntimeException runtimeException = new RuntimeException(); when( tokens.relationshipTypesGetAllTokens() ).thenThrow( runtimeException ); // When try { call( "db.relationshipTypes" ); fail( "Procedure call should have failed" ); } catch ( Exception e ) { assertThat( e.getCause(), is( runtimeException ) ); // expected } // Then verify( statement ).close(); }
@Override public void close( boolean success ) { if ( isOpen ) { try { statement.queryRegistration().unregisterExecutingQuery( executingQuery ); statement.close(); if ( success ) { transaction.success(); } else { transaction.failure(); } transaction.close(); } finally { statement = null; kernelTransaction = null; transaction = null; isOpen = false; } } }
private ResourceIterator<Node> allNodesWithLabel( final Label myLabel ) { KernelTransaction ktx = statementContext.getKernelTransactionBoundToThisThread( true ); Statement statement = ktx.acquireStatement(); int labelId = ktx.tokenRead().nodeLabel( myLabel.name() ); if ( labelId == TokenRead.NO_TOKEN ) { statement.close(); return Iterators.emptyResourceIterator(); } NodeLabelIndexCursor cursor = ktx.cursors().allocateNodeLabelIndexCursor(); ktx.dataRead().nodeLabelScan( labelId, cursor ); return new NodeCursorResourceIterator<>( cursor, statement, this::newNodeProxy ); }
private ResourceIterator<Node> nodesByLabelAndProperty( KernelTransaction transaction, int labelId, IndexQuery query ) { Statement statement = transaction.acquireStatement(); Read read = transaction.dataRead(); if ( query.propertyKeyId() == TokenRead.NO_TOKEN || labelId == TokenRead.NO_TOKEN ) { statement.close(); return emptyResourceIterator(); } IndexReference index = transaction.schemaRead().index( labelId, query.propertyKeyId() ); if ( index != IndexReference.NO_INDEX ) { // Ha! We found an index - let's use it to find matching nodes try { NodeValueIndexCursor cursor = transaction.cursors().allocateNodeValueIndexCursor(); read.nodeIndexSeek( index, cursor, IndexOrder.NONE, false, query ); return new NodeCursorResourceIterator<>( cursor, statement, this::newNodeProxy ); } catch ( KernelException e ) { // weird at this point but ignore and fallback to a label scan } } return getNodesByLabelAndPropertyWithoutIndex( statement, labelId, query ); }
private ResourceIterator<Node> nodesByLabelAndProperties( KernelTransaction transaction, int labelId, IndexQuery.ExactPredicate... queries ) { Statement statement = transaction.acquireStatement(); Read read = transaction.dataRead(); if ( isInvalidQuery( labelId, queries ) ) { statement.close(); return emptyResourceIterator(); } int[] propertyIds = getPropertyIds( queries ); IndexReference index = findMatchingIndex( transaction, labelId, propertyIds ); if ( index != IndexReference.NO_INDEX ) { try { NodeValueIndexCursor cursor = transaction.cursors().allocateNodeValueIndexCursor(); read.nodeIndexSeek( index, cursor, IndexOrder.NONE, false, getReorderedIndexQueries( index.properties(), queries ) ); return new NodeCursorResourceIterator<>( cursor, statement, this::newNodeProxy ); } catch ( KernelException e ) { // weird at this point but ignore and fallback to a label scan } } return getNodesByLabelAndPropertyWithoutIndex( statement, labelId, queries ); }
try oldStatement.close(); oldTransaction.success(); oldTransaction.close();
@Override public void close() { statement.close(); }
@Override public void close() { statement.close(); }
@Override public void close() { if ( statement != null ) { statement.close(); statement = null; } }
@Override public void cleanForReuse() { // close the old statement reference after the statement has been "upgraded" // to either a schema data or a schema statement, so that the locks are "handed over". statement.queryRegistration().unregisterExecutingQuery( executingQuery ); statement.close(); statement = txBridge.get(); statement.queryRegistration().registerExecutingQuery( executingQuery ); }
private ResourceIterator<Node> allNodesWithLabel( final Label myLabel ) { KernelTransaction ktx = statementContext.getKernelTransactionBoundToThisThread( true ); Statement statement = ktx.acquireStatement(); int labelId = ktx.tokenRead().nodeLabel( myLabel.name() ); if ( labelId == TokenRead.NO_TOKEN ) { statement.close(); return Iterators.emptyResourceIterator(); } NodeLabelIndexCursor cursor = ktx.cursors().allocateNodeLabelIndexCursor(); ktx.dataRead().nodeLabelScan( labelId, cursor ); return new NodeCursorResourceIterator<>( cursor, statement, this::newNodeProxy ); }
private ResourceIterator<Node> nodesByLabelAndProperty( KernelTransaction transaction, int labelId, IndexQuery query ) { Statement statement = transaction.acquireStatement(); Read read = transaction.dataRead(); if ( query.propertyKeyId() == TokenRead.NO_TOKEN || labelId == TokenRead.NO_TOKEN ) { statement.close(); return emptyResourceIterator(); } IndexReference index = transaction.schemaRead().index( labelId, query.propertyKeyId() ); if ( index != IndexReference.NO_INDEX ) { // Ha! We found an index - let's use it to find matching nodes try { NodeValueIndexCursor cursor = transaction.cursors().allocateNodeValueIndexCursor(); read.nodeIndexSeek( index, cursor, IndexOrder.NONE, false, query ); return new NodeCursorResourceIterator<>( cursor, statement, this::newNodeProxy ); } catch ( KernelException e ) { // weird at this point but ignore and fallback to a label scan } } return getNodesByLabelAndPropertyWithoutIndex( statement, labelId, query ); }
private ResourceIterator<Node> nodesByLabelAndProperties( KernelTransaction transaction, int labelId, IndexQuery.ExactPredicate... queries ) { Statement statement = transaction.acquireStatement(); Read read = transaction.dataRead(); if ( isInvalidQuery( labelId, queries ) ) { statement.close(); return emptyResourceIterator(); } int[] propertyIds = getPropertyIds( queries ); IndexReference index = findMatchingIndex( transaction, labelId, propertyIds ); if ( index != IndexReference.NO_INDEX ) { try { NodeValueIndexCursor cursor = transaction.cursors().allocateNodeValueIndexCursor(); read.nodeIndexSeek( index, cursor, IndexOrder.NONE, false, getReorderedIndexQueries( index.properties(), queries ) ); return new NodeCursorResourceIterator<>( cursor, statement, this::newNodeProxy ); } catch ( KernelException e ) { // weird at this point but ignore and fallback to a label scan } } return getNodesByLabelAndPropertyWithoutIndex( statement, labelId, queries ); }