    @Test
    public void closingTheCursorMustUnlockModifiedPage() throws Exception
    {
        writeInitialDataTo( file( "a" ) );

        final MuninnPageCache pageCache = createPageCache( fs, 2, 8, PageCacheTracer.NULL );
        final PagedFile pagedFile = pageCache.map( file( "a" ), 8 );

        Future<?> task = executor.submit( () -> {
            try ( PageCursor cursor = pagedFile.io( 0, PF_EXCLUSIVE_LOCK ) )
            {
                assertTrue( cursor.next() );
                cursor.putLong( 41 );
            }
            catch ( IOException e )
            {
                throw new RuntimeException( e );
            }
        } );
        task.get();

        try ( PageCursor cursor = pagedFile.io( 0, PF_EXCLUSIVE_LOCK ) )
        {
            assertTrue( cursor.next() );
            long value = cursor.getLong();
            cursor.setOffset( 0 );
            cursor.putLong( value + 1 );
        }

        int clockArm = pageCache.evictPages( 1, 0, EvictionRunEvent.NULL );
        assertThat( clockArm, is( 1 ) );

        ByteBuffer buf = ByteBuffer.allocate( 16 );
        StoreChannel channel = fs.open( file( "a" ), "r" );
        channel.read( buf );
        buf.flip();
        assertThat( buf.getLong(), is( 42L ) );
        assertThat( buf.getLong(), is( y ) );
    }

    @Test
    public void closingTheCursorMustUnlockModifiedPage() throws Exception
    {
        writeInitialDataTo( file( "a" ) );

        final MuninnPageCache pageCache = createPageCache( fs, 2, 8, PageCacheTracer.NULL );
        final PagedFile pagedFile = pageCache.map( file( "a" ), 8 );

        Future<?> task = executor.submit( new Runnable()
        {
            @Override
            public void run()
            {
                try ( PageCursor cursor = pagedFile.io( 0, PF_EXCLUSIVE_LOCK ) )
                {
                    assertTrue( cursor.next() );
                    cursor.putLong( 41 );
                }
                catch ( IOException e )
                {
                    throw new RuntimeException( e );
                }
            }
        } );
        task.get();

        try ( PageCursor cursor = pagedFile.io( 0, PF_EXCLUSIVE_LOCK ) )
        {
            assertTrue( cursor.next() );
            long value = cursor.getLong();
            cursor.setOffset( 0 );
            cursor.putLong( value + 1 );
        }

        int clockArm = pageCache.evictPages( 1, 0, EvictionRunEvent.NULL );
        assertThat( clockArm, is( 1 ) );

        ByteBuffer buf = ByteBuffer.allocate( 16 );
        StoreChannel channel = fs.open( file( "a" ), "r" );
        channel.read( buf );
        buf.flip();
        assertThat( buf.getLong(), is( 42L ) );
        assertThat( buf.getLong(), is( y ) );
    }

Replace Anonymous With Lambda org.neo4j.io.pagecache.impl.muninn.MuninnPageCacheTest.closingTheCursorMustUnlockModifiedPage.task.submit.new Runnable with () -> {try(PageCursor cursor=pagedFile.io(0,PF_EXCLUSIVE_LOCK))assertTrue(cursor.next()); in method public closingTheCursorMustUnlockModifiedPage() : void from class org.neo4j.io.pagecache.impl.muninn.MuninnPageCacheTest


    private String[] backupArguments( String from, String to, String clusterName )
    {
        List<String> args = new ArrayList<>();
        args.add( "-from" );
        args.add( from );
        args.add( "-to" );
        args.add( to );
        if ( clusterName != null )
        {
            args.add( "-cluster" );
            args.add( clusterName );
        }
        return args.toArray( new String[args.size()] );
    }

    private String[] backupArguments( String from, String to, String clusterName )
    {
        List<String> args = new ArrayList<String>();
        args.add( "-from" );
        args.add( from );
        args.add( "-to" );
        args.add( to );
        if ( clusterName != null )
        {
            args.add( "-cluster" );
            args.add( clusterName );
        }
        return args.toArray( new String[args.size()] );
    }

Replace Generic With Diamond ArrayList<String> with ArrayList<> in method private backupArguments(from String, to String, clusterName String) : String[] from class org.neo4j.ha.BackupHaIT


    private static Sampleable[] checkDataSources( String rrdPath, Sampleable[] sampleables ) throws IOException
    {
        RrdDb rrdDb = new RrdDb( rrdPath, true );
        List<Sampleable> missing = new ArrayList<>();
        for ( Sampleable sampleable : sampleables )
        {
            if ( rrdDb.getDatasource( sampleable.getName() ) == null )
            {
                missing.add( sampleable );
            }
        }
        rrdDb.close();
        return missing.toArray( new Sampleable[missing.size()] );
    }

    private static Sampleable[] checkDataSources( String rrdPath, Sampleable[] sampleables ) throws IOException
    {
        RrdDb rrdDb = new RrdDb( rrdPath, true );
        List<Sampleable> missing = new ArrayList<Sampleable>();
        for ( Sampleable sampleable : sampleables )
        {
            if ( rrdDb.getDatasource( sampleable.getName() ) == null )
            {
                missing.add( sampleable );
            }
        }
        rrdDb.close();
        return missing.toArray( new Sampleable[missing.size()] );
    }

Replace Generic With Diamond ArrayList<Sampleable> with ArrayList<> in method private checkDataSources(rrdPath String, sampleables Sampleable[]) : Sampleable[] from class org.neo4j.server.rrd.RrdFactory


	private void emit( Walker walker, GraphvizRenderer renderer )
	    throws IOException
	{
		walker.accept( new Visualizer<>( renderer ) );
	}

	private void emit( Walker walker, GraphvizRenderer renderer )
	    throws IOException
	{
		walker.accept( new Visualizer<IOException>( renderer ) );
	}

Replace Generic With Diamond Visualizer<IOException> with Visualizer<> in method private emit(walker Walker, renderer GraphvizRenderer) : void from class org.neo4j.visualization.graphviz.GraphvizWriter


    private ObjectName createObjectName( final String domainName, final String objectName )
    {
        try
        {
            return new ObjectName( domainName + ":" + URLDecoder.decode( objectName, StandardCharsets.UTF_8.name() ) );
        }
        catch ( MalformedObjectNameException | UnsupportedEncodingException e )
        {
            throw new WebApplicationException( e, 400 );
        }
    }

    private ObjectName createObjectName( final String domainName, final String objectName )
    {
        try
        {
            return new ObjectName( domainName + ":" + URLDecoder.decode( objectName, "UTF-8" ) );
        }
        catch ( MalformedObjectNameException e )
        {
            throw new WebApplicationException( e, 400 );
        }
        catch ( UnsupportedEncodingException e )
        {
            throw new WebApplicationException( e, 400 );
        }
    }

Merge Catch [catch(MalformedObjectNameException e), catch(UnsupportedEncodingException e)] to catch(MalformedObjectNameException|UnsupportedEncodingException e) in method private createObjectName(domainName String, objectName String) : ObjectName from class org.neo4j.server.rest.management.JmxService


    /**
     * Creates a new id generator.
     *
     * @param fileName The name of the id generator
     * @param throwIfFileExists if {@code true} will cause an {@link UnderlyingStorageException} to be thrown if
     * the file already exists. if {@code false} will truncate the file writing the header in it.
     */
    public static void createGenerator( FileSystemAbstraction fs, File fileName, long highId,
                                        boolean throwIfFileExists )
    {
        // sanity checks
        if ( fs == null )
        {
            throw new IllegalArgumentException( "Null filesystem" );
        }
        if ( fileName == null )
        {
            throw new IllegalArgumentException( "Null filename" );
        }
        if ( throwIfFileExists && fs.fileExists( fileName ) )
        {
            throw new IllegalStateException( "Can't create IdGeneratorFile["
                + fileName + "], file already exists" );
        }
        try ( StoreChannel channel = fs.create( fileName ) )
        {
            // write the header
            channel.truncate( 0 );
            ByteBuffer buffer = ByteBuffer.allocate( HEADER_SIZE );
            buffer.put( CLEAN_GENERATOR ).putLong( highId ).flip();
            channel.write( buffer );
            channel.force( false );
        }
        catch ( IOException e )
        {
            throw new UnderlyingStorageException(
                "Unable to create id generator" + fileName, e );
        }
    }

    /**
     * Creates a new id generator.
     *
     * @param fileName
     *            The name of the id generator
     * @param throwIfFileExists
     */
    public static void createGenerator( FileSystemAbstraction fs, File fileName, long highId,
                                        boolean throwIfFileExists )
    {
        // sanity checks
        if ( fs == null )
        {
            throw new IllegalArgumentException( "Null filesystem" );
        }
        if ( fileName == null )
        {
            throw new IllegalArgumentException( "Null filename" );
        }
        if ( throwIfFileExists && fs.fileExists( fileName ) )
        {
            throw new IllegalStateException( "Can't create IdGeneratorFile["
                + fileName + "], file already exists" );
        }
        try
        {
            StoreChannel channel = fs.create( fileName );
            // write the header
            ByteBuffer buffer = ByteBuffer.allocate( HEADER_SIZE );
            buffer.put( CLEAN_GENERATOR ).putLong( highId ).flip();
            channel.write( buffer );
            channel.force( false );
            channel.close();
        }
        catch ( IOException e )
        {
            throw new UnderlyingStorageException(
                "Unable to create id generator" + fileName, e );
        }
    }

Try With Resources try(StoreChannel channel=fs.create(fileName)) in method public createGenerator(fs FileSystemAbstraction, fileName File, highId long, throwIfFileExists boolean) : void from class org.neo4j.kernel.impl.store.id.IdGeneratorImpl


    private void mapMachineIds()
    {
        machineIds = new InstanceId[cluster.size()];
        machineIds[0] = cluster.getServerId( cluster.getMaster() );
        List<HighlyAvailableGraphDatabase> slaves = new ArrayList<>();
        for ( HighlyAvailableGraphDatabase hadb : cluster.getAllMembers() )
        {
            if ( !hadb.isMaster() )
            {
                slaves.add( hadb );
            }
        }
        Collections.sort( slaves, new Comparator<HighlyAvailableGraphDatabase>()
        {
            @Override
            public int compare( HighlyAvailableGraphDatabase o1, HighlyAvailableGraphDatabase o2 )
            {
                return cluster.getServerId( o1 ) .compareTo(  cluster.getServerId( o2 ) );
            }
        } );
        Iterator<HighlyAvailableGraphDatabase> iter = slaves.iterator();
        for ( int i = 1; iter.hasNext(); i++ )
        {
            machineIds[i] = cluster.getServerId( iter.next() );
        }
    }

    private void mapMachineIds()
    {
        machineIds = new InstanceId[cluster.size()];
        machineIds[0] = cluster.getServerId( cluster.getMaster() );
        List<HighlyAvailableGraphDatabase> slaves = new ArrayList<HighlyAvailableGraphDatabase>();
        for ( HighlyAvailableGraphDatabase hadb : cluster.getAllMembers() )
        {
            if ( !hadb.isMaster() )
            {
                slaves.add( hadb );
            }
        }
        Collections.sort( slaves, new Comparator<HighlyAvailableGraphDatabase>()
        {
            @Override
            public int compare( HighlyAvailableGraphDatabase o1, HighlyAvailableGraphDatabase o2 )
            {
                return cluster.getServerId( o1 ) .compareTo(  cluster.getServerId( o2 ) );
            }
        } );
        Iterator<HighlyAvailableGraphDatabase> iter = slaves.iterator();
        for ( int i = 1; iter.hasNext(); i++ )
        {
            machineIds[i] = cluster.getServerId( iter.next() );
        }
    }

Replace Generic With Diamond ArrayList<HighlyAvailableGraphDatabase> with ArrayList<> in method private mapMachineIds() : void from class org.neo4j.kernel.ha.TxPushStrategyConfigIT


    void dump( File storeDir ) throws IOException
    {
        DefaultFileSystemAbstraction fs = new DefaultFileSystemAbstraction();

        try ( PageCache pageCache = createPageCache( fs ) )
        {
            DefaultIdGeneratorFactory idGeneratorFactory = new DefaultIdGeneratorFactory( fs );
            Config config = new Config();
            StoreFactory storeFactory = new StoreFactory( storeDir, config, idGeneratorFactory, pageCache, fs, logProvider() );
            try ( NeoStores neoStores = storeFactory.openNeoStores( false ) )
            {
                RecordStore<RECORD> store = store( neoStores );
                for ( long next = first; next != -1; )
                {
                    RECORD record = store.forceGetRecord( next );
                    System.out.println( record );
                    next = next( record );
                }
            }
        }
    }

    void dump( File storeDir ) throws IOException
    {
        DefaultFileSystemAbstraction fs = new DefaultFileSystemAbstraction();

        try ( PageCache pageCache = createPageCache( fs ) )
        {
            DefaultIdGeneratorFactory idGeneratorFactory = new DefaultIdGeneratorFactory( fs );
            Config config = new Config();
            StoreFactory storeFactory = new StoreFactory( null, config, idGeneratorFactory, pageCache, fs, logProvider() );
            RecordStore<RECORD> store = store( storeFactory, storeDir );
            try
            {
                for ( long next = first; next != -1; )
                {
                    RECORD record = store.forceGetRecord( next );
                    System.out.println( record );
                    next = next( record );
                }
            }
            finally
            {
                store.close();
            }
        }
    }

Try With Resources try(NeoStores neoStores=storeFactory.openNeoStores(false)) in method package dump(storeDir File) : void from class org.neo4j.kernel.impl.store.DumpStoreChain


    @Test
    public void shouldRecognizeDesignatedInUseBit() throws Exception
    {
        // GIVEN
        try ( AbstractDynamicStore store = newTestableDynamicStore() )
        {
            // WHEN
            byte otherBitsInTheInUseByte = 0;
            for ( int i = 0; i < 8; i++ )
            {
                // THEN
                assertRecognizesByteAsInUse( store, otherBitsInTheInUseByte );
                otherBitsInTheInUseByte <<= 1;
                otherBitsInTheInUseByte |= 1;
            }
        }
    }

    @Test
    public void shouldRecognizeDesignatedInUseBit() throws Exception
    {
        // GIVEN
        AbstractDynamicStore store = newTestableDynamicStore();
        try
        {
            // WHEN
            byte otherBitsInTheInUseByte = 0;
            for ( int i = 0; i < 8; i++ )
            {
                // THEN
                assertRecognizesByteAsInUse( store, otherBitsInTheInUseByte );
                otherBitsInTheInUseByte <<= 1;
                otherBitsInTheInUseByte |= 1;
            }
        }
        finally
        {
            store.close();
        }
    }

Try With Resources try(AbstractDynamicStore store=newTestableDynamicStore()) in method public shouldRecognizeDesignatedInUseBit() : void from class org.neo4j.kernel.impl.store.AbstractDynamicStoreTest


    @Test
    public void slaveShouldNotBeAbleToModifyNodeDeletedOnMaster() throws Exception
    {
        // GIVEN
        // -- node created on slave
        HighlyAvailableGraphDatabase aSlave = cluster.getAnySlave();
        Node node = createNode( aSlave );
        // -- that node delete on master, but the slave doesn't see it yet
        deleteNode( cluster.getMaster(), node.getId() );

        // WHEN
        try(Transaction tx = aSlave.beginTx())
        {
            node.setProperty( "name", "test" );
            fail( "Shouldn't be able to modify a node deleted on master" );
        }
        catch ( NotFoundException e )
        {
            // THEN
            // -- the transactions gotten back in the response should delete that node
        }
    }

    @Test
    public void slaveShouldNotBeAbleToModifyNodeDeletedOnMaster() throws Exception
    {
        // GIVEN
        // -- node created on slave
        HighlyAvailableGraphDatabase aSlave = cluster.getAnySlave();
        Node node = createNode( aSlave );
        // -- that node delete on master, but the slave doesn't see it yet
        deleteNode( cluster.getMaster(), node.getId() );

        // WHEN
        Transaction tx = aSlave.beginTx();
        try
        {
            node.setProperty( "name", "test" );
            fail( "Shouldn't be able to modify a node deleted on master" );
        }
        catch ( NotFoundException e )
        {
            // THEN
            // -- the transactions gotten back in the response should delete that node
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=aSlave.beginTx()) in method public slaveShouldNotBeAbleToModifyNodeDeletedOnMaster() : void from class org.neo4j.ha.TransactionConstraintsIT


            @Override
            public Iterator<Relationship> iterator()
            {
                return new ArrayIterator<>( path );
            }

            @Override
            public Iterator<Relationship> iterator()
            {
                return new ArrayIterator<Relationship>( path );
            }

Replace Generic With Diamond ArrayIterator<Relationship> with ArrayIterator<> in method public iterator() : Iterator<Relationship> from class org.neo4j.graphalgo.impl.util.PathImpl.relationships.new Iterable<Relationship>


    public Iterable<Relationship> relationships()
    {
        return new Iterable<Relationship>()
        {
            @Override
            public Iterator<Relationship> iterator()
            {
                return new ArrayIterator<>( path );
            }
        };
    }

    public Iterable<Relationship> relationships()
    {
        return new Iterable<Relationship>()
        {
            @Override
            public Iterator<Relationship> iterator()
            {
                return new ArrayIterator<Relationship>( path );
            }
        };
    }

Replace Generic With Diamond ArrayIterator<Relationship> with ArrayIterator<> in method public relationships() : Iterable<Relationship> from class org.neo4j.graphalgo.impl.util.PathImpl


            @Override
            public Iterator<Relationship> iterator()
            {
                return new ReverseArrayIterator<>( path );
            }

            @Override
            public Iterator<Relationship> iterator()
            {
                return new ReverseArrayIterator<Relationship>( path );
            }

Replace Generic With Diamond ReverseArrayIterator<Relationship> with ReverseArrayIterator<> in method public iterator() : Iterator<Relationship> from class org.neo4j.graphalgo.impl.util.PathImpl.reverseRelationships.new Iterable<Relationship>


    @Override
    public Iterable<Relationship> reverseRelationships()
    {
        return new Iterable<Relationship>()
        {
            @Override
            public Iterator<Relationship> iterator()
            {
                return new ReverseArrayIterator<>( path );
            }
        };
    }

    @Override
    public Iterable<Relationship> reverseRelationships()
    {
        return new Iterable<Relationship>()
        {
            @Override
            public Iterator<Relationship> iterator()
            {
                return new ReverseArrayIterator<Relationship>( path );
            }
        };
    }

Replace Generic With Diamond ReverseArrayIterator<Relationship> with ReverseArrayIterator<> in method public reverseRelationships() : Iterable<Relationship> from class org.neo4j.graphalgo.impl.util.PathImpl


    /**
     * TODO: This method re-binds nodes and relationships. It should not.
     *
     * Returns the default string representation of a {@link Path}. It uses
     * the {@link DefaultPathDescriptor} to get representations.
     * @param path the {@link Path} to build a string representation of.
     * @return the default string representation of a {@link Path}.
     */
    public static String defaultPathToString( Path path )
    {
        return pathToString( path, new DefaultPathDescriptor<>() );
    }

    /**
     * TODO: This method re-binds nodes and relationships. It should not.
     *
     * Returns the default string representation of a {@link Path}. It uses
     * the {@link DefaultPathDescriptor} to get representations.
     * @param path the {@link Path} to build a string representation of.
     * @return the default string representation of a {@link Path}.
     */
    public static String defaultPathToString( Path path )
    {
        return pathToString( path, new DefaultPathDescriptor<Path>() );
    }

Replace Generic With Diamond DefaultPathDescriptor<Path> with DefaultPathDescriptor<> in method public defaultPathToString(path Path) : String from class org.neo4j.graphdb.traversal.Paths


    private long calculateHighestIdInUseByLookingAtFileSize()
    {
        int recordAlignedPageSize = pageCache.pageSize() - pageCache.pageSize() % getRecordSize();
        try ( PagedFile pagedFile = pageCache.map( getStorageFileName(), recordAlignedPageSize ) )
        {
            long id = recordsPerPage() * (pagedFile.getLastPageId() + 1);
            if ( id == 0 )
            {
                return -1;
            }
            return id;
        }
        catch ( IOException e )
        {
            throw new RuntimeException( e );
        }
    }

    private long calculateHighestIdInUseByLookingAtFileSize()
    {
        try
        {
            return getFileChannel().size() / getRecordSize();
        }
        catch ( IOException e )
        {
            throw new RuntimeException( e );
        }
    }

Try With Resources try(PagedFile pagedFile=pageCache.map(getStorageFileName(),recordAlignedPageSize)) in method private calculateHighestIdInUseByLookingAtFileSize() : long from class org.neo4j.kernel.impl.store.CommonAbstractStore


    @Test
    public void shouldNotOpenStoreWithNodesOrRelationshipsInIt() throws Exception
    {
        // GIVEN
        someDataInTheDatabase();

        // WHEN
        try ( PageCache pageCache = pageCacheRule.getPageCache( fsr.get() ) )
        {
            new BatchingNeoStore( fsr.get(), storeDir, DEFAULT,
                    NullLogService.getInstance(), new Monitors(), EMPTY );
            fail( "Should fail on existing data" );
        }
        catch ( IllegalStateException e )
        {
            // THEN
            assertThat( e.getMessage(), containsString( "already contains" ) );
        }
    }

    @Test
    public void shouldNotOpenStoreWithNodesOrRelationshipsInIt() throws Exception
    {
        // GIVEN
        someDataInTheDatabase();

        // WHEN
        PageCache pageCache = new BatchingPageCache( fsr.get(), 10_000, 1, SYNCHRONOUS, NO_MONITOR );
        try
        {
            new BatchingNeoStore( fsr.get(), storeDir, DEFAULT, NO_MONITOR,
                    NullLogService.getInstance(), new Monitors(), SYNCHRONOUS, EMPTY );
            fail( "Should fail on existing data" );
        }
        catch ( IllegalStateException e )
        {
            // THEN
            assertThat( e.getMessage(), containsString( "already contains" ) );
        }
        finally
        {
            pageCache.close();
        }
    }

Try With Resources try(PageCache pageCache=pageCacheRule.getPageCache(fsr.get())) in method public shouldNotOpenStoreWithNodesOrRelationshipsInIt() : void from class org.neo4j.unsafe.impl.batchimport.store.BatchingNeoStoreTest


    @Test
    public void shouldSortLabelIdsWhenGetOrCreate() throws Exception
    {
        // GIVEN
        BatchInserter inserter = newBatchInserter();

        // WHEN
        long nodeId = inserter.createNode( map( "Item", 123456789123l ), DynamicLabel.label( "AA" ),
                DynamicLabel.label( "BB" ), DynamicLabel.label( "CC" ), DynamicLabel.label( "DD" ) );
        inserter.setNodeLabels( nodeId, DynamicLabel.label( "CC" ), DynamicLabel.label( "AA" ),
                DynamicLabel.label( "DD" ), DynamicLabel.label( "EE" ), DynamicLabel.label( "FF" ) );

        // THEN
        try ( NeoStore neoStore = switchToNeoStore( inserter ) )
        {
            NodeRecord node = neoStore.getNodeStore().getRecord( nodeId );
            NodeLabels labels = NodeLabelsField.parseLabelsField( node );

            long[] labelIds = labels.get( neoStore.getNodeStore() );
            long[] sortedLabelIds = labelIds.clone();
            Arrays.sort( sortedLabelIds );
            assertArrayEquals( sortedLabelIds, labelIds );
        }
    }

    @Test
    public void shouldSortLabelIdsWhenGetOrCreate() throws Exception
    {
        // GIVEN
        BatchInserter inserter = newBatchInserter();

        // WHEN
        long nodeId = inserter.createNode( map( "Item", 123456789123l ), DynamicLabel.label( "AA" ),
                DynamicLabel.label( "BB" ), DynamicLabel.label( "CC" ), DynamicLabel.label( "DD" ) );
        inserter.setNodeLabels( nodeId, DynamicLabel.label( "CC" ), DynamicLabel.label( "AA" ),
                DynamicLabel.label( "DD" ), DynamicLabel.label( "EE" ), DynamicLabel.label( "FF" ) );

        // THEN
        NeoStore neoStore = switchToNeoStore( inserter );
        try
        {
            NodeRecord node = neoStore.getNodeStore().getRecord( nodeId );
            NodeLabels labels = NodeLabelsField.parseLabelsField( node );

            long[] labelIds = labels.get( neoStore.getNodeStore() );
            long[] sortedLabelIds = labelIds.clone();
            Arrays.sort( sortedLabelIds );
            assertArrayEquals( sortedLabelIds, labelIds );
        }
        finally
        {
            neoStore.close();
        }
    }

Try With Resources try(NeoStore neoStore=switchToNeoStore(inserter)) in method public shouldSortLabelIdsWhenGetOrCreate() : void from class org.neo4j.unsafe.batchinsert.BatchInsertTest


    public void put( K key, V value )
    {
        if ( key == null )
        {
            throw new IllegalArgumentException( "null key not allowed" );
        }
        if ( value == null )
        {
            throw new IllegalArgumentException( "null value not allowed" );
        }
        Page<V> theValue = cache.get( key );
        if ( theValue == null )
        {
            theValue = new Page<>();
            cache.put( key, theValue );
            clock.offer( theValue );
        }
        if ( theValue.value == null )
        {
            currentSize.incrementAndGet();
        }
        theValue.flag = true;
        theValue.value = value;
        checkSize();
    }

    public void put( K key, V value )
    {
        if ( key == null )
        {
            throw new IllegalArgumentException( "null key not allowed" );
        }
        if ( value == null )
        {
            throw new IllegalArgumentException( "null value not allowed" );
        }
        Page<V> theValue = cache.get( key );
        if ( theValue == null )
        {
            theValue = new Page<V>();
            cache.put( key, theValue );
            clock.offer( theValue );
        }
        if ( theValue.value == null )
        {
            currentSize.incrementAndGet();
        }
        theValue.flag = true;
        theValue.value = value;
        checkSize();
    }

Replace Generic With Diamond Page<V> with Page<> in method public put(key K, value V) : void from class org.neo4j.kernel.impl.cache.ClockCache


    public Collection<V> values()
    {
        Set<V> toReturn = new HashSet<>();
        for ( Page<V> page : cache.values() )
        {
            if ( page.value != null )
            {
                toReturn.add( page.value );
            }
        }
        return toReturn;
    }

    public Collection<V> values()
    {
        Set<V> toReturn = new HashSet<V>();
        for ( Page<V> page : cache.values() )
        {
            if ( page.value != null )
            {
                toReturn.add( page.value );
            }
        }
        return toReturn;
    }

Replace Generic With Diamond HashSet<V> with HashSet<> in method public values() : Collection<V> from class org.neo4j.kernel.impl.cache.ClockCache


	private String[] getScriptArgs( ArgReader reader )
	{
		reader.mark();
		try
		{
			ArrayList<String> list = new ArrayList<>();
			while ( reader.hasNext() )
			{
				String arg = reader.next();
				if ( arg.startsWith( "--" ) )
				{
					break;
				}
				list.add( arg );
				reader.mark();
			}
			return list.toArray( new String[ list.size() ] );
		}
		finally
		{
			reader.flip();
		}
	}

	private String[] getScriptArgs( ArgReader reader )
	{
		reader.mark();
		try
		{
			ArrayList<String> list = new ArrayList<String>();
			while ( reader.hasNext() )
			{
				String arg = reader.next();
				if ( arg.startsWith( "--" ) )
				{
					break;
				}
				list.add( arg );
				reader.mark();
			}
			return list.toArray( new String[ list.size() ] );
		}
		finally
		{
			reader.flip();
		}
	}

Replace Generic With Diamond ArrayList<String> with ArrayList<> in method private getScriptArgs(reader ArgReader) : String[] from class org.neo4j.shell.apps.extra.ScriptExecutor


	private List<String> getEnvPaths( Session session )
		throws ShellException
	{
	    List<String> list = new ArrayList<>();
	    collectPaths( list, ( String ) session.get( getPathKey() ) );
	    collectPaths( list, getDefaultPaths() );
	    return list;
	}

	private List<String> getEnvPaths( Session session )
		throws ShellException
	{
	    List<String> list = new ArrayList<String>();
	    collectPaths( list, ( String ) session.get( getPathKey() ) );
	    collectPaths( list, getDefaultPaths() );
	    return list;
	}

Replace Generic With Diamond ArrayList<String> with ArrayList<> in method private getEnvPaths(session Session) : List<String> from class org.neo4j.shell.apps.extra.ScriptExecutor


    public Collection<Injectable<?>> initializePackages( Iterable<String> packageNames )
    {
        GraphDatabaseAPI graphDatabaseService = neoServer.getDatabase().getGraph();
        Config configuration = neoServer.getConfig();

        Collection<Injectable<?>> injectables = new HashSet<>();
        for ( PluginLifecycle lifecycle : lifecycles )
        {
            if ( hasPackage( lifecycle, packageNames ) )
            {
                if ( lifecycle instanceof SPIPluginLifecycle )
                {
                    SPIPluginLifecycle lifeCycleSpi = (SPIPluginLifecycle) lifecycle;
                    injectables.addAll( lifeCycleSpi.start( neoServer ) );
                }
                else
                {
                    injectables.addAll( lifecycle.start( graphDatabaseService, new ConfigWrappingConfiguration( configuration ) ) );
                }
            }
        }
        return injectables;
    }

    public Collection<Injectable<?>> initializePackages( Iterable<String> packageNames )
    {
        GraphDatabaseAPI graphDatabaseService = neoServer.getDatabase().getGraph();
        Config configuration = neoServer.getConfig();

        Collection<Injectable<?>> injectables = new HashSet<Injectable<?>>();
        for ( PluginLifecycle lifecycle : lifecycles )
        {
            if ( hasPackage( lifecycle, packageNames ) )
            {
                if ( lifecycle instanceof SPIPluginLifecycle )
                {
                    SPIPluginLifecycle lifeCycleSpi = (SPIPluginLifecycle) lifecycle;
                    injectables.addAll( lifeCycleSpi.start( neoServer ) );
                }
                else
                {
                    injectables.addAll( lifecycle.start( graphDatabaseService, new ConfigWrappingConfiguration( configuration ) ) );
                }
            }
        }
        return injectables;
    }

Replace Generic With Diamond HashSet<Injectable<?>> with HashSet<> in method public initializePackages(packageNames Iterable<String>) : Collection<Injectable<?>> from class org.neo4j.server.modules.ExtensionInitializer


    @Override
    public boolean nodeExists( KernelStatement state, long nodeId )
    {
        try ( NodeCursor cursor = nodeCursor( state, nodeId ) )
        {
            return cursor.next();
        }
    }

    @Override
    public boolean nodeExists( KernelStatement state, long nodeId )
    {
        try ( NodeCursor cursor = nodeCursor( state, nodeId ) )
        {
            try
            {
                return cursor.next();
            }
            catch ( IllegalStateException e )
            {
                // Deleted in this transaction
                return false;
            }
        }
    }

Try With Resources try(NodeCursor cursor=nodeCursor(state,nodeId)) in method public nodeExists(state KernelStatement, nodeId long) : boolean from class org.neo4j.kernel.impl.api.StateHandlingStatementOperations


    @Override
    public boolean relationshipExists( KernelStatement state, long relId )
    {
        try ( RelationshipCursor cursor = relationshipCursor( state, relId ) )
        {
            return cursor.next();
        }
    }

    @Override
    public boolean relationshipExists( KernelStatement state, long relId )
    {
        try ( RelationshipCursor cursor = relationshipCursor( state, relId ) )
        {
            try
            {
                return cursor.next();
            }
            catch ( IllegalStateException e )
            {
                // Deleted in this transaction
                return false;
            }
        }
    }

Try With Resources try(RelationshipCursor cursor=relationshipCursor(state,relId)) in method public relationshipExists(state KernelStatement, relId long) : boolean from class org.neo4j.kernel.impl.api.StateHandlingStatementOperations


    protected static <T> void expect( Iterable<? extends T> items,
            Representation<T> representation, Set<String> expected )
    {
        try ( Transaction tx = beginTx() )
        {
            for ( T item : items )
            {
                String repr = representation.represent( item );
                assertTrue( repr + " not expected ", expected.remove( repr ) );
            }
            tx.success();
        }

        if ( !expected.isEmpty() )
        {
            fail( "The exepected elements " + expected + " were not returned." );
        }
    }

    protected static <T> void expect( Iterable<? extends T> items,
            Representation<T> representation, Set<String> expected )
    {
        Transaction tx = beginTx();
        try
        {
            for ( T item : items )
            {
                String repr = representation.represent( item );
                assertTrue( repr + " not expected ", expected.remove( repr ) );
            }
            tx.success();
        }
        finally
        {
            tx.finish();
        }

        if ( !expected.isEmpty() )
        {
            fail( "The exepected elements " + expected + " were not returned." );
        }
    }

Try With Resources try(Transaction tx=beginTx()) in method protected expect(items Iterable<? extends T>, representation Representation<T>, expected Set<String>) : void from class common.AbstractTestBase


    public Node create( GraphDatabaseService graphdb )
    {
        Map<String, Node> nodes = new HashMap<String, Node>();
        Node node = null;
        try ( Transaction tx = graphdb.beginTx() )
        {
            for ( RelationshipDescription rel : description )
            {
                node = rel.create( graphdb, nodes ).getEndNode();
            }
            tx.success();
        }
        return node;
    }

    public Node create( GraphDatabaseService graphdb )
    {
        Map<String, Node> nodes = new HashMap<String, Node>();
        Node node = null;
        Transaction tx = graphdb.beginTx();
        try
        {
            for ( RelationshipDescription rel : description )
            {
                node = rel.create( graphdb, nodes ).getEndNode();
            }
            tx.success();
        }
        finally
        {
            tx.finish();
        }
        return node;
    }

Try With Resources try(Transaction tx=graphdb.beginTx()) in method public create(graphdb GraphDatabaseService) : Node from class common.GraphDescription


    @Test
    @Graph( { "root contains child1", "child1 contains child11",
            "child1 contains child12", "root contains child2",
            "child12 contains child121", "child1 contains child13" } )
    public void test()
    {
        RelationshipExpander expander = Traversal.expanderForTypes(Rels.contains, Direction.INCOMING);

        List<Node> nodeSet = new ArrayList<Node>();
        Map<String, Node> graph = data.get();
        nodeSet.add( graph.get( "child1" ) );
        nodeSet.add( graph.get( "root" ) );

        try ( Transaction transaction = gdb.beginTx() )
        {
            Node ancestor = AncestorsUtil.lowestCommonAncestor( nodeSet, expander);
            assertEquals(graph.get( "root" ), ancestor);

            nodeSet.clear();
            nodeSet.add( graph.get( "child12" ) );
            nodeSet.add( graph.get( "child11" ) );
            ancestor = AncestorsUtil.lowestCommonAncestor( nodeSet, expander);
            assertEquals(graph.get( "child1" ), ancestor);

            nodeSet.clear();
            nodeSet.add( graph.get( "child121" ) );
            nodeSet.add( graph.get( "child12" ) );
            ancestor = AncestorsUtil.lowestCommonAncestor( nodeSet, expander);
            assertEquals(graph.get( "child12" ), ancestor);

            nodeSet.clear();
            nodeSet.add( graph.get( "child11" ) );
            nodeSet.add( graph.get( "child13" ) );
            ancestor = AncestorsUtil.lowestCommonAncestor( nodeSet, expander);
            assertEquals(graph.get( "child1" ), ancestor);

            nodeSet.clear();
            nodeSet.add( graph.get( "child2" ) );
            nodeSet.add( graph.get( "child121" ) );
            ancestor = AncestorsUtil.lowestCommonAncestor( nodeSet, expander);
            assertEquals(graph.get( "root" ), ancestor);

            nodeSet.clear();
            nodeSet.add( graph.get( "child11" ) );
            nodeSet.add( graph.get( "child12" ) );
            nodeSet.add( graph.get( "child13" ) );
            ancestor = AncestorsUtil.lowestCommonAncestor( nodeSet, expander);
            assertEquals(graph.get( "child1" ), ancestor);

            nodeSet.clear();
            nodeSet.add( graph.get( "child11" ) );
            nodeSet.add( graph.get( "child12" ) );
            nodeSet.add( graph.get( "child13" ) );
            nodeSet.add( graph.get( "child121" ) );
            ancestor = AncestorsUtil.lowestCommonAncestor( nodeSet, expander);
            assertEquals(graph.get( "child1" ), ancestor);

            nodeSet.clear();
            nodeSet.add( graph.get( "child11" ) );
            nodeSet.add( graph.get( "child12" ) );
            nodeSet.add( graph.get( "child13" ) );
            nodeSet.add( graph.get( "child121" ) );
            nodeSet.add( graph.get( "child2" ) );
            ancestor = AncestorsUtil.lowestCommonAncestor( nodeSet, expander);
            assertEquals(graph.get( "root" ), ancestor);

            nodeSet.clear();
            nodeSet.add( graph.get( "child11" ) );
            nodeSet.add( graph.get( "child12" ) );
            nodeSet.add( graph.get( "child13" ) );
            nodeSet.add( graph.get( "child121" ) );
            nodeSet.add( graph.get( "child12" ) );
            nodeSet.add( graph.get( "root" ) );
            ancestor = AncestorsUtil.lowestCommonAncestor( nodeSet, expander);
            assertEquals(graph.get( "root" ), ancestor);
        }
    }

    @Test
    @Graph( { "root contains child1", "child1 contains child11",
            "child1 contains child12", "root contains child2",
            "child12 contains child121", "child1 contains child13" } )
    public void test()
    {
        RelationshipExpander expander = Traversal.expanderForTypes(Rels.contains, Direction.INCOMING);

        List<Node> nodeSet = new ArrayList<Node>();
        Map<String, Node> graph = data.get();
        nodeSet.add( graph.get( "child1" ) );
        nodeSet.add( graph.get( "root" ) );

        Transaction transaction = gdb.beginTx();
        try
        {
            Node ancestor = AncestorsUtil.lowestCommonAncestor( nodeSet, expander);
            assertEquals(graph.get( "root" ), ancestor);

            nodeSet.clear();
            nodeSet.add( graph.get( "child12" ) );
            nodeSet.add( graph.get( "child11" ) );
            ancestor = AncestorsUtil.lowestCommonAncestor( nodeSet, expander);
            assertEquals(graph.get( "child1" ), ancestor);

            nodeSet.clear();
            nodeSet.add( graph.get( "child121" ) );
            nodeSet.add( graph.get( "child12" ) );
            ancestor = AncestorsUtil.lowestCommonAncestor( nodeSet, expander);
            assertEquals(graph.get( "child12" ), ancestor);

            nodeSet.clear();
            nodeSet.add( graph.get( "child11" ) );
            nodeSet.add( graph.get( "child13" ) );
            ancestor = AncestorsUtil.lowestCommonAncestor( nodeSet, expander);
            assertEquals(graph.get( "child1" ), ancestor);

            nodeSet.clear();
            nodeSet.add( graph.get( "child2" ) );
            nodeSet.add( graph.get( "child121" ) );
            ancestor = AncestorsUtil.lowestCommonAncestor( nodeSet, expander);
            assertEquals(graph.get( "root" ), ancestor);

            nodeSet.clear();
            nodeSet.add( graph.get( "child11" ) );
            nodeSet.add( graph.get( "child12" ) );
            nodeSet.add( graph.get( "child13" ) );
            ancestor = AncestorsUtil.lowestCommonAncestor( nodeSet, expander);
            assertEquals(graph.get( "child1" ), ancestor);

            nodeSet.clear();
            nodeSet.add( graph.get( "child11" ) );
            nodeSet.add( graph.get( "child12" ) );
            nodeSet.add( graph.get( "child13" ) );
            nodeSet.add( graph.get( "child121" ) );
            ancestor = AncestorsUtil.lowestCommonAncestor( nodeSet, expander);
            assertEquals(graph.get( "child1" ), ancestor);

            nodeSet.clear();
            nodeSet.add( graph.get( "child11" ) );
            nodeSet.add( graph.get( "child12" ) );
            nodeSet.add( graph.get( "child13" ) );
            nodeSet.add( graph.get( "child121" ) );
            nodeSet.add( graph.get( "child2" ) );
            ancestor = AncestorsUtil.lowestCommonAncestor( nodeSet, expander);
            assertEquals(graph.get( "root" ), ancestor);

            nodeSet.clear();
            nodeSet.add( graph.get( "child11" ) );
            nodeSet.add( graph.get( "child12" ) );
            nodeSet.add( graph.get( "child13" ) );
            nodeSet.add( graph.get( "child121" ) );
            nodeSet.add( graph.get( "child12" ) );
            nodeSet.add( graph.get( "root" ) );
            ancestor = AncestorsUtil.lowestCommonAncestor( nodeSet, expander);
            assertEquals(graph.get( "root" ), ancestor);
        }
        finally
        {
            transaction.finish();
        }
    }

Try With Resources try(Transaction transaction=gdb.beginTx()) in method public test() : void from class org.neo4j.graphalgo.impl.ancestor.AncestorTestCase


    @Test
    public void somePerformanceTesting() throws Exception
    {
        // GIVEN
        int numberOfNodes = 200000;
        if ( REBUILD )
        {
            GeoDataGenerator generator = new GeoDataGenerator( numberOfNodes, 5d, 1000, 1000 );
            generator.generate( directory );
        }

        // WHEN
        long[][] points = new long[][] {
                new long[] {9415, 158154},
                new long[] {89237, 192863},
                new long[] {68072, 150484},
                new long[] {186309, 194495},
                new long[] {152097, 99289},
                new long[] {92150, 161182},
                new long[] {188446, 115873},
                new long[] {85033, 7772},
                new long[] {291, 86707},
                new long[] {188345, 158468}
        };
        GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase( directory.getAbsolutePath() );
        PathFinder<WeightedPath> algo = aStar( allTypesAndDirections(),
                doubleCostEvaluator( "weight", 0 ), GeoDataGenerator.estimateEvaluator() );
        for ( int i = 0; i < 10; i++ )
        {
            System.out.println( "----- " + i );
            for ( long[] p : points )
            {
                try ( Transaction tx = db.beginTx() )
                {
                    Node start = db.getNodeById( p[0] );
                    Node end = db.getNodeById( p[1] );
                    long time = currentTimeMillis();
                    WeightedPath path = algo.findSinglePath( start, end );
                    time = currentTimeMillis() - time;
                    System.out.println( "time: " + time + ", len:" + path.length() + ", weight:" + path.weight() );
                    tx.success();
                }
            }
        }

        // THEN
        db.shutdown();
    }

    @Test
    public void somePerformanceTesting() throws Exception
    {
        // GIVEN
        int numberOfNodes = 200000;
        if ( REBUILD )
        {
            GeoDataGenerator generator = new GeoDataGenerator( numberOfNodes, 5d, 1000, 1000 );
            generator.generate( directory );
        }

        // WHEN
        long[][] points = new long[][] {
                new long[] {9415, 158154},
                new long[] {89237, 192863},
                new long[] {68072, 150484},
                new long[] {186309, 194495},
                new long[] {152097, 99289},
                new long[] {92150, 161182},
                new long[] {188446, 115873},
                new long[] {85033, 7772},
                new long[] {291, 86707},
                new long[] {188345, 158468}
        };
        GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase( directory.getAbsolutePath() );
        PathFinder<WeightedPath> algo = aStar( allTypesAndDirections(),
                doubleCostEvaluator( "weight", 0 ), GeoDataGenerator.estimateEvaluator() );
        for ( int i = 0; i < 10; i++ )
        {
            System.out.println( "----- " + i );
            for ( long[] p : points )
            {
                Transaction tx = db.beginTx();
                try
                {
                    Node start = db.getNodeById( p[0] );
                    Node end = db.getNodeById( p[1] );
                    long time = currentTimeMillis();
                    WeightedPath path = algo.findSinglePath( start, end );
                    time = currentTimeMillis() - time;
                    System.out.println( "time: " + time + ", len:" + path.length() + ", weight:" + path.weight() );
                    tx.success();
                }
                finally
                {
                    tx.finish();
                }
            }
        }

        // THEN
        db.shutdown();
    }

Try With Resources try(Transaction tx=db.beginTx()) in method public somePerformanceTesting() : void from class org.neo4j.graphalgo.path.AStarPerformanceIT


    long findPath( long startId, long endId, GraphDatabaseService db, PathFinder<? extends Path> pathFinder,
                   int warmUpRuns )
    {
        long runTime = -1;
        try ( Transaction tx = db.beginTx() )
        {
            Node startNode = db.getNodeById( startId );
            Node endNode = db.getNodeById( endId );
            for ( int run = 0; run < warmUpRuns; run++ )
            {
                runPathOnce( startNode, endNode, db, pathFinder );
            }
            runTime = runPathOnce( startNode, endNode, db, pathFinder );
            tx.success();
        }
        catch ( Exception e )
        {
            throw new RuntimeException(e);
        }
        return runTime;
    }

    long findPath( long startId, long endId, GraphDatabaseService db, PathFinder<? extends Path> pathFinder,
                   int warmUpRuns )
    {
        long runTime = -1;
        Transaction tx = db.beginTx();
        try
        {
            Node startNode = db.getNodeById( startId );
            Node endNode = db.getNodeById( endId );
            for ( int run = 0; run < warmUpRuns; run++ )
            {
                runPathOnce( startNode, endNode, db, pathFinder );
            }
            runTime = runPathOnce( startNode, endNode, db, pathFinder );
            tx.success();
        }
        catch ( Exception e )
        {
            tx.failure();
            throw new RuntimeException(e);
        }
        finally
        {
            tx.finish();
        }
        return runTime;
    }

Try With Resources try(Transaction tx=db.beginTx()) in method package findPath(startId long, endId long, db GraphDatabaseService, pathFinder PathFinder<? extends Path>, warmUpRuns int) : long from class org.neo4j.graphalgo.path.PathExplosionIT


    long[] createPathGraphAndReturnStartAndEnd( int length, int width, GraphDatabaseService db )
    {
        long startId = -1;
        long endId = -1;
        try ( Transaction tx = db.beginTx() )
        {
            Node startNode = null;
            Node endNode = db.createNode();
            startId = endNode.getId();
            for ( int l = 0; l < length; l++ )
            {
                startNode = endNode;
                endNode = db.createNode();
                for ( int w = 0; w < width; w++ )
                {
                    startNode.createRelationshipTo( endNode, RelTypes.SomeRelType );
                }
            }
            endId = endNode.getId();
            tx.success();
        }
        return new long[] { startId, endId };
    }

    long[] createPathGraphAndReturnStartAndEnd( int length, int width, GraphDatabaseService db )
    {
        long startId = -1;
        long endId = -1;
        Transaction tx = db.beginTx();
        try
        {
            Node startNode = null;
            Node endNode = db.createNode();
            startId = endNode.getId();
            for ( int l = 0; l < length; l++ )
            {
                startNode = endNode;
                endNode = db.createNode();
                for ( int w = 0; w < width; w++ )
                {
                    startNode.createRelationshipTo( endNode, RelTypes.SomeRelType );
                }
            }
            endId = endNode.getId();
            tx.success();
        }
        finally
        {
            tx.finish();
        }
        return new long[] { startId, endId };
    }

Try With Resources try(Transaction tx=db.beginTx()) in method package createPathGraphAndReturnStartAndEnd(length int, width int, db GraphDatabaseService) : long[] from class org.neo4j.graphalgo.path.PathExplosionIT


    @BeforeClass
    public static void setUpDb()
    {
        String storeDir = TargetDirectory.forTest(
                TestMatchingOfCircularPattern.class ).makeGraphDbDir().getAbsolutePath();
        graphdb = new TestGraphDatabaseFactory().newEmbeddedDatabase( storeDir );
        try ( Transaction tx = graphdb.beginTx() )
        {
            setupGraph();
            tx.success();
        }
    }

    @BeforeClass
    public static void setUpDb()
    {
        String storeDir = TargetDirectory.forTest(
                TestMatchingOfCircularPattern.class ).makeGraphDbDir().getAbsolutePath();
        graphdb = new TestGraphDatabaseFactory().newEmbeddedDatabase( storeDir );
        Transaction tx = graphdb.beginTx();
        try
        {
            setupGraph();
            tx.success();
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=graphdb.beginTx()) in method public setUpDb() : void from class matching.TestMatchingOfCircularPattern


    @Test
    public void testSimpleGraph() throws Exception
    {
        GraphDatabaseService neo = dbRule.getGraphDatabaseService();
        try ( Transaction tx = neo.beginTx() )
        {
            final Node emil = neo.createNode();
            emil.setProperty( "name", "Emil Eifrém" );
            emil.setProperty( "country_of_residence", "USA" );
            final Node tobias = neo.createNode();
            tobias.setProperty( "name", "Tobias Ivarsson" );
            tobias.setProperty( "country_of_residence", "Sweden" );
            final Node johan = neo.createNode();
            johan.setProperty( "name", "Johan Svensson" );
            johan.setProperty( "country_of_residence", "Sweden" );

            final Relationship emilKNOWStobias = emil.createRelationshipTo( tobias, type.KNOWS );
            final Relationship johanKNOWSemil = johan.createRelationshipTo( emil, type.KNOWS );
            final Relationship tobiasKNOWSjohan = tobias.createRelationshipTo( johan, type.KNOWS );
            final Relationship tobiasWORKS_FORemil = tobias.createRelationshipTo( emil, type.WORKS_FOR );

            OutputStream out = new ByteArrayOutputStream();
            SubgraphMapper subgraphMapper = new SubgraphMapper()
            {
                @Override
                public String getSubgraphFor( Node node )
                {
                    if ( node.hasProperty( "country_of_residence" ) )
                    {
                        return (String) node.getProperty( "country_of_residence" );
                    }
                    return null;
                }
            };
            GraphvizWriter writer = new GraphvizWriter();

            SubgraphMapper.SubgraphMappingWalker walker = new SubgraphMapper.SubgraphMappingWalker( subgraphMapper )
            {
                @Override
                protected Iterable<Node> nodes()
                {
                    return asList( emil, tobias, johan );
                }

                @Override
                protected Iterable<Relationship> relationships()
                {
                    return asList( emilKNOWStobias, johanKNOWSemil, tobiasKNOWSjohan, tobiasWORKS_FORemil );
                }
            };

            writer.emit( out, walker );
            tx.success();
        }
    }

    @Test
    public void testSimpleGraph() throws Exception
    {
        GraphDatabaseService neo = dbRule.getGraphDatabaseService();
        Transaction tx = neo.beginTx();
        try
        {
            final Node emil = neo.createNode();
            emil.setProperty( "name", "Emil Eifrém" );
            emil.setProperty( "country_of_residence", "USA" );
            final Node tobias = neo.createNode();
            tobias.setProperty( "name", "Tobias Ivarsson" );
            tobias.setProperty( "country_of_residence", "Sweden" );
            final Node johan = neo.createNode();
            johan.setProperty( "name", "Johan Svensson" );
            johan.setProperty( "country_of_residence", "Sweden" );

            final Relationship emilKNOWStobias = emil.createRelationshipTo( tobias, type.KNOWS );
            final Relationship johanKNOWSemil = johan.createRelationshipTo( emil, type.KNOWS );
            final Relationship tobiasKNOWSjohan = tobias.createRelationshipTo( johan, type.KNOWS );
            final Relationship tobiasWORKS_FORemil = tobias.createRelationshipTo( emil, type.WORKS_FOR );

            OutputStream out = new ByteArrayOutputStream();
            SubgraphMapper subgraphMapper = new SubgraphMapper()
            {
                @Override
                public String getSubgraphFor( Node node )
                {
                    if ( node.hasProperty( "country_of_residence" ) )
                    {
                        return (String) node.getProperty( "country_of_residence" );
                    }
                    return null;
                }
            };
            GraphvizWriter writer = new GraphvizWriter();

            SubgraphMapper.SubgraphMappingWalker walker = new SubgraphMapper.SubgraphMappingWalker( subgraphMapper )
            {
                @Override
                protected Iterable<Node> nodes()
                {
                    return asList( emil, tobias, johan );
                }

                @Override
                protected Iterable<Relationship> relationships()
                {
                    return asList( emilKNOWStobias, johanKNOWSemil, tobiasKNOWSjohan, tobiasWORKS_FORemil );
                }
            };

            writer.emit( out, walker );
            tx.success();
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=neo.beginTx()) in method public testSimpleGraph() : void from class org.neo4j.visualization.graphviz.TestGraphvizSubgraphOutput


	@Test
	public void testSimpleGraph() throws Exception
	{
	    GraphDatabaseService neo = dbRule.getGraphDatabaseService();
		try ( Transaction tx = neo.beginTx() )
		{
			final Node emil = neo.createNode();
			emil.setProperty( "name", "Emil Eifrém" );
			emil.setProperty( "age", 30 );
			final Node tobias = neo.createNode();
			tobias.setProperty( "name", "Tobias \"thobe\" Ivarsson" );
			tobias.setProperty( "age", 23 );
			tobias.setProperty( "hours", new int[] { 10, 10, 4, 4, 0 } );
			final Node johan = neo.createNode();
			johan.setProperty( "!<>)", "!<>)" );
            johan.setProperty( "name", "!<>Johan '\\n00b' !<>Svensson" );
			final Relationship emilKNOWStobias = emil.createRelationshipTo(
			    tobias, type.KNOWS );
			emilKNOWStobias.setProperty( "since", "2003-08-17" );
			final Relationship johanKNOWSemil = johan.createRelationshipTo(
			    emil, type.KNOWS );
			final Relationship tobiasKNOWSjohan = tobias.createRelationshipTo(
			    johan, type.KNOWS );
			final Relationship tobiasWORKS_FORemil = tobias
			    .createRelationshipTo( emil, type.WORKS_FOR );
			OutputStream out = new ByteArrayOutputStream();
			GraphvizWriter writer = new GraphvizWriter();
            writer.emit( out, Walker.crosscut( emil.traverse( Order.DEPTH_FIRST,
                    StopEvaluator.END_OF_GRAPH, ReturnableEvaluator.ALL, type.KNOWS,
                    Direction.BOTH, type.WORKS_FOR, Direction.BOTH ), type.KNOWS, type.WORKS_FOR ) );
			tx.success();
			out.toString();
		}
	}

	@Test
	public void testSimpleGraph() throws Exception
	{
	    GraphDatabaseService neo = dbRule.getGraphDatabaseService();
		Transaction tx = neo.beginTx();
		try
		{
			final Node emil = neo.createNode();
			emil.setProperty( "name", "Emil Eifrém" );
			emil.setProperty( "age", 30 );
			final Node tobias = neo.createNode();
			tobias.setProperty( "name", "Tobias \"thobe\" Ivarsson" );
			tobias.setProperty( "age", 23 );
			tobias.setProperty( "hours", new int[] { 10, 10, 4, 4, 0 } );
			final Node johan = neo.createNode();
			johan.setProperty( "!<>)", "!<>)" );
            johan.setProperty( "name", "!<>Johan '\\n00b' !<>Svensson" );
			final Relationship emilKNOWStobias = emil.createRelationshipTo(
			    tobias, type.KNOWS );
			emilKNOWStobias.setProperty( "since", "2003-08-17" );
			final Relationship johanKNOWSemil = johan.createRelationshipTo(
			    emil, type.KNOWS );
			final Relationship tobiasKNOWSjohan = tobias.createRelationshipTo(
			    johan, type.KNOWS );
			final Relationship tobiasWORKS_FORemil = tobias
			    .createRelationshipTo( emil, type.WORKS_FOR );
			OutputStream out = new ByteArrayOutputStream();
			GraphvizWriter writer = new GraphvizWriter();
            writer.emit( out, Walker.crosscut( emil.traverse( Order.DEPTH_FIRST,
                    StopEvaluator.END_OF_GRAPH, ReturnableEvaluator.ALL, type.KNOWS,
                    Direction.BOTH, type.WORKS_FOR, Direction.BOTH ), type.KNOWS, type.WORKS_FOR ) );
			tx.success();
			out.toString();
		}
		finally
		{
			tx.finish();
		}
	}

Try With Resources try(Transaction tx=neo.beginTx()) in method public testSimpleGraph() : void from class org.neo4j.visualization.graphviz.TestNewGraphvizWriter


				@Override
				public void run()
				{
					while ( true )
					{
						try ( Transaction tx = db.beginTx() )
						{
							for ( int i = 0; i < 100; i++ )
							{
                                String key = keys[i%keys.length];
                                String value = values[i%values.length]+i;

								Node node = db.createNode();
                                node.setProperty( key, value );
								index.add( node, key, value );
							}
							tx.success();
						}
					}
				}

				@Override
				public void run()
				{
					while ( true )
					{
						Transaction tx = db.beginTx();
						try
						{
							for ( int i = 0; i < 100; i++ )
							{
                                String key = keys[i%keys.length];
                                String value = values[i%values.length]+i;

								Node node = db.createNode();
                                node.setProperty( key, value );
								index.add( node, key, value );
							}
							tx.success();
						}
						finally
						{
							tx.finish();
						}
					}
				}

Try With Resources try(Transaction tx=db.beginTx()) in method public run() : void from class org.neo4j.index.impl.lucene.Inserter.main.start.new Thread


    private static Index<Node> getIndex( GraphDatabaseService db )
    {
		try ( Transaction transaction = db.beginTx() )
		{
            Index<Node> index = db.index().forNodes( "myIndex" );
            transaction.success();
            return index;
        }
    }

    private static Index<Node> getIndex( GraphDatabaseService db )
    {
        Transaction transaction = db.beginTx();
        try
        {
            Index<Node> index = db.index().forNodes( "myIndex" );
            transaction.success();
            return index;
        }
        finally
        {
            transaction.finish();
        }
    }

Try With Resources try(Transaction transaction=db.beginTx()) in method private getIndex(db GraphDatabaseService) : Index<Node> from class org.neo4j.index.impl.lucene.Inserter


                @Override
                public void run()
                {
                    for ( int i = 0; System.currentTimeMillis() - time < 60*1000*2; i++ )
                    {
                        if ( i%10 == 0 )
                        {
                            if ( i%100 == 0 )
                            {
                                int type = (int)(System.currentTimeMillis()%3);
                                if ( type == 0 )
                                {
                                    IndexHits<Node> itr = index.get( "key", "value5" );
                                    try
                                    {
                                        itr.getSingle();
                                    }
                                    catch ( NoSuchElementException e )
                                    { // For when there are multiple hits
                                    }
                                }
                                else if ( type == 1 )
                                {
                                    IndexHits<Node> itr = index.get( "key", "value5" );
                                    for ( int size = 0; itr.hasNext() && size < 5; size++ )
                                    {
                                        itr.next();
                                    }
                                    itr.close();
                                }
                                else
                                {
                                    IndexHits<Node> itr = index.get( "key", "crap value" ); /* Will return 0 hits */
                                    // Iterate over the hits sometimes (it's always gonna be 0 sized)
                                    if ( System.currentTimeMillis() % 10 > 5 )
                                    {
                                        IteratorUtil.count( (Iterator<Node>) itr );
                                    }
                                }
                            }
                            else
                            {
                                IteratorUtil.count( (Iterator<Node>) index.get( "key", "value5" ) );
                            }
                        }
                        else
                        {
                            try ( Transaction tx = graphDb.beginTx() )
                            {
                                for ( int ii = 0; ii < 20; ii++ )
                                {
                                    Node node = graphDb.createNode();
                                    index.add( node, "key", "value" + ii );
                                }
                                tx.success();
                            }
                        }
                    }
                }

                @Override
                public void run()
                {
                    for ( int i = 0; System.currentTimeMillis() - time < 60*1000*2; i++ )
                    {
                        if ( i%10 == 0 )
                        {
                            if ( i%100 == 0 )
                            {
                                int type = (int)(System.currentTimeMillis()%3);
                                if ( type == 0 )
                                {
                                    IndexHits<Node> itr = index.get( "key", "value5" );
                                    try
                                    {
                                        itr.getSingle();
                                    }
                                    catch ( NoSuchElementException e )
                                    { // For when there are multiple hits
                                    }
                                }
                                else if ( type == 1 )
                                {
                                    IndexHits<Node> itr = index.get( "key", "value5" );
                                    for ( int size = 0; itr.hasNext() && size < 5; size++ )
                                    {
                                        itr.next();
                                    }
                                    itr.close();
                                }
                                else
                                {
                                    IndexHits<Node> itr = index.get( "key", "crap value" ); /* Will return 0 hits */
                                    // Iterate over the hits sometimes (it's always gonna be 0 sized)
                                    if ( System.currentTimeMillis() % 10 > 5 )
                                    {
                                        IteratorUtil.count( (Iterator<Node>) itr );
                                    }
                                }
                            }
                            else
                            {
                                IteratorUtil.count( (Iterator<Node>) index.get( "key", "value5" ) );
                            }
                        }
                        else
                        {
                            Transaction tx = graphDb.beginTx();
                            try
                            {
                                for ( int ii = 0; ii < 20; ii++ )
                                {
                                    Node node = graphDb.createNode();
                                    index.add( node, "key", "value" + ii );
                                }
                                tx.success();
                            }
                            finally
                            {
                                tx.finish();
                            }
                        }
                    }
                }

Try With Resources try(Transaction tx=graphDb.beginTx()) in method public run() : void from class org.neo4j.index.impl.lucene.PerformanceAndSanityIT.makeSureFilesAreClosedProperly.execute.new Runnable


                @Override
                public void run()
                {
                    try
                    {
                        for ( int i = 0; i < count; i+=group )
                        {
                            if ( halt.get() ) break;
                            try ( Transaction tx = graphDb.beginTx() )
                            {
                                for ( int ii = 0; ii < group; ii++ )
                                {
                                    Node node = graphDb.createNode();
                                    index.get( "key", "value" + System.currentTimeMillis()%count ).getSingle();
                                    index.add( node, "key", "value" + id.getAndIncrement() );
                                }
                                tx.success();
                            }
                            if ( i%100 == 0 ) System.out.println( threadId + ": " + i );
                        }
                    }
                    catch ( Exception e )
                    {
                        e.printStackTrace( System.out );
                        halt.set( true );
                    }
                }

                @Override
                public void run()
                {
                    try
                    {
                        for ( int i = 0; i < count; i+=group )
                        {
                            if ( halt.get() ) break;
                            Transaction tx = graphDb.beginTx();
                            try
                            {
                                for ( int ii = 0; ii < group; ii++ )
                                {
                                    Node node = graphDb.createNode();
                                    index.get( "key", "value" + System.currentTimeMillis()%count ).getSingle();
                                    index.add( node, "key", "value" + id.getAndIncrement() );
                                }
                                tx.success();
                            }
                            finally
                            {
                                tx.finish();
                            }
                            if ( i%100 == 0 ) System.out.println( threadId + ": " + i );
                        }
                    }
                    catch ( Exception e )
                    {
                        e.printStackTrace( System.out );
                        halt.set( true );
                    }
                }

Try With Resources try(Transaction tx=graphDb.beginTx()) in method public run() : void from class org.neo4j.index.impl.lucene.PerformanceAndSanityIT.testPerformanceForManySmallTransactions.thread.new Thread


    @Test
    public void testHardCoreRecovery() throws Exception
    {
        String path = "target/hcdb";
        FileUtils.deleteRecursively( new File( path ) );
        Process process = Runtime.getRuntime().exec( new String[]{
                "java", "-cp", System.getProperty( "java.class.path" ),
                Inserter.class.getName(), path
        } );

        // Let it run for a while and then kill it, and wait for it to die
        awaitFile( new File( path, "started" ) );
        Thread.sleep( 5000 );
        process.destroy();
        process.waitFor();

        final GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabase( path );
        try ( Transaction transaction = db.beginTx() )
        {
            assertTrue( db.index().existsForNodes( "myIndex" ) );
            Index<Node> index = db.index().forNodes( "myIndex" );
            for ( Node node : GlobalGraphOperations.at( db ).getAllNodes() )
            {
                for ( String key : node.getPropertyKeys() )
                {
                    String value = (String) node.getProperty( key );
                    boolean found = false;
                    for ( Node indexedNode : index.get( key, value ) )
                    {
                        if ( indexedNode.equals( node ) )
                        {
                            found = true;
                            break;
                        }
                    }
                    if ( !found )
                    {
                        throw new IllegalStateException( node + " has property '" + key + "'='" +
                                value + "', but not in index" );
                    }
                }
            }
        }

        // Added due to a recovery issue where the lucene data source write wasn't released properly after recovery.
        Thread t = new Thread()
        {
            @Override
            public void run()
            {
                try ( Transaction tx = db.beginTx() )
                {
                    Index<Node> index = db.index().forNodes( "myIndex" );
                    index.add( db.createNode(), "one", "two" );
                    tx.success();
                }
            }
        };
        t.start();
        t.join();

        db.shutdown();
    }

    @Test
    public void testHardCoreRecovery() throws Exception
    {
        String path = "target/hcdb";
        FileUtils.deleteRecursively( new File( path ) );
        Process process = Runtime.getRuntime().exec( new String[]{
                "java", "-cp", System.getProperty( "java.class.path" ),
                Inserter.class.getName(), path
        } );

        // Let it run for a while and then kill it, and wait for it to die
        awaitFile( new File( path, "started" ) );
        Thread.sleep( 5000 );
        process.destroy();
        process.waitFor();

        final GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabase( path );
        Transaction transaction = db.beginTx();
        try
        {
            assertTrue( db.index().existsForNodes( "myIndex" ) );
            Index<Node> index = db.index().forNodes( "myIndex" );
            for ( Node node : GlobalGraphOperations.at( db ).getAllNodes() )
            {
                for ( String key : node.getPropertyKeys() )
                {
                    String value = (String) node.getProperty( key );
                    boolean found = false;
                    for ( Node indexedNode : index.get( key, value ) )
                    {
                        if ( indexedNode.equals( node ) )
                        {
                            found = true;
                            break;
                        }
                    }
                    if ( !found )
                    {
                        throw new IllegalStateException( node + " has property '" + key + "'='" +
                                value + "', but not in index" );
                    }
                }
            }
        }
        finally
        {
            transaction.finish();
        }

        // Added due to a recovery issue where the lucene data source write wasn't released properly after recovery.
        Thread t = new Thread()
        {
            @Override
            public void run()
            {
                try ( Transaction tx = db.beginTx() )
                {
                    Index<Node> index = db.index().forNodes( "myIndex" );
                    index.add( db.createNode(), "one", "two" );
                    tx.success();
                }
            }
        };
        t.start();
        t.join();

        db.shutdown();
    }

Try With Resources try(Transaction transaction=db.beginTx()) in method public testHardCoreRecovery() : void from class org.neo4j.index.impl.lucene.RecoveryIT


    private void removeProvidersFromIndexDbFile( File storeDir )
    {
        IndexConfigStore indexStore = new IndexConfigStore( storeDir, new DefaultFileSystemAbstraction() );
        for ( Class<? extends PropertyContainer> cls : new Class[] {Node.class, Relationship.class} )
        {
            for ( String name : indexStore.getNames( cls ) )
            {
                Map<String, String> config = indexStore.get( cls, name );
                config = new HashMap<>( config );
                config.remove( IndexManager.PROVIDER );
                indexStore.set( Node.class, name, config );
            }
        }
    }

    private void removeProvidersFromIndexDbFile( File storeDir )
    {
        IndexConfigStore indexStore = new IndexConfigStore( storeDir, new DefaultFileSystemAbstraction() );
        for ( Class<? extends PropertyContainer> cls : new Class[] {Node.class, Relationship.class} )
        {
            for ( String name : indexStore.getNames( cls ) )
            {
                Map<String, String> config = indexStore.get( cls, name );
                config = new HashMap<String, String>( config );
                config.remove( IndexManager.PROVIDER );
                indexStore.set( Node.class, name, config );
            }
        }
    }

Replace Generic With Diamond HashMap<String,String> with HashMap<> in method private removeProvidersFromIndexDbFile(storeDir File) : void from class org.neo4j.index.impl.lucene.TestMigration


    @Test
    public void shouldFailToValidateConstraintsIfUnderlyingIndexIsFailed() throws Exception
    {
        // given
        dbWithConstraint();
        storeIndexFailure( "Injected failure" );

        // when
        GraphDatabaseService db = startDatabase();
        try
        {
            try ( Transaction tx = db.beginTx() )
            {
                db.createNode( label( "Label1" ) ).setProperty( "key1", "value1" );

                fail( "expected exception" );
            }
            // then
            catch ( ConstraintViolationException e )
            {
                assertThat( e.getCause(), instanceOf( UnableToValidateConstraintKernelException.class ) );
                assertThat( e.getCause().getCause().getMessage(), equalTo( "The index is in a failed state: 'Injected failure'.") );
            }
        }
        finally
        {
            db.shutdown();
        }
    }

    @Test
    public void shouldFailToValidateConstraintsIfUnderlyingIndexIsFailed() throws Exception
    {
        // given
        dbWithConstraint();
        storeIndexFailure( "Injected failure" );

        // when
        GraphDatabaseService db = startDatabase();
        try
        {
            Transaction tx = db.beginTx();
            try
            {
                db.createNode( label( "Label1" ) ).setProperty( "key1", "value1" );

                fail( "expected exception" );
            }
            // then
            catch ( ConstraintViolationException e )
            {
                assertThat( e.getCause(), instanceOf( UnableToValidateConstraintKernelException.class ) );
                assertThat( e.getCause().getCause().getMessage(), equalTo( "The index is in a failed state: 'Injected failure'.") );
            }
            finally
            {
                tx.finish();
            }
        }
        finally
        {
            db.shutdown();
        }
    }

Try With Resources try(Transaction tx=db.beginTx()) in method public shouldFailToValidateConstraintsIfUnderlyingIndexIsFailed() : void from class org.neo4j.index.lucene.ConstraintIndexFailureIT


    private void dbWithConstraint()
    {
        GraphDatabaseService db = startDatabase();
        try
        {
            try ( Transaction tx = db.beginTx() )
            {
                db.schema().constraintFor( label( "Label1" ) ).assertPropertyIsUnique( "key1" ).create();

                tx.success();
            }
        }
        finally
        {
            db.shutdown();
        }
    }

    private void dbWithConstraint()
    {
        GraphDatabaseService db = startDatabase();
        try
        {
            Transaction tx = db.beginTx();
            try
            {
                db.schema().constraintFor( label( "Label1" ) ).assertPropertyIsUnique( "key1" ).create();

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

Try With Resources try(Transaction tx=db.beginTx()) in method private dbWithConstraint() : void from class org.neo4j.index.lucene.ConstraintIndexFailureIT


    private static void doStuff( GraphDatabaseService db, Label label, String propertyKey )
    {
        try ( Transaction tx = db.beginTx() )
        {
            for ( Node node : loop( db.findNodes( label, propertyKey, 3323 ) ) )
            {
                count( node.getLabels() );
            }
        }
    }

    private static void doStuff( GraphDatabaseService db, Label label, String propertyKey )
    {
        Transaction tx = db.beginTx();
        try
        {
            for ( Node node : loop( db.findNodes( label, propertyKey, 3323 ) ) )
            {
                count( node.getLabels() );
            }
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=db.beginTx()) in method private doStuff(db GraphDatabaseService, label Label, propertyKey String) : void from class org.neo4j.kernel.api.impl.index.SchemaIndexAcceptanceTest


    private void createSomeData( Label label, String propertyKey )
    {
        try ( Transaction tx = db.beginTx() )
        {
            Node node = db.createNode( label );
            node.setProperty( propertyKey, "yeah" );
            tx.success();
        }
    }

    private void createSomeData( Label label, String propertyKey )
    {
        Transaction tx = db.beginTx();
        try
        {
            Node node = db.createNode( label );
            node.setProperty( propertyKey, "yeah" );
            tx.success();
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=db.beginTx()) in method private createSomeData(label Label, propertyKey String) : void from class org.neo4j.kernel.api.impl.index.SchemaIndexAcceptanceTest


    @GET
    @Path( "inject-test" )
    @Produces( MediaType.TEXT_PLAIN )
    public Response countNodes( @Context GraphDatabaseService db )
    {
        try (Transaction transaction = db.beginTx())
        {
            return Response.ok()
                    .entity( String.valueOf( countNodesIn( db ) ) )
                    .build();
        }
    }

    @GET
    @Path( "inject-test" )
    @Produces( MediaType.TEXT_PLAIN )
    public Response countNodes( @Context GraphDatabaseService db )
    {
        Transaction transaction = db.beginTx();
        try
        {
            return Response.ok()
                    .entity( String.valueOf( countNodesIn( db ) ) )
                    .build();
        }
        finally
        {
            transaction.finish();
        }
    }

Try With Resources try(Transaction transaction=db.beginTx()) in method public countNodes(db GraphDatabaseService) : Response from class org.dummy.web.service.DummyThirdPartyWebService


    public Map<String, Object> getNodeProperties( long nodeId )
    {
        try (Transaction tx = database.getGraph().beginTx())
        {
            Node node = database.getGraph().getNodeById( nodeId );
            Map<String, Object> allProperties = new HashMap<>();
            for ( String propertyKey : node.getPropertyKeys() )
            {
                allProperties.put( propertyKey, node.getProperty( propertyKey ) );
            }
            tx.success();
            return allProperties;
        }
    }

    public Map<String, Object> getNodeProperties( long nodeId )
    {
        Transaction tx = database.getGraph().beginTx();
        try
        {
            Node node = database.getGraph().getNodeById( nodeId );
            Map<String, Object> allProperties = new HashMap<>();
            for ( String propertyKey : node.getPropertyKeys() )
            {
                allProperties.put( propertyKey, node.getProperty( propertyKey ) );
            }
            tx.success();
            return allProperties;
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=database.getGraph().beginTx()) in method public getNodeProperties(nodeId long) : Map<String,Object> from class org.neo4j.server.rest.domain.GraphDbHelper


    public void setNodeProperties( long nodeId, Map<String, Object> properties )
    {
        try ( Transaction tx = database.getGraph().beginTx() )
        {
            Node node = database.getGraph().getNodeById( nodeId );
            for ( Map.Entry<String, Object> propertyEntry : properties.entrySet() )
            {
                node.setProperty( propertyEntry.getKey(), propertyEntry.getValue() );
            }
            tx.success();
        }
    }

    public void setNodeProperties( long nodeId, Map<String, Object> properties )
    {
        Transaction tx = database.getGraph().beginTx();
        try
        {
            Node node = database.getGraph().getNodeById( nodeId );
            for ( Map.Entry<String, Object> propertyEntry : properties.entrySet() )
            {
                node.setProperty( propertyEntry.getKey(), propertyEntry.getValue() );
            }
            tx.success();
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=database.getGraph().beginTx()) in method public setNodeProperties(nodeId long, properties Map<String,Object>) : void from class org.neo4j.server.rest.domain.GraphDbHelper


    public long createNode( Label... labels )
    {
        try ( Transaction tx = database.getGraph().beginTx() )
        {
            Node node = database.getGraph().createNode( labels );
            tx.success();
            return node.getId();
        }
    }

    public long createNode( Label... labels )
    {
        Transaction tx = database.getGraph().beginTx();
        try
        {
            Node node = database.getGraph().createNode( labels );
            tx.success();
            return node.getId();
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=database.getGraph().beginTx()) in method public createNode(labels Label...) : long from class org.neo4j.server.rest.domain.GraphDbHelper


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

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

Try With Resources try(Transaction tx=database.getGraph().beginTx()) in method public createNode(properties Map<String,Object>, labels Label...) : long from class org.neo4j.server.rest.domain.GraphDbHelper


    public void deleteNode( long id )
    {
        try (Transaction tx = database.getGraph().beginTx())
        {
            Node node = database.getGraph().getNodeById( id );
            node.delete();
            tx.success();
        }
    }

    public void deleteNode( long id )
    {
        Transaction tx = database.getGraph().beginTx();
        try
        {
            Node node = database.getGraph().getNodeById( id );
            node.delete();
            tx.success();
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=database.getGraph().beginTx()) in method public deleteNode(id long) : void from class org.neo4j.server.rest.domain.GraphDbHelper


    public long createRelationship( String type, long startNodeId, long endNodeId )
    {
        try (Transaction tx = database.getGraph().beginTx())
        {
            Node startNode = database.getGraph().getNodeById( startNodeId );
            Node endNode = database.getGraph().getNodeById( endNodeId );
            Relationship relationship = startNode.createRelationshipTo( endNode,
                    DynamicRelationshipType.withName( type ) );
            tx.success();
            return relationship.getId();
        }
    }

    public long createRelationship( String type, long startNodeId, long endNodeId )
    {
        Transaction tx = database.getGraph().beginTx();
        try
        {
            Node startNode = database.getGraph().getNodeById( startNodeId );
            Node endNode = database.getGraph().getNodeById( endNodeId );
            Relationship relationship = startNode.createRelationshipTo( endNode,
                    DynamicRelationshipType.withName( type ) );
            tx.success();
            return relationship.getId();
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=database.getGraph().beginTx()) in method public createRelationship(type String, startNodeId long, endNodeId long) : long from class org.neo4j.server.rest.domain.GraphDbHelper


    public long createRelationship( String type )
    {
        try ( Transaction tx = database.getGraph().beginTx() )
        {
            Node startNode = database.getGraph().createNode();
            Node endNode = database.getGraph().createNode();
            Relationship relationship = startNode.createRelationshipTo( endNode,
                    DynamicRelationshipType.withName( type ) );
            tx.success();
            return relationship.getId();
        }
    }

    public long createRelationship( String type )
    {
        Transaction tx = database.getGraph().beginTx();
        try
        {
            Node startNode = database.getGraph().createNode();
            Node endNode = database.getGraph().createNode();
            Relationship relationship = startNode.createRelationshipTo( endNode,
                    DynamicRelationshipType.withName( type ) );
            tx.success();
            return relationship.getId();
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=database.getGraph().beginTx()) in method public createRelationship(type String) : long from class org.neo4j.server.rest.domain.GraphDbHelper


    public void setRelationshipProperties( long relationshipId, Map<String, Object> properties )

    {
        try ( Transaction tx = database.getGraph().beginTx() )
        {
            Relationship relationship = database.getGraph().getRelationshipById( relationshipId );
            for ( Map.Entry<String, Object> propertyEntry : properties.entrySet() )
            {
                relationship.setProperty( propertyEntry.getKey(), propertyEntry.getValue() );
            }
            tx.success();
        }
    }

    public void setRelationshipProperties( long relationshipId, Map<String, Object> properties )

    {
        Transaction tx = database.getGraph().beginTx();
        try
        {
            Relationship relationship = database.getGraph().getRelationshipById( relationshipId );
            for ( Map.Entry<String, Object> propertyEntry : properties.entrySet() )
            {
                relationship.setProperty( propertyEntry.getKey(), propertyEntry.getValue() );
            }
            tx.success();
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=database.getGraph().beginTx()) in method public setRelationshipProperties(relationshipId long, properties Map<String,Object>) : void from class org.neo4j.server.rest.domain.GraphDbHelper


    public Map<String, Object> getRelationshipProperties( long relationshipId )
    {
        try ( Transaction tx = database.getGraph().beginTx() )
        {
            Relationship relationship = database.getGraph().getRelationshipById( relationshipId );
            Map<String, Object> allProperties = new HashMap<>();
            for ( String propertyKey : relationship.getPropertyKeys() )
            {
                allProperties.put( propertyKey, relationship.getProperty( propertyKey ) );
            }
            tx.success();
            return allProperties;
        }
    }

    public Map<String, Object> getRelationshipProperties( long relationshipId )
    {
        Transaction tx = database.getGraph().beginTx();
        try
        {
            Relationship relationship = database.getGraph().getRelationshipById( relationshipId );
            Map<String, Object> allProperties = new HashMap<>();
            for ( String propertyKey : relationship.getPropertyKeys() )
            {
                allProperties.put( propertyKey, relationship.getProperty( propertyKey ) );
            }
            tx.success();
            return allProperties;
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=database.getGraph().beginTx()) in method public getRelationshipProperties(relationshipId long) : Map<String,Object> from class org.neo4j.server.rest.domain.GraphDbHelper


    public Relationship getRelationship( long relationshipId )
    {
        try (Transaction tx = database.getGraph().beginTx())
        {
            Relationship relationship = database.getGraph().getRelationshipById( relationshipId );
            tx.success();
            return relationship;
        }
    }

    public Relationship getRelationship( long relationshipId )
    {
        Transaction tx = database.getGraph().beginTx();
        try
        {
            Relationship relationship = database.getGraph().getRelationshipById( relationshipId );
            tx.success();
            return relationship;
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=database.getGraph().beginTx()) in method public getRelationship(relationshipId long) : Relationship from class org.neo4j.server.rest.domain.GraphDbHelper


    public void addNodeToIndex( String indexName, String key, Object value, long id )
    {
        try (Transaction tx = database.getGraph().beginTx())
        {
            database.getGraph().index().forNodes( indexName ).add( database.getGraph().getNodeById( id ), key, value );
            tx.success();
        }
    }

    public void addNodeToIndex( String indexName, String key, Object value, long id )
    {
        Transaction tx = database.getGraph().beginTx();
        try
        {
            database.getGraph().index().forNodes( indexName ).add( database.getGraph().getNodeById( id ), key, value );
            tx.success();
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=database.getGraph().beginTx()) in method public addNodeToIndex(indexName String, key String, value Object, id long) : void from class org.neo4j.server.rest.domain.GraphDbHelper


    public Collection<Long> queryIndexedNodes( String indexName, String key, Object value )
    {
        try ( Transaction tx = database.getGraph().beginTx() )
        {
            Collection<Long> result = new ArrayList<>();
            for ( Node node : database.getGraph().index().forNodes( indexName ).query( key, value ) )
            {
                result.add( node.getId() );
            }
            tx.success();
            return result;
        }
    }

    public Collection<Long> queryIndexedNodes( String indexName, String key, Object value )
    {
        Transaction tx = database.getGraph().beginTx();
        try
        {
            Collection<Long> result = new ArrayList<>();
            for ( Node node : database.getGraph().index().forNodes( indexName ).query( key, value ) )
            {
                result.add( node.getId() );
            }
            tx.success();
            return result;
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=database.getGraph().beginTx()) in method public queryIndexedNodes(indexName String, key String, value Object) : Collection<Long> from class org.neo4j.server.rest.domain.GraphDbHelper


    public Collection<Long> getIndexedNodes( String indexName, String key, Object value )
    {
        try ( Transaction tx = database.getGraph().beginTx() )
        {
            Collection<Long> result = new ArrayList<>();
            for ( Node node : database.getGraph().index().forNodes( indexName ).get( key, value ) )
            {
                result.add( node.getId() );
            }
            tx.success();
            return result;
        }
    }

    public Collection<Long> getIndexedNodes( String indexName, String key, Object value )
    {
        Transaction tx = database.getGraph().beginTx();
        try
        {
            Collection<Long> result = new ArrayList<>();
            for ( Node node : database.getGraph().index().forNodes( indexName ).get( key, value ) )
            {
                result.add( node.getId() );
            }
            tx.success();
            return result;
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=database.getGraph().beginTx()) in method public getIndexedNodes(indexName String, key String, value Object) : Collection<Long> from class org.neo4j.server.rest.domain.GraphDbHelper