Created
October 25, 2013 19:31
-
-
Save pepperbob/7160488 to your computer and use it in GitHub Desktop.
Patch for RDFBean issue #56
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/rdfbean-virtuoso/pom.xml b/rdfbean-virtuoso/pom.xml | |
| index b410b7d..5ad612e 100644 | |
| --- a/rdfbean-virtuoso/pom.xml | |
| +++ b/rdfbean-virtuoso/pom.xml | |
| @@ -23,6 +23,11 @@ | |
| <artifactId>rdfbean-core</artifactId> | |
| <version>${project.version}</version> | |
| </dependency> | |
| + <dependency> | |
| + <groupId>com.mysema.rdf</groupId> | |
| + <artifactId>rdfbean-sesame2</artifactId> | |
| + <version>${project.version}</version> | |
| + </dependency> | |
| <dependency> | |
| <groupId>com.openlinksw</groupId> | |
| <artifactId>virtjdbc4</artifactId> | |
| diff --git a/rdfbean-virtuoso/src/main/java/com/mysema/rdfbean/virtuoso/VirtuosoRepositoryConnection.java b/rdfbean-virtuoso/src/main/java/com/mysema/rdfbean/virtuoso/VirtuosoRepositoryConnection.java | |
| index 0b02b6d..fd180d9 100644 | |
| --- a/rdfbean-virtuoso/src/main/java/com/mysema/rdfbean/virtuoso/VirtuosoRepositoryConnection.java | |
| +++ b/rdfbean-virtuoso/src/main/java/com/mysema/rdfbean/virtuoso/VirtuosoRepositoryConnection.java | |
| @@ -18,6 +18,13 @@ import java.util.Set; | |
| import javax.annotation.Nullable; | |
| +import org.openrdf.model.impl.ValueFactoryImpl; | |
| +import org.openrdf.rio.RDFFormat; | |
| +import org.openrdf.rio.RDFHandlerException; | |
| +import org.openrdf.rio.RDFParseException; | |
| +import org.openrdf.rio.RDFParser; | |
| +import org.openrdf.rio.Rio; | |
| +import org.openrdf.rio.helpers.StatementCollector; | |
| import org.slf4j.Logger; | |
| import org.slf4j.LoggerFactory; | |
| @@ -51,6 +58,7 @@ import com.mysema.rdfbean.model.io.SPARQLUpdateWriter; | |
| import com.mysema.rdfbean.model.io.TurtleStringWriter; | |
| import com.mysema.rdfbean.object.SQLConnectionCallback; | |
| import com.mysema.rdfbean.owl.OWL; | |
| +import com.mysema.rdfbean.sesame.SesameDialect; | |
| /** | |
| * @author tiwe | |
| @@ -493,14 +501,9 @@ public class VirtuosoRepositoryConnection implements RDFConnection { | |
| stmt.setString(1, content); | |
| stmt.setString(2, context != null ? context.getId() : defaultGraph.getId()); | |
| } else if (format == Format.RDFXML) { | |
| - // String content = IOUtils.toString(is, "UTF-8"); // TODO : | |
| - // proper XML load | |
| - String content = new String(bytes, Charsets.UTF_8); // TODO : | |
| - // propert | |
| - // XML load | |
| - stmt = connection.prepareStatement("DB.DBA.RDF_LOAD_RDFXML(?,'',?,0)"); | |
| - stmt.setString(1, content); | |
| - stmt.setString(2, context != null ? context.getId() : defaultGraph.getId()); | |
| + | |
| + loadRdfXml(is, context); | |
| + | |
| } else { | |
| throw new IllegalArgumentException("Unsupported forma " + format); | |
| } | |
| @@ -512,6 +515,47 @@ public class VirtuosoRepositoryConnection implements RDFConnection { | |
| } | |
| } | |
| + | |
| + private void loadRdfXml(InputStream is, @Nullable UID context) { | |
| + try { | |
| + | |
| + UID currentContext = context != null ? context : defaultGraph; | |
| + | |
| + RDFParser rioParser = Rio.createParser(RDFFormat.RDFXML); | |
| + StatementCollector handler = new StatementCollector(); | |
| + rioParser.setRDFHandler(handler); | |
| + rioParser.parse(is, currentContext.getId()); | |
| + | |
| + SesameDialect dialect = new SesameDialect(ValueFactoryImpl.getInstance()); | |
| + Collection<STMT> stmts = new ArrayList<STMT>(); | |
| + int count = 0; | |
| + | |
| + for(org.openrdf.model.Statement s : handler.getStatements()) { | |
| + ID subject = dialect.getID(s.getSubject()); | |
| + UID predicate = dialect.getUID(s.getPredicate()); | |
| + NODE object = dialect.getNODE(s.getObject()); | |
| + | |
| + stmts.add(new STMT(subject, predicate, object, currentContext)); | |
| + | |
| + count++; | |
| + if(count > BATCH_SIZE) { | |
| + update(null, stmts); | |
| + stmts.clear(); | |
| + count = 0; | |
| + } | |
| + } | |
| + | |
| + update(null, stmts); | |
| + | |
| + } catch (RDFParseException e) { | |
| + throw new RepositoryException(e); | |
| + } catch (RDFHandlerException e) { | |
| + throw new RepositoryException(e); | |
| + } catch (IOException e) { | |
| + throw new RepositoryException(e); | |
| + } | |
| + } | |
| + | |
| private void remove(Collection<STMT> removedStatements) throws SQLException { | |
| verifyNotReadOnly(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment