0

I am creating a new database in stardog using java.

When I am creating the database and importing a RDF file in localhost its working.

But when I am creating db in remote server I am getting a file not found exception for the same RDF file.

Please take a look at my code

    System.out.println("start updating db");
    String myDBName = "myDB" ;

    StardogDBMS dbms =
            //StardogDBMS.toServer("snarl://localhost:5820/")
            StardogDBMS.toServer("snarl://myRemoteServer:5820/")
            .credentials("admin", "admin".toCharArray()).login();

    File file = new File("src\\main\\webapp\\test.rdf"))

    System.out.println("creating " + myDBName +" and loading the rdf file" );

    dbms.disk(myDBName).create(file));
    dbms.logout();
    System.out.println("created " + myDBName +" and loaded the rdf file" );

please help. Is there any turnaround like passing a stream to database for importing RDF file. Here is the exception I am getting.

start updating db
creating myDB and loading the rdf file      
File: xxx\xxxx\test.RDF Message: java.io.FileNotFoundException: xxx\xxxx\test.RDF (No such file or directory)
created myDB and loaded the rdf file
Vishnudev K
  • 2,874
  • 3
  • 27
  • 42

3 Answers3

2

The error message indicates that the bulk loader for the disk database cannot find the specified file. Files are not transferred from the client to the server for bulk loading when using the SNARL protocol, which is probably the source of the error.

If both server & client are running on the same machine, it's likely that your relative path is incorrect when the server is reading it, that path would be relative to STARDOG_HOME, and likely incorrect in that case. So if they're both on the same machine, use an absolute path and it should work. If they're on separate machines, bulk load from the CLI on the machine with the server.

If you want to use HTTP, the files will be transferred, but you will get poor bulk load performance because of the network overhead of sending the file to the server. Again, you are best served doing bulk loads on the machine with the server.

Michael
  • 4,858
  • 19
  • 32
1

Without knowing what dbms.disk(myDBName).create(file)); is doing it's hard to say, but are you sure it's not attempting to read a file src\\main\\webapp\\test.rdf which exists locally but not on the remote server?

artbristol
  • 32,010
  • 5
  • 70
  • 103
1

I guess what Michael answered is the reason for the exception. I found a go around method for this issue.

Instead of creating database and bulk loading the RDF/OWL files. Create a connection to the stardog DB. and import the RDF files through the connection.

sample code is given below

System.out.println("start updating db");
String myDBName = "myDB" ;

StardogDBMS dbms =
        //StardogDBMS.toServer("snarl://localhost:5820/")
        StardogDBMS.toServer("snarl://myRemoteServer:5820/")
        .credentials("admin", "admin".toCharArray()).login();

File file = new File("src\\main\\webapp\\test.rdf"))

System.out.println("creating " + myDBName);

dbms.disk(myDBName).create());
dbms.logout();

aConn = ConnectionConfiguration.to(myDBName) // the name of the db to connect to
            .credentials("admin", "admin") // the credentials with which to connect
            .url("snarl://myRemoteServer:5820/")
            .connect(); // now open the connection

    System.out.println("importing files to "+myDBName);
    aConn.begin();
    aConn.add().io().format(RDFFormat.RDFXML).stream(file);     
    aConn.commit();
    System.out.println("files imported to "+myDBName);

    System.out.println("DB Updated");
Vishnudev K
  • 2,874
  • 3
  • 27
  • 42
  • 1
    While this is true, you're no longer able to use Stardog's bulk loader after the database is created. So this approach is fine for incremental changes to the database, but it is not an acceptable approach for bulk additions of millions or tens of millions (or more) triples. Adding that much data to Stardog should be done at creation time. – Michael Apr 15 '13 at 13:12
  • So whats the way out. How do it looks for the file in the server. I don't even have a read access in server directories. – Vishnudev K Apr 16 '13 at 06:30
  • Stardog looks for files on the server in the same way that anything would look for a file on a machine, you give it a file path, either relative or absolute, and it will open the file at that location. An alternative to adding large amounts of data post-creation is to add the data in smaller chunks, say, 250k triples at a time. – Michael Apr 16 '13 at 11:48
  • any way my requirement was importing very small files(80kb-100Kb files). what will happen if we add very large files post-creation of DB. – Vishnudev K Apr 16 '13 at 12:21
  • 1
    it will work, and it will be slower than bulk loading at creation time. – Michael Apr 16 '13 at 17:38