Permalink
Browse files

Bug : add class SQLToolKit.

Bug : Direct Mapping refs blank nodes ID.
  • Loading branch information...
1 parent 8f6a0fc commit c9acf879bd18ef3d0cfd164872a45c7c39b013c7 @jhomo jhomo committed Apr 18, 2012
View
@@ -1,15 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="src" path="src/main/java"/>
- <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry including="**/*.java" kind="src" path="src/main/java"/>
+ <classpathentry excluding="**/*.java" kind="src" path="src/main/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry kind="lib" path="/home/jhomo/workspace/Libs/commons-cli-1.2/commons-cli-1.2.jar"/>
- <classpathentry kind="lib" path="/home/jhomo/workspace/Libs/commons-logging-1.1.1/commons-logging-1.1.1.jar"/>
- <classpathentry kind="lib" path="/home/jhomo/workspace/Libs/openrdf-sesame-2.6.1-onejar.jar"/>
- <classpathentry kind="lib" path="/home/jhomo/workspace/Libs/mysql-connector-java-5.1.18/mysql-connector-java-5.1.18-bin.jar"/>
- <classpathentry kind="lib" path="/home/jhomo/workspace/Libs/postgresql-9.1-901.jdbc4.jar"/>
- <classpathentry kind="lib" path="/home/jhomo/workspace/Libs/slf4j-1.6.4/slf4j-simple-1.6.4.jar"/>
- <classpathentry kind="lib" path="/home/jhomo/workspace/Libs/slf4j-1.6.4/slf4j-api-1.6.4.jar"/>
- <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
+ <classpathentry kind="var" path="M2_REPO/junit/junit/4.8.2/junit-4.8.2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/mysql/mysql-connector-java/5.1.15/mysql-connector-java-5.1.15.jar"/>
+ <classpathentry kind="var" path="M2_REPO/commons-cli/commons-cli/1.2/commons-cli-1.2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/openrdf/sesame/sesame-sail-nativerdf/2.5.1/sesame-sail-nativerdf-2.5.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/openrdf/sesame/sesame-sail-api/2.5.1/sesame-sail-api-2.5.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/openrdf/sesame/sesame-query/2.5.1/sesame-query-2.5.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/openrdf/sesame/sesame-model/2.5.1/sesame-model-2.5.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/info/aduna/commons/aduna-commons-collections/2.8.0/aduna-commons-collections-2.8.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/info/aduna/commons/aduna-commons-concurrent/2.7.0/aduna-commons-concurrent-2.7.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/info/aduna/commons/aduna-commons-io/2.10.0/aduna-commons-io-2.10.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/info/aduna/commons/aduna-commons-i18n/1.4.0/aduna-commons-i18n-1.4.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/info/aduna/commons/aduna-commons-text/2.7.0/aduna-commons-text-2.7.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/openrdf/sesame/sesame-rio-api/2.5.1/sesame-rio-api-2.5.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/info/aduna/commons/aduna-commons-lang/2.9.0/aduna-commons-lang-2.9.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/info/aduna/commons/aduna-commons-net/2.7.0/aduna-commons-net-2.7.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/info/aduna/commons/aduna-commons-iteration/2.10.0/aduna-commons-iteration-2.10.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/openrdf/sesame/sesame-queryalgebra-model/2.5.1/sesame-queryalgebra-model-2.5.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/openrdf/sesame/sesame-sail-inferencer/2.5.1/sesame-sail-inferencer-2.5.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/openrdf/sesame/sesame-queryparser-api/2.5.1/sesame-queryparser-api-2.5.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/openrdf/sesame/sesame-queryparser-serql/2.5.1/sesame-queryparser-serql-2.5.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/openrdf/sesame/sesame-queryalgebra-evaluation/2.5.1/sesame-queryalgebra-evaluation-2.5.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/openrdf/sesame/sesame-repository-sparql/2.5.1/sesame-repository-sparql-2.5.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/openrdf/sesame/sesame-repository-api/2.5.1/sesame-repository-api-2.5.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/openrdf/sesame/sesame-http-client/2.5.1/sesame-http-client-2.5.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/openrdf/sesame/sesame-http-protocol/2.5.1/sesame-http-protocol-2.5.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/openrdf/sesame/sesame-rio-ntriples/2.5.1/sesame-rio-ntriples-2.5.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/info/aduna/commons/aduna-commons-xml/2.7.0/aduna-commons-xml-2.7.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/openrdf/sesame/sesame-queryresultio-api/2.5.1/sesame-queryresultio-api-2.5.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/commons-httpclient/commons-httpclient/3.1/commons-httpclient-3.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/commons-codec/commons-codec/1.4/commons-codec-1.4.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/openrdf/sesame/sesame-queryresultio-sparqlxml/2.5.1/sesame-queryresultio-sparqlxml-2.5.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/openrdf/sesame/sesame-queryparser-sparql/2.5.1/sesame-queryparser-sparql-2.5.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/openrdf/sesame/sesame-queryresultio-binary/2.5.1/sesame-queryresultio-binary-2.5.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/openrdf/sesame/sesame-queryresultio-sparqljson/2.5.1/sesame-queryresultio-sparqljson-2.5.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/openrdf/sesame/sesame-queryresultio-text/2.5.1/sesame-queryresultio-text-2.5.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/openrdf/sesame/sesame-repository-manager/2.5.1/sesame-repository-manager-2.5.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/openrdf/sesame/sesame-repository-event/2.5.1/sesame-repository-event-2.5.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/openrdf/sesame/sesame-repository-sail/2.5.1/sesame-repository-sail-2.5.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/openrdf/sesame/sesame-sail-memory/2.5.1/sesame-sail-memory-2.5.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/openrdf/sesame/sesame-repository-http/2.5.1/sesame-repository-http-2.5.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/openrdf/sesame/sesame-repository-dataset/2.5.1/sesame-repository-dataset-2.5.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/openrdf/sesame/sesame-repository-contextaware/2.5.1/sesame-repository-contextaware-2.5.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/openrdf/sesame/sesame-rio-binary/2.5.1/sesame-rio-binary-2.5.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/openrdf/sesame/sesame-rio-n3/2.5.1/sesame-rio-n3-2.5.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/openrdf/sesame/sesame-rio-turtle/2.5.1/sesame-rio-turtle-2.5.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/openrdf/sesame/sesame-rio-rdfxml/2.5.1/sesame-rio-rdfxml-2.5.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/openrdf/sesame/sesame-rio-trix/2.5.1/sesame-rio-trix-2.5.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/openrdf/sesame/sesame-rio-trig/2.5.1/sesame-rio-trig-2.5.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/openrdf/sesame/sesame-sail-rdbms/2.5.1/sesame-sail-rdbms-2.5.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/commons-dbcp/commons-dbcp/1.3/commons-dbcp-1.3.jar"/>
+ <classpathentry kind="var" path="M2_REPO/commons-pool/commons-pool/1.5.4/commons-pool-1.5.4.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-simple/1.6.1/slf4j-simple-1.6.1.jar"/>
+ <classpathentry kind="lib" path="/home/jhomo/Code/DB2TRIPLES/direct-mapping_lib/postgresql-9.1-901.jdbc4.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
View
@@ -1,23 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
- <name>db2triples</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.maven.ide.eclipse.maven2Builder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.jdt.core.javanature</nature>
- <nature>org.maven.ide.eclipse.maven2Nature</nature>
- </natures>
-</projectDescription>
+ <name>db2triples</name>
+ <comment>RDB2RDF Implementation from Antidot. NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment>
+ <projects/>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ </buildCommand>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
+ </natures>
+</projectDescription>
View
@@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.antidot</groupId>
<artifactId>db2triples</artifactId>
- <version>0.90</version>
+ <version>0.99</version>
<name>DB2Triples</name>
<description>RDB2RDF Implementation from Antidot</description>
<packaging>jar</packaging>
@@ -28,6 +28,11 @@
<artifactId>mysql-connector-java</artifactId>
<version>5.1.15</version>
</dependency>
+ <dependency>
+ <groupId>postgresql</groupId>
+ <artifactId>postgresql</artifactId>
+ <version>9.1-901.jdbc4</version>
+ </dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
@@ -53,6 +58,7 @@
<type>jar</type>
<scope>runtime</scope>
</dependency>
+
</dependencies>
<url>https://github.com/antidot/db2triples</url>
@@ -110,9 +110,10 @@ public String constructSQLQuery(String driver, ResultSet headersSet,
* @param headersSet
* @param tableName
* @return
+ * @throws UnsupportedEncodingException
*/
public String constructReferencedSQLQuery(String driver,
- ResultSet headersSet, String tableName, Key key, Tuple tuple);
+ ResultSet headersSet, String tableName, Key key, Tuple tuple) throws UnsupportedEncodingException;
/**
* Extract Sesame triples from generic tuples depends on used norm.
@@ -492,19 +492,20 @@ private Resource phi(StdTable t, Row r, String baseURI)
*/
private Resource phi(StdTable t, Row row, Row referencedRow, String baseURI)
throws UnsupportedEncodingException {
- if (log.isDebugEnabled())
- log.debug("[DirectMappingEngine:phi] Table : " + t);
+ log.debug("[DirectMappingEngine:phi] Table : " + t);
+
CandidateKey primaryKey = t.getPrimaryKey();
if (primaryKey != null) {
// Unique Node IRI
String stringURI = generateUniqNodeIRI(referencedRow, t,
primaryKey, baseURI);
+
URI uri = vf.createURI(baseURI, stringURI);
// URIs.put(r, uri);
return uri;
} else {
// Blank node
- BNode bnode = vf.createBNode(generateUniqBlankNodeName(row));
+ BNode bnode = vf.createBNode(generateUniqBlankNodeName(referencedRow));
return bnode;
}
}
@@ -608,7 +609,7 @@ private String generateUniqBlankNodeName(Row r)
*/
private HashSet<SemiStatement> convertRef(Row row, Row referencedRow,
ForeignKey fk, String baseURI) throws UnsupportedEncodingException {
- log.debug("[DirectMappingEngine:convertRef] Row : " + row);
+ log.debug("[DirectMappingEngine:convertRef] Row : " + row + " Referenced row : " + referencedRow);
HashSet<SemiStatement> result = new HashSet<SemiStatement>();
ArrayList<String> columnNames = new ArrayList<String>();
columnNames.addAll(fk.getColumnNames());
@@ -49,7 +49,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-
public class StdTable implements Table {
// Log
@@ -91,6 +90,7 @@ public StdHeader getHeader() {
/**
* Set the standard header of this table.
+ *
* @param header
*/
public void setHeader(StdHeader header) {
@@ -99,12 +99,13 @@ public void setHeader(StdHeader header) {
/**
* Return candidates keys of this table.
+ *
* @return
*/
public ArrayList<CandidateKey> getCandidateKeys() {
return candidateKeys;
}
-
+
public ArrayList<Key> getKeys() {
ArrayList<Key> keys = new ArrayList<Key>();
keys.addAll(getCandidateKeys());
@@ -114,6 +115,7 @@ public void setHeader(StdHeader header) {
/**
* Set candidates keys of this table.
+ *
* @param candidateKeys
*/
public void setCandidateKeys(ArrayList<CandidateKey> candidateKeys) {
@@ -137,6 +139,7 @@ public void setCandidateKeys(ArrayList<CandidateKey> candidateKeys) {
/**
* Return foreign keys of this table.
+ *
* @return
*/
public HashSet<ForeignKey> getForeignKeys() {
@@ -150,6 +153,7 @@ public void setCandidateKeys(ArrayList<CandidateKey> candidateKeys) {
/**
* Set foreign keys of this table.
+ *
* @param foreignKeys
*/
public void setForeignKeys(HashSet<ForeignKey> foreignKeys) {
@@ -176,11 +180,11 @@ public void indexesRows(ForeignKey fk) {
// Save values of columns in the fk for current row
columnNames.add(r.getValues().get(columnName));
}
- if (log.isDebugEnabled())
- log.debug("[Table:indexesRows] Row r = " + r
- + " columnNames = " + columnNames);
+ log.debug("[Table:indexesRows] Row r = " + r + " columnNames = "
+ + columnNames);
if (indexedRows.get(columnNames) == null) {
- indexedRows.put(new HashSet<String>(columnNames), new HashSet<Row>());
+ indexedRows.put(new HashSet<String>(columnNames),
+ new HashSet<Row>());
}
indexedRows.get(columnNames).add(r);
columnNames.clear();
@@ -195,8 +199,7 @@ public void indexesRows(ForeignKey fk) {
"[Table:getIndexedRow] A indexed row is required whereas this table has not been indexed.");
if (indexedRowsByFk.get(fk) == null)
if (log.isWarnEnabled())
- log
- .warn("[Table:getIndexedRow] No indexed row for this foreign key.");
+ log.warn("[Table:getIndexedRow] No indexed row for this foreign key.");
if (log.isDebugEnabled())
log.debug("[Table:getIndexedRow] Table = " + tableName
+ " indexedRow at this value = " + indexedRowsByFk.get(fk)
@@ -210,6 +213,7 @@ public Body getBody() {
/**
* Set standard body of this table.
+ *
* @param body
*/
public void setBody(StdBody body) {
@@ -229,6 +233,7 @@ public CandidateKey getPrimaryKey() {
/**
* Returns names of column which are not targeted by a unary foreign key.
+ *
* @return
*/
public HashSet<String> getLexicals() {
@@ -258,8 +263,8 @@ public String toString() {
+ "\tforeignKeys = [";
for (ForeignKey key : getForeignKeys())
result += key;
- //result += "];" + System.getProperty("line.separator") + "\tbody = "
- // + body;
+ // result += "];" + System.getProperty("line.separator") + "\tbody = "
+ // + body;
result += "];" + System.getProperty("line.separator")
+ "\tindexed rows = " + indexedRowsByFk.keySet();
return result;
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2011 Antidot opensource@antidot.net
+ * https://github.com/antidot/db2triples
+ *
+ * DB2Triples is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * DB2Triples is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+/***************************************************************************
+ *
+ * SQL : SQL Toolkit
+ *
+ * Collection of useful tool-methods used in SQL.
+ *
+ *
+ ****************************************************************************/
+package net.antidot.sql.model.tools;
+
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+
+public class SQLToolkit {
+
+ /**
+ * Check if the row at the cursor of rs1 is contained by rs2.
+ * @param rs1
+ * @param rs2
+ * @return
+ * @throws SQLException
+ */
+ public static boolean containsTheSameRow(ResultSet rs1, ResultSet rs2) throws SQLException{
+ ResultSetMetaData metas1 = rs1.getMetaData();
+ ResultSetMetaData metas2 = rs2.getMetaData();
+ if (metas1.getColumnCount() != metas2.getColumnCount()) return false;
+ int index2 = rs2.getRow();
+ // Init
+ rs2.beforeFirst();
+ boolean result = false;
+ while (rs2.next()){
+ boolean sameRow = true;
+ for (int i = 1; i <= metas2.getColumnCount(); i++){
+ sameRow &= rs1.getString(i).equals(rs2.getString(i));
+ }
+ if (sameRow) {
+ result = true;
+ break;
+ }
+ }
+ // Restore last index
+ rs2.beforeFirst();
+ rs2.relative(index2);
+ return result;
+ }
+
+ /**
+ * SQL identifiers can be delimited identifiers : with double quotes.
+ * @return
+ */
+ public static boolean isDelimitedIdentifier(String identifier){
+ return identifier != null && identifier.startsWith("\"") && identifier.endsWith("\"");
+ }
+
+ public static String extractValueFromDelimitedIdentifier(String identifier){
+ if (!isDelimitedIdentifier(identifier)) return null;
+ return identifier.substring(1, identifier.length() - 1);
+ }
+
+}

0 comments on commit c9acf87

Please sign in to comment.