Permalink
Browse files

drop jena sdb support in favor of tdb

  • Loading branch information...
1 parent d879a04 commit b3c93ae06e704c74c0f80ddf84f499d275eee4ba @nkons committed Nov 26, 2013
View
@@ -22,6 +22,6 @@ You are free to use and distribute this work as long as you provide proper refer
1. N. Konstantinou, D.E. Spanos, N. Houssos, N. Mitrou: "Exposing Scholarly Information as Linked Open Data: RDFizing DSpace contents". In The Electronic Library, 2014 (to appear) [(pdf)](http://www.cn.ntua.gr/~nkons/r2rml_parser-2014_post_peer-review.pdf)
-1. N. Konstantinou, D.E. Spanos, N. Mitrou: "Transient and persistent RDF views over relational databases in the context of digital repositories". In 7th Metadata and Semantics Research Conference (MTSR'13), Thessaloniki, Greece, Springer, CCIS 390, pp. 342-354, November 2013 [(doi:10.1007/978-3-319-03437-9_33)](http://dx.doi.org/10.1007/978-3-319-03437-9_33) [(pdf)](http://www.cn.ntua.gr/~nkons/mtsr13.pdf)
+1. N. Konstantinou, D.E. Spanos, N. Mitrou: "Transient and persistent RDF views over relational databases in the context of digital repositories". In 7th Metadata and Semantics Research Conference (MTSR'13), Thessaloniki, Greece, Springer, CCIS 390, pp. 342-354, November 2013 [(doi:10.1007/978-3-319-03437-9_33)](http://dx.doi.org/10.1007/978-3-319-03437-9_33) [(pdf)](http://www.cn.ntua.gr/~nkons/mtsr13.pdf) [(slides)](http://www.slideshare.net/nkons/transient-and-persistent-rdf-views-over-relational-databases-in-the-context-of-digital-repositories)
1. N. Konstantinou, N. Houssos, A. Manta: "Exposing Bibliographic Information as Linked Open Data using Standards-based Mappings: Methodology and Results". In 3rd International Conference on Integrated Information (IC-ININFO'13), Prague, Czech Republic, September 2013 [(pdf)](http://www.cn.ntua.gr/~nkons/konstantinou_icininfo2013.pdf) [(slides)](http://www.slideshare.net/nkons/exposing-bibliographic-information-as-linked-open-data-using-standardsbased-mappings-methodology-and-results)
View
17 pom.xml
@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>gr.seab</groupId>
<artifactId>r2rml-parser</artifactId>
- <version>0.4</version>
+ <version>0.5</version>
<packaging>jar</packaging>
<name>R2RML Parser</name>
<properties>
@@ -110,19 +110,10 @@
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
- <artifactId>jena-sdb</artifactId>
- <version>1.3.5</version>
- </dependency>
- <!-- <dependency>
- <groupId>org.apache.jena</groupId>
- <artifactId>jena-core</artifactId>
+ <artifactId>apache-jena-libs</artifactId>
+ <type>pom</type>
<version>2.10.1</version>
- </dependency>-->
- <!-- <dependency>
- <groupId>org.apache.jena</groupId>
- <artifactId>jena-arq</artifactId>
- <version>2.10.1</version>
- </dependency>-->
+ </dependency>
</dependencies>
<licenses>
View
@@ -1,4 +1,4 @@
@echo off
-echo This is R2RML Parser 0.4-alpha
+echo This is R2RML Parser 0.5-alpha
java -Xms128m -Xmx1024m -cp "./*;./lib/*;" gr.seab.r2rml.beans.Main %1
-echo R2RML Parser 0.4-alpha. Done.
+echo R2RML Parser 0.5-alpha. Done.
View
@@ -1,3 +1,3 @@
-echo "This is R2RML Parser 0.4-alpha"
-java -Xms128m -Xmx1024m -cp "./*;./lib/*;" -jar lib/r2rml-parser-0.4.jar
-echo "R2RML Parser 0.4-alpha. Done."
+echo "This is R2RML Parser 0.5-alpha"
+java -Xms128m -Xmx1024m -cp "./*;./lib/*;" -jar lib/r2rml-parser-0.5.jar
+echo "R2RML Parser 0.5-alpha. Done."
View
@@ -46,24 +46,20 @@ db.password=postgres
db.driver=org.postgresql.Driver
#---------------------------------------------------------------#
-#------------------ Jena Database Output ----------------------#
+#---------------------- Jena TDB Output -----------------------#
#---------------------------------------------------------------#
-jena.db.host=127.0.0.1
-jena.db.port=3306
-jena.db.name=jena
-jena.db.login=root
-jena.db.password=1234
-jena.db.driver=com.mysql.jdbc.Driver
-# Store the resulting triples in the database.
-jena.storeOutputModelInDatabase=false
-# Clean database on startup is activated only when the output model is stored in the database, i.e. jena.storeOutputModelInDatabase is true.
-jena.cleanDbOnStartup=false
+# Store the resulting triples using TDB.
+jena.storeOutputModelUsingTdb=true
+# Clean TDB on startup is taken into account only when jena.storeOutputModelUsingTdb is true.
+jena.cleanTdbOnStartup=true
+# The directory containing the dataset
+jena.tdb.directory=tdb
#---------------------------------------------------------------#
#---------------------- Jena File Output -----------------------#
#---------------------------------------------------------------#
-#in case we will output the resulting triples in a file. This matters if property jena.storeOutputModelInDatabase is false.
-jena.destinationFileName=dump1-epersons.rdf
+#in case we will output the resulting triples in a file. This matters if property jena.storeOutputModelUsingTdb is false.
+jena.destinationFileName=dump.rdf
jena.destinationFileSyntax=N3
@@ -14,16 +14,10 @@
import java.sql.Connection;
import java.sql.ResultSet;
-import com.hp.hpl.jena.sdb.Store;
-import com.hp.hpl.jena.sdb.sql.SDBConnection;
-
public interface Database {
public Connection openConnection();
- public SDBConnection openJenaConnection();
-
public ResultSet query(String query);
-
- public Store jenaStore();
+
}
@@ -11,7 +11,6 @@
*/
package gr.seab.r2rml.beans;
-
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
@@ -24,13 +23,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.hp.hpl.jena.sdb.SDBFactory;
-import com.hp.hpl.jena.sdb.Store;
-import com.hp.hpl.jena.sdb.StoreDesc;
-import com.hp.hpl.jena.sdb.sql.SDBConnection;
-import com.hp.hpl.jena.sdb.store.DatabaseType;
-import com.hp.hpl.jena.sdb.store.LayoutType;
-
/**
* Database functions
* @author nkons
@@ -42,10 +34,6 @@
private Connection connection;
- private SDBConnection jenaConnection;
-
- private Store store;
-
private Properties properties = new Properties();
private String propertiesFilename;
@@ -90,57 +78,6 @@ public Connection openConnection() {
return null;
}
- public SDBConnection openJenaConnection() {
- log.info("Establishing target (jena/triplestore) connection.");
- if (jenaConnection == null) {
- try {
-
- String jenaDriver = properties.getProperty("jena.db.driver");
- Class.forName(jenaDriver);
- String jenaDatabaseType = util.findDatabaseType(jenaDriver);
- String jenaConnectionString = "jdbc:" + jenaDatabaseType + "://" + properties.getProperty("jena.db.host") + ":" + properties.getProperty("jena.db.port") + "/" + properties.getProperty("jena.db.name");
- log.info("jena repository at " + jenaConnectionString);
-
- jenaConnection = new SDBConnection(jenaConnectionString, properties.getProperty("jena.db.login"), properties.getProperty("jena.db.password")) ;
-
- StoreDesc storeDesc = null;
- if ("postgresql".equals(jenaDatabaseType)) {
- storeDesc = new StoreDesc(LayoutType.LayoutTripleNodesHash, DatabaseType.PostgreSQL);
- } else if ("mysql".equals(jenaDatabaseType)) {
- storeDesc = new StoreDesc(LayoutType.LayoutTripleNodesHash, DatabaseType.MySQL);
- }
- store = SDBFactory.connectStore(jenaConnection, storeDesc);
-
- if ("true".equals(properties.getProperty("jena.cleanDbOnStartup"))) {
- log.info("Cleaning up database");
- store.getTableFormatter().create();
- }
-
- log.info("Established target (jena/triplestore) connection.");
-
- return jenaConnection;
- } catch (Exception e) {
- //e.printStackTrace();
- log.error(e.getMessage());
- System.exit(0);
- }
- } else {
- return jenaConnection;
- }
- return null;
- }
-
- public Store jenaStore() {
- try {
- @SuppressWarnings("unused")
- long storeSize = store.getSize();
- } catch (Exception e) {
- log.info("Initializing Jena store.");
- store.getTableFormatter().create();
- }
- return store;
- }
-
public ResultSet query(String query) {
ResultSet result = null;
@@ -38,6 +38,8 @@
import org.slf4j.LoggerFactory;
import com.hp.hpl.jena.datatypes.BaseDatatype;
+import com.hp.hpl.jena.query.Dataset;
+import com.hp.hpl.jena.query.ReadWrite;
import com.hp.hpl.jena.rdf.model.AnonId;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Model;
@@ -49,8 +51,7 @@
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.StmtIterator;
-import com.hp.hpl.jena.sdb.SDBFactory;
-import com.hp.hpl.jena.sdb.Store;
+import com.hp.hpl.jena.tdb.TDBFactory;
import com.hp.hpl.jena.util.FileManager;
import com.hp.hpl.jena.vocabulary.DC;
import com.hp.hpl.jena.vocabulary.RDF;
@@ -91,7 +92,7 @@ public Generator() {
public void createTriples(MappingDocument mappingDocument) {
verbose = properties.containsKey("default.verbose") && properties.getProperty("default.verbose").contains("true");
- storeOutputModelInDatabase = properties.containsKey("jena.storeOutputModelInDatabase") && properties.getProperty("jena.storeOutputModelInDatabase").contains("true");
+ storeOutputModelInDatabase = properties.containsKey("jena.storeOutputModelUsingTdb") && properties.getProperty("jena.storeOutputModelUsingTdb").contains("true");
incremental = !storeOutputModelInDatabase && properties.containsKey("default.incremental") && properties.getProperty("default.incremental").contains("true");
writeReifiedModel = incremental;
@@ -640,10 +641,11 @@ public void createTriples(MappingDocument mappingDocument) {
Calendar c0 = Calendar.getInstance();
long t0 = c0.getTimeInMillis();
//Sync start
- //before writing the result, check the existing
- Store store = db.jenaStore();
- Model existingDbModel = SDBFactory.connectDefaultModel(store);
- //log.info("Existing model has " + existingDbModel.listStatements().toList().size() + " statements.");
+ Dataset dataset = TDBFactory.createDataset(properties.getProperty("jena.tdb.directory"));
+ dataset.begin(ReadWrite.WRITE);
+ Model existingDbModel = dataset.getDefaultModel();
+
+ log.info("Existing model has " + existingDbModel.size() + " statements.");
List<Statement> statementsToRemove = new ArrayList<Statement>();
List<Statement> statementsToAdd = new ArrayList<Statement>();
@@ -670,27 +672,17 @@ public void createTriples(MappingDocument mappingDocument) {
differenceModel.close();
log.info("Will add " + statementsToAdd.size() + " statements.");
-// int statementsToAddIter = 0;
-// StmtIterator stmtResultIter = resultModel.listStatements();
-// while (stmtResultIter.hasNext()) {
-// Statement stmt = stmtResultIter.nextStatement();
-// if (existingDbModel.isEmpty() || !existingDbModel.contains(stmt)) {
-// statementsToAdd.add(stmt);
-// statementsToAddIter++;
-// }
-// if (statementsToAddIter % 10000 == 0) log.info("At " + statementsToAddIter);
-// }
-// stmtResultIter.close();
-// log.info("Will add " + statementsToAdd.size() + " statements.");
-
existingDbModel.remove(statementsToRemove);
existingDbModel.add(statementsToAdd);
+ dataset.commit();
+ dataset.end();
+
//Sync end
Calendar c1 = Calendar.getInstance();
long t1 = c1.getTimeInMillis();
log.info("Updating model in database took " + (t1 - t0) + " milliseconds.");
- mappingDocument.getTimestamps().add(Calendar.getInstance().getTimeInMillis()); //3 Wrote clean model to database.
- //log.info("3 Wrote clean model to database.");
+ mappingDocument.getTimestamps().add(Calendar.getInstance().getTimeInMillis()); //3 Wrote clean model to tdb.
+ //log.info("3 Wrote clean model to tdb.");
}
} else {
log.info("Skipping writing the output model. No changes detected.");
@@ -41,14 +41,16 @@
import org.slf4j.LoggerFactory;
import com.hp.hpl.jena.datatypes.BaseDatatype;
+import com.hp.hpl.jena.query.Dataset;
+import com.hp.hpl.jena.query.ReadWrite;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.NodeIterator;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.ResIterator;
import com.hp.hpl.jena.rdf.model.Resource;
-import com.hp.hpl.jena.sdb.SDBFactory;
+import com.hp.hpl.jena.tdb.TDBFactory;
import com.hp.hpl.jena.util.FileManager;
/**
@@ -616,8 +618,8 @@ public SubjectMap createSubjectMapForResource(Resource r) {
SelectQuery selectQuery = new SelectQuery(query, properties);
//if the dump is incremental, add an order by to ensure results are retrieved in the same order
- if (properties.containsKey("jena.storeOutputModelInDatabase")
- && properties.getProperty("jena.storeOutputModelInDatabase").contains("false")
+ if (properties.containsKey("jena.jena.storeOutputModelUsingTdb")
+ && properties.getProperty("jena.jena.storeOutputModelUsingTdb").contains("false")
&& properties.containsKey("default.incremental")
&& properties.getProperty("default.incremental").contains("true")) {
String q = selectQuery.getQuery();
@@ -694,11 +696,6 @@ public void init() {
//test source database
db.openConnection();
-
- //test destination database
- if (properties.containsKey("jena.storeOutputModelInDatabase") && properties.getProperty("jena.storeOutputModelInDatabase").contains("true")) {
- db.openJenaConnection();
- }
this.baseNs = properties.getProperty("default.namespace");
String mappingFilename = properties.getProperty("mapping.file");
@@ -722,38 +719,36 @@ public void init() {
}
//resultBaseModel.write(System.out, properties.getProperty("input.model.type"));
- String storeInDatabase = properties.getProperty("jena.storeOutputModelInDatabase");
- String cleanDbOnStartup = properties.getProperty("jena.cleanDbOnStartup");
+ String storeInTdb = properties.getProperty("jena.storeOutputModelUsingTdb");
+ String cleanTdbOnStartup = properties.getProperty("jena.cleanTdbOnStartup");
verbose = properties.containsKey("default.verbose") && properties.getProperty("default.verbose").contains("true");
log.info("Initialising Parser");
- if (Boolean.valueOf(storeInDatabase)) {
- if (Boolean.valueOf(cleanDbOnStartup)) {
- db.jenaStore().getTableFormatter().create();
+ if (Boolean.valueOf(storeInTdb)) {
+ if (Boolean.valueOf(cleanTdbOnStartup)) {
+ Dataset dataset = TDBFactory.createDataset(properties.getProperty("jena.tdb.directory"));
+ dataset.begin(ReadWrite.WRITE);
+ Model m = dataset.getDefaultModel();
+ m.removeAll();
+ dataset.commit();
+ dataset.end();
}
- Model resultDbModel = SDBFactory.connectDefaultModel(db.jenaStore());
-
+ Dataset dataset = TDBFactory.createDataset(properties.getProperty("jena.tdb.directory"));
+ dataset.begin(ReadWrite.READ);
+ Model resultDbModel = dataset.getDefaultModel();
+ dataset.end();
+
if (StringUtils.isNotBlank(inputModelFileName)) {
InputStream isRes = FileManager.get().open(inputModelFileName);
resultDbModel.read(isRes, baseNs, properties.getProperty("input.model.type"));
}
- log.info("Store size is " + db.jenaStore().getSize());
-// if (store.getSize() > 0) {
-// StmtIterator sIter = resultDbModel.listStatements();
-// for ( ; sIter.hasNext() ; ) {
-// Statement stmt = sIter.nextStatement() ;
-// log.info("stmt " + stmt) ;
-// }
-// sIter.close() ;
-// }
+ log.info("Store size is " + resultDbModel.size());
- //Model resultDbModel = ModelFactory.createModelRDBMaker(db.getJenaConnection()).createModel("fresh");
resultDbModel.add(resultBaseModel);
- //resultModel = ModelFactory.createInfModel(ReasonerRegistry.getRDFSReasoner(), resultDbModel);
resultModel = ModelFactory.createDefaultModel();
Map<String, String> prefixes = mapModel.getNsPrefixMap();

0 comments on commit b3c93ae

Please sign in to comment.