neo4j / neo4j-ogm

Java Object-Graph Mapping Library for Neo4j
https://neo4j.com/docs/ogm-manual/
Apache License 2.0
337 stars 165 forks source link

Can't use EmbeddedDriver with absolute path on Windows #179

Closed torstenkuhnhenne closed 7 years ago

torstenkuhnhenne commented 8 years ago

Neo4j OGM Version 2.0.3 / Java 8 / Windows 10

I want to use the embedded driver with an absolute path, but this will always throw an exception in EmbeddedDriver.createPermanentFileStore(String). The path I want to use does not exist!

Maybe a very simple workaround is to use file.toPath() instead of Paths.get( uri.getRawPath() ). This will work with the 1. and 3. uri.

Testcase:

import java.io.File;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.junit.Test;

public class EmbeddedDriverWithAbsolutePath {
    @Test
    public void test() {
        final String[] uris = new String[] {
                // URI shown in Firefox
                // => java.nio.file.InvalidPathException: Illegal char <:> at index 2: /D:/git/xom/core/temp/neo4j-junit/
                // This one should work!
                "file:///D:/temp/neo4j-junit/",
                // 2. test
                // => java.lang.IllegalArgumentException: URI has an authority component
                "file://D:/temp/neo4j-junit/",
                // URI when i use new File("d:/ ....).toURI().toString()
                // => java.nio.file.InvalidPathException: Illegal char <:> at index 2: /D:/git/xom/core/temp/neo4j-junit/
                // This one should work!
                "file:/D:/temp/neo4j-junit/",
                // 4. Test
                // => java.lang.IllegalArgumentException: URI is not hierarchical
                "file:D:/temp/neo4j-junit/" };

        for ( final String strPath : uris ) {
            try {
                final URI uri = new URI( strPath );
                final File file = new File( uri );
                if ( !file.exists() ) {
                    final Path graphDir = Files.createDirectories( Paths.get( uri.getRawPath() ) );

                    // Possible workaround:
                    final Path graphDirWorking = Files.createDirectories( file.toPath() );
                }
            }
            catch ( final Exception e ) {
                System.out.println( "URI: " + strPath );
                e.printStackTrace();
            }
        }
    }
}
meistermeier commented 7 years ago

Duplicate of #411