    @Test
    @Graph( nodes = {
            @NODE( name = "I", properties = {
                    @PROP( key = "name", value = "me" ),
                    @PROP( key = "bool", value = "true", type = GraphDescription.PropType.BOOLEAN ) } ),
            @NODE( name = "you", setNameProperty = true ) }, relationships = { @REL( start = "I", end = "you", type = "knows", properties = {
            @PROP( key = "name", value = "relProp" ),
            @PROP( key = "valid", value = "true", type = GraphDescription.PropType.BOOLEAN ) } ) }, autoIndexRelationships = true )
    public void canCreateMoreInvolvedGraphWithPropertiesAndAutoIndex()
            throws Exception
    {
        data.get();
        verifyIKnowYou( "knows", "me" );
        try(Transaction ignored = graphdb.beginTx())
        {
            assertEquals( true, data.get().get( "I" ).getProperty( "bool" ) );
            assertFalse( "node autoindex enabled.",
                    graphdb().index().getNodeAutoIndexer().isEnabled() );
            assertTrue(
                    "can't look up rel.",
                    graphdb().index().getRelationshipAutoIndexer().getAutoIndex().get(
                            "name", "relProp" ).hasNext() );
            assertTrue( "relationship autoindex enabled.",
                    graphdb().index().getRelationshipAutoIndexer().isEnabled() );
        }
    }

    @Test
    @Graph( nodes = {
            @NODE( name = "I", properties = {
                    @PROP( key = "name", value = "me" ),
                    @PROP( key = "bool", value = "true", type = GraphDescription.PropType.BOOLEAN ) } ),
            @NODE( name = "you", setNameProperty = true ) }, relationships = { @REL( start = "I", end = "you", type = "knows", properties = {
            @PROP( key = "name", value = "relProp" ),
            @PROP( key = "valid", value = "true", type = GraphDescription.PropType.BOOLEAN ) } ) }, autoIndexRelationships = true )
    public void canCreateMoreInvolvedGraphWithPropertiesAndAutoIndex()
            throws Exception
    {
        data.get();
        verifyIknowYou( "knows", "me" );
        Transaction transaction = graphdb.beginTx();
        try
        {
            assertEquals( true, data.get().get( "I" ).getProperty( "bool" ) );
            assertFalse( "node autoindex enabled.",
                    graphdb().index().getNodeAutoIndexer().isEnabled() );
            assertTrue(
                    "can't look up rel.",
                    graphdb().index().getRelationshipAutoIndexer().getAutoIndex().get(
                            "name", "relProp" ).hasNext() );
            assertTrue( "relationship autoindex enabled.",
                    graphdb().index().getRelationshipAutoIndexer().isEnabled() );
        }
        finally
        {
            transaction.finish();
        }
    }

Try With Resources try(Transaction ignored=graphdb.beginTx()) in method public canCreateMoreInvolvedGraphWithPropertiesAndAutoIndex() : void from class org.neo4j.metatest.TestGraphDescription


    @Graph( value = { "I know you" }, nodes = { @NODE( name = "I", properties = { @PROP( key = "name", value = "me" ) } ) } )
    private void verifyIKnowYou( String type, String myName )
    {
        try(Transaction ignored = graphdb.beginTx())
        {
            Map<String, Node> graph = data.get();
            assertEquals( "Wrong graph size.", 2, graph.size() );
            Node I = graph.get( "I" );
            assertNotNull( "The node 'I' was not defined", I );
            Node you = graph.get( "you" );
            assertNotNull( "The node 'you' was not defined", you );
            assertEquals( "'I' has wrong 'name'.", myName, I.getProperty( "name" ) );
            assertEquals( "'you' has wrong 'name'.", "you",
                    you.getProperty( "name" ) );

            Iterator<Relationship> rels = I.getRelationships().iterator();
            assertTrue( "'I' has too few relationships", rels.hasNext() );
            Relationship rel = rels.next();
            assertEquals( "'I' is not related to 'you'", you, rel.getOtherNode( I ) );
            assertEquals( "Wrong relationship type.", type, rel.getType().name() );
            assertFalse( "'I' has too many relationships", rels.hasNext() );

            rels = you.getRelationships().iterator();
            assertTrue( "'you' has too few relationships", rels.hasNext() );
            rel = rels.next();
            assertEquals( "'you' is not related to 'i'", I, rel.getOtherNode( you ) );
            assertEquals( "Wrong relationship type.", type, rel.getType().name() );
            assertFalse( "'you' has too many relationships", rels.hasNext() );

            assertEquals( "wrong direction", I, rel.getStartNode() );
        }
    }

    @Graph( value = { "I know you" }, nodes = { @NODE( name = "I", properties = { @PROP( key = "name", value = "me" ) } ) } )
    private void verifyIknowYou( String type, String myName )
    {
        Transaction transaction = graphdb.beginTx();

        try
        {
            Map<String, Node> graph = data.get();
            assertEquals( "Wrong graph size.", 2, graph.size() );
            Node I = graph.get( "I" );
            assertNotNull( "The node 'I' was not defined", I );
            Node you = graph.get( "you" );
            assertNotNull( "The node 'you' was not defined", you );
            assertEquals( "'I' has wrong 'name'.", myName, I.getProperty( "name" ) );
            assertEquals( "'you' has wrong 'name'.", "you",
                    you.getProperty( "name" ) );

            Iterator<Relationship> rels = I.getRelationships().iterator();
            assertTrue( "'I' has too few relationships", rels.hasNext() );
            Relationship rel = rels.next();
            assertEquals( "'I' is not related to 'you'", you, rel.getOtherNode( I ) );
            assertEquals( "Wrong relationship type.", type, rel.getType().name() );
            assertFalse( "'I' has too many relationships", rels.hasNext() );

            rels = you.getRelationships().iterator();
            assertTrue( "'you' has too few relationships", rels.hasNext() );
            rel = rels.next();
            assertEquals( "'you' is not related to 'i'", I, rel.getOtherNode( you ) );
            assertEquals( "Wrong relationship type.", type, rel.getType().name() );
            assertFalse( "'you' has too many relationships", rels.hasNext() );

            assertEquals( "wrong direction", I, rel.getStartNode() );
        }
        finally
        {
            transaction.finish();
        }
    }

Try With Resources try(Transaction ignored=graphdb.beginTx()) in method private verifyIKnowYou(type String, myName String) : void from class org.neo4j.metatest.TestGraphDescription


    private static void create1pcTx( GraphDatabaseService db )
    {
        try(Transaction tx = db.beginTx())
        {
            db.createNode();
            tx.success();
        }
    }

    private static void create1pcTx( GraphDatabaseService db )
    {
        Transaction tx = db.beginTx();
        try
        {
            db.createNode();
            tx.success();
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=db.beginTx()) in method private create1pcTx(db GraphDatabaseService) : void from class recovery.CreateTransactionsAndDie


    private static void create2pcTx( GraphDatabaseService db )
    {
        try(Transaction tx = db.beginTx())
        {
            Node node = db.createNode();
            db.index().forNodes( "index" ).add( node, "key", "value" );
            tx.success();
        }
    }

    private static void create2pcTx( GraphDatabaseService db )
    {
        Transaction tx = db.beginTx();
        try
        {
            Node node = db.createNode();
            db.index().forNodes( "index" ).add( node, "key", "value" );
            tx.success();
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=db.beginTx()) in method private create2pcTx(db GraphDatabaseService) : void from class recovery.CreateTransactionsAndDie


        @Override
        public void run( GraphDatabaseAPI graphdb )
        {
            try(Transaction tx = graphdb.beginTx())
            {
                Node node = graphdb.createNode();
                node.setProperty( "correct", "yes" );
                graphdb.index().forNodes( "nodes" ).add( node, "name", "value" );

                tx.success();
            }
        }

        @Override
        public void run( GraphDatabaseAPI graphdb )
        {
            Transaction tx = graphdb.beginTx();
            try
            {
                Node node = graphdb.createNode();
                node.setProperty( "correct", "yes" );
                graphdb.index().forNodes( "nodes" ).add( node, "name", "value" );

                tx.success();
            }
            finally
            {
                tx.finish();
            }
        }

Try With Resources try(Transaction tx=graphdb.beginTx()) in method public run(graphdb GraphDatabaseAPI) : void from class recovery.TestRecoveryIssues.SingleWriteTransaction


        @Override
        public void run( GraphDatabaseAPI graphdb )
        {
            try(Transaction tx = graphdb.beginTx())
            {
                Node parent = graphdb.createNode();
                for ( int i = 0; i < 10; i++ )
                {
                    Node child = graphdb.createNode();
                    parent.createRelationshipTo( child, TYPE );
                }
                tx.success();
            }
        }

        @Override
        public void run( GraphDatabaseAPI graphdb )
        {
            Transaction tx = graphdb.beginTx();
            try
            {
                Node parent = graphdb.createNode();
                for ( int i = 0; i < 10; i++ )
                {
                    Node child = graphdb.createNode();
                    parent.createRelationshipTo( child, TYPE );
                }
                tx.success();
            }
            finally
            {
                tx.finish();
            }
        }

Try With Resources try(Transaction tx=graphdb.beginTx()) in method public run(graphdb GraphDatabaseAPI) : void from class recovery.TestRecoveryLogTimingIssues.DoSimpleTransaction


        @Override
        public void run( GraphDatabaseAPI graphdb )
        {
            try(Transaction tx = graphdb.beginTx())
            {
                Node parent = graphdb.createNode();
                graphdb.index().forNodes( "index" ).add( parent, "name", "test" );
                for ( int i = 0; i < 10; i++ )
                {
                    Node child = graphdb.createNode();
                    parent.createRelationshipTo( child, TYPE );
                }
                tx.success();
            }
        }

        @Override
        public void run( GraphDatabaseAPI graphdb )
        {
            Transaction tx = graphdb.beginTx();
            try
            {
                Node parent = graphdb.createNode();
                graphdb.index().forNodes( "index" ).add( parent, "name", "test" );
                for ( int i = 0; i < 10; i++ )
                {
                    Node child = graphdb.createNode();
                    parent.createRelationshipTo( child, TYPE );
                }
                tx.success();
            }
            finally
            {
                tx.finish();
            }
        }

Try With Resources try(Transaction tx=graphdb.beginTx()) in method public run(graphdb GraphDatabaseAPI) : void from class recovery.TestRecoveryLogTimingIssues.DoGraphAndIndexTransaction


    /**
     * Tests an issue where loading all relationship types and property indexes after
     * the neostore data source had been started internally. The db would be in a
     * state where it would need recovery for the neostore data source, as well as some
     * other data source. This would fail since eventually TxManager#getTransaction()
     * would be called, which would fail since it hadn't as of yet recovered fully.
     * Whereas that failure would happen in a listener and merely be logged, one effect
     * of it would be that there would seem to be no relationship types in the database.
     */
    @Test
    public void recoverNeoAndIndexHavingAllRelationshipTypesAfterRecovery() throws Exception
    {
        // Given (create transactions and kill process, leaving it needing for recovery)
        deleteRecursively( new File( dir ) );
        assertEquals( 0, getRuntime().exec( new String[] { "java", "-cp", getProperty( "java.class.path" ),
                getClass().getName() } ).waitFor() );

        // When
        GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase( dir );

        // Then
        try(Transaction ignored = db.beginTx())
        {
            assertEquals( MyRelTypes.TEST.name(), GlobalGraphOperations.at( db ).getAllRelationshipTypes().iterator().next().name() );
        }
        finally
        {
            db.shutdown();
        }
    }

    /**
     * Tests an issue where loading all relationship types and property indexes after
     * the neostore data source had been started internally. The db would be in a
     * state where it would need recovery for the neostore data source, as well as some
     * other data source. This would fail since eventually TxManager#getTransaction()
     * would be called, which would fail since it hadn't as of yet recovered fully.
     * Whereas that failure would happen in a listener and merely be logged, one effect
     * of it would be that there would seem to be no relationship types in the database.
     */
    @Test
    public void recoverNeoAndIndexHavingAllRelationshipTypesAfterRecovery() throws Exception
    {
        // Given (create transactions and kill process, leaving it needing for recovery)
        deleteRecursively( new File( dir ) );
        assertEquals( 0, getRuntime().exec( new String[] { "java", "-cp", getProperty( "java.class.path" ),
                getClass().getName() } ).waitFor() );

        // When
        GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase( dir );

        // Then
        Transaction transaction = db.beginTx();
        try
        {
            assertEquals( MyRelTypes.TEST.name(), GlobalGraphOperations.at( db ).getAllRelationshipTypes().iterator().next().name() );
        }
        finally
        {
            transaction.finish();
            db.shutdown();
        }
    }

Try With Resources try(Transaction ignored=db.beginTx()) in method public recoverNeoAndIndexHavingAllRelationshipTypesAfterRecovery() : void from class recovery.TestRecoveryMultipleDataSources


    private static Node createNodeWithNameProperty( GraphDatabaseService db, String name )
    {
        try(Transaction tx = db.beginTx())
        {
            Node node = db.createNode();
            node.setProperty( "name", name );
            db.index().forNodes( "index" ).add( node, "name", name );
            tx.success();
            return node;
        }
    }

    private static Node createNodeWithNameProperty( GraphDatabaseService db, String name )
    {
        Transaction tx = db.beginTx();
        try
        {
            Node node = db.createNode();
            node.setProperty( "name", name );
            db.index().forNodes( "index" ).add( node, "name", name );
            tx.success();
            return node;
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=db.beginTx()) in method private createNodeWithNameProperty(db GraphDatabaseService, name String) : Node from class recovery.TestRecoveryNotHappening


        @Override
        public void run( GraphDatabaseAPI graphdb )
        {
            try(Transaction ignored = graphdb.beginTx())
            {
                assertTrue( (Boolean) graphdb.getReferenceNode().getProperty( "success" ) );
            }
        }

        @Override
        public void run( GraphDatabaseAPI graphdb )
        {
            Transaction transaction = graphdb.beginTx();
            try
            {
                assertTrue( (Boolean) graphdb.getReferenceNode().getProperty( "success" ) );
            }
            finally
            {
                transaction.finish();
            }
        }

Try With Resources try(Transaction ignored=graphdb.beginTx()) in method public run(graphdb GraphDatabaseAPI) : void from class synchronization.TestConcurrentRotation.Verifier


        @Override
        public void run( GraphDatabaseAPI graphdb )
        {
            try(Transaction tx = graphdb.beginTx())
            {
                for ( int i = 0; i < 3; i++ ) graphdb.index().forNodes( "index" + i ).add( graphdb.createNode(), "name", "" + i );
                tx.success();
            }
        }

        @Override
        public void run( GraphDatabaseAPI graphdb )
        {
            Transaction tx = graphdb.beginTx();
            try
            {
                for ( int i = 0; i < 3; i++ ) graphdb.index().forNodes( "index" + i ).add( graphdb.createNode(), "name", "" + i );
                tx.success();
            }
            finally
            {
                tx.finish();
            }
        }

Try With Resources try(Transaction tx=graphdb.beginTx()) in method public run(graphdb GraphDatabaseAPI) : void from class synchronization.TestConcurrentRotation.CreateInitialStateTask


        @Override
        public void run( GraphDatabaseAPI graphdb )
        {
            try(Transaction ignored = graphdb.beginTx())
            {
                for ( int i = 0; i < count; i++ ) graphdb.index().forNodes( "index" + i ).get( "name", i ).getSingle();
            }
            if ( resume ) resumeFlushThread();
        }

        @Override
        public void run( GraphDatabaseAPI graphdb )
        {
            Transaction transaction = graphdb.beginTx();
            try
            {
                for ( int i = 0; i < count; i++ ) graphdb.index().forNodes( "index" + i ).get( "name", i ).getSingle();
            }
            finally
            {
                transaction.finish();
            }
            if ( resume ) resumeFlushThread();
        }

Try With Resources try(Transaction ignored=graphdb.beginTx()) in method public run(graphdb GraphDatabaseAPI) : void from class synchronization.TestConcurrentRotation.LoadIndexesTask


        private void setSuccess( GraphDatabaseAPI graphdb, boolean success )
        {
            try(Transaction tx = graphdb.beginTx())
            {
                graphdb.getReferenceNode().setProperty( "success", success );
                tx.success();
            }
        }

        private void setSuccess( GraphDatabaseAPI graphdb, boolean success )
        {
            Transaction tx = graphdb.beginTx();
            try
            {
                graphdb.getReferenceNode().setProperty( "success", success );
                tx.success();
            }
            finally
            {
                tx.finish();
            }
        }

Try With Resources try(Transaction tx=graphdb.beginTx()) in method private setSuccess(graphdb GraphDatabaseAPI, success boolean) : void from class synchronization.TestConcurrentRotation.RotateIndexLogTask


    @Test
    public void shouldNotMakeIndexWritesVisibleUntilCommit() throws Exception
    {
        try(Transaction transaction = graphDatabaseService.beginTx())
        {
            // index write first so that that datastore is added first
            graphDatabaseService.index().forNodes( INDEX_NAME ).add( graphDatabaseService.getReferenceNode(),
                    INDEX_KEY, INDEX_VALUE );
            graphDatabaseService.getReferenceNode().setProperty( PROPERTY_NAME, PROPERTY_VALUE );

            assertReferenceNodeIsNotIndexedOutsideThisTransaction();
            assertReferenceNodeIsUnchangedOutsideThisTransaction();

            transaction.success();

            assertReferenceNodeIsNotIndexedOutsideThisTransaction();
            assertReferenceNodeIsUnchangedOutsideThisTransaction();
        }

        assertReferenceNodeIsIndexed();
        assertReferenceNodeHasBeenUpdated();
    }

    @Test
    public void shouldNotMakeIndexWritesVisibleUntilCommit() throws Exception
    {
        Transaction transaction = graphDatabaseService.beginTx();
        try
        {
            // index write first so that that datastore is added first
            graphDatabaseService.index().forNodes( INDEX_NAME ).add( graphDatabaseService.getReferenceNode(),
                    INDEX_KEY, INDEX_VALUE );
            graphDatabaseService.getReferenceNode().setProperty( PROPERTY_NAME, PROPERTY_VALUE );

            assertReferenceNodeIsNotIndexedOutsideThisTransaction();
            assertReferenceNodeIsUnchangedOutsideThisTransaction();

            transaction.success();

            assertReferenceNodeIsNotIndexedOutsideThisTransaction();
            assertReferenceNodeIsUnchangedOutsideThisTransaction();
        }
        finally
        {
            transaction.finish();
        }

        assertReferenceNodeIsIndexed();
        assertReferenceNodeHasBeenUpdated();
    }

Try With Resources try(Transaction transaction=graphDatabaseService.beginTx()) in method public shouldNotMakeIndexWritesVisibleUntilCommit() : void from class visibility.TestDatasourceCommitOrderDataVisibility


            @Override
            public void run()
            {
                try(Transaction ignored = graphDatabaseService.beginTx())
                {
                    assertThat( graphDatabaseService.index().forNodes( INDEX_NAME ).get( INDEX_KEY,
                            INDEX_VALUE ).size(), is( 0 ) );
                }
                catch ( Throwable t )
                {
                    problems.add( new Exception( t ) );
                }
            }

            @Override
            public void run()
            {
                Transaction transaction = graphDatabaseService.beginTx();
                try
                {
                    assertThat( graphDatabaseService.index().forNodes( INDEX_NAME ).get( INDEX_KEY,
                            INDEX_VALUE ).size(), is( 0 ) );
                }
                catch ( Throwable t )
                {
                    problems.add( new Exception( t ) );
                }
                finally
                {
                    transaction.finish();
                }
            }

Try With Resources try(Transaction ignored=graphDatabaseService.beginTx()) in method public run() : void from class visibility.TestDatasourceCommitOrderDataVisibility.assertReferenceNodeIsNotIndexedOutsideThisTransaction.thread.new Thread.new Runnable


            @Override
            public void run()
            {
                try(Transaction ignored = graphDatabaseService.beginTx())
                {
                    assertThat( graphDatabaseService.getReferenceNode().hasProperty( PROPERTY_NAME ), is( false ) );
                }
                catch ( Throwable t )
                {
                    problems.add( new Exception( t ) );
                }
            }

            @Override
            public void run()
            {
                Transaction transaction = graphDatabaseService.beginTx();
                try
                {
                    assertThat( graphDatabaseService.getReferenceNode().hasProperty( PROPERTY_NAME ), is( false ) );
                }
                catch ( Throwable t )
                {
                    problems.add( new Exception( t ) );
                }
                finally
                {
                    transaction.finish();
                }
            }

Try With Resources try(Transaction ignored=graphDatabaseService.beginTx()) in method public run() : void from class visibility.TestDatasourceCommitOrderDataVisibility.assertReferenceNodeIsUnchangedOutsideThisTransaction.thread.new Thread.new Runnable


            @Override
            public void run()
            {
                try(Transaction ignored = graphDatabaseService.beginTx())
                {
                    Node node = graphDatabaseService.index().forNodes( INDEX_NAME ).get( INDEX_KEY,
                            INDEX_VALUE ).getSingle();
                    assertThat( node, is( graphDatabaseService.getReferenceNode() ) );
                }
                catch ( Throwable t )
                {
                    problems.add( new Exception( t ) );
                }
            }

            @Override
            public void run()
            {
                Transaction transaction = graphDatabaseService.beginTx();
                try
                {
                    Node node = graphDatabaseService.index().forNodes( INDEX_NAME ).get( INDEX_KEY,
                            INDEX_VALUE ).getSingle();
                    assertThat( node, is( graphDatabaseService.getReferenceNode() ) );
                }
                catch ( Throwable t )
                {
                    problems.add( new Exception( t ) );
                }
                finally
                {
                    transaction.finish();
                }
            }

Try With Resources try(Transaction ignored=graphDatabaseService.beginTx()) in method public run() : void from class visibility.TestDatasourceCommitOrderDataVisibility.assertReferenceNodeIsIndexed.thread.new Thread.new Runnable


            @Override
            public void run()
            {
                try(Transaction ignored = graphDatabaseService.beginTx())
                {
                    assertThat( (Integer) graphDatabaseService.getReferenceNode().getProperty( PROPERTY_NAME ),
                            is( PROPERTY_VALUE ) );
                }
                catch ( Throwable t )
                {
                    problems.add( new Exception( t ) );
                }
            }

            @Override
            public void run()
            {
                Transaction transaction = graphDatabaseService.beginTx();
                try
                {
                    assertThat( (Integer) graphDatabaseService.getReferenceNode().getProperty( PROPERTY_NAME ),
                            is( PROPERTY_VALUE ) );
                }
                catch ( Throwable t )
                {
                    problems.add( new Exception( t ) );
                }
                finally
                {
                    transaction.finish();
                }
            }

Try With Resources try(Transaction ignored=graphDatabaseService.beginTx()) in method public run() : void from class visibility.TestDatasourceCommitOrderDataVisibility.assertReferenceNodeHasBeenUpdated.thread.new Thread.new Runnable


        @Override
        public void run( GraphDatabaseAPI graphdb )
        {
            try(Transaction tx = graphdb.beginTx())
            {
                Node node = graphdb.createNode();
                node.setProperty( "value", "present" );
                graphdb.index().forNodes( "nodes" ).add( node, "value", "present" );
                enableBreakPoints();

                tx.success();
            }
            done();
        }

        @Override
        public void run( GraphDatabaseAPI graphdb )
        {
            Transaction tx = graphdb.beginTx();
            try
            {
                Node node = graphdb.createNode();
                node.setProperty( "value", "present" );
                graphdb.index().forNodes( "nodes" ).add( node, "value", "present" );
                enableBreakPoints();

                tx.success();
            }
            finally
            {
                tx.finish();
            }
            done();
        }

Try With Resources try(Transaction tx=graphdb.beginTx()) in method public run(graphdb GraphDatabaseAPI) : void from class visibility.TestPropertyReadOnNewEntityBeforeLockRelease.CreateData


        @Override
        public void run( GraphDatabaseAPI graphdb )
        {
            try(Transaction ignored = graphdb.beginTx())
            {
                Node node = graphdb.index().forNodes( "nodes" ).get( "value", "present" ).getSingle();
                assertNotNull( "did not get the node from the index", node );
                assertEquals( "present", node.getProperty( "value" ) );
            }
            resumeThread();
        }

        @Override
        public void run( GraphDatabaseAPI graphdb )
        {
            Transaction transaction = graphdb.beginTx();
            try
            {
                Node node = graphdb.index().forNodes( "nodes" ).get( "value", "present" ).getSingle();
                assertNotNull( "did not get the node from the index", node );
                assertEquals( "present", node.getProperty( "value" ) );
            }
            finally
            {
                transaction.finish();
            }

            resumeThread();
        }

Try With Resources try(Transaction ignored=graphdb.beginTx()) in method public run(graphdb GraphDatabaseAPI) : void from class visibility.TestPropertyReadOnNewEntityBeforeLockRelease.ReadData


    private Node node( long id ) throws NodeNotFoundException
    {
        try(Transaction tx = graphDb.beginTx())
        {
            Node node = graphDb.getNodeById( id );

            tx.success();
            return node;
        }
        catch ( NotFoundException e )
        {
            throw new NodeNotFoundException( e );
        }
    }

    private Node node( long id ) throws NodeNotFoundException
    {
        Transaction tx = graphDb.beginTx();
        try
        {
            Node node = graphDb.getNodeById( id );

            tx.success();
            return node;
        }
        catch ( NotFoundException e )
        {
            throw new NodeNotFoundException( e );
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=graphDb.beginTx()) in method private node(id long) : Node from class org.neo4j.server.rest.web.ExtensionService


    private Relationship relationship( long id ) throws RelationshipNotFoundException
    {
        try(Transaction tx = graphDb.beginTx())
        {
            Relationship relationship = graphDb.getRelationshipById( id );

            tx.success();
            return relationship;
        }
        catch ( NotFoundException e )
        {
            throw new RelationshipNotFoundException();
        }
    }

    private Relationship relationship( long id ) throws RelationshipNotFoundException
    {
        Transaction tx = graphDb.beginTx();
        try
        {
            Relationship relationship = graphDb.getRelationshipById( id );

            tx.success();
            return relationship;
        }
        catch ( NotFoundException e )
        {
            throw new RelationshipNotFoundException();
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=graphDb.beginTx()) in method private relationship(id long) : Relationship from class org.neo4j.server.rest.web.ExtensionService


    /**
     * Parse a string as CypherDoc-enhanced AsciiDoc.
     *
     * @param input
     * @return
     */
    public static String parse( String input )
    {
        List<Block> blocks = parseBlocks( input );

        StringBuilder output = new StringBuilder( 4096 );
        GraphDatabaseService database = new TestGraphDatabaseFactory().newImpermanentDatabase();
        try(Transaction ignored = database.beginTx())
        {
            ExecutionEngine engine = new ExecutionEngine( database );
            State state = new State( engine, database );

            removeReferenceNode( database );

            boolean hasConsole = false;
            for ( Block block : blocks )
            {
                if ( block.type == BlockType.CONSOLE )
                {
                    hasConsole = true;
                }
                output.append( block.process( state ) )
                        .append( EOL )
                        .append( EOL );
            }
            if ( !hasConsole )
            {
                output.append( BlockType.CONSOLE.process( null, state ) );
            }

            return output.toString();
        }
    }

    /**
     * Parse a string as CypherDoc-enhanced AsciiDoc.
     *
     * @param input
     * @return
     */
    public static String parse( String input )
    {
        List<Block> blocks = parseBlocks( input );

        StringBuilder output = new StringBuilder( 4096 );
        GraphDatabaseService database = new TestGraphDatabaseFactory().newImpermanentDatabase();
        Transaction transaction = database.beginTx();
        try
        {
            ExecutionEngine engine = new ExecutionEngine( database );
            State state = new State( engine, database );

            removeReferenceNode( database );

            boolean hasConsole = false;
            for ( Block block : blocks )
            {
                if ( block.type == BlockType.CONSOLE )
                {
                    hasConsole = true;
                }
                output.append( block.process( state ) )
                        .append( EOL )
                        .append( EOL );
            }
            if ( !hasConsole )
            {
                output.append( BlockType.CONSOLE.process( null, state ) );
            }

            return output.toString();
        }
        finally
        {
            transaction.finish();
        }
    }

Try With Resources try(Transaction ignored=database.beginTx()) in method public parse(input String) : String from class org.neo4j.doc.cypherdoc.CypherDoc


    static void removeReferenceNode( GraphDatabaseService database )
    {
        try(Transaction tx = database.beginTx())
        {
            //noinspection deprecation
            database.getReferenceNode()
                    .delete();
            tx.success();
        }
    }

    @SuppressWarnings( "deprecation" )
    static void removeReferenceNode( GraphDatabaseService database )
    {
        Transaction tx = database.beginTx();
        try
        {
            database.getReferenceNode()
                    .delete();
            tx.success();
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=database.beginTx()) in method package removeReferenceNode(database GraphDatabaseService) : void from class org.neo4j.doc.cypherdoc.CypherDoc


    private HashMap<Object, Long> newBatchMap()
    {
        return new HashMap<>( (int) (batchSize / LOAD_FACTOR), LOAD_FACTOR );
    }

    private HashMap<Object, Long> newBatchMap()
    {
        return new HashMap<Object, Long>( (int) (batchSize / LOAD_FACTOR), LOAD_FACTOR );
    }

Replace Generic With Diamond HashMap<Object,Long> with HashMap<> in method private newBatchMap() : HashMap<Object,Long> from class org.neo4j.kernel.api.impl.index.UniqueLuceneIndexPopulator


    @Test
    public void shouldBeAbleToMoveTransactionToAnotherThread() throws Exception
    {
        // Given
        GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI();
        final TransactionManager tm = db.getDependencyResolver().resolveDependency( TransactionManager.class );

        final Node node = createNode();

        // And that I have added a label to a node in a transaction
        db.beginTx();
        node.addLabel( Labels.MY_LABEL );

        // And that I suspend the transaction in this thread
        final Transaction jtaTx = tm.suspend();

        // When
        OtherThreadExecutor<Boolean> otherThread = new OtherThreadExecutor<>( "Thread to resume tx in", null );
        boolean result = otherThread.execute( new OtherThreadExecutor.WorkerCommand<Boolean, Boolean>()
        {
            @Override
            public Boolean doWork( Boolean ignore )
            {
                try
                {
                    tm.resume( jtaTx );
                    // Then
                    return node.hasLabel( Labels.MY_LABEL );
                }
                catch ( Throwable e )
                {
                    throw new RuntimeException( e );
                }
            }
        } );

        // Then
        assertTrue("The label should be visible when I've resumed the transaction.", result);
    }

    @Test
    public void shouldBeAbleToMoveTransactionToAnotherThread() throws Exception
    {
        // Given
        GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI();
        final TransactionManager tm = db.getDependencyResolver().resolveDependency( TransactionManager.class );

        final Node node = createNode();

        // And that I have added a label to a node in a transaction
        db.beginTx();
        node.addLabel( Labels.MY_LABEL );

        // And that I suspend the transaction in this thread
        final Transaction jtaTx = tm.suspend();

        // When
        OtherThreadExecutor<Boolean> otherThread = new OtherThreadExecutor<Boolean>( "Thread to resume tx in", null );
        boolean result = otherThread.execute( new OtherThreadExecutor.WorkerCommand<Boolean, Boolean>()
        {
            @Override
            public Boolean doWork( Boolean ignore )
            {
                try
                {
                    tm.resume( jtaTx );
                    // Then
                    return node.hasLabel( Labels.MY_LABEL );
                }
                catch ( Throwable e )
                {
                    throw new RuntimeException( e );
                }
            }
        } );

        // Then
        assertTrue("The label should be visible when I've resumed the transaction.", result);
    }

Replace Generic With Diamond OtherThreadExecutor<Boolean> with OtherThreadExecutor<> in method public shouldBeAbleToMoveTransactionToAnotherThread() : void from class org.neo4j.kernel.impl.transaction.ExternalTransactionControlIT


        public ArrayMap<Integer, RelIdArray> getRelationshipAddMap( boolean create )
        {
            if ( relationshipAddMap == null && create )
            {
                relationshipAddMap = new ArrayMap<>();
            }
            return relationshipAddMap;
        }

        public ArrayMap<Integer, RelIdArray> getRelationshipAddMap( boolean create )
        {
            if ( relationshipAddMap == null && create )
            {
                relationshipAddMap = new ArrayMap<Integer, RelIdArray>();
            }
            return relationshipAddMap;
        }

Replace Generic With Diamond ArrayMap<Integer,RelIdArray> with ArrayMap<> in method public getRelationshipAddMap(create boolean) : ArrayMap<Integer,RelIdArray> from class org.neo4j.kernel.impl.core.WritableTransactionState.CowNodeElement


        public ArrayMap<Integer, Collection<Long>> getRelationshipRemoveMap( boolean create )
        {
            if ( relationshipRemoveMap == null && create )
            {
                relationshipRemoveMap = new ArrayMap<>();
            }
            return relationshipRemoveMap;
        }

        public ArrayMap<Integer, Collection<Long>> getRelationshipRemoveMap( boolean create )
        {
            if ( relationshipRemoveMap == null && create )
            {
                relationshipRemoveMap = new ArrayMap<Integer, Collection<Long>>();
            }
            return relationshipRemoveMap;
        }

Replace Generic With Diamond ArrayMap<Integer,Collection<Long>> with ArrayMap<> in method public getRelationshipRemoveMap(create boolean) : ArrayMap<Integer,Collection<Long>> from class org.neo4j.kernel.impl.core.WritableTransactionState.CowNodeElement


        public Collection<Long> getRelationshipRemoveMap( int type, boolean create )
        {
            ArrayMap<Integer, Collection<Long>> map = getRelationshipRemoveMap( create );
            if ( map == null )
            {
                return null;
            }
            Collection<Long> result = map.get( type );
            if ( result == null && create )
            {
                result = new HashSet<>();
                map.put( type, result );
            }
            return result;
        }

        public Collection<Long> getRelationshipRemoveMap( int type, boolean create )
        {
            ArrayMap<Integer, Collection<Long>> map = getRelationshipRemoveMap( create );
            if ( map == null )
            {
                return null;
            }
            Collection<Long> result = map.get( type );
            if ( result == null && create )
            {
                result = new HashSet<Long>();
                map.put( type, result );
            }
            return result;
        }

Replace Generic With Diamond HashSet<Long> with HashSet<> in method public getRelationshipRemoveMap(type int, create boolean) : Collection<Long> from class org.neo4j.kernel.impl.core.WritableTransactionState.CowNodeElement


    private void addLockToTransaction( LockElement lock )
    {
        boolean firstLock = false;
        if ( lockElements == null )
        {
            lockElements = new ArrayList<>();
            firstLock = true;
        }
        lockElements.add( lock );

        if ( firstLock )
        {
            try
            {
                tx.registerSynchronization( new ReadOnlyTxReleaser() );
            }
            catch ( Exception e )
            {
                throw new TransactionFailureException(
                        "Failed to register lock release synchronization hook", e );
            }
        }
    }

    private void addLockToTransaction( LockElement lock )
    {
        boolean firstLock = false;
        if ( lockElements == null )
        {
            lockElements = new ArrayList<LockElement>();
            firstLock = true;
        }
        lockElements.add( lock );

        if ( firstLock )
        {
            try
            {
                tx.registerSynchronization( new ReadOnlyTxReleaser() );
            }
            catch ( Exception e )
            {
                throw new TransactionFailureException(
                        "Failed to register lock release synchronization hook", e );
            }
        }
    }

Replace Generic With Diamond ArrayList<LockElement> with ArrayList<> in method private addLockToTransaction(lock LockElement) : void from class org.neo4j.kernel.impl.core.WritableTransactionState


    private void releaseLocks()
    {
        if ( lockElements != null )
        {
            Collection<LockElement> releaseFailures = null;
            Exception releaseException = null;
            for ( LockElement lockElement : lockElements )
            {
                try
                {
                    lockElement.releaseIfAcquired();
                }
                catch ( Exception e )
                {
                    releaseException = e;
                    if ( releaseFailures == null )
                    {
                        releaseFailures = new ArrayList<>();
                    }
                    releaseFailures.add( lockElement );
                }
            }

            if ( releaseException != null )
            {
                log.warn( "Unable to release locks: " + releaseFailures + ". Example of exception:" +
                        releaseException );
            }
        }
    }

    private void releaseLocks()
    {
        if ( lockElements != null )
        {
            Collection<LockElement> releaseFailures = null;
            Exception releaseException = null;
            for ( LockElement lockElement : lockElements )
            {
                try
                {
                    lockElement.releaseIfAcquired();
                }
                catch ( Exception e )
                {
                    releaseException = e;
                    if ( releaseFailures == null )
                    {
                        releaseFailures = new ArrayList<LockElement>();
                    }
                    releaseFailures.add( lockElement );
                }
            }

            if ( releaseException != null )
            {
                log.warn( "Unable to release locks: " + releaseFailures + ". Example of exception:" +
                        releaseException );
            }
        }
    }

Replace Generic With Diamond ArrayList<LockElement> with ArrayList<> in method private releaseLocks() : void from class org.neo4j.kernel.impl.core.WritableTransactionState


    public static Map<String, String> readMap( ReadableByteChannel channel, ByteBuffer buffer ) throws IOException
    {
        int size = readInt( channel, buffer );
        Map<String, String> map = new HashMap<>();
        for ( int i = 0; i < size; i++ )
        {
            String key = readLengthAndString( channel, buffer );
            String value = readLengthAndString( channel, buffer );
            if ( key == null || value == null )
            {
                return null;
            }
            map.put( key, value );
        }
        return map;
    }

    public static Map<String, String> readMap( ReadableByteChannel channel, ByteBuffer buffer ) throws IOException
    {
        int size = readInt( channel, buffer );
        Map<String, String> map = new HashMap<String, String>();
        for ( int i = 0; i < size; i++ )
        {
            String key = readLengthAndString( channel, buffer );
            String value = readLengthAndString( channel, buffer );
            if ( key == null || value == null )
            {
                return null;
            }
            map.put( key, value );
        }
        return map;
    }

Replace Generic With Diamond HashMap<String,String> with HashMap<> in method public readMap(channel ReadableByteChannel, buffer ByteBuffer) : Map<String,String> from class org.neo4j.kernel.impl.util.IoPrimitiveUtils


    @Override
    public Iterable<BatchRelationship> getRelationships( long nodeId )
    {
        NodeRecord nodeRecord = getNodeRecord( nodeId );
        long nextRel = nodeRecord.getNextRel();
        List<BatchRelationship> rels = new ArrayList<>();
        while ( nextRel != Record.NO_NEXT_RELATIONSHIP.intValue() )
        {
            RelationshipRecord relRecord = getRelationshipRecord( nextRel );
            RelationshipType type = new RelationshipTypeImpl(
                    relationshipTypeTokens.nameOf( relRecord.getType() ) );
            rels.add( new BatchRelationship( relRecord.getId(),
                                             relRecord.getFirstNode(), relRecord.getSecondNode(), type ) );
            long firstNode = relRecord.getFirstNode();
            long secondNode = relRecord.getSecondNode();
            if ( firstNode == nodeId )
            {
                nextRel = relRecord.getFirstNextRel();
            }
            else if ( secondNode == nodeId )
            {
                nextRel = relRecord.getSecondNextRel();
            }
            else
            {
                throw new InvalidRecordException( "Node[" + nodeId +
                                                  "] not part of firstNode[" + firstNode +
                                                  "] or secondNode[" + secondNode + "]" );
            }
        }
        return rels;
    }

    @Override
    public Iterable<BatchRelationship> getRelationships( long nodeId )
    {
        NodeRecord nodeRecord = getNodeRecord( nodeId );
        long nextRel = nodeRecord.getNextRel();
        List<BatchRelationship> rels = new ArrayList<BatchRelationship>();
        while ( nextRel != Record.NO_NEXT_RELATIONSHIP.intValue() )
        {
            RelationshipRecord relRecord = getRelationshipRecord( nextRel );
            RelationshipType type = new RelationshipTypeImpl(
                    relationshipTypeTokens.nameOf( relRecord.getType() ) );
            rels.add( new BatchRelationship( relRecord.getId(),
                                             relRecord.getFirstNode(), relRecord.getSecondNode(), type ) );
            long firstNode = relRecord.getFirstNode();
            long secondNode = relRecord.getSecondNode();
            if ( firstNode == nodeId )
            {
                nextRel = relRecord.getFirstNextRel();
            }
            else if ( secondNode == nodeId )
            {
                nextRel = relRecord.getSecondNextRel();
            }
            else
            {
                throw new InvalidRecordException( "Node[" + nodeId +
                                                  "] not part of firstNode[" + firstNode +
                                                  "] or secondNode[" + secondNode + "]" );
            }
        }
        return rels;
    }

Replace Generic With Diamond ArrayList<BatchRelationship> with ArrayList<> in method public getRelationships(nodeId long) : Iterable<BatchRelationship> from class org.neo4j.unsafe.batchinsert.BatchInserterImpl


    @Test
    public void addingANodeWithPropertyShouldGetIndexed() throws Exception
    {
        // Given
        String indexProperty = "indexProperty";
        GatheringIndexWriter writer = newWriter( indexProperty );
        createIndex( db, myLabel, indexProperty );

        // When
        int value1 = 12;
        String otherProperty = "otherProperty";
        int otherValue = 17;
        Node node = createNode( map( indexProperty, value1, otherProperty, otherValue ), myLabel );

        // Then, for now, this should trigger two NodePropertyUpdates
        try ( Transaction tx = db.beginTx() )
        {
            DataWriteOperations statement = ctxProvider.statement().dataWriteOperations();
            int propertyKey1 = statement.propertyKeyGetForName( indexProperty );
            long[] labels = new long[]{statement.labelGetForName( myLabel.name() )};
            assertThat( writer.updates, equalTo( asSet(
                    NodePropertyUpdate.add( node.getId(), propertyKey1, value1, labels ) ) ) );
            tx.success();
        }
        // We get two updates because we both add a label and a property to be indexed
        // in the same transaction, in the future, we should optimize this down to
        // one NodePropertyUpdate.
    }

    @Test
    public void addingANodeWithPropertyShouldGetIndexed() throws Exception
    {
        // Given
        String indexProperty = "indexProperty";
        GatheringIndexWriter writer = newWriter( indexProperty );
        createIndex( db, myLabel, indexProperty );

        // When
        int value1 = 12;
        String otherProperty = "otherProperty";
        int otherValue = 17;
        Node node = createNode( map( indexProperty, value1, otherProperty, otherValue ), myLabel );

        // Then, for now, this should trigger two NodePropertyUpdates
        Transaction tx = db.beginTx();
        try
        {
            DataWriteOperations statement = ctxProvider.statement().dataWriteOperations();
            long propertyKey1 = statement.propertyKeyGetForName( indexProperty );
            long[] labels = new long[]{statement.labelGetForName( myLabel.name() )};
            assertThat( writer.updates, equalTo( asSet(
                    NodePropertyUpdate.add( node.getId(), propertyKey1, value1, labels ) ) ) );
        }
        finally
        {
            tx.finish();
        }
        // We get two updates because we both add a label and a property to be indexed
        // in the same transaction, in the future, we should optimize this down to
        // one NodePropertyUpdate.
    }

Try With Resources try(Transaction tx=db.beginTx()) in method public addingANodeWithPropertyShouldGetIndexed() : void from class org.neo4j.kernel.impl.api.index.IndexCRUDIT


    @Test
    public void addingALabelToPreExistingNodeShouldGetIndexed() throws Exception
    {
        // GIVEN
        String indexProperty = "indexProperty";
        GatheringIndexWriter writer = newWriter( indexProperty );
        createIndex( db, myLabel, indexProperty );

        // WHEN
        String otherProperty = "otherProperty";
        int value = 12;
        int otherValue = 17;
        Node node = createNode( map( indexProperty, value, otherProperty, otherValue ) );

        // THEN
        assertThat( writer.updates.size(), equalTo( 0 ) );

        // AND WHEN
        try ( Transaction tx = db.beginTx() )
        {
            node.addLabel( myLabel );
            tx.success();
        }

        // THEN
        try ( Transaction tx = db.beginTx() )
        {
            DataWriteOperations statement = ctxProvider.statement().dataWriteOperations();
            int propertyKey1 = statement.propertyKeyGetForName( indexProperty );
            long[] labels = new long[]{statement.labelGetForName( myLabel.name() )};
            assertThat( writer.updates, equalTo( asSet(
                    NodePropertyUpdate.add( node.getId(), propertyKey1, value, labels ) ) ) );
            tx.success();
        }
    }

    @Test
    public void addingALabelToPreExistingNodeShouldGetIndexed() throws Exception
    {
        // GIVEN
        String indexProperty = "indexProperty";
        GatheringIndexWriter writer = newWriter( indexProperty );
        createIndex( db, myLabel, indexProperty );

        // WHEN
        String otherProperty = "otherProperty";
        int value = 12;
        int otherValue = 17;
        Node node = createNode( map( indexProperty, value, otherProperty, otherValue ) );

        // THEN
        assertThat( writer.updates.size(), equalTo( 0 ) );

        // AND WHEN
        Transaction tx = db.beginTx();
        node.addLabel( myLabel );
        tx.success();
        tx.finish();

        // THEN
        tx = db.beginTx();
        try
        {
            DataWriteOperations statement = ctxProvider.statement().dataWriteOperations();
            long propertyKey1 = statement.propertyKeyGetForName( indexProperty );
            long[] labels = new long[]{statement.labelGetForName( myLabel.name() )};
            assertThat( writer.updates, equalTo( asSet(
                    NodePropertyUpdate.add( node.getId(), propertyKey1, value, labels ) ) ) );
        }
        finally
        {
            tx.finish();
        }

    }

Try With Resources try(Transaction tx=db.beginTx()) in method public addingALabelToPreExistingNodeShouldGetIndexed() : void from class org.neo4j.kernel.impl.api.index.IndexCRUDIT


    private IndexPopulationJob newIndexPopulationJob( Label label, String propertyKey,
                                                      FailedIndexProxyFactory failureDelegateFactory,
                                                      IndexPopulator populator,
                                                      FlippableIndexProxy flipper, IndexStoreView storeView,
                                                      StringLogger logger )
    {
        IndexDescriptor descriptor;
        try ( Transaction tx = db.beginTx() )
        {
            ReadOperations statement = ctxProvider.statement().readOperations();
            descriptor = new IndexDescriptor( statement.labelGetForName( label.name() ),
                    statement.propertyKeyGetForName( propertyKey ) );
            tx.success();
        }

        flipper.setFlipTarget( mock( IndexProxyFactory.class ) );
        return new IndexPopulationJob(
                descriptor, PROVIDER_DESCRIPTOR,
                format( ":%s(%s)", label.name(), propertyKey ),
                failureDelegateFactory,
                populator, flipper, storeView,
                stateHolder, new SingleLoggingService( logger ) );
    }

    private IndexPopulationJob newIndexPopulationJob( Label label, String propertyKey,
                                                      FailedIndexProxyFactory failureDelegateFactory,
                                                      IndexPopulator populator,
                                                      FlippableIndexProxy flipper, IndexStoreView storeView,
                                                      StringLogger logger )
            throws LabelNotFoundKernelException, PropertyKeyNotFoundException
    {
        IndexDescriptor descriptor;
        Transaction tx = db.beginTx();
        try
        {
            ReadOperations statement = ctxProvider.statement().readOperations();
            descriptor = new IndexDescriptor( statement.labelGetForName( label.name() ),
                    statement.propertyKeyGetForName( propertyKey ) );
            tx.success();
        }
        finally
        {
            tx.finish();
        }

        flipper.setFlipTarget( mock( IndexProxyFactory.class ) );
        return new IndexPopulationJob(
                descriptor, PROVIDER_DESCRIPTOR,
                format( ":%s(%s)", label.name(), propertyKey ),
                failureDelegateFactory,
                populator, flipper, storeView,
                stateHolder, new SingleLoggingService( logger ) );
    }

Try With Resources try(Transaction tx=db.beginTx()) in method private newIndexPopulationJob(label Label, propertyKey String, failureDelegateFactory FailedIndexProxyFactory, populator IndexPopulator, flipper FlippableIndexProxy, storeView IndexStoreView, logger StringLogger) : IndexPopulationJob from class org.neo4j.kernel.impl.api.index.IndexPopulationJobTest


    private long createNode( Map<String, Object> properties, Label... labels )
    {
        try ( Transaction tx = db.beginTx() )
        {
            Node node = db.createNode( labels );
            for ( Map.Entry<String, Object> property : properties.entrySet() )
            {
                node.setProperty( property.getKey(), property.getValue() );
            }
            tx.success();
            return node.getId();
        }
    }

    private long createNode( Map<String, Object> properties, Label... labels )
    {
        Transaction tx = db.beginTx();
        try
        {
            Node node = db.createNode( labels );
            for ( Map.Entry<String, Object> property : properties.entrySet() )
            {
                node.setProperty( property.getKey(), property.getValue() );
            }
            tx.success();
            return node.getId();
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=db.beginTx()) in method private createNode(properties Map<String,Object>, labels Label...) : long from class org.neo4j.kernel.impl.api.index.IndexPopulationJobTest


            @Override
            public Long call()
            {
                try ( Transaction tx = db.beginTx() )
                {
                    Node node = db.createNode( label( "Foo" ) );
                    node.setProperty( "name", "foo" );
                    tx.success();
                    return node.getId();
                }
            }

            @Override
            public Long call()
            {
                Transaction tx = db.beginTx();
                try
                {
                    Node node = db.createNode( label( "Foo" ) );
                    node.setProperty( "name", "foo" );
                    tx.success();
                    return node.getId();
                }
                finally
                {
                    tx.finish();
                }
            }

Try With Resources try(Transaction tx=db.beginTx()) in method public call() : Long from class org.neo4j.kernel.impl.api.integrationtest.UniquenessConstraintVerificationIT.shouldFailOnCommitIfConstraintIsBrokenAfterConstraintAddedButBeforeConstraintCommitted.node2.get.submit.new Callable<Long>


    /**
     * Create/reserve an empty failure file for the given indexId.
     *
     * This will overwrite any pre-existing failure file.
     *
     * @param indexId id of the index
     * @throws IOException if the failure file could not be created
     */
    public synchronized void reserveForIndex( long indexId ) throws IOException
    {
        File failureFile = failureFile( indexId );
        try ( RandomAccessFile rwFile = new RandomAccessFile( failureFile, "rw" ) )
        {
            FileChannel channel = rwFile.getChannel();
            channel.write( ByteBuffer.wrap( new byte[MAX_FAILURE_SIZE] ) );
            channel.force( true );
            channel.close();
        }
    }

    /**
     * Create/reserve an empty failure file for the given indexId.
     *
     * This will overwrite any pre-existing failure file.
     *
     * @param indexId id of the index
     * @throws IOException if the failure file could not be created
     */
    public synchronized void reserveForIndex( long indexId ) throws IOException
    {
        File failureFile = failureFile( indexId );
        RandomAccessFile rwFile = new RandomAccessFile( failureFile, "rw" );
        try
        {
            FileChannel channel = rwFile.getChannel();
            channel.write( wrap( new byte[ MAX_FAILURE_SIZE ] ) );
            channel.force( true );
            channel.close();
        }
        finally
        {
            rwFile.close();
        }
    }

Try With Resources try(RandomAccessFile rwFile=new RandomAccessFile(failureFile,"rw")) in method public reserveForIndex(indexId long) : void from class org.neo4j.kernel.api.index.util.FailureStorage


    /**
     * Store failure in failure file for index with the given id
     *
     * @param indexId of the index that failed
     * @param failure message describing the failure that needs to be stored
     * @throws IOException if the failure could not be stored
     */
    public synchronized void storeIndexFailure( long indexId, String failure ) throws IOException
    {
        File failureFile = failureFile( indexId );
        try ( RandomAccessFile rwFile = new RandomAccessFile( failureFile, "rw" ) )
        {
            FileChannel channel = rwFile.getChannel();
            byte[] data = failure.getBytes( "utf-8" );
            channel.write( ByteBuffer.wrap( data, 0, Math.min( data.length, MAX_FAILURE_SIZE ) ) );

            channel.force( true );
            channel.close();
        }
    }

    /**
     * Store failure in failure file for index with the given id
     *
     * @param indexId of the index that failed
     * @param failure message describing the failure that needs to be stored
     * @throws IOException if the failure could not be stored
     */
    public synchronized void storeIndexFailure( long indexId, String failure ) throws IOException
    {
        File failureFile = failureFile( indexId );
        RandomAccessFile rwFile = new RandomAccessFile( failureFile, "rw" );
        try
        {
            FileChannel channel = rwFile.getChannel();
            byte[] data = failure.getBytes( "utf-8" );
            channel.write( wrap( data, 0, Math.min( data.length, MAX_FAILURE_SIZE ) ) );

            channel.force( true );
            channel.close();
        }
        finally
        {
            rwFile.close();
        }
    }

Try With Resources try(RandomAccessFile rwFile=new RandomAccessFile(failureFile,"rw")) in method public storeIndexFailure(indexId long, failure String) : void from class org.neo4j.kernel.api.index.util.FailureStorage


    private String readFailure( File failureFile ) throws IOException
    {
        try ( RandomAccessFile rwFile = new RandomAccessFile( failureFile, "r" ) )
        {
            FileChannel channel = rwFile.getChannel();
            byte[] data = new byte[(int) channel.size()];
            int readData = channel.read( ByteBuffer.wrap( data ) );
            channel.close();

            return readData <= 0 ? "" : new String( withoutZeros( data ), "utf-8" );
        }
    }

    private String readFailure( File failureFile ) throws IOException
    {
        RandomAccessFile rwFile = new RandomAccessFile( failureFile, "r" );
        try
        {
            FileChannel channel = rwFile.getChannel();
            byte[] data = new byte[ (int) channel.size() ];
            int readData = channel.read( wrap( data ) );
            channel.close();

            return readData <= 0 ? "" : new String( withoutZeros( data) , "utf-8" );
        }
        finally
        {
            rwFile.close();
        }
    }

Try With Resources try(RandomAccessFile rwFile=new RandomAccessFile(failureFile,"r")) in method private readFailure(failureFile File) : String from class org.neo4j.kernel.api.index.util.FailureStorage


    private boolean isFailed( File failureFile ) throws IOException
    {
        try ( RandomAccessFile rFile = new RandomAccessFile( failureFile, "r" ) )
        {
            FileChannel channel = rFile.getChannel();
            byte[] data = new byte[(int) channel.size()];
            channel.read( ByteBuffer.wrap( data ) );
            channel.close();
            return !allZero( data );
        }
    }

    private boolean isFailed( File failureFile ) throws IOException
    {
        RandomAccessFile rFile = new RandomAccessFile( failureFile, "r" );
        try
        {
            FileChannel channel = rFile.getChannel();
            byte[] data = new byte[ (int) channel.size() ];
            channel.read( ByteBuffer.wrap( data ) );
            channel.close();
            return !allZero( data );
        }
        finally
        {
            rFile.close();
        }
    }

Try With Resources try(RandomAccessFile rFile=new RandomAccessFile(failureFile,"r")) in method private isFailed(failureFile File) : boolean from class org.neo4j.kernel.api.index.util.FailureStorage


    void delistResourcesForTransaction() throws NotInTransactionException
    {
        Transaction tx = this.getCurrentTransaction();
        if ( tx == null )
        {
            throw new NotInTransactionException();
        }
        T con = txConnectionMap.get( tx );
        if ( con != null )
        {
            try
            {
                con.delistResource(tx, XAResource.TMSUCCESS);
            }
            catch ( IllegalStateException | SystemException e )
            {
                throw new RuntimeException(
                        "Unable to delist lucene resource from tx", e );
            }
        }
    }

    void delistResourcesForTransaction() throws NotInTransactionException
    {
        Transaction tx = this.getCurrentTransaction();
        if ( tx == null )
        {
            throw new NotInTransactionException();
        }
        T con = txConnectionMap.get( tx );
        if ( con != null )
        {
            try
            {
                con.delistResource(tx, XAResource.TMSUCCESS);
            }
            catch ( IllegalStateException e )
            {
                throw new RuntimeException(
                        "Unable to delist lucene resource from tx", e );
            }
            catch ( SystemException e )
            {
                throw new RuntimeException(
                        "Unable to delist lucene resource from tx", e );
            }
        }
    }

Merge Catch [catch(IllegalStateException e), catch(SystemException e)] to catch(IllegalStateException|SystemException e) in method package delistResourcesForTransaction() : void from class org.neo4j.kernel.impl.index.IndexConnectionBroker


    public static void validateUniqueness( Iterable<NodePropertyUpdate> updates, Lookup lookup )
            throws IndexEntryConflictException, IOException
    {
        Map<Object, DiffSets<Long>> referenceCount = new HashMap<>();

        for ( NodePropertyUpdate update : updates )
        {
            switch ( update.getUpdateMode() )
            {
                case ADDED:
                    propertyValueDiffSet( referenceCount, update.getValueAfter() ).add( update.getNodeId() );
                    break;
                case CHANGED:
                    propertyValueDiffSet( referenceCount, update.getValueBefore() ).remove( update.getNodeId() );
                    propertyValueDiffSet( referenceCount, update.getValueAfter() ).add( update.getNodeId() );
                    break;
                case REMOVED:
                    propertyValueDiffSet( referenceCount, update.getValueBefore() ).remove( update.getNodeId() );
                    break;
                default:
                    throw new UnsupportedOperationException();
            }
        }

        for ( Map.Entry<Object, DiffSets<Long>> entry : referenceCount.entrySet() )
        {
            Object value = entry.getKey();
            int delta = entry.getValue().delta();
            if ( delta > 1 )
            {
                throw new DuplicateIndexEntryConflictException( value, asSet( entry.getValue().getAdded() ) );
            }
            if ( delta == 1 )
            {
                Long addedNode = single( entry.getValue().getAdded() );

                Long existingNode = lookup.currentlyIndexedNode( value );

                if ( existingNode != null && !addedNode.equals( existingNode ) )
                {
                    throw new PreexistingIndexEntryConflictException( value, existingNode, addedNode );
                }
            }
        }
    }

    public static void validateUniqueness( Iterable<NodePropertyUpdate> updates, Lookup lookup )
            throws IndexEntryConflictException, IOException
    {
        Map<Object, DiffSets<Long>> referenceCount = new HashMap<Object, DiffSets<Long>>();

        for ( NodePropertyUpdate update : updates )
        {
            switch ( update.getUpdateMode() )
            {
                case ADDED:
                    propertyValueDiffSet( referenceCount, update.getValueAfter() ).add( update.getNodeId() );
                    break;
                case CHANGED:
                    propertyValueDiffSet( referenceCount, update.getValueBefore() ).remove( update.getNodeId() );
                    propertyValueDiffSet( referenceCount, update.getValueAfter() ).add( update.getNodeId() );
                    break;
                case REMOVED:
                    propertyValueDiffSet( referenceCount, update.getValueBefore() ).remove( update.getNodeId() );
                    break;
                default:
                    throw new UnsupportedOperationException();
            }
        }

        for ( Map.Entry<Object, DiffSets<Long>> entry : referenceCount.entrySet() )
        {
            Object value = entry.getKey();
            int delta = entry.getValue().delta();
            if ( delta > 1 )
            {
                throw new DuplicateIndexEntryConflictException( value, asSet( entry.getValue().getAdded() ) );
            }
            if ( delta == 1 )
            {
                Long addedNode = single( entry.getValue().getAdded() );

                Long existingNode = lookup.currentlyIndexedNode( value );

                if ( existingNode != null && !addedNode.equals( existingNode ) )
                {
                    throw new PreexistingIndexEntryConflictException( value, existingNode, addedNode );
                }
            }
        }
    }

Replace Generic With Diamond HashMap<Object,DiffSets<Long>> with HashMap<> in method public validateUniqueness(updates Iterable<NodePropertyUpdate>, lookup Lookup) : void from class org.neo4j.kernel.impl.api.index.PropertyUpdateUniquenessValidator


    private static DiffSets<Long> propertyValueDiffSet( Map<Object, DiffSets<Long>> referenceCount, Object value )
    {
        DiffSets<Long> diffSets = referenceCount.get( value );
        if ( diffSets == null )
        {
            referenceCount.put( value, diffSets = new DiffSets<>() );
        }
        return diffSets;
    }

    private static DiffSets<Long> propertyValueDiffSet( Map<Object, DiffSets<Long>> referenceCount, Object value )
    {
        DiffSets<Long> diffSets = referenceCount.get( value );
        if ( diffSets == null )
        {
            referenceCount.put( value, diffSets = new DiffSets<Long>() );
        }
        return diffSets;
    }

Replace Generic With Diamond DiffSets<Long> with DiffSets<> in method private propertyValueDiffSet(referenceCount Map<Object,DiffSets<Long>>, value Object) : DiffSets<Long> from class org.neo4j.kernel.impl.api.index.PropertyUpdateUniquenessValidator


            @Override
            public void run()
            {
                latch.awaitStart();
                Statement statement = statementContextProvider.statement();
                try ( Transaction tx = db.beginTx() )
                {
                    statement.readOperations().nodeGetUniqueFromIndexLookup( index, value );
                    statement.close();
                    tx.success();
                }
                catch ( IndexNotFoundKernelException | IndexBrokenKernelException e )
                {
                    throw new RuntimeException( e );
                }
                finally
                {
                    latch.finish();
                }
            }

            @Override
            public void run()
            {
                latch.awaitStart();
                Transaction tx = db.beginTx();
                Statement statement = statementContextProvider.statement();
                try
                {
                    statement.readOperations().nodeGetUniqueFromIndexLookup( index, value );
                    statement.close();
                    tx.success();
                }
                catch ( IndexNotFoundKernelException | IndexBrokenKernelException e )
                {
                    throw new RuntimeException( e );
                }
                finally
                {
                    tx.close();
                    latch.finish();
                }
            }

Try With Resources try(Transaction tx=db.beginTx()) in method public run() : void from class org.neo4j.kernel.impl.api.integrationtest.NodeGetUniqueFromIndexLookupIT.shouldBlockUniqueNodeLookupFromCompetingTransaction.runnableForThread2.new Runnable


    private <T> T transaction( Function<? super GraphDatabaseService, T> function, boolean commit )
    {
        try ( Transaction tx = database.beginTx() )
        {
            T result = function.apply( database );

            if ( commit )
            {
                tx.success();
            }
            return result;
        }
    }

    public <T> T transaction( Function<GraphDatabaseService, T> function, boolean commit )
    {
        Transaction tx = database.beginTx();
        try
        {
            T result = function.apply( database );

            if ( commit )
            {
                tx.success();
            }
            return result;
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=database.beginTx()) in method private transaction(function Function<? super GraphDatabaseService,T>, commit boolean) : T from class org.neo4j.test.DatabaseRule


    @Override
    public <RESULT, FAILURE extends KernelException> RESULT execute( MicroTransaction<RESULT, FAILURE> transaction )
            throws FAILURE
    {
        try ( Statement statement = acquireStatement() )
        {
            return transaction.work.perform( operations, statement );
        }
    }

    @Override
    public <RESULT, FAILURE extends KernelException> RESULT execute( MicroTransaction<RESULT, FAILURE> transaction )
            throws FAILURE
    {
        Statement statement = acquireStatement();
        try
        {
            return transaction.work.perform( operations, statement );
        }
        finally
        {
            releaseStatement( statement );
        }
    }

Try With Resources try(Statement statement=acquireStatement()) in method public execute(transaction MicroTransaction<RESULT,FAILURE>) : RESULT from class org.neo4j.kernel.api.KernelTransactionImplementation


            @Override
            public void run()
            {
                latch.awaitStart();
                Transaction tx = db.beginTx();
                Statement statement = statementContextProvider.statement();
                try
                {
                    statement.readOperations().nodeGetUniqueFromIndexLookup( index, value );
                    statement.close();
                    tx.success();
                }
                catch ( IndexNotFoundKernelException | IndexBrokenKernelException e )
                {
                    throw new RuntimeException( e );
                }
                finally
                {
                    tx.close();
                    latch.finish();
                }
            }

            @Override
            public void run()
            {
                latch.awaitStart();
                Transaction tx = db.beginTx();
                DataStatement statement = statementContextProvider.dataStatement();
                try
                {
                    statement.nodeGetUniqueFromIndexLookup( index, value );
                    statement.close();
                    tx.success();
                }
                catch ( IndexNotFoundKernelException e )
                {
                    throw new RuntimeException( e );
                }
                catch ( IndexBrokenKernelException e )
                {
                    throw new RuntimeException( e );
                }
                finally
                {
                    tx.close();
                    latch.finish();
                }
            }

Merge Catch [catch(IndexNotFoundKernelException e), catch(IndexBrokenKernelException e)] to catch(IndexNotFoundKernelException|IndexBrokenKernelException e) in method public run() : void from class org.neo4j.kernel.impl.api.integrationtest.NodeGetUniqueFromIndexLookupIT.shouldBlockUniqueNodeLookupFromCompetingTransaction.runnableForThread2.new Runnable


    public T obtainEntity()
    {
        GraphDatabaseService graphDatabaseService = dbRule.getGraphDatabaseService();

        try ( Transaction tx = graphDatabaseService.beginTx() )
        {
            T result = obtainEntityInTransaction( graphDatabaseService );
            tx.success();

            return result;
        }
    }

    public T obtainEntity()
    {
        GraphDatabaseService graphDatabaseService = dbRule.getGraphDatabaseService();

        Transaction tx = graphDatabaseService.beginTx();
        try
        {
            T result = obtainEntityInTransaction( graphDatabaseService );
            tx.success();

            return result;
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=graphDatabaseService.beginTx()) in method public obtainEntity() : T from class org.neo4j.graphdb.AbstractMandatoryTransactionsTest


    private void createAlistairAndStefanNodes()
    {
        try ( Transaction tx = graphDb.beginTx() )
        {
            alistair = graphDb.createNode( label );
            alistair.setProperty( "name", "Alistair" );
            stefan = graphDb.createNode( label );
            stefan.setProperty( "name", "Stefan" );
            tx.success();
        }
    }

    private void createAlistairAndStefanNodes()
    {
        Transaction tx = graphDb.beginTx();
        try
        {
            alistair = graphDb.createNode( label );
            alistair.setProperty( "name", "Alistair" );
            stefan = graphDb.createNode( label );
            stefan.setProperty( "name", "Stefan" );
            tx.success();
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=graphDb.beginTx()) in method private createAlistairAndStefanNodes() : void from class org.neo4j.kernel.impl.nioneo.xa.NeoStoreIndexStoreViewTest


    private void deleteAlistairAndStefanNodes()
    {
        try ( Transaction tx = graphDb.beginTx() )
        {
            alistair.delete();
            stefan.delete();
            tx.success();
        }
    }

    private void deleteAlistairAndStefanNodes()
    {
        Transaction tx = graphDb.beginTx();
        try
        {
            alistair.delete();
            stefan.delete();
            tx.success();
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=graphDb.beginTx()) in method private deleteAlistairAndStefanNodes() : void from class org.neo4j.kernel.impl.nioneo.xa.NeoStoreIndexStoreViewTest


    private void getOrCreateIds() throws SchemaKernelException
    {
        try ( Transaction tx = graphDb.beginTx() )
        {
            ThreadToStatementContextBridge bridge =
                    graphDb.getDependencyResolver().resolveDependency( ThreadToStatementContextBridge.class );

            try ( DataStatement statement = bridge.dataStatement() )
            {
                labelId = statement.labelGetOrCreateForName( "Person" );
                propertyKeyId = statement.propertyKeyGetOrCreateForName(  "name" );
            }
            tx.success();
        }
    }

    private void getOrCreateIds() throws SchemaKernelException
    {
        Transaction tx = graphDb.beginTx();
        try
        {
            ThreadToStatementContextBridge bridge =
                    graphDb.getDependencyResolver().resolveDependency( ThreadToStatementContextBridge.class );

            DataStatement statement = bridge.dataStatement();
            labelId = statement.labelGetOrCreateForName( "Person" );
            propertyKeyId = statement.propertyKeyGetOrCreateForName(  "name" );
            statement.close();
            tx.success();
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(DataStatement statement=bridge.dataStatement()) in method private getOrCreateIds() : void from class org.neo4j.kernel.impl.nioneo.xa.NeoStoreIndexStoreViewTest


    @Deprecated
    public static Args parseMapFromConfigValue( String name, String configValue )
    {
        Map<String, String> result = new HashMap<>();
        for ( String part : configValue.split( quote( "," ) ) )
        {
            String[] tokens = part.split( quote( "=" ) );
            if ( tokens.length != 2 )
            {
                throw new RuntimeException( "Invalid configuration value '" + configValue +
                        "' for " + name + ". The format is [true/false] or [key1=value1,key2=value2...]" );
            }
            result.put( tokens[0], tokens[1] );
        }
        return new Args( result );
    }

    @Deprecated
    public static Args parseMapFromConfigValue( String name, String configValue )
    {
        Map<String, String> result = new HashMap<String, String>();
        for ( String part : configValue.split( quote( "," ) ) )
        {
            String[] tokens = part.split( quote( "=" ) );
            if ( tokens.length != 2 )
            {
                throw new RuntimeException( "Invalid configuration value '" + configValue +
                        "' for " + name + ". The format is [true/false] or [key1=value1,key2=value2...]" );
            }
            result.put( tokens[0], tokens[1] );
        }
        return new Args( result );
    }

Replace Generic With Diamond HashMap<String,String> with HashMap<> in method public parseMapFromConfigValue(name String, configValue String) : Args from class org.neo4j.kernel.configuration.GraphDatabaseConfigurationMigrator


    @Test
    public void crudOnHighIds() throws Exception
    {
        // Create stuff
        List<Node> nodes = new ArrayList<>();
        Transaction tx = db.beginTx();
        int numberOfNodes = SIZE_PER_JUMP * 3;
        String stringValue = "a longer string than short";
        byte[] arrayValue = new byte[]{3, 7};
        for ( int i = 0; i < numberOfNodes; i++ )
        {
            Node node = db.createNode();
            node.setProperty( "number", i );
            node.setProperty( "string", stringValue );
            node.setProperty( "array", arrayValue );
            nodes.add( node );
        }

        int numberOfRels = numberOfNodes - 100;
        for ( int i = 0; i < numberOfRels; i++ )
        {
            Node node1 = nodes.get( i / 100 );
            Node node2 = nodes.get( i + 1 );
            node1.createRelationshipTo( node2, TYPE );
        }

        tx.success();
        tx.finish();

        // Verify
        tx = db.beginTx();
        int relCount = 0;
        for ( int t = 0; t < 2; t++ )
        {
            int nodeCount = 0;
            relCount = 0;
            for ( Node node : nodes )
            {
                node = db.getNodeById( node.getId() );
                assertProperties( map( "number", nodeCount++, "string", stringValue, "array", arrayValue ), node );
                relCount += count( node.getRelationships( Direction.OUTGOING ) );
            }
            db.getNodeManager().clearCache();
        }
        assertEquals( numberOfRels, relCount );
        tx.finish();

        // Remove stuff
        tx = db.beginTx();
        for ( int i = 0; i < nodes.size(); i++ )
        {
            Node node = nodes.get( i );
            switch ( i % 6 )
            {
                case 0:
                    node.removeProperty( "number" );
                    break;
                case 1:
                    node.removeProperty( "string" );
                    break;
                case 2:
                    node.removeProperty( "array" );
                    break;
                case 3:
                    node.removeProperty( "number" );
                    node.removeProperty( "string" );
                    node.removeProperty( "array" );
                    break;
                case 4:
                    node.setProperty( "new", 34 );
                    break;
                case 5:
                    Object oldValue = node.getProperty( "string", null );
                    if ( oldValue != null )
                    {
                        node.setProperty( "string", "asjdkasdjkasjdkasjdkasdjkasdj" );
                        node.setProperty( "string", stringValue );
                    }
            }

            if ( count( node.getRelationships() ) > 50 )
            {
                if ( i % 2 == 0 )
                {
                    deleteIfNotNull( firstOrNull( node.getRelationships() ) );
                    deleteIfNotNull( lastOrNull( node.getRelationships() ) );
                }
                else
                {
                    deleteEveryOther( node.getRelationships() );
                }

                setPropertyOnAll( node.getRelationships( Direction.OUTGOING ), "relprop", "rel value" );
            }
            else if ( i % 20 == 0 )
            {
                Node otherNode = nodes.get( nodes.size() - i - 1 );
                Relationship rel = node.createRelationshipTo( otherNode, TYPE2 );
                rel.setProperty( "other relprop", 1010 );
            }
        }
        tx.success();
        tx.finish();

        // Verify again
        tx = db.beginTx();
        for ( int t = 0; t < 2; t++ )
        {
            int nodeCount = 0;
            for ( Node node : nodes )
            {
                node = db.getNodeById( node.getId() );
                switch ( nodeCount % 6 )
                {
                    case 0:
                        assertProperties( map( "string", stringValue, "array", arrayValue ), node );
                        break;
                    case 1:
                        assertProperties( map( "number", nodeCount, "array", arrayValue ), node );
                        break;
                    case 2:
                        assertProperties( map( "number", nodeCount, "string", stringValue ), node );
                        break;
                    case 3:
                        assertEquals( 0, count( node.getPropertyKeys() ) );
                        break;
                    case 4:
                        assertProperties( map( "number", nodeCount, "string", stringValue, "array", arrayValue,
                                "new", 34 ), node );
                        break;
                    case 5:
                        assertProperties( map( "number", nodeCount, "string", stringValue, "array", arrayValue ),
                                node );
                        break;
                    default:
                }

                for ( Relationship rel : node.getRelationships( Direction.OUTGOING ) )
                {
                    if ( rel.isType( TYPE ) )
                    {
                        assertProperties( map( "relprop", "rel value" ), rel );
                    }
                    else if ( rel.isType( TYPE2 ) )
                    {
                        assertProperties( map( "other relprop", 1010 ), rel );
                    }
                    else
                    {
                        fail( "Invalid type " + rel.getType() + " for " + rel );
                    }
                }
                nodeCount++;
            }
            db.getNodeManager().clearCache();
        }
        tx.finish();
    }

    @Test
    public void crudOnHighIds() throws Exception
    {
        // Create stuff
        List<Node> nodes = new ArrayList<Node>();
        Transaction tx = db.beginTx();
        int numberOfNodes = SIZE_PER_JUMP * 3;
        String stringValue = "a longer string than short";
        byte[] arrayValue = new byte[]{3, 7};
        for ( int i = 0; i < numberOfNodes; i++ )
        {
            Node node = db.createNode();
            node.setProperty( "number", i );
            node.setProperty( "string", stringValue );
            node.setProperty( "array", arrayValue );
            nodes.add( node );
        }

        int numberOfRels = numberOfNodes - 100;
        for ( int i = 0; i < numberOfRels; i++ )
        {
            Node node1 = nodes.get( i / 100 );
            Node node2 = nodes.get( i + 1 );
            node1.createRelationshipTo( node2, TYPE );
        }

        tx.success();
        tx.finish();

        // Verify
        tx = db.beginTx();
        int relCount = 0;
        for ( int t = 0; t < 2; t++ )
        {
            int nodeCount = 0;
            relCount = 0;
            for ( Node node : nodes )
            {
                node = db.getNodeById( node.getId() );
                assertProperties( map( "number", nodeCount++, "string", stringValue, "array", arrayValue ), node );
                relCount += count( node.getRelationships( Direction.OUTGOING ) );
            }
            db.getNodeManager().clearCache();
        }
        assertEquals( numberOfRels, relCount );
        tx.finish();

        // Remove stuff
        tx = db.beginTx();
        for ( int i = 0; i < nodes.size(); i++ )
        {
            Node node = nodes.get( i );
            switch ( i % 6 )
            {
                case 0:
                    node.removeProperty( "number" );
                    break;
                case 1:
                    node.removeProperty( "string" );
                    break;
                case 2:
                    node.removeProperty( "array" );
                    break;
                case 3:
                    node.removeProperty( "number" );
                    node.removeProperty( "string" );
                    node.removeProperty( "array" );
                    break;
                case 4:
                    node.setProperty( "new", 34 );
                    break;
                case 5:
                    Object oldValue = node.getProperty( "string", null );
                    if ( oldValue != null )
                    {
                        node.setProperty( "string", "asjdkasdjkasjdkasjdkasdjkasdj" );
                        node.setProperty( "string", stringValue );
                    }
            }

            if ( count( node.getRelationships() ) > 50 )
            {
                if ( i % 2 == 0 )
                {
                    deleteIfNotNull( firstOrNull( node.getRelationships() ) );
                    deleteIfNotNull( lastOrNull( node.getRelationships() ) );
                }
                else
                {
                    deleteEveryOther( node.getRelationships() );
                }

                setPropertyOnAll( node.getRelationships( Direction.OUTGOING ), "relprop", "rel value" );
            }
            else if ( i % 20 == 0 )
            {
                Node otherNode = nodes.get( nodes.size() - i - 1 );
                Relationship rel = node.createRelationshipTo( otherNode, TYPE2 );
                rel.setProperty( "other relprop", 1010 );
            }
        }
        tx.success();
        tx.finish();

        // Verify again
        tx = db.beginTx();
        for ( int t = 0; t < 2; t++ )
        {
            int nodeCount = 0;
            for ( Node node : nodes )
            {
                node = db.getNodeById( node.getId() );
                switch ( nodeCount % 6 )
                {
                    case 0:
                        assertProperties( map( "string", stringValue, "array", arrayValue ), node );
                        break;
                    case 1:
                        assertProperties( map( "number", nodeCount, "array", arrayValue ), node );
                        break;
                    case 2:
                        assertProperties( map( "number", nodeCount, "string", stringValue ), node );
                        break;
                    case 3:
                        assertEquals( 0, count( node.getPropertyKeys() ) );
                        break;
                    case 4:
                        assertProperties( map( "number", nodeCount, "string", stringValue, "array", arrayValue,
                                "new", 34 ), node );
                        break;
                    case 5:
                        assertProperties( map( "number", nodeCount, "string", stringValue, "array", arrayValue ),
                                node );
                        break;
                    default:
                }

                for ( Relationship rel : node.getRelationships( Direction.OUTGOING ) )
                {
                    if ( rel.isType( TYPE ) )
                    {
                        assertProperties( map( "relprop", "rel value" ), rel );
                    }
                    else if ( rel.isType( TYPE2 ) )
                    {
                        assertProperties( map( "other relprop", 1010 ), rel );
                    }
                    else
                    {
                        fail( "Invalid type " + rel.getType() + " for " + rel );
                    }
                }
                nodeCount++;
            }
            db.getNodeManager().clearCache();
        }
        tx.finish();
    }

Replace Generic With Diamond ArrayList<Node> with ArrayList<> in method public crudOnHighIds() : void from class org.neo4j.kernel.impl.core.BigJumpingStoreIT


    private static Map<TestValue, Set<Object>> runFindByLabelAndProperty( GraphDatabaseService db )
    {
        HashMap<TestValue, Set<Object>> results = new HashMap<>();
        try ( Transaction tx = db.beginTx() )
        {
            for ( TestValue value : TestValue.values() )
            {
                addToResults( db, results, value );
            }
            tx.success();
        }
        return results;
    }

    private static Map<TestValue, Set<Object>> runFindByLabelAndProperty( GraphDatabaseService db )
    {
        HashMap<TestValue, Set<Object>> results = new HashMap<>();
        Transaction tx = db.beginTx();
        try
        {
            for ( TestValue value : TestValue.values() )
            {
                addToResults( db, results, value );
            }
        }
        finally
        {
            tx.finish();
        }
        return results;
    }

Try With Resources try(Transaction tx=db.beginTx()) in method private runFindByLabelAndProperty(db GraphDatabaseService) : Map<TestValue,Set<Object>> from class org.neo4j.kernel.api.index.SchemaProviderApprovalTest


        @Override
        public Iterable<Relationship> getRelationships( Direction direction )
        {
            return new ArrayList<>();
        }

        @Override
        public Iterable<Relationship> getRelationships( Direction direction )
        {
            return new ArrayList<Relationship>();
        }

Replace Generic With Diamond ArrayList<Relationship> with ArrayList<> in method public getRelationships(direction Direction) : Iterable<Relationship> from class org.neo4j.shell.kernel.apps.NodeOrRelationship.WrapRelationship


        @Override
        public IndexReader newReader( long indexId ) throws IndexNotFoundKernelException
        {
            if( indexReaders == null )
            {
                indexReaders = new HashMap<>();
            }

            IndexReader reader = indexReaders.get( indexId );
            if ( reader == null )
            {
                IndexProxy index = indexingService.getProxyForRule( indexId );
                reader = index.newReader();
                indexReaders.put( indexId, reader );
            }
            return reader;
        }

        @Override
        public IndexReader newReader( long indexId ) throws IndexNotFoundKernelException
        {
            if( indexReaders == null )
            {
                indexReaders = new HashMap<Long, IndexReader>();
            }

            IndexReader reader = indexReaders.get( indexId );
            if ( reader == null )
            {
                IndexProxy index = indexingService.getProxyForRule( indexId );
                reader = index.newReader();
                indexReaders.put( indexId, reader );
            }
            return reader;
        }

Replace Generic With Diamond HashMap<Long,IndexReader> with HashMap<> in method public newReader(indexId long) : IndexReader from class org.neo4j.kernel.impl.api.IndexReaderFactory.Caching


    private static Node createLabeledNode( GraphDatabaseService db, Map<String, Object> properties, Label... labels )
    {
        try ( Transaction tx = db.beginTx() )
        {
            Node node = db.createNode( labels );
            for ( Map.Entry<String, Object> property : properties.entrySet() )
            {
                node.setProperty( property.getKey(), property.getValue() );
            }
            tx.success();
            return node;
        }
    }

    private static Node createLabeledNode( GraphDatabaseService db, Map<String, Object> properties, Label... labels )
    {
        Transaction tx = db.beginTx();
        try
        {
            Node node = db.createNode( labels );
            for ( Map.Entry<String, Object> property : properties.entrySet() )
                node.setProperty( property.getKey(), property.getValue() );
            tx.success();
            return node;
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=db.beginTx()) in method private createLabeledNode(db GraphDatabaseService, properties Map<String,Object>, labels Label...) : Node from class org.neo4j.kernel.impl.api.StoreStatementOperationsTest