diff --git a/pom.xml b/pom.xml
index 49d367c..0a80ba9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,12 +3,12 @@
4.0.0
gr.seab
r2rml-parser
- 0.5
+ 0.6
jar
R2RML Parser
true
- 4.0.0.RELEASE
+ 4.0.5.RELEASE
UTF-8
@@ -106,13 +106,13 @@
org.slf4j
slf4j-log4j12
- 1.7.5
+ 1.7.7
org.apache.jena
apache-jena-libs
pom
- 2.11.1
+ 2.11.2
com.oracle
@@ -145,7 +145,7 @@
Nikolaos Konstantinou
nkons at cn.ntua.gr
- http://www.cn.ntua.gr/~nkons/
+ https://www.researchgate.net/profile/Nikolaos_Konstantinou/
Hellenic Academic Libraries Link/National Technical University of Athens (HEAL-Link/NTUA)
http://www.seab.gr
diff --git a/r2rml-parser.bat b/r2rml-parser.bat
index a1f0f72..1c06c22 100644
--- a/r2rml-parser.bat
+++ b/r2rml-parser.bat
@@ -1,4 +1,4 @@
@echo off
-echo This is R2RML Parser 0.5-alpha
+echo This is R2RML Parser 0.6-alpha
java -Xms128m -Xmx1024m -cp "./*;./lib/*;" gr.seab.r2rml.beans.Main %1
-echo R2RML Parser 0.5-alpha. Done.
+echo R2RML Parser 0.6-alpha. Done.
diff --git a/r2rml-parser.sh b/r2rml-parser.sh
index e42e95f..3ac0282 100644
--- a/r2rml-parser.sh
+++ b/r2rml-parser.sh
@@ -1,3 +1,3 @@
-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."
\ No newline at end of file
+echo "This is R2RML Parser 0.6-alpha"
+java -Xms128m -Xmx1024m -cp "./*;./lib/*;" -jar lib/r2rml-parser-0.6.jar
+echo "R2RML Parser 0.6-alpha. Done."
\ No newline at end of file
diff --git a/src/main/java/gr/seab/r2rml/beans/DatabaseImpl.java b/src/main/java/gr/seab/r2rml/beans/DatabaseImpl.java
index a1ae5ee..274f07c 100644
--- a/src/main/java/gr/seab/r2rml/beans/DatabaseImpl.java
+++ b/src/main/java/gr/seab/r2rml/beans/DatabaseImpl.java
@@ -64,8 +64,8 @@ public Connection openConnection() {
Class.forName(driver);
String dbConnectionString = properties.getProperty("db.url");
if (dbConnectionString == null) {
- String databaseType = util.findDatabaseType(driver);
- dbConnectionString = "jdbc:" + databaseType + "://" + properties.getProperty("db.host") + ":" + properties.getProperty("db.port") + "/" + properties.getProperty("db.name");
+ log.error("The property db.url cannot be empty! It must contain a valid database connection string.");
+ System.exit(0);
}
connection = DriverManager.getConnection(dbConnectionString, properties.getProperty("db.login"), properties.getProperty("db.password"));
diff --git a/src/main/java/gr/seab/r2rml/beans/Generator.java b/src/main/java/gr/seab/r2rml/beans/Generator.java
index ca62ed3..9e8d933 100644
--- a/src/main/java/gr/seab/r2rml/beans/Generator.java
+++ b/src/main/java/gr/seab/r2rml/beans/Generator.java
@@ -55,6 +55,7 @@
import com.hp.hpl.jena.util.FileManager;
import com.hp.hpl.jena.vocabulary.DC;
import com.hp.hpl.jena.vocabulary.RDF;
+import gr.seab.r2rml.entities.DatabaseType;
/**
* Generates the resulting graph, based on the mapping document
@@ -143,7 +144,6 @@ public void createTriples(MappingDocument mappingDocument) {
resultModel.remove(statementsToRemove); //.toArray(new Statement[statementsToRemove.size()]));
log.info("Removed " + statementsToRemove.size() + " old statements.");
}
- String databaseType = util.findDatabaseType(properties.getProperty("db.driver"));
boolean executeAllMappings = false;
int mappingsExecuted = 0;
@@ -460,7 +460,7 @@ public void createTriples(MappingDocument mappingDocument) {
if (parentQuery.getTables().size() == 1) {
String parentFieldName = predicateObjectMap.getRefObjectMap().getParent();
- if (databaseType.equals("mysql")) parentFieldName = parentFieldName.replaceAll("\"", ""); //in mysql, table names must not be enclosed in quotes
+ if (mappingDocument.getDatabaseType() == DatabaseType.MYSQL) parentFieldName = parentFieldName.replaceAll("\"", ""); //in mysql, table names must not be enclosed in quotes
boolean containsWhere = parentQueryText.toLowerCase().contains("where");
String addition = (containsWhere ? " AND " : " WHERE ") + parentFieldName + " = " + childValue;
int order = parentQueryText.toUpperCase().indexOf("ORDER BY");
diff --git a/src/main/java/gr/seab/r2rml/beans/Parser.java b/src/main/java/gr/seab/r2rml/beans/Parser.java
index 6cbd723..9430dcb 100644
--- a/src/main/java/gr/seab/r2rml/beans/Parser.java
+++ b/src/main/java/gr/seab/r2rml/beans/Parser.java
@@ -52,6 +52,7 @@
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.tdb.TDBFactory;
import com.hp.hpl.jena.util.FileManager;
+import gr.seab.r2rml.entities.DatabaseType;
/**
* Parses a valid R2RML file and produces a mapping document
@@ -130,7 +131,9 @@ public MappingDocument parse() {
log.info("Initialized.");
try {
- //First find the logical table views
+ DatabaseType databaseType = util.findDatabaseType(properties.getProperty("db.driver"));
+ mappingDocument.setDatabaseType(databaseType);
+ //First find the logical table views
LinkedList logicalTableViews = findLogicalTableViews();
mappingDocument.setLogicalTableViews(logicalTableViews);
log.info("Mapping document has " + logicalTableViews.size() + " logical table views.");
@@ -647,19 +650,17 @@ public LinkedList findLogicalTableViews() {
}
public String createQueryForTable(String tableName) {
- //If true, we are in postgres, otherwise in mysql
- String databaseType = util.findDatabaseType(properties.getProperty("db.driver"));
String result = "SELECT ";
try {
ArrayList fields = new ArrayList();
java.sql.ResultSet rs;
- if (databaseType.equals("postgresql")) {
+ if (mappingDocument.getDatabaseType() == DatabaseType.POSTGRESQL) {
rs = db.query("SELECT column_name FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '" + tableName + "'");
- } else if (databaseType.equals("mysql")) {
+ } else if (mappingDocument.getDatabaseType() == DatabaseType.MYSQL) {
rs = db.query("DESCRIBE " + tableName);
- } else if (databaseType.equals("oracle")) {
+ } else if (mappingDocument.getDatabaseType() == DatabaseType.ORACLE) {
rs = db.query("SELECT column_name FROM all_tab_cols WHERE table_name = '" + tableName + "'");
} else {
rs = null;
@@ -670,14 +671,14 @@ public String createQueryForTable(String tableName) {
rs.beforeFirst();
while (rs.next()) {
//mysql: fields.add(rs.getString("Field"));
- if (databaseType.equals("postgresql") || databaseType.equals("oracle")) {
+ if (mappingDocument.getDatabaseType() == DatabaseType.POSTGRESQL || mappingDocument.getDatabaseType() == DatabaseType.ORACLE) {
fields.add("\"" + rs.getString(1) + "\"");
} else {
fields.add(rs.getString("Field"));
}
}
for (String f : fields) {
- if (databaseType.equals("postgresql") || databaseType.equals("oracle")) {
+ if (mappingDocument.getDatabaseType() == DatabaseType.POSTGRESQL || mappingDocument.getDatabaseType() == DatabaseType.ORACLE) {
result += "\"" + tableName + "\"" + "." + f + ", ";
} else {
result += tableName + "." + f + ", ";
@@ -686,7 +687,7 @@ public String createQueryForTable(String tableName) {
result = result.substring(0, result.lastIndexOf(','));
rs.close();
- if (databaseType.equals("postgresql") || databaseType.equals("oracle")) {
+ if (mappingDocument.getDatabaseType() == DatabaseType.POSTGRESQL || mappingDocument.getDatabaseType() == DatabaseType.ORACLE) {
result += " FROM " + "\"" + tableName + "\"";
} else {
result += " FROM " + tableName;
diff --git a/src/main/java/gr/seab/r2rml/beans/Util.java b/src/main/java/gr/seab/r2rml/beans/Util.java
index b18af67..e89ae85 100644
--- a/src/main/java/gr/seab/r2rml/beans/Util.java
+++ b/src/main/java/gr/seab/r2rml/beans/Util.java
@@ -19,12 +19,13 @@
import com.hp.hpl.jena.datatypes.BaseDatatype;
import com.hp.hpl.jena.rdf.model.Model;
+import gr.seab.r2rml.entities.DatabaseType;
public interface Util {
String fillTemplate(Template template, ResultSet rs);
- String findDatabaseType(String driver);
+ DatabaseType findDatabaseType(String driver);
String stripQuotes(String input);
diff --git a/src/main/java/gr/seab/r2rml/beans/UtilImpl.java b/src/main/java/gr/seab/r2rml/beans/UtilImpl.java
index 7e68969..d88d65c 100644
--- a/src/main/java/gr/seab/r2rml/beans/UtilImpl.java
+++ b/src/main/java/gr/seab/r2rml/beans/UtilImpl.java
@@ -41,6 +41,7 @@
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource;
+import gr.seab.r2rml.entities.DatabaseType;
/**
* Collection of utility functions
@@ -115,19 +116,19 @@ public String fillTemplate(Template template, ResultSet rs) {
return result;
}
- public String findDatabaseType(String driver) {
+ public DatabaseType findDatabaseType(String driver) {
if (driver.contains("mysql")) {
- return "mysql";
+ return DatabaseType.MYSQL;
} else if (driver.contains("postgresql")) {
- return "postgresql";
+ return DatabaseType.POSTGRESQL;
} else if (driver.contains("oracle")) {
- return "oracle";
+ return DatabaseType.ORACLE;
} else {
- System.out.println("Unknown database type.");
+ log.error("Unknown database type.");
System.exit(1);
}
- return null;
+ return DatabaseType.OTHER;
}
public String stripQuotes(String input) {
diff --git a/src/main/java/gr/seab/r2rml/entities/DatabaseType.java b/src/main/java/gr/seab/r2rml/entities/DatabaseType.java
new file mode 100644
index 0000000..5b47cf4
--- /dev/null
+++ b/src/main/java/gr/seab/r2rml/entities/DatabaseType.java
@@ -0,0 +1,22 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package gr.seab.r2rml.entities;
+
+/**
+ *
+ * @author nkons
+ */
+public enum DatabaseType {
+
+ MYSQL,
+
+ POSTGRESQL,
+
+ ORACLE,
+
+ OTHER;
+}
diff --git a/src/main/java/gr/seab/r2rml/entities/MappingDocument.java b/src/main/java/gr/seab/r2rml/entities/MappingDocument.java
index a0cdd2a..5967ab2 100644
--- a/src/main/java/gr/seab/r2rml/entities/MappingDocument.java
+++ b/src/main/java/gr/seab/r2rml/entities/MappingDocument.java
@@ -31,6 +31,8 @@ public class MappingDocument {
private Map prefixes;
private ArrayList timestamps = new ArrayList();
+ private DatabaseType databaseType = DatabaseType.OTHER;
+
/**
*
*/
@@ -106,4 +108,12 @@ public ArrayList getTimestamps() {
public void setTimestamps(ArrayList timestamps) {
this.timestamps = timestamps;
}
+
+ public DatabaseType getDatabaseType() {
+ return databaseType;
+ }
+
+ public void setDatabaseType(DatabaseType databaseType) {
+ this.databaseType = databaseType;
+ }
}