Question

I am building a play application and want to configure Apache Jena TDB, however I am also swapping between this database and a relational database in postgresql. I have the postgresql database configured correctly. This is a two part question:

  1. What is the best way to configure two databases that will be used interchangeably, not concurrently. It seems there are two general options in play 2, I could either configure the databases on separate servers (seems like the best option for running databases concurrently). Or the option I am leaning toward is configuring both databases under database configuration then setting a global object to the database I want to use and having if - else statements in the model to determine which dataset to use. Any advice on which design might work better for swapping between two databases?

  2. What driver do I need to use for my TDB configuration? I tried:

    db.tdb.driver=org.apache.jena.jena-jdbc-driver-tdb
    db.tdb.url="jdbc:jena:tdb:location=/localhost/application"
    db.tdb.user=tdb
    db.tdb.password=password
    

However, play does not recognize this driver. Does anyone know what driver works for play? I am using Jena 2.10.2. Any advice would help, thanks!

Brad

Was it helpful?

Solution

I can't answer part 1 not knowing the Play Framework but as the primary developer on the Jena JDBC component I can take a stab at part 2

The connection settings you have look slightly wrong, an example from their documentation is as follows:

# Default database configuration
db.default.driver=org.h2.Driver
db.default.url=jdbc:h2:mem:play

So it looks like you want the class name of the driver not the JAR name as you appear to have used so TDB configuration should look roughly like the following:

db.tdb.driver=org.apache.jena.jdbc.tdb.TDBDriver
db.tdb.url=jdbc:jena:tdb:location=/localhost/application

And there should be no need to provide a username/password.

Also note that as described in their Connecting with JDBC documentation you will need to add the TDB Driver JAR as an additional dependency to your application following the Managing Library Dependencies documentation.

If you still cannot make a successful connection then this may be down to a known bug JENA-646, Jena JDBC does not currently expose the appropriate meta information for drivers to be automatically detected by the Java Service Provider mechanism so if Play relies on this you may not be able to make a connection without somehow first initialising the TDBDriver class. You can either call TDBDriver.register() in your code or take advantage of the jdbc.drivers system property as detailed in the JENA-646 comments.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top