You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by "Trejkaz (JIRA)" <ji...@apache.org> on 2016/09/30 03:35:20 UTC

[jira] [Comment Edited] (DERBY-6912) Allow loading a database from a Path instead of a String file path

    [ https://issues.apache.org/jira/browse/DERBY-6912?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15534888#comment-15534888 ] 

Trejkaz edited comment on DERBY-6912 at 9/30/16 3:35 AM:
---------------------------------------------------------

Correct, there is no way to turn a String obtained from toString() back into a Path.

As an example:

{code}
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class PathDemo
{
    public static void main(String[] args) throws Exception
    {
        try (FileSystem fs1 = FileSystems.newFileSystem(Paths.get("/Data/test1.zip"), PathDemo.class.getClassLoader());
             FileSystem fs2 = FileSystems.newFileSystem(Paths.get("/Data/test2.zip"), PathDemo.class.getClassLoader()))
        {
            System.out.println("---- test1.zip ----");
            Path root1 = fs1.getRootDirectories().iterator().next();
            System.out.println(root1);
            Files.list(root1).forEach(System.out::println);

            System.out.println("---- test2.zip ----");
            Path root2 = fs2.getRootDirectories().iterator().next();
            Path sub2 = root2.resolve("/");
            System.out.println(sub2);
            Files.list(root2).forEach(System.out::println);
        }
    }
}
{code}

This prints:

{noformat}
---- test1.zip ----
/
/first layer/
/test.gif
---- test2.zip ----
/
/test.zip
/test.doc
{noformat}

i.e., toString() returns the same value for two paths which are different.



was (Author: trejkaz):
Correct, there is no way to turn a String obtained from toString() back into a Path.


> Allow loading a database from a Path instead of a String file path
> ------------------------------------------------------------------
>
>                 Key: DERBY-6912
>                 URL: https://issues.apache.org/jira/browse/DERBY-6912
>             Project: Derby
>          Issue Type: Improvement
>            Reporter: Trejkaz
>
> Java 7 added the new filesystem abstraction (Path) API.
> Our data is made up of a collection of multiple other databases. Other components of our data, such as Lucene, already use the new Path API in the current released versions, so it's now only Derby holding us up.
> I can make an alternative DirStorageFactory7, DirFile7, DirRandomAccessFile7 which all use Path to do their work, instead of File. This turns out to be fairly easy, in fact.
> The blocker is currently that Derby currently forces us to provide the path to the database as a string. This comes down to EmbeddedDataSourceInterface forcing me to pass a string for pretty much everything. For instance, the database "name" usually becomes the file path, but that's a string.
> {code}
>     void setDatabaseName(String name);
>     String getDatabaseName();
> {code}
> Even if I wanted to work around it by making a custom protocol, ignoring the name and then using the connection attributes, the connection attributes were done as a string as well:
> {code}
>     void setConnectionAttributes(String attributes);
>     String getConnectionAttributes();
> {code}
> It would have been nice if this were a Map so that I could put other objects inside it.
> As far as other workarounds go, I can't extend EmbedPooledConnection, so I can't usefully extend InternalDriver, so I can't usefully extend EmbeddedConnectionPoolDataSource myself. If there is any other possibility which I have missed, I'd be interested to know.
> Really what I would like is a way to pass the Path directly to EmbeddedConnectionPoolDataSource.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)