You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by en...@apache.org on 2014/03/29 19:05:28 UTC
[5/5] git commit: CLEREZZA-813 Moved the two virtuoso modules to the
clerezza root folder. Added to the main pom.xml
CLEREZZA-813 Moved the two virtuoso modules to the clerezza root folder. Added to the main pom.xml
Project: http://git-wip-us.apache.org/repos/asf/clerezza/repo
Commit: http://git-wip-us.apache.org/repos/asf/clerezza/commit/bb87e83f
Tree: http://git-wip-us.apache.org/repos/asf/clerezza/tree/bb87e83f
Diff: http://git-wip-us.apache.org/repos/asf/clerezza/diff/bb87e83f
Branch: refs/heads/master
Commit: bb87e83fedb6843be6dd2c31c4a51e47707651ca
Parents: b8776a5
Author: enridaga <en...@apache.org>
Authored: Sat Mar 29 18:05:14 2014 +0000
Committer: enridaga <en...@apache.org>
Committed: Sat Mar 29 18:05:14 2014 +0000
----------------------------------------------------------------------
clerezza-virtuoso/README.md | 54 --
clerezza-virtuoso/ext.virtuoso.jdbc/pom.xml | 143 ---
.../repo/virtuoso/virtjdbc/4.0/virtjdbc-4.0.jar | Bin 217690 -> 0 bytes
.../repo/virtuoso/virtjdbc/4.0/virtjdbc-4.0.pom | 27 -
.../repo/virtuoso/virtjdbc/4.1/virtjdbc-4.1.jar | Bin 214811 -> 0 bytes
.../repo/virtuoso/virtjdbc/4.1/virtjdbc-4.1.pom | 27 -
.../virtuoso/virtjdbc/maven-metadata-local.xml | 30 -
.../rdf.virtuoso.storage/README.md | 2 -
clerezza-virtuoso/rdf.virtuoso.storage/pom.xml | 271 ------
.../rdf/virtuoso/storage/VirtuosoBNode.java | 45 -
.../rdf/virtuoso/storage/VirtuosoGraph.java | 94 --
.../rdf/virtuoso/storage/VirtuosoMGraph.java | 191 ----
.../rdf/virtuoso/storage/access/DataAccess.java | 949 -------------------
.../access/VirtuosoWeightedProvider.java | 937 ------------------
....clerezza.rdf.core.access.WeightedTcProvider | 1 -
.../src/main/resources/log4j.properties | 5 -
.../src/test/java/.DS_Store | Bin 6148 -> 0 bytes
.../clerezza/rdf/virtuoso/storage/.DS_Store | Bin 6148 -> 0 bytes
.../rdf/virtuoso/storage/ConnectionTest.java | 138 ---
.../rdf/virtuoso/storage/RdfIOTest.java | 352 -------
.../rdf/virtuoso/storage/TestUtils.java | 185 ----
.../rdf/virtuoso/storage/ThreadSafetyTest.java | 341 -------
.../rdf/virtuoso/storage/VirtuosoGraphTest.java | 32 -
.../virtuoso/storage/VirtuosoMGraphTest.java | 526 ----------
.../virtuoso/storage/access/DataAccessTest.java | 129 ---
.../access/VirtuosoWeightedProviderTest.java | 310 ------
.../src/test/resources/log4j.properties | 6 -
ext.virtuoso.jdbc/pom.xml | 143 +++
.../repo/virtuoso/virtjdbc/4.0/virtjdbc-4.0.jar | Bin 0 -> 217690 bytes
.../repo/virtuoso/virtjdbc/4.0/virtjdbc-4.0.pom | 27 +
.../repo/virtuoso/virtjdbc/4.1/virtjdbc-4.1.jar | Bin 0 -> 214811 bytes
.../repo/virtuoso/virtjdbc/4.1/virtjdbc-4.1.pom | 27 +
.../virtuoso/virtjdbc/maven-metadata-local.xml | 30 +
pom.xml | 4 +
rdf.virtuoso.storage/README.md | 49 +
rdf.virtuoso.storage/pom.xml | 271 ++++++
.../rdf/virtuoso/storage/VirtuosoBNode.java | 45 +
.../rdf/virtuoso/storage/VirtuosoGraph.java | 94 ++
.../rdf/virtuoso/storage/VirtuosoMGraph.java | 191 ++++
.../rdf/virtuoso/storage/access/DataAccess.java | 949 +++++++++++++++++++
.../access/VirtuosoWeightedProvider.java | 937 ++++++++++++++++++
....clerezza.rdf.core.access.WeightedTcProvider | 1 +
.../src/main/resources/log4j.properties | 5 +
.../rdf/virtuoso/storage/ConnectionTest.java | 138 +++
.../rdf/virtuoso/storage/RdfIOTest.java | 352 +++++++
.../rdf/virtuoso/storage/TestUtils.java | 185 ++++
.../rdf/virtuoso/storage/ThreadSafetyTest.java | 341 +++++++
.../rdf/virtuoso/storage/VirtuosoGraphTest.java | 32 +
.../virtuoso/storage/VirtuosoMGraphTest.java | 526 ++++++++++
.../virtuoso/storage/access/DataAccessTest.java | 129 +++
.../access/VirtuosoWeightedProviderTest.java | 310 ++++++
.../src/test/resources/log4j.properties | 6 +
52 files changed, 4792 insertions(+), 4795 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/clerezza/blob/bb87e83f/clerezza-virtuoso/README.md
----------------------------------------------------------------------
diff --git a/clerezza-virtuoso/README.md b/clerezza-virtuoso/README.md
deleted file mode 100644
index 03a501c..0000000
--- a/clerezza-virtuoso/README.md
+++ /dev/null
@@ -1,54 +0,0 @@
-# Virtuoso/Clerezza storage adapter
-
-This is an implementation of the storage API of Clerezza[1] to use Virtuoso as storage.
-
-
-## Build and Install
-To build this project you need Maven.
-
-### Simple build
-From the main folder:
-
- $ mvn clean install
-
-Results will be 2 bundles:
-
-* ext.virtuoso.jdbc : contains JDBC drivers form Virtuoso
-* rdf.virtuoso.storage : contains the implementation of the clerezza storage API for Virtuoso
-
-Bundles are in the /target folders:
-
-* ext.virtuoso.jdbc/target/ext.virtuoso.jdbc-<version>.jar
-* rdf.virtuoso.storage/target/rdf.virtuoso.storage-<version>.jar
-
-### Build forcing tests
-You must have a Virtuoso running server to do tests.
-To activate tests, you must execute maven with the virtuoso-do-tests profile, for example:
-
- $ mvn test -Pvirtuoso-do-tests
-
-By default, the tests will use the parameters configured in the pom.xml. Change the parameters' values to the ones that fit your installation of Virtuoso.
-
-You can configure the following parameters:
-
-* virtuoso.test (default is null, sets to true if you activate the 'virtuoso-do-tests' profile)
-* virtuoso.driver (default is 'virtuoso.jdbc4.Driver')
-* virtuoso.host (default is 'localhost')
-* virtuoso.port (default is '1111')
-* virtuoso.user (default is 'dba')
-* virtuoso.password (default is 'dba')
-
-To override them from cli, you can also do the following:
-
- $ mvn test -Pvirtuoso-do-tests -DargLine="-Dvirtuoso.password=mypassword -Dvirtuoso.port=1234"
-
-
-### Hot deploy on a Clerezza or Stanbol[2] running servers
-
-To deploy the bundles in a running Sling instance you can do:
-
- $ mvn install -PinstallBundle -Dsling.url=http://localhost:8080/system/console (change this to be the actual server admin interface)
-
-
-* [1] http://incubator.apache.org/clerezza/
-* [2] http://incubator.apache.org/stanbol/
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/clerezza/blob/bb87e83f/clerezza-virtuoso/ext.virtuoso.jdbc/pom.xml
----------------------------------------------------------------------
diff --git a/clerezza-virtuoso/ext.virtuoso.jdbc/pom.xml b/clerezza-virtuoso/ext.virtuoso.jdbc/pom.xml
deleted file mode 100644
index bea990e..0000000
--- a/clerezza-virtuoso/ext.virtuoso.jdbc/pom.xml
+++ /dev/null
@@ -1,143 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?><!--
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-
---><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.clerezza</groupId>
- <artifactId>clerezza</artifactId>
- <version>0.5-SNAPSHOT</version>
- <relativePath>../../parent</relativePath>
- </parent>
- <artifactId>ext.virtuoso.jdbc</artifactId>
- <name>Clerezza/Virtuoso Ext - Virtuoso JDBC OSGi Bundle</name>
- <description>Virtuoso JDBC</description>
- <version>0.3-SNAPSHOT</version>
- <repositories>
- <repository>
- <releases>
- <updatePolicy>always</updatePolicy>
- </releases>
- <snapshots>
- <updatePolicy>always</updatePolicy>
- </snapshots>
- <id>virtuoso-jdbc4-embedded</id>
- <url>file://localhost/${project.basedir}/src/main/resources/maven/repo</url>
- </repository>
- </repositories>
- <dependencies>
- <dependency>
- <groupId>virtuoso</groupId>
- <artifactId>virtjdbc</artifactId>
- <type>jar</type>
- <version>4.1</version>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
- <Embed-Dependency>*;scope=compile;artifactId=!slf4j-api</Embed-Dependency>
- <!-- Embed-Transitive>true</Embed-Transitive -->
- <!-- Import-Package> </Import-Package -->
- <Export-Package>
- openlink.util.*,
- virtuoso.javax.*,
- virtuoso.jdbc4.*,
- virtuoso.sql.*
- </Export-Package>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- <pluginManagement>
- <plugins>
- <!--This plugin's configuration is used to store Eclipse m2e settings
- only. It has no influence on the Maven build itself. -->
- <plugin>
- <groupId>org.eclipse.m2e</groupId>
- <artifactId>lifecycle-mapping</artifactId>
- <version>1.0.0</version>
- <configuration>
- <lifecycleMappingMetadata>
- <pluginExecutions>
- <pluginExecution>
- <pluginExecutionFilter>
- <groupId>
- org.apache.felix
- </groupId>
- <artifactId>
- maven-scr-plugin
- </artifactId>
- <versionRange>
- [1.7.0,)
- </versionRange>
- <goals>
- <goal>scr</goal>
- </goals>
- </pluginExecutionFilter>
- <action>
- <ignore></ignore>
- </action>
- </pluginExecution>
- </pluginExecutions>
- </lifecycleMappingMetadata>
- </configuration>
- </plugin>
- </plugins>
- </pluginManagement>
- </build>
- <packaging>bundle</packaging>
- <profiles>
- <profile>
- <!-- This profile allows for installing/updating a bundle in a running
- Sling instance right after building it. Example: mvn clean install -P installBundle
- -Dsling.url=http://localhost:8080/system/console Or, to make it faster without
- cleaning up or running tests: mvn -o install -DskipTests -P installBundle
- -Dsling.url=http://localhost:8080/system/console -->
- <id>installBundle</id>
- <activation>
- <activeByDefault>false</activeByDefault>
- </activation>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.sling</groupId>
- <artifactId>maven-sling-plugin</artifactId>
- <executions>
- <execution>
- <id>install-bundle</id>
- <goals>
- <goal>install</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- </profile>
- </profiles>
-</project>
http://git-wip-us.apache.org/repos/asf/clerezza/blob/bb87e83f/clerezza-virtuoso/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/4.0/virtjdbc-4.0.jar
----------------------------------------------------------------------
diff --git a/clerezza-virtuoso/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/4.0/virtjdbc-4.0.jar b/clerezza-virtuoso/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/4.0/virtjdbc-4.0.jar
deleted file mode 100644
index b207f0c..0000000
Binary files a/clerezza-virtuoso/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/4.0/virtjdbc-4.0.jar and /dev/null differ
http://git-wip-us.apache.org/repos/asf/clerezza/blob/bb87e83f/clerezza-virtuoso/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/4.0/virtjdbc-4.0.pom
----------------------------------------------------------------------
diff --git a/clerezza-virtuoso/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/4.0/virtjdbc-4.0.pom b/clerezza-virtuoso/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/4.0/virtjdbc-4.0.pom
deleted file mode 100644
index 02fa48e..0000000
--- a/clerezza-virtuoso/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/4.0/virtjdbc-4.0.pom
+++ /dev/null
@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?><!--
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-
---><project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <modelVersion>4.0.0</modelVersion>
- <groupId>virtuoso</groupId>
- <artifactId>virtjdbc</artifactId>
- <version>4.0</version>
- <description>POM was created from install:install-file</description>
-</project>
http://git-wip-us.apache.org/repos/asf/clerezza/blob/bb87e83f/clerezza-virtuoso/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/4.1/virtjdbc-4.1.jar
----------------------------------------------------------------------
diff --git a/clerezza-virtuoso/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/4.1/virtjdbc-4.1.jar b/clerezza-virtuoso/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/4.1/virtjdbc-4.1.jar
deleted file mode 100755
index 1c6ccec..0000000
Binary files a/clerezza-virtuoso/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/4.1/virtjdbc-4.1.jar and /dev/null differ
http://git-wip-us.apache.org/repos/asf/clerezza/blob/bb87e83f/clerezza-virtuoso/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/4.1/virtjdbc-4.1.pom
----------------------------------------------------------------------
diff --git a/clerezza-virtuoso/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/4.1/virtjdbc-4.1.pom b/clerezza-virtuoso/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/4.1/virtjdbc-4.1.pom
deleted file mode 100644
index 87605c7..0000000
--- a/clerezza-virtuoso/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/4.1/virtjdbc-4.1.pom
+++ /dev/null
@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?><!--
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-
---><project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <modelVersion>4.0.0</modelVersion>
- <groupId>virtuoso</groupId>
- <artifactId>virtjdbc</artifactId>
- <version>4.1</version>
- <description>POM was created from install:install-file</description>
-</project>
http://git-wip-us.apache.org/repos/asf/clerezza/blob/bb87e83f/clerezza-virtuoso/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/maven-metadata-local.xml
----------------------------------------------------------------------
diff --git a/clerezza-virtuoso/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/maven-metadata-local.xml b/clerezza-virtuoso/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/maven-metadata-local.xml
deleted file mode 100644
index a0d93d6..0000000
--- a/clerezza-virtuoso/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/maven-metadata-local.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?><!--
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-
---><metadata>
- <groupId>virtuoso</groupId>
- <artifactId>virtjdbc</artifactId>
- <versioning>
- <release>4.1</release>
- <versions>
- <version>4.1</version>
- <version>4.0</version>
- </versions>
- </versioning>
-</metadata>
http://git-wip-us.apache.org/repos/asf/clerezza/blob/bb87e83f/clerezza-virtuoso/rdf.virtuoso.storage/README.md
----------------------------------------------------------------------
diff --git a/clerezza-virtuoso/rdf.virtuoso.storage/README.md b/clerezza-virtuoso/rdf.virtuoso.storage/README.md
deleted file mode 100644
index 965d494..0000000
--- a/clerezza-virtuoso/rdf.virtuoso.storage/README.md
+++ /dev/null
@@ -1,2 +0,0 @@
-# Virtuoso Storage bindings for Clerezza
-
http://git-wip-us.apache.org/repos/asf/clerezza/blob/bb87e83f/clerezza-virtuoso/rdf.virtuoso.storage/pom.xml
----------------------------------------------------------------------
diff --git a/clerezza-virtuoso/rdf.virtuoso.storage/pom.xml b/clerezza-virtuoso/rdf.virtuoso.storage/pom.xml
deleted file mode 100644
index 1b1d668..0000000
--- a/clerezza-virtuoso/rdf.virtuoso.storage/pom.xml
+++ /dev/null
@@ -1,271 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?><!--
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-
---><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <artifactId>clerezza</artifactId>
- <groupId>org.apache.clerezza</groupId>
- <version>0.5-SNAPSHOT</version>
- <relativePath>../../parent</relativePath>
- </parent>
- <artifactId>rdf.virtuoso.storage</artifactId>
- <name>Clerezza - SCB Virtuoso storage provider</name>
- <description>A virtuoso based storage provider</description>
- <packaging>bundle</packaging>
- <version>0.3-SNAPSHOT</version>
-
- <dependencies>
- <!-- CLEREZZA -->
- <dependency>
- <groupId>org.apache.clerezza</groupId>
- <artifactId>rdf.core</artifactId>
- <version>0.14-SNAPSHOT</version>
- <scope>provided</scope>
- </dependency>
-
- <dependency>
- <groupId>org.wymiwyg</groupId>
- <artifactId>wymiwyg-commons-core</artifactId>
- </dependency>
- <!-- VIRTUOSO Dependencies -->
- <dependency>
- <groupId>clerezza-virtuoso</groupId>
- <artifactId>ext.virtuoso.jdbc</artifactId>
- <version>0.3-SNAPSHOT</version>
- <scope>provided</scope>
- </dependency>
-
- <!-- OSGI -->
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.core</artifactId>
- </dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.compendium</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.scr.annotations</artifactId>
- </dependency>
-
- <!-- LOGGING -->
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- <scope>provided</scope>
- </dependency>
-
- <!-- TEST (generic) -->
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
-<!-- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <scope>test</scope>
- <version></version>
- </dependency>
--->
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-simple</artifactId>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.apache.clerezza</groupId>
- <artifactId>platform.config</artifactId>
- <version>0.3-incubating</version>
- <type>bundle</type>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.clerezza</groupId>
- <artifactId>rdf.jena.parser</artifactId>
- <version>0.11</version>
- <type>bundle</type>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>com.hp.hpl.jena</groupId>
- <artifactId>jena</artifactId>
- <version>2.6.4</version>
- <scope>test</scope>
- <exclusions>
- <exclusion>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.apache.clerezza</groupId>
- <artifactId>rdf.jena.facade</artifactId>
- <version>0.13</version>
- <type>bundle</type>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.clerezza</groupId>
- <artifactId>rdf.jena.commons</artifactId>
- <version>0.6</version>
- <type>bundle</type>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- <profiles>
- <profile>
- <id>virtuoso-do-tests</id>
- <activation>
- <activeByDefault>false</activeByDefault>
- </activation>
- <properties>
- <virtuoso.test>true</virtuoso.test>
- </properties>
- </profile>
- </profiles>
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-surefire-plugin</artifactId>
- <executions>
- <execution>
- <id>default-test</id>
- <phase>test</phase>
- <goals>
- <goal>test</goal>
- </goals>
- <configuration>
- <systemPropertyVariables>
- <virtuoso.test>${virtuoso.test}</virtuoso.test>
- <virtuoso.driver>virtuoso.jdbc4.Driver</virtuoso.driver>
- <virtuoso.host>localhost</virtuoso.host>
- <virtuoso.port>1111</virtuoso.port>
- <virtuoso.user>dba</virtuoso.user>
- <virtuoso.password>dba</virtuoso.password>
- </systemPropertyVariables>
- </configuration>
- </execution>
- </executions>
- </plugin>
-
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-scr-plugin</artifactId>
- <executions>
- <execution>
- <id>generate-scr-scrdescriptor</id>
- <goals>
- <goal>scr</goal>
- </goals>
- </execution>
- </executions>
- <!-- see http://felix.apache.org/site/apache-felix-scr-plugin-faq.html#ApacheFelixSCRPluginFAQ-NoClassDefFoundErrorduringbuild -->
- <dependencies>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-simple</artifactId>
- <version>1.6.1</version>
- </dependency>
- </dependencies>
- </plugin>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Include-Resource>
- src/main/resources,
- target/scr-plugin-generated
- </Include-Resource>
- <Service-Component>
- OSGI-INF/serviceComponents.xml
- </Service-Component>
- <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- <pluginManagement>
- <plugins>
-
- <!-- plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
- <Embed-Dependency>*;scope=compile|runtime;artifactId=!slf4j-api</Embed-Dependency>
- <Import-Package>*</Import-Package>
- <Export-Package>
- rdf.virtuoso.storage.*
- </Export-Package>
- </instructions>
- </configuration>
- </plugin -->
-
- <!--This plugin's configuration is used to store Eclipse m2e settings
- only. It has no influence on the Maven build itself. -->
- <plugin>
- <groupId>org.eclipse.m2e</groupId>
- <artifactId>lifecycle-mapping</artifactId>
- <version>1.0.0</version>
- <configuration>
- <lifecycleMappingMetadata>
- <pluginExecutions>
- <pluginExecution>
- <pluginExecutionFilter>
- <groupId>
- org.apache.felix
- </groupId>
- <artifactId>
- maven-scr-plugin
- </artifactId>
- <versionRange>
- [1.7.0,)
- </versionRange>
- <goals>
- <goal>scr</goal>
- </goals>
- </pluginExecutionFilter>
- <action>
- <ignore></ignore>
- </action>
- </pluginExecution>
- </pluginExecutions>
- </lifecycleMappingMetadata>
- </configuration>
- </plugin>
- </plugins>
- </pluginManagement>
- </build>
-</project>
http://git-wip-us.apache.org/repos/asf/clerezza/blob/bb87e83f/clerezza-virtuoso/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/VirtuosoBNode.java
----------------------------------------------------------------------
diff --git a/clerezza-virtuoso/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/VirtuosoBNode.java b/clerezza-virtuoso/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/VirtuosoBNode.java
deleted file mode 100644
index e8cc46f..0000000
--- a/clerezza-virtuoso/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/VirtuosoBNode.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.clerezza.rdf.virtuoso.storage;
-
-import org.apache.clerezza.rdf.core.BNode;
-
-public class VirtuosoBNode extends BNode {
- private String skolemId;
- public VirtuosoBNode(String skolemId) {
- this.skolemId = skolemId;
- }
-
- public String getSkolemId(){
- return skolemId;
- }
-
- public String asSkolemIri(){
- return new StringBuilder().append('<').append(skolemId).append('>').toString();
- }
-
- public String toString(){
- return skolemId;
- }
-
- @Override
- public boolean equals(Object obj) {
- return (obj instanceof VirtuosoBNode) && (obj.toString().equals(toString()));
- }
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/bb87e83f/clerezza-virtuoso/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/VirtuosoGraph.java
----------------------------------------------------------------------
diff --git a/clerezza-virtuoso/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/VirtuosoGraph.java b/clerezza-virtuoso/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/VirtuosoGraph.java
deleted file mode 100644
index 2516fdc..0000000
--- a/clerezza-virtuoso/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/VirtuosoGraph.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.clerezza.rdf.virtuoso.storage;
-
-import java.util.Collection;
-
-import org.apache.clerezza.rdf.core.Graph;
-import org.apache.clerezza.rdf.core.Triple;
-import org.apache.clerezza.rdf.virtuoso.storage.access.DataAccess;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-/**
- * This is a read-only version of {@link VirtuosoMGraph}
- * @author enridaga
- *
- */
-public class VirtuosoGraph extends VirtuosoMGraph implements Graph{
-
- /**
- * Logger
- */
- protected Logger logger = LoggerFactory
- .getLogger(VirtuosoGraph.class);
-
- public VirtuosoGraph(String name, DataAccess dataAccess) {
- super(name, dataAccess);
- }
-
- @Override
- public synchronized boolean add(Triple e) {
- logger.warn("Attempting modifying an immutable graph");
- throw new UnsupportedOperationException();
- }
-
- @Override
- public synchronized boolean addAll(Collection<? extends Triple> c) {
- logger.warn("Attempting modifying an immutable graph");
- throw new UnsupportedOperationException();
- }
-
- @Override
- public synchronized void clear() {
- logger.warn("Attempting modifying an immutable graph");
- throw new UnsupportedOperationException();
- }
-
- @Override
- public synchronized boolean remove(Object o) {
- logger.warn("Attempting modifying an immutable graph");
- throw new UnsupportedOperationException();
- }
-
- @Override
- public synchronized boolean removeAll(Collection<?> col) {
- logger.warn("Attempting modifying an immutable graph");
- throw new UnsupportedOperationException();
- }
-
- /**
- * Must be a VirtuosoGraph with the same name.
- */
- @Override
- public boolean equals(Object o) {
- logger.debug("equals({})",o.getClass());
- if (o instanceof VirtuosoGraph) {
- logger.debug("{} is a VirtuosoGraph)",o);
- if (((VirtuosoGraph) o).getName().equals(this.getName())) {
- logger.debug("Names are equal! They are equal!");
- return true;
- }
- }else{
- logger.debug("Not a VirtuosoGraph instance: {}",o.getClass());
- }
- return false;
- }
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/bb87e83f/clerezza-virtuoso/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/VirtuosoMGraph.java
----------------------------------------------------------------------
diff --git a/clerezza-virtuoso/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/VirtuosoMGraph.java b/clerezza-virtuoso/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/VirtuosoMGraph.java
deleted file mode 100644
index e4dc6d6..0000000
--- a/clerezza-virtuoso/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/VirtuosoMGraph.java
+++ /dev/null
@@ -1,191 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.clerezza.rdf.virtuoso.storage;
-
-import java.util.Iterator;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-
-import org.apache.clerezza.rdf.core.Graph;
-import org.apache.clerezza.rdf.core.Literal;
-import org.apache.clerezza.rdf.core.MGraph;
-import org.apache.clerezza.rdf.core.NonLiteral;
-import org.apache.clerezza.rdf.core.Resource;
-import org.apache.clerezza.rdf.core.Triple;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.access.LockableMGraph;
-import org.apache.clerezza.rdf.core.impl.AbstractMGraph;
-import org.apache.clerezza.rdf.virtuoso.storage.access.DataAccess;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-/**
- * Implementation of MGraph for the Virtuoso quad store.
- *
- * @author enridaga
- *
- */
-public class VirtuosoMGraph extends AbstractMGraph implements MGraph,
- LockableMGraph {
-
- private final ReadWriteLock lock = new ReentrantReadWriteLock();
- private final Lock readLock = lock.readLock();
- private final Lock writeLock = lock.writeLock();
-
- /**
- * Logger
- */
- protected Logger logger = LoggerFactory.getLogger(VirtuosoMGraph.class);
-
- /**
- * The name of the graph
- */
- private String name = null;
- // private int size = 0;
-
- private VirtuosoGraph readOnly = null;
- private DataAccess dataAccess = null;
-
- /**
- * Creates a {@link VirtuosoMGraph} Virtuoso MGraph binds directly to the
- * store.
- *
- * @param connection
- */
- public VirtuosoMGraph(String name, DataAccess dataAccess) {
- logger.debug("VirtuosoMGraph(String {}, DataAccess {})", name,
- dataAccess);
- this.name = name;
- // this.provider = provider;
- this.dataAccess = dataAccess;
- }
-
- @Override
- public ReadWriteLock getLock() {
- logger.debug("getLock()");
- return lock;
- }
-
- @Override
- public Graph getGraph() {
- logger.debug("getGraph()");
- return asVirtuosoGraph();
- }
-
- public VirtuosoGraph asVirtuosoGraph() {
- logger.debug("asVirtuosoGraph()");
- if (this.readOnly == null) {
- logger.debug("create embedded singleton read-only instance");
- this.readOnly = new VirtuosoGraph(name, getDataAccess());
- }
- return readOnly;
- }
-
- protected DataAccess getDataAccess() {
- return this.dataAccess;
- }
-
- @Override
- protected Iterator<Triple> performFilter(NonLiteral subject,
- UriRef predicate, Resource object) {
- readLock.lock();
- Iterator<Triple> tit = getDataAccess().filter(getName(), subject,
- predicate, object);
- readLock.unlock();
- return tit;
- }
-
- /**
- * We load the size every time it is requested.
- */
- @Override
- public int size() {
- logger.debug("size()");
- readLock.lock();
- int size = getDataAccess().size(getName());
- readLock.unlock();
- return size;
- }
-
- @Override
- public void clear() {
- logger.debug("clear()");
- writeLock.lock();
- getDataAccess().clearGraph(getName());
- writeLock.unlock();
- }
-
- protected boolean performAdd(Triple triple) {
- logger.debug("performAdd(Triple {})", triple);
-
- // If the object is a very long literal we use plan B
- // Reason:
- // Virtuoso Error:
- // SR449: Key is too long, index RDF_QUAD, ruling part is 1901 bytes
- // that exceeds 1900 byte limit
- // We use alternative method for literals
- writeLock.lock();
- if (triple.getObject() instanceof Literal) {
- getDataAccess().performAddPlanB(getName(), triple);
- }else{
- getDataAccess().insertQuad(getName(), triple);
- }
- writeLock.unlock();
- return true;
- }
-
- protected boolean performRemove(Triple triple) {
- logger.debug("performRemove(Triple triple)", triple);
- writeLock.lock();
- getDataAccess().deleteQuad(getName(), triple);
- writeLock.unlock();
- return true;
- }
-
- /**
- * Returns the graph name
- *
- * @return
- */
- public String getName() {
- logger.debug("getName()");
- return name;
- }
-
- /**
- * Must be a VirtuosoMGraph with the same name. Subclasses are not assumed
- * to be equals (VirtuosoGraph is not the same as VirtuosoMGraph)
- */
- public boolean equals(Object o) {
- logger.debug("equals({})", o.getClass());
- // It must be an instance of VirtuosoMGraph
- if (o.getClass().equals(VirtuosoMGraph.class)) {
- logger.debug("{} is a VirtuosoMGraph)", o);
- if (((VirtuosoMGraph) o).getName().equals(this.getName())) {
- logger.debug("Names are equal! They are equal!");
- return true;
- }
- } else {
- logger.debug("Not a VirtuosoMGraph instance: {}", o.getClass());
- }
- return false;
- }
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/bb87e83f/clerezza-virtuoso/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/access/DataAccess.java
----------------------------------------------------------------------
diff --git a/clerezza-virtuoso/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/access/DataAccess.java b/clerezza-virtuoso/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/access/DataAccess.java
deleted file mode 100644
index 5bc29fc..0000000
--- a/clerezza-virtuoso/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/access/DataAccess.java
+++ /dev/null
@@ -1,949 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.clerezza.rdf.virtuoso.storage.access;
-
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.clerezza.rdf.core.BNode;
-import org.apache.clerezza.rdf.core.Language;
-import org.apache.clerezza.rdf.core.NonLiteral;
-import org.apache.clerezza.rdf.core.PlainLiteral;
-import org.apache.clerezza.rdf.core.Resource;
-import org.apache.clerezza.rdf.core.Triple;
-import org.apache.clerezza.rdf.core.TypedLiteral;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
-import org.apache.clerezza.rdf.core.impl.TypedLiteralImpl;
-import org.apache.clerezza.rdf.virtuoso.storage.VirtuosoBNode;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.wymiwyg.commons.util.collections.BidiMap;
-import org.wymiwyg.commons.util.collections.BidiMapImpl;
-
-import virtuoso.jdbc4.VirtuosoConnection;
-import virtuoso.jdbc4.VirtuosoException;
-import virtuoso.jdbc4.VirtuosoExtendedString;
-import virtuoso.jdbc4.VirtuosoPreparedStatement;
-import virtuoso.jdbc4.VirtuosoRdfBox;
-import virtuoso.jdbc4.VirtuosoResultSet;
-
-/**
- *
- * @author enridaga
- *
- */
-public class DataAccess {
- private Logger logger = LoggerFactory.getLogger(DataAccess.class);
-
- final static String DRIVER = "virtuoso.jdbc4.Driver";
-
- // XXX This is only used to create a new bnode identifier in virtuoso
- final static String INSERT_NEW_BNODE = "SPARQL INSERT INTO iri(??) { [] `iri(??)` "
- + "`iri(??)`}";
-
- // XXX This is only used to delete a new bnode identifier in virtuoso
- final static String DELETE_NEW_BNODE = "SPARQL DELETE FROM iri(??) { ?s ?p ?o } WHERE { ?s ?p ?o . filter( ?p = iri(??) && "
- + " ?o = iri(??) ) }";
-
- final static String INSERT_QUAD = "SPARQL INSERT INTO iri(??) {`iri(??)` `iri(??)` "
- + "`bif:__rdf_long_from_batch_params(??,??,??)`}";
- final static String DELETE_QUAD = "SPARQL DELETE FROM iri(??) { ?s ?p ?o } WHERE { ?s ?p ?o . filter( ?s = iri(??) && ?p = iri(??) && "
- + " ?o = bif:__rdf_long_from_batch_params(??,??,??) ) } ";
- final static String LIST_GRAPHS = "SPARQL SELECT DISTINCT ?G WHERE {GRAPH ?G {[] [] []} }";
- final static String CLEAR_GRAPH = "SPARQL CLEAR GRAPH iri(??)";
- final static String COUNT_TRIPLES_OF_GRAPH = "SPARQL SELECT COUNT(*) WHERE { bind( iri(??) as ?graph ) . graph ?graph { [] [] [] } }";
- final static String SELECT__ = "SPARQL SELECT ?subject ?predicate ?object WHERE { bind( iri(??) as ?graph ) . GRAPH ?graph { ?subject ?predicate ?object ";
- final static String SELECT_TRIPLES_NULL_NULL_NULL = SELECT__ + " } }";
- final static String SELECT_TRIPLES_S_NULL_NULL = SELECT__ + " . FILTER( ?subject = iri(??) ) } }";
- final static String SELECT_TRIPLES_S_P_NULL = SELECT__ + " . FILTER( ?subject = iri(??) && ?predicate = iri(??) ) } }";
- final static String SELECT_TRIPLES_S_P_O = SELECT__ + " . FILTER( ?subject = iri(??) && ?predicate = iri(??) && ?object = bif:__rdf_long_from_batch_params(??,??,??) ) } }";
- final static String SELECT_TRIPLES_NULL_P_NULL = SELECT__ + " . FILTER( ?predicate = iri(??) ) } }";
- final static String SELECT_TRIPLES_NULL_P_O = SELECT__ + " . FILTER( ?predicate = iri(??) && ?object = bif:__rdf_long_from_batch_params(??,??,??) ) } }";
- final static String SELECT_TRIPLES_NULL_NULL_O = SELECT__ + " . FILTER( ?object = bif:__rdf_long_from_batch_params(??,??,??) ) } }";
- final static String SELECT_TRIPLES_S_NULL_O = SELECT__ + " . FILTER( ?subject = iri(??) && ?object = bif:__rdf_long_from_batch_params(??,??,??) ) } }";
-
- private final static String[] filterQueries = new String[] {
- SELECT_TRIPLES_NULL_NULL_NULL, SELECT_TRIPLES_S_NULL_NULL,
- SELECT_TRIPLES_S_P_O, SELECT_TRIPLES_NULL_NULL_O,
- SELECT_TRIPLES_NULL_P_NULL, SELECT_TRIPLES_S_P_NULL,
- SELECT_TRIPLES_NULL_P_O, SELECT_TRIPLES_S_NULL_O };
-
- /**
- * Bidirectional map for managing the conversion from virtuoso blank nodes
- * (strings) to clerezza blank nodes and vice versa.
- */
- private final BidiMap<VirtuosoBNode, BNode> bnodesMap;
-
- private Map<String, VirtuosoPreparedStatement> preparedStatements = null;
- private VirtuosoConnection connection = null;
- private String connectionString;
- private String user;
- private String pwd;
-
- // We protect the constructor from outside the package...
- DataAccess(String connectionString, String user, String pwd) {
- this.connectionString = connectionString;
- this.user = user;
- this.pwd = pwd;
-
- connection = createConnection(connectionString, user, pwd);
-
- // Init collections
- this.preparedStatements = new HashMap<String,VirtuosoPreparedStatement>();
- this.bnodesMap = new BidiMapImpl<VirtuosoBNode, BNode>();
-
- }
-
- private VirtuosoConnection createConnection(final String cs, final String u, final String p) {
- try {
- VirtuosoConnection c = AccessController.doPrivileged(
- new PrivilegedAction<VirtuosoConnection>() {
- public VirtuosoConnection run() {
- try {
- Class.forName(VirtuosoWeightedProvider.DRIVER, true, this
- .getClass().getClassLoader());
- return (VirtuosoConnection) DriverManager
- .getConnection(cs, u, p);
- } catch (ClassNotFoundException e) {
- throw new RuntimeException(e);
- } catch (SQLException e) {
- throw new RuntimeException(e);
- }
- }
- }
- );
- c.setAutoCommit(true);
- return c;
- } catch (SQLException e) {
- throw new RuntimeException(e);
- }
- }
-
- // A simple renewal policy
- private int statementCalls = 0;
- protected PreparedStatement getStatement(String query)
- throws VirtuosoException {
- if(statementCalls >= 10000){
- statementCalls=0;
- renew();
- }else{
- statementCalls++;
- }
- if (!preparedStatements.containsKey(query)) {
- VirtuosoPreparedStatement ps = (VirtuosoPreparedStatement) connection
- .prepareStatement(query);
- preparedStatements.put(query, ps);
- }
- return preparedStatements.get(query);
- }
-
- private VirtuosoBNode toVirtBnode(BNode bnode) {
- logger.debug("toVirtBnode(BNode {})", bnode);
- if (bnode instanceof VirtuosoBNode) {
- return ((VirtuosoBNode) bnode);
- } else {
- VirtuosoBNode virtBnode = bnodesMap.getKey(bnode);
- if (virtBnode == null) {
- // We create a local bnode mapped to the BNode given
- virtBnode = nextVirtBnode(bnode);
- bnodesMap.put(virtBnode, bnode);
- }
- return virtBnode;
- }
- }
-
- public void renew() {
- logger.trace("renewing...");
- close();
- connection = createConnection(connectionString, user, pwd);
- }
-
- public void close() {
- logger.trace("closing resources...");
- Collection<VirtuosoPreparedStatement> pss = preparedStatements.values();
- for (VirtuosoPreparedStatement ps : pss) {
- try {
- logger.trace("Closing prepared statement {}", ps);
- ps.close();
- } catch (Exception e) {
- logger.error("Cannot close statement", e);
- }
- }
- logger.trace("closed {} statements.", pss.size());
- preparedStatements.clear();
- try {
- connection.close();
- logger.trace("Connection closed");
- } catch (Exception e) {
- logger.error("Cannot close connection", e);
- }
- }
-
- private void close(String statementId){
- try {
- VirtuosoPreparedStatement ps = preparedStatements.get(statementId);
- if (ps == null) {
- logger.warn(
- "Attempting to close a statement that was not prepared: {}",
- statementId);
- } else {
- logger.trace("Closing prepared statement {}", ps);
- ps.close();
- }
- } catch (Exception e) {
- logger.error("Cannot close statement", e);
- } finally {
- // We won't reuse a statement that thrown a n exception on close...
- preparedStatements.remove(statementId);
- }
- }
-
- private void bindValue(PreparedStatement st, int i, Resource object)
- throws SQLException {
- if (object instanceof UriRef) {
- st.setInt(i, 1);
- st.setString(i + 1, ((UriRef) object).getUnicodeString());
- st.setNull(i + 2, java.sql.Types.VARCHAR);
- } else if (object instanceof BNode) {
- st.setInt(i, 1);
- st.setString(i + 1, ((VirtuosoBNode) object).getSkolemId());
- st.setNull(i + 2, java.sql.Types.VARCHAR);
- } else if (object instanceof TypedLiteral) {
- TypedLiteral tl = ((TypedLiteral) object);
- st.setInt(i, 4);
- st.setString(i + 1, tl.getLexicalForm());
- st.setString(i + 2, tl.getDataType().getUnicodeString());
- } else if (object instanceof PlainLiteral) {
- PlainLiteral pl = (PlainLiteral) object;
- if (pl.getLanguage() != null) {
- st.setInt(i, 5);
- st.setString(i + 1, pl.getLexicalForm());
- st.setString(i + 2, pl.getLanguage().toString());
- } else {
- st.setInt(i, 3);
- st.setString(i + 1, pl.getLexicalForm());
- st.setNull(i + 2, java.sql.Types.VARCHAR);
- }
- } else
- throw new IllegalArgumentException(object.toString());
- }
-
- private void bindPredicate(PreparedStatement st, int i, UriRef predicate)
- throws SQLException {
- st.setString(i, predicate.getUnicodeString());
- }
-
- private void bindSubject(PreparedStatement st, int i, NonLiteral subject)
- throws SQLException {
- if (subject instanceof UriRef) {
- st.setString(i, ((UriRef) subject).getUnicodeString());
- } else {
- st.setString(i, ((VirtuosoBNode) subject).getSkolemId());
- }
- }
-
- private void bindGraph(PreparedStatement st, int i, UriRef uriRef)
- throws SQLException {
- st.setString(i, uriRef.getUnicodeString());
- }
-
-
- private void bindGraph(PreparedStatement st, int i, String uri)
- throws SQLException {
- st.setString(i, uri);
- }
-
- /**
- * Generate a new local bnode to be used in virtuoso queries
- *
- * @return
- */
- private VirtuosoBNode nextVirtBnode(BNode bn) {
- logger.debug("nextVirtBnode(BNode)");
- /**
- * XXX Here we force virtuoso to generate a valid skolem uri for a blank
- * node we are going to insert for the first time.
- *
- * All this process should be more efficient, possibly invoking a native
- * procedure, instead of insert/select/delete a fake triple as it is
- * now.
- */
- UriRef g = new UriRef("urn:x-virtuoso:bnode-tmp");
- UriRef p = new UriRef("urn:x-virtuoso:bnode:object");
- UriRef o = new UriRef(new StringBuilder()
- .append("urn:x-virtuoso:bnode:").append(bn).toString());
-
- Exception e = null;
- VirtuosoResultSet rs = null;
-
- String bnodeId = null;
- // insert
- try {
- PreparedStatement insert = getStatement(INSERT_NEW_BNODE);
- bindGraph(insert, 1, g);
- bindPredicate(insert, 2, p);
- bindSubject(insert, 3, o);
- insert.executeUpdate();
-
- // select
- PreparedStatement select = getStatement(SELECT_TRIPLES_NULL_P_O);
- bindGraph(select, 1, g);
- bindPredicate(select, 2, p);
- bindValue(select, 3, o);
- rs = (VirtuosoResultSet) select.executeQuery();
- rs.next();
- bnodeId = rs.getString(1);
- rs.close();
-
- // delete
- PreparedStatement delete = getStatement(DELETE_NEW_BNODE);
- bindGraph(delete, 1, g);
- bindPredicate(delete, 2, p);
- bindSubject(delete, 3, o); // It is a IRI
- delete.executeUpdate();
-
- } catch (VirtuosoException ve) {
- logger.error("ERROR while executing statement", ve);
- e = ve;
- } catch (SQLException se) {
- logger.error("ERROR while executing statement", se);
- e = se;
- } finally {
- try {
- if (rs != null)
- rs.close();
- } catch (Exception ex) {
- logger.error("Error attempting to close result set", ex);
- }
- }
- if (e != null) {
- close(INSERT_NEW_BNODE);
- close(SELECT_TRIPLES_NULL_P_O);
- close(DELETE_NEW_BNODE);
- throw new RuntimeException(e);
- }
- return new VirtuosoBNode(bnodeId);
-
- }
- public void insertQuad(String graph, Triple triple) {
- NonLiteral s = triple.getSubject();
- UriRef p = triple.getPredicate() ;
- Resource o = triple.getObject();
-
- // Skolemize bnodes
- if(s instanceof BNode){
- s = toVirtBnode((BNode) s);
- }
- if(o instanceof BNode){
- o = toVirtBnode((BNode) o);
- }
-
- try {
- PreparedStatement st = getStatement(INSERT_QUAD);
- bindGraph(st, 1, graph);
- bindSubject(st, 2, s);
- bindPredicate(st, 3, p);
- bindValue(st, 4, o);
- st.executeUpdate();
- } catch (VirtuosoException e) {
- logger.error("Cannot execute statement", e);
- throw new RuntimeException(e);
- } catch (SQLException e) {
- logger.error("Cannot execute statement", e);
- throw new RuntimeException(e);
- }
- }
-
- public void deleteQuad(String graph, Triple triple) {
- NonLiteral s = triple.getSubject();
- UriRef p = triple.getPredicate() ;
- Resource o = triple.getObject();
-
- // Skolemize bnodes
- if(s instanceof BNode){
- s = toVirtBnode((BNode) s);
- }
- if(o instanceof BNode){
- o = toVirtBnode((BNode) o);
- }
- Exception e = null;
- try {
- PreparedStatement st = getStatement(DELETE_QUAD);
- bindGraph(st, 1, graph);
- bindSubject(st, 2, s);
- bindPredicate(st, 3, p);
- bindValue(st, 4, o);
- st.executeUpdate();
- } catch (VirtuosoException ex) {
- logger.error("Cannot execute statement", ex);
- e = ex;
- } catch (SQLException ex) {
- logger.error("Cannot execute statement", ex);
- e = ex;
- }
-
- if (e != null) {
- close(DELETE_QUAD);
- throw new RuntimeException(e);
- }
- }
-
- public Set<UriRef> listGraphs() {
- Exception e = null;
-
- Set<UriRef> graphs = new HashSet<UriRef>();
- try {
- PreparedStatement st = getStatement(LIST_GRAPHS);
- ResultSet rs = st.executeQuery();
- while (rs.next()) {
- UriRef graph = new UriRef(rs.getString(1));
- logger.debug(" > Graph {}", graph);
- graphs.add(graph);
- }
- } catch (VirtuosoException ex) {
- logger.error("Cannot execute query", ex);
- e = ex;
- } catch (SQLException ex) {
- logger.error("Cannot execute query", ex);
- e = ex;
- }
-
- if(e != null){
- close(LIST_GRAPHS);
- throw new RuntimeException(e);
- }
-
- return Collections.unmodifiableSet(graphs);
- }
-
- public void clearGraph(String graph) {
- Exception e = null;
- try {
- PreparedStatement st = getStatement(CLEAR_GRAPH);
- bindGraph(st, 1, graph);
- st.executeUpdate();
- } catch (VirtuosoException ex) {
- logger.error("Cannot execute statement", ex);
- e = ex;
- } catch (SQLException ex) {
- logger.error("Cannot execute statement", ex);
- e = ex;
- }
-
- if(e != null){
- close(CLEAR_GRAPH);
- throw new RuntimeException(e);
- }
- }
-
- private VirtuosoBNode toBNode(String virtbnode) {
- VirtuosoBNode bnode;
- bnode = new VirtuosoBNode(virtbnode);
- return bnode;
- }
-
- public Iterator<Triple> filter(String graph, NonLiteral subject,
- UriRef predicate, Resource object) {
- logger.debug("filter(String graph, NonLiteral s, UriRef p, Resource o)");
-
- // Override blank node object to be a skolemized IRI
- if (object != null && object instanceof BNode) {
- object = new UriRef(toVirtBnode((BNode) object).getSkolemId());
- }
-
- // Override blank node subjects to be a skolemized IRI
- if (subject != null && subject instanceof BNode) {
- subject = new UriRef(toVirtBnode((BNode) subject).getSkolemId());
- }
-
- if (logger.isTraceEnabled()) {
- logger.trace(" > g: {}", graph);
- logger.trace(" > s: {}", subject);
- logger.trace(" > p: {}", predicate);
- logger.trace(" > o: {}", object);
- }
-
- List<Triple> list = null;
- Exception e = null;
- Set<String> filters = new HashSet<String>(Arrays.asList(filterQueries));
-
- //
- if (subject == null) {
- filters.remove(SELECT_TRIPLES_S_P_O);
- filters.remove(SELECT_TRIPLES_S_NULL_NULL);
- filters.remove(SELECT_TRIPLES_S_P_NULL);
- filters.remove(SELECT_TRIPLES_S_NULL_O);
- } else {
- filters.remove(SELECT_TRIPLES_NULL_NULL_NULL);
- filters.remove(SELECT_TRIPLES_NULL_NULL_O);
- filters.remove(SELECT_TRIPLES_NULL_P_NULL);
- filters.remove(SELECT_TRIPLES_NULL_P_O);
- }
- if (predicate == null) {
- filters.remove(SELECT_TRIPLES_S_P_O);
- filters.remove(SELECT_TRIPLES_NULL_P_NULL);
- filters.remove(SELECT_TRIPLES_NULL_P_O);
- filters.remove(SELECT_TRIPLES_S_P_NULL);
- } else {
- filters.remove(SELECT_TRIPLES_S_NULL_O);
- filters.remove(SELECT_TRIPLES_NULL_NULL_NULL);
- filters.remove(SELECT_TRIPLES_NULL_NULL_O);
- filters.remove(SELECT_TRIPLES_S_NULL_NULL);
- }
- if (object == null) {
- filters.remove(SELECT_TRIPLES_S_P_O);
- filters.remove(SELECT_TRIPLES_S_NULL_O);
- filters.remove(SELECT_TRIPLES_NULL_P_O);
- filters.remove(SELECT_TRIPLES_NULL_NULL_O);
- } else {
- filters.remove(SELECT_TRIPLES_S_P_NULL);
- filters.remove(SELECT_TRIPLES_NULL_NULL_NULL);
- filters.remove(SELECT_TRIPLES_NULL_P_NULL);
- filters.remove(SELECT_TRIPLES_S_NULL_NULL);
- }
-
- // There must be only 1 boss
- String filter = filters.iterator().next();
- PreparedStatement ps = null;
- VirtuosoResultSet rs = null;
- try {
- logger.debug("query: {}", filter);
- ps = getStatement(filter);
- // In any case the first binding is the graph
- bindGraph(ps, 1, graph);
-
- int index = 2;
- if (subject != null) {
- bindSubject(ps, index, subject);
- index++;
- }
- if (predicate != null) {
- bindPredicate(ps, index, predicate);
- index++;
- }
- if (object != null) {
- bindValue(ps, index, object);
- }
-
- rs = (VirtuosoResultSet) ps.executeQuery();
- list = new ArrayList<Triple>();
-
- while (rs.next()) {
- list.add(new TripleBuilder(rs.getObject(1), rs.getObject(2), rs
- .getObject(3)).build());
- }
- } catch (VirtuosoException e1) {
- logger.error("ERROR while executing statement", ps);
- e = e1;
- } catch (SQLException e1) {
- logger.error("ERROR while executing statement", ps);
- e = e1;
- } finally {
- try {
- if (rs != null)
- rs.close();
- } catch (Throwable ex) {
- logger.error("Cannot close result set", ex);
- }
- }
-
- if (list == null || e != null) {
- // We also close the statement
- close(filter);
- throw new RuntimeException(e);
- }
- return list.iterator();
- }
-
- public int size(String graph){
- logger.trace("called size({})", graph);
- Exception e = null;
- PreparedStatement ps = null;
- VirtuosoResultSet rs = null;
- int size = -1;
- try {
- ps = getStatement(COUNT_TRIPLES_OF_GRAPH);
- logger.trace("statement got: {}", ps);
- // In any case the first binding is the graph
- bindGraph(ps, 1, graph);
- logger.trace("bound value: {}", graph);
- boolean r = ps.execute();
- logger.trace("Executed statement: {}", r);
- if(r){
- rs = (VirtuosoResultSet) ps.getResultSet();
- logger.trace("Got result set, has next?");
- boolean hn = rs.next();
- logger.trace(" > {}", hn);
- if(hn){
- size = rs.getInt(1);
- }else{
- e = new RuntimeException("Incosistent result. A result row was expected. None obtained.");
- }
- }else{
- e = new RuntimeException("Incosistent result. ResultSet expected but 'false' returned by statement execute() ");
- }
- } catch (VirtuosoException e1) {
- logger.error("ERROR while executing statement", ps);
- e = e1;
- } catch (SQLException e1) {
- logger.error("ERROR while executing statement", ps);
- e = e1;
- } finally {
- try {
- if (rs != null)
- rs.close();
- } catch (Throwable ex) {
- logger.error("Cannot close result set", ex);
- }
- }
-
- if (size == -1 || e != null) {
- // We also close the statement
- close(COUNT_TRIPLES_OF_GRAPH);
- throw new RuntimeException(e);
- }
-
- return size;
- }
-
- /**
- * Builds a clerezza Triple from Virtuoso result types
- *
- */
- private class TripleBuilder {
-
- Object s = null;
- Object p = null;
- Object o = null;
-
- public TripleBuilder(Object s, Object p, Object o) {
- if (logger.isDebugEnabled()) {
- logger.debug("TripleBuilder(Object s, Object p, Object o)");
- logger.debug("> s: {}", s);
- logger.debug("> p: {}", p);
- logger.debug("> o: {}", o);
- }
- this.s = s;
- this.p = p;
- this.o = o;
- }
-
- private NonLiteral buildSubject() {
- logger.debug("TripleBuilder.getSubject() : {}", s);
- if (s instanceof VirtuosoExtendedString) {
- VirtuosoExtendedString vs = (VirtuosoExtendedString) s;
- if (vs.iriType == VirtuosoExtendedString.IRI
- && (vs.strType & 0x01) == 0x01) {
- // Subject is IRI
- return new UriRef(vs.str);
- } else if (vs.iriType == VirtuosoExtendedString.BNODE) {
- return DataAccess.this.toBNode(vs.str);
- } else {
- // !Cannot happen
- throw new IllegalStateException(
- "Subject must be an IRI or a BNODE");
- }
- } else {
- throw new IllegalStateException(
- "Subject must be an instance of VirtuosoExtendedString");
- }
- }
-
- private UriRef buildPredicate() {
- logger.debug("TripleBuilder.getPredicate() : {}", p);
- if (p instanceof VirtuosoExtendedString) {
- VirtuosoExtendedString vs = (VirtuosoExtendedString) p;
- if (vs.iriType == VirtuosoExtendedString.IRI
- && (vs.strType & 0x01) == 0x01) {
- // Subject is IRI
- return new UriRef(vs.str);
- } else {
- // !Cannot happen
- throw new IllegalStateException("Predicate must be an IRI ");
- }
- } else {
- throw new IllegalStateException("Predicate must be an IRI");
- }
- }
-
- Resource buildObject() {
- logger.debug("TripleBuilder.getObject() : {}", o);
-
- if (o instanceof VirtuosoExtendedString) {
- // In case is IRI
- VirtuosoExtendedString vs = (VirtuosoExtendedString) o;
- if (vs.iriType == VirtuosoExtendedString.IRI
- && (vs.strType & 0x01) == 0x01) {
- // Is IRI
- return new UriRef(vs.str);
- } else if (vs.iriType == VirtuosoExtendedString.BNODE) {
- //
- return DataAccess.this.toBNode(vs.str);
- } else {
- // Is a plain literal
- return new PlainLiteralImpl(vs.str);
- }
- } else if (o instanceof VirtuosoRdfBox) {
- // In case is typed literal
- VirtuosoRdfBox rb = (VirtuosoRdfBox) o;
-
- String value;
- if (rb.rb_box.getClass().isAssignableFrom(String.class)) {
- value = (String) rb.rb_box;
- String lang = rb.getLang();
- String type = rb.getType();
- if (type == null) {
- Language language = lang == null ? null : new Language(
- lang);
- return new PlainLiteralImpl(value, language);
- } else {
- return new TypedLiteralImpl(value, new UriRef(type));
- }
- } else if (rb.rb_box instanceof VirtuosoExtendedString) {
- VirtuosoExtendedString vs = (VirtuosoExtendedString) rb.rb_box;
-
- if (vs.iriType == VirtuosoExtendedString.IRI
- && (vs.strType & 0x01) == 0x01) {
- // Is IRI
- return new UriRef(vs.str);
- } else if (vs.iriType == VirtuosoExtendedString.BNODE) {
- //
- return DataAccess.this.toBNode(vs.str);
- } else {
- String type = rb.getType();
- if (type == null) {
- String lang = rb.getLang();
- if (lang != null) {
- return new PlainLiteralImpl(vs.str,
- new Language(lang));
- }
- // Is a plain literal
- return new PlainLiteralImpl(vs.str);
- } else {
- return new TypedLiteralImpl(vs.str,
- new UriRef(type));
- }
- }
- }
- } else if (o == null) {
- // Raise an exception
- throw new IllegalStateException("Object cannot be NULL!");
- }
-
- // FIXME (not clear this...)
- return new PlainLiteralImpl(o.toString());
- }
-
- public Triple build() {
- logger.debug("TripleBuilder.build()");
- return new TripleImpl(buildSubject(), buildPredicate(),
- buildObject());
- }
- }
-
- /**
- * The following private methods are used to support the triple addition
- * plan B
- */
-
- public boolean performAddPlanB(String graph, Triple triple) {
-
- StringBuilder b = new StringBuilder();
- b.append(toVirtSubject(triple.getSubject())).append(" ")
- .append(toVirtPredicate(triple.getPredicate())).append(" ")
- .append(toVirtObject(triple.getObject())).append(" . ");
- String sql = new StringBuilder().append("db.dba.ttlp(?, '', '").append(graph).append("', 0)").toString();
- logger.debug("Exec Plan B: {}", sql);
- Exception e = null;
- PreparedStatement st = null;
- try {
- st = getStatement(sql);
- String s = b.toString();
- logger.trace(" TTL is \n{}\n", s);
- st.setNString(1, b.toString());
- st.execute();
- } catch (VirtuosoException ve) {
- logger.error("ERROR while executing statement", ve);
- e = ve;
- } catch (SQLException se) {
- logger.error("ERROR while executing statement", se);
- e = se;
- }
- if (e != null) {
- close(sql);
- if(logger.isDebugEnabled()){
- logger.error("S {}", triple.getSubject());
- logger.error("P {}", triple.getPredicate());
- logger.error("O {}", triple.getObject());
- logger.error(" O length: {}", triple.getObject().toString()
- .length());
- }
- logger.error("Sql: {}", sql);
- throw new RuntimeException(e);
- }
- return true;
- }
-
- /**
- * Returns a string to be used inline in SQL statements as Object of a
- * triple.
- *
- * @param object
- * @return
- */
- private String toVirtObject(Resource object) {
- logger.debug("toVirtObject(Resource {})", object);
- if (object == null)
- return null;
- if (object instanceof UriRef) {
- return toVirtIri((UriRef) object);
- } else if (object instanceof BNode) {
- return toVirtBnode((BNode) object).asSkolemIri();
- } else if (object instanceof PlainLiteral) {
- return toVirtPlainLiteral((PlainLiteral) object);
- } else if (object instanceof TypedLiteral) {
- return toVirtTypedLiteral((TypedLiteral) object);
- }
- // XXX throw exception here?
- return null;
- }
-
- /**
- * Returns a string to be used in SQL statements.
- *
- * @param object
- * @return
- */
- private String toVirtTypedLiteral(TypedLiteral object) {
- logger.debug("toVirtTypedLiteral(TypedLiteral {})", object);
- UriRef dt = object.getDataType();
- String literal = object.getLexicalForm();// .replaceAll("\"", "\\\\\"");
- StringBuilder prepared;
- // If XMLLiteral, prepare XML entities
- prepared = prepareString(
- literal,
- dt.getUnicodeString()
- .equals("http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral"));
- return new StringBuilder().append('"').append('"').append('"')
- .append(prepared).append('"').append('"').append('"')
- .append("^^").append(toVirtIri(dt)).toString();
- }
-
- private StringBuilder prepareString(String str, boolean xml) {
- StringBuilder retStr = new StringBuilder();
- for (int i = 0; i < str.length(); i++) {
- int cp = Character.codePointAt(str, i);
- int charCount = Character.charCount(cp);
- if (charCount > 1) {
- i += charCount - 1; // 2.
- if (i >= str.length()) {
- throw new IllegalArgumentException("truncated unexpectedly");
- }
- }
-
- if (cp < 128) {
- retStr.appendCodePoint(cp);
- } else {
- if (xml) {
- retStr.append(String.format("&#x%04x;", cp));
- } else {
- retStr.append(String.format("\\u%04x", cp));
- }
- }
- }
- return retStr;
- }
-
- /**
- * Returns a string to be used in SQL statements.
- *
- * @param object
- * @return
- */
- private String toVirtPlainLiteral(PlainLiteral object) {
- logger.debug("toVirtPlainLiteral(PlainLiteral {})", object);
- Language lang = object.getLanguage();
- String literal = object.getLexicalForm();
- StringBuilder sb = new StringBuilder().append('"').append('"')
- .append('"').append(prepareString(literal, false)).append('"')
- .append('"').append('"');
- if (lang == null) {
- return sb.toString();
- } else {
- return sb.append("@").append(lang).toString();
- }
- }
-
- /**
- * Returns a string to be used in SQL statements as Predicate of a triple.
- *
- * @param predicate
- * @return
- */
- private String toVirtPredicate(UriRef predicate) {
- logger.debug("toVirtPredicate(UriRef {}) ", predicate);
- if (predicate == null)
- return null;
- return toVirtIri(predicate);
- }
-
- private String toVirtIri(UriRef ur) {
- logger.debug("toVirtIri(UriRef {})", ur);
- return "<" + ur.getUnicodeString() + ">";
- }
-
- /**
- * Returns a string to be used in SQL statements as Subject of a triple.
- *
- * @param subject
- * @return
- */
- private String toVirtSubject(NonLiteral subject) {
- logger.debug("toVirtSubject(NonLiteral {})", subject);
- if (subject == null) {
- return null;
- }
- if (subject instanceof UriRef) {
- return toVirtIri((UriRef) subject);
- } else if (subject instanceof BNode) {
- return toVirtBnode((BNode) subject).asSkolemIri();
- } else {
- // These should be the only 2 implementations
- throw new IllegalArgumentException(
- "subject must be BNode or UriRef");
- }
- }
-
-}