From: <mrp...@us...> - 2014-05-07 20:25:03
|
Revision: 8223 http://sourceforge.net/p/bigdata/code/8223 Author: mrpersonick Date: 2014-05-07 20:24:56 +0000 (Wed, 07 May 2014) Log Message: ----------- Commit of Blueprints/Gremlin support. See ticket 913. Modified Paths: -------------- branches/BIGDATA_RELEASE_1_3_0/.classpath branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/remote/BigdataSailRemoteRepository.java branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/remote/BigdataSailRemoteRepositoryConnection.java branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/RESTServlet.java branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/RemoteRepository.java branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/webapp/TestNanoSparqlClient2.java branches/BIGDATA_RELEASE_1_3_0/build.properties branches/BIGDATA_RELEASE_1_3_0/build.xml branches/BIGDATA_RELEASE_1_3_0/pom.xml Added Paths: ----------- branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/LEGAL/jettison-license.txt branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/lib/blueprints-test-2.4.0.jar branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/lib/jettison-1.3.3.jar branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataEdge.java branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataElement.java branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataGraph.java branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataGraphBulkLoad.java branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataGraphClient.java branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataGraphEmbedded.java branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataGraphFactory.java branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataRDFFactory.java branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataVertex.java branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BlueprintsRDFFactory.java branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/edge.rq branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/edges.rq branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/edgesByProperty.rq branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/vertex.rq branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/test/ branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/test/com/ branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/test/com/bigdata/ branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/test/com/bigdata/blueprints/ branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/test/com/bigdata/blueprints/TestBigdataGraphClient.java branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/test/com/bigdata/blueprints/TestBigdataGraphEmbedded.java branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/test/com/bigdata/blueprints/graph-example-1.xml branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailFactory.java branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/BlueprintsServlet.java Removed Paths: ------------- branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataBlueprintsGraph.java branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataEdge.java branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataElement.java branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataEventTransactionalGraph.java branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataVertex.java branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/QueryManager.java Modified: branches/BIGDATA_RELEASE_1_3_0/.classpath =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/.classpath 2014-05-07 15:57:53 UTC (rev 8222) +++ branches/BIGDATA_RELEASE_1_3_0/.classpath 2014-05-07 20:24:56 UTC (rev 8223) @@ -1,16 +1,19 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> + <classpathentry kind="src" path="bigdata/src/java"/> <classpathentry kind="src" path="bigdata-rdf/src/java"/> + <classpathentry kind="src" path="bigdata-sails/src/java"/> + <classpathentry kind="src" path="bigdata-blueprints/src/java"/> + <classpathentry kind="src" path="bigdata/src/test"/> + <classpathentry kind="src" path="bigdata-rdf/src/test"/> + <classpathentry kind="src" path="bigdata-sails/src/test"/> + <classpathentry kind="src" path="bigdata-blueprints/src/test"/> + <classpathentry kind="src" path="bigdata-war/src"/> + <classpathentry kind="src" path="bigdata/src/resources/logging"/> <classpathentry kind="src" path="bigdata-rdf/src/samples"/> <classpathentry kind="src" path="dsi-utils/src/java"/> - <classpathentry kind="src" path="bigdata/src/resources/logging"/> <classpathentry kind="src" path="bigdata-sails/src/samples"/> <classpathentry kind="src" path="bigdata-jini/src/test"/> - <classpathentry kind="src" path="bigdata-sails/src/java"/> - <classpathentry kind="src" path="bigdata/src/java"/> - <classpathentry kind="src" path="bigdata-rdf/src/test"/> - <classpathentry kind="src" path="bigdata/src/test"/> - <classpathentry kind="src" path="bigdata-sails/src/test"/> <classpathentry kind="src" path="bigdata-jini/src/java"/> <classpathentry kind="src" path="contrib/src/problems"/> <classpathentry kind="src" path="bigdata/src/samples"/> @@ -21,7 +24,6 @@ <classpathentry kind="src" path="junit-ext/src/java"/> <classpathentry kind="src" path="lgpl-utils/src/java"/> <classpathentry kind="src" path="lgpl-utils/src/test"/> - <classpathentry kind="src" path="bigdata-war/src"/> <classpathentry kind="src" path="bigdata-ganglia/src/java"/> <classpathentry kind="src" path="bigdata-ganglia/src/test"/> <classpathentry kind="src" path="bigdata-rdf/src/resources/service-providers"/> @@ -92,5 +94,8 @@ <classpathentry exported="true" kind="lib" path="bigdata/lib/jetty/jetty-webapp-9.1.4.v20140401.jar" sourcepath="/Users/bryan/Downloads/org.eclipse.jetty.project-jetty-9.1.4.v20140401"/> <classpathentry exported="true" kind="lib" path="bigdata/lib/jetty/jetty-xml-9.1.4.v20140401.jar"/> <classpathentry exported="true" kind="lib" path="bigdata-sails/lib/jackson-core-2.2.3.jar"/> + <classpathentry kind="lib" path="bigdata-blueprints/lib/blueprints-core-2.4.0.jar"/> + <classpathentry kind="lib" path="bigdata-blueprints/lib/blueprints-test-2.4.0.jar"/> + <classpathentry kind="lib" path="bigdata-blueprints/lib/jettison-1.3.3.jar"/> <classpathentry kind="output" path="bin"/> </classpath> Added: branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/LEGAL/jettison-license.txt =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/LEGAL/jettison-license.txt (rev 0) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/LEGAL/jettison-license.txt 2014-05-07 20:24:56 UTC (rev 8223) @@ -0,0 +1,13 @@ +Copyright 2006 Envoi Solutions LLC + +Licensed 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. \ No newline at end of file Property changes on: branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/LEGAL/jettison-license.txt ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/lib/blueprints-test-2.4.0.jar =================================================================== (Binary files differ) Index: branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/lib/blueprints-test-2.4.0.jar =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/lib/blueprints-test-2.4.0.jar 2014-05-07 15:57:53 UTC (rev 8222) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/lib/blueprints-test-2.4.0.jar 2014-05-07 20:24:56 UTC (rev 8223) Property changes on: branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/lib/blueprints-test-2.4.0.jar ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Added: branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/lib/jettison-1.3.3.jar =================================================================== (Binary files differ) Index: branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/lib/jettison-1.3.3.jar =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/lib/jettison-1.3.3.jar 2014-05-07 15:57:53 UTC (rev 8222) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/lib/jettison-1.3.3.jar 2014-05-07 20:24:56 UTC (rev 8223) Property changes on: branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/lib/jettison-1.3.3.jar ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Deleted: branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataBlueprintsGraph.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataBlueprintsGraph.java 2014-05-07 15:57:53 UTC (rev 8222) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataBlueprintsGraph.java 2014-05-07 20:24:56 UTC (rev 8223) @@ -1,141 +0,0 @@ -package com.bigdata.blueprints; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -import sun.reflect.generics.reflectiveObjects.NotImplementedException; - -import com.tinkerpop.blueprints.Edge; -import com.tinkerpop.blueprints.Features; -import com.tinkerpop.blueprints.GraphQuery; -import com.tinkerpop.blueprints.TransactionalGraph; -import com.tinkerpop.blueprints.Vertex; - - -public abstract class BigdataBlueprintsGraph implements BigdataEventTransactionalGraph { - // elements that we will be deleting from the store - private ArrayList<BigdataElement> removedElements = new ArrayList<BigdataElement>(); - // vertices that we will be adding to the store - private HashMap<String,BigdataVertex> addedVertices = new HashMap<String,BigdataVertex>(); - // elements that we will be adding to the store - private HashMap<String,BigdataEdge> addedEdges = new HashMap<String,BigdataEdge>(); - private QueryManager qm = null; - - public BigdataBlueprintsGraph () { } - - public BigdataBlueprintsGraph (QueryManager qm) { this.qm = qm; } - - public void setQueryManager(QueryManager qm) { this.qm = qm; } - public QueryManager getQueryManager() { return qm; } - - public void commit() { - // form and submit query - // - // - // - throwUnimplemented( "commit" ); - } - - public void rollback() { - throwUnimplemented( "rollback" ); - } - - public void stopTransaction(TransactionalGraph.Conclusion conclusion) { - throwUnimplemented( "stopTransaction" ); - } - - public void shutdown() { - throwUnimplemented( "shutdown" ); - } - - public Vertex getVertex(Object id) { - // we can only remove an item from the "add" queue - return addedVertices.get( (String) id ); - } - - public BigdataBlueprintsGraph getBasseGraph() { return this; } - - public Edge addEdge(Object id, BigdataVertex outVertex, BigdataVertex inVertex, String label) { - BigdataEdge edge = new BigdataEdge( (String)id, outVertex, inVertex, label ); - addedEdges.put((String)id, edge); - return edge; - } - - public Features getFeatures() { - throwUnimplemented( "getFeatures" ); - return (Features)null; - } - - public Vertex addVertex(Object id) { - BigdataVertex v = new BigdataVertex( (String)id ); - addedVertices.put( (String)id, v ); - return v; - } - - public void removeVertex(BigdataVertex vertex) { - addedVertices.remove( vertex.getId() ); // if present - removedElements.add( vertex ); - } - - public Iterable<Vertex> getVertices(String key, Object value) { - throwUnimplemented( "getVertices(String key, Object value)" ); - return (Iterable<Vertex>)null; - } - - public Iterable<Vertex> getVertices() { - // we only return what is in the "add" queue - final List<Vertex> vertexList = new ArrayList<Vertex>(); - vertexList.addAll( addedVertices.values() ); - return vertexList; - } - - public Edge getEdge(Object id) { - // we can only remove an item from the "add" queue - return addedEdges.get( (String) id ); - } - - public void removeEdge(BigdataEdge edge) { - addedEdges.remove( edge.getId() ); // if present - removedElements.add( edge ); - } - - public Iterable<Edge> getEdges(String key, Object value) { - throwUnimplemented( "getEdges(String key, Object value)" ); - return (Iterable<Edge>)null; - } - - public Iterable<Edge> getEdges() { - // we only return what is in the add queue - final List<Edge> edgeList = new ArrayList<Edge>(); - edgeList.addAll( addedEdges.values() ); - return edgeList; - } - - public GraphQuery query() { - throwUnimplemented( "queries" ); - return (GraphQuery)null; - } - - // @SuppressWarnings("deprecation") - private void throwUnimplemented(String method) { - // unchecked( new Exception( "The '" + method + "' has not been implemented." ) ); - throw new NotImplementedException(); - } - - - /* Maybe use later - * - public static RuntimeException unchecked(Throwable e) { - BigdataBlueprintsGraph.<RuntimeException>throwAny(e); - return null; - } - - @SuppressWarnings("unchecked") - private static <E extends Throwable> void throwAny(Throwable e) throws E { - throw (E)e; - } - */ - -} - Deleted: branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataEdge.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataEdge.java 2014-05-07 15:57:53 UTC (rev 8222) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataEdge.java 2014-05-07 20:24:56 UTC (rev 8223) @@ -1,52 +0,0 @@ -package com.bigdata.blueprints; - -import sun.reflect.generics.reflectiveObjects.NotImplementedException; - -import com.tinkerpop.blueprints.Direction; -import com.tinkerpop.blueprints.Edge; -import com.tinkerpop.blueprints.Vertex; - - -public class BigdataEdge extends BigdataElement implements Edge { - - protected BigdataVertex vOut = null; - protected BigdataVertex vIn = null; - - - public BigdataEdge(String id) { - super(id); - } - - public BigdataEdge(String id, String label) { - super(id,label); - } - - public BigdataEdge(String id, BigdataVertex out, BigdataVertex in, String label) { - super(id,label); - this.vOut = out; - this.vIn = in; - } - - public Vertex getVertex(Direction direction) throws IllegalArgumentException { - if( direction == Direction.IN ) { - return vIn; - } - else if( direction == Direction.OUT ) { - return vOut; - } - else { - throw new NotImplementedException(); - } - } - - @Override - public void remove() { - throw new NotImplementedException(); - } - - public String toString() { - // toTTLString(); - return "Not Implemented"; - } - -} Added: branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataEdge.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataEdge.java (rev 0) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataEdge.java 2014-05-07 20:24:56 UTC (rev 8223) @@ -0,0 +1,107 @@ +/** +Copyright (C) SYSTAP, LLC 2006-2014. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program 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; version 2 of the License. + +This program 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, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +package com.bigdata.blueprints; + +import java.util.Arrays; +import java.util.List; + +import org.openrdf.model.Statement; +import org.openrdf.model.URI; +import org.openrdf.model.vocabulary.RDFS; + +import com.tinkerpop.blueprints.Direction; +import com.tinkerpop.blueprints.Edge; +import com.tinkerpop.blueprints.Vertex; + +/** + * Edge implementation that wraps an Edge statement and points to a + * {@link BigdataGraph} instance. + * + * @author mikepersonick + * + */ +public class BigdataEdge extends BigdataElement implements Edge { + + private static final List<String> blacklist = Arrays.asList(new String[] { + "id", "", "label" + }); + + protected final Statement stmt; + + public BigdataEdge(final Statement stmt, final BigdataGraph graph) { + super(stmt.getPredicate(), graph); + + this.stmt = stmt; + } + + @Override + public Object getId() { + return graph.factory.fromEdgeURI(uri); + } + + @Override + public void remove() { + graph.removeEdge(this); + } + + @Override + public String getLabel() { + return (String) graph.getProperty(uri, RDFS.LABEL); + } + + @Override + public Vertex getVertex(final Direction dir) throws IllegalArgumentException { + + if (dir == Direction.BOTH) { + throw new IllegalArgumentException(); + } + + final URI uri = (URI) + (dir == Direction.OUT ? stmt.getSubject() : stmt.getObject()); + + final String id = graph.factory.fromVertexURI(uri); + + return graph.getVertex(id); + + } + + @Override + public void setProperty(final String property, final Object val) { + + if (property == null || blacklist.contains(property)) { + throw new IllegalArgumentException(); + } + + super.setProperty(property, val); + + } + + @Override + public String toString() { + final URI s = (URI) stmt.getSubject(); + final URI p = (URI) stmt.getPredicate(); + final URI o = (URI) stmt.getObject(); + return "e["+p.getLocalName()+"]["+s.getLocalName()+"->"+o.getLocalName()+"]"; + } + +} Property changes on: branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataEdge.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Deleted: branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataElement.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataElement.java 2014-05-07 15:57:53 UTC (rev 8222) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataElement.java 2014-05-07 20:24:56 UTC (rev 8223) @@ -1,70 +0,0 @@ -package com.bigdata.blueprints; - -import sun.reflect.generics.reflectiveObjects.NotImplementedException; - -import java.util.HashMap; -import java.util.Set; - -import org.openrdf.model.vocabulary.RDFS; -import com.tinkerpop.blueprints.Element; - -public class BigdataElement implements Element { - - protected String id = null; // must be a URI - - // implied here is that the properties exist in the graph store, we would need a 2nd property setter - private HashMap<String,String> properties = new HashMap<String,String>(); - // properties that we will be deleting from the store - private HashMap<String,String> removedProperties = new HashMap<String,String>(); - // properties that we will be adding to the store - private HashMap<String,String> addedProperties = new HashMap<String,String>(); - - public BigdataElement(String id) { - this.id = id; - } - - public BigdataElement(String id, String label) { - this.id = id; - setProperty( RDFS.LABEL.toString(), label ); - } - - @SuppressWarnings("unchecked") - public <T> T getProperty(String key) { - return (T) properties.get(key); - } - - public Set<String> getPropertyKeys() { - Set<String> keys = properties.keySet(); - keys.addAll( addedProperties.keySet() ); - return keys; - } - - public void setProperty(String key, Object value) { - addedProperties.put(key,(String)value ); - properties.put(key, (String)value); - } - - @SuppressWarnings("unchecked") - public <T> T removeProperty(String key) { - removedProperties.put(key, key); - return (T) properties.remove(key); - } - - public void remove() { - // delete from graph - throw new NotImplementedException(); - } - - public Object getId() { - return id; - } - - public boolean equals(Object obj) { - return obj.toString().equals(this.toString()); - } - - public String getLabel() { - return getProperty( RDFS.LABEL.toString() ); - } - -} Added: branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataElement.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataElement.java (rev 0) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataElement.java 2014-05-07 20:24:56 UTC (rev 8223) @@ -0,0 +1,134 @@ +/** +Copyright (C) SYSTAP, LLC 2006-2014. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program 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; version 2 of the License. + +This program 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, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +package com.bigdata.blueprints; + +import java.util.Arrays; +import java.util.List; +import java.util.Set; + +import org.openrdf.model.Literal; +import org.openrdf.model.URI; + +import com.tinkerpop.blueprints.Element; + +/** + * Base class for {@link BigdataVertex} and {@link BigdataEdge}. Handles + * property-related methods. + * + * @author mikepersonick + * + */ +public abstract class BigdataElement implements Element { + + private static final List<String> blacklist = Arrays.asList(new String[] { + "id", "" + }); + + protected final URI uri; + protected final BigdataGraph graph; + + public BigdataElement(final URI uri, final BigdataGraph graph) { + this.uri = uri; + this.graph = graph; + } + + @Override + @SuppressWarnings("unchecked") + public <T> T getProperty(final String property) { + + final URI p = graph.factory.toPropertyURI(property); + + return (T) graph.getProperty(uri, p); + + } + + @Override + public Set<String> getPropertyKeys() { + + return graph.getPropertyKeys(uri); + + } + + @Override + @SuppressWarnings("unchecked") + public <T> T removeProperty(final String property) { + + final URI p = graph.factory.toPropertyURI(property); + + return (T) graph.removeProperty(uri, p); + + } + + @Override + public void setProperty(final String property, final Object val) { + + if (property == null || blacklist.contains(property)) { + throw new IllegalArgumentException(); + } + + final URI p = graph.factory.toPropertyURI(property); + + final Literal o = graph.factory.toLiteral(val); + + graph.setProperty(uri, p, o); + + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((graph == null) ? 0 : graph.hashCode()); + result = prime * result + ((uri == null) ? 0 : uri.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + BigdataElement other = (BigdataElement) obj; + if (graph == null) { + if (other.graph != null) + return false; + } else if (!graph.equals(other.graph)) + return false; + if (uri == null) { + if (other.uri != null) + return false; + } else if (!uri.equals(other.uri)) + return false; + return true; + } + + @Override + public String toString() { + return uri.toString(); + } + + +} Property changes on: branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataElement.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Deleted: branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataEventTransactionalGraph.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataEventTransactionalGraph.java 2014-05-07 15:57:53 UTC (rev 8222) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataEventTransactionalGraph.java 2014-05-07 20:24:56 UTC (rev 8223) @@ -1,8 +0,0 @@ -package com.bigdata.blueprints; - -import com.tinkerpop.blueprints.Graph; -import com.tinkerpop.blueprints.ThreadedTransactionalGraph; - -public interface BigdataEventTransactionalGraph extends Graph, ThreadedTransactionalGraph { - -} Added: branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataGraph.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataGraph.java (rev 0) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataGraph.java 2014-05-07 20:24:56 UTC (rev 8223) @@ -0,0 +1,843 @@ +/** +Copyright (C) SYSTAP, LLC 2006-2014. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program 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; version 2 of the License. + +This program 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, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +package com.bigdata.blueprints; + +import info.aduna.iteration.CloseableIteration; + +import java.util.Iterator; +import java.util.LinkedHashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; +import java.util.UUID; + +import org.apache.commons.io.IOUtils; +import org.openrdf.OpenRDFException; +import org.openrdf.model.Literal; +import org.openrdf.model.Statement; +import org.openrdf.model.URI; +import org.openrdf.model.Value; +import org.openrdf.model.impl.StatementImpl; +import org.openrdf.model.impl.URIImpl; +import org.openrdf.model.vocabulary.RDF; +import org.openrdf.model.vocabulary.RDFS; +import org.openrdf.query.GraphQueryResult; +import org.openrdf.query.QueryLanguage; +import org.openrdf.repository.RepositoryConnection; +import org.openrdf.repository.RepositoryResult; + +import com.bigdata.rdf.store.BD; +import com.tinkerpop.blueprints.Direction; +import com.tinkerpop.blueprints.Edge; +import com.tinkerpop.blueprints.Features; +import com.tinkerpop.blueprints.Graph; +import com.tinkerpop.blueprints.GraphQuery; +import com.tinkerpop.blueprints.Vertex; +import com.tinkerpop.blueprints.util.DefaultGraphQuery; + +/** + * A base class for a Blueprints wrapper around a bigdata back-end. + * + * @author mikepersonick + * + */ +public abstract class BigdataGraph implements Graph { + + public static final URI VERTEX = new URIImpl(BD.NAMESPACE + "Vertex"); + + public static final URI EDGE = new URIImpl(BD.NAMESPACE + "Edge"); + +// final BigdataSailRepository repo; +// +// transient BigdataSailRepositoryConnection cxn; + + final BlueprintsRDFFactory factory; + +// public BigdataGraph(final BigdataSailRepository repo) { +// this(repo, BigdataRDFFactory.INSTANCE); +// } + + public BigdataGraph(//final BigdataSailRepository repo, + final BlueprintsRDFFactory factory) { +// try { +// this.repo = repo; +// this.cxn = repo.getUnisolatedConnection(); +// this.cxn.setAutoCommit(false); + this.factory = factory; +// } catch (RepositoryException ex) { +// throw new RuntimeException(ex); +// } + } + + public String toString() { + return getClass().getSimpleName().toLowerCase(); + } + + protected abstract RepositoryConnection cxn() throws Exception; + +// public BigdataSailRepositoryConnection getConnection() { +// return this.cxn; +// } +// +// public BlueprintsRDFFactory getFactory() { +// return this.factory; +// } + +// public Value getValue(final URI s, final URI p) { +// +// try { +// +// final RepositoryResult<Statement> result = +// cxn.getStatements(s, p, null, false); +// +// if (result.hasNext()) { +// +// final Value o = result.next().getObject(); +// +// if (result.hasNext()) { +// throw new RuntimeException(s +// + ": more than one value for p: " + p +// + ", did you mean to call getValues()?"); +// } +// +// return o; +// +// } +// +// return null; +// +// } catch (Exception ex) { +// throw new RuntimeException(ex); +// } +// +// } + + public Object getProperty(final URI s, final URI p) { + + try { + + final RepositoryResult<Statement> result = + cxn().getStatements(s, p, null, false); + + if (result.hasNext()) { + + final Value value = result.next().getObject(); + + if (result.hasNext()) { + throw new RuntimeException(s + + ": more than one value for p: " + p + + ", did you mean to call getValues()?"); + } + + if (!(value instanceof Literal)) { + throw new RuntimeException("not a property: " + value); + } + + final Literal lit = (Literal) value; + + return factory.fromLiteral(lit); + + } + + return null; + + } catch (Exception ex) { + throw new RuntimeException(ex); + } + + } + +// public List<Value> getValues(final URI s, final URI p) { +// +// try { +// +// final RepositoryResult<Statement> result = +// cxn().getStatements(s, p, null, false); +// +// final List<Value> values = new LinkedList<Value>(); +// +// while (result.hasNext()) { +// +// final Value o = result.next().getObject(); +// +// values.add(o); +// +// } +// +// return values; +// +// } catch (Exception ex) { +// throw new RuntimeException(ex); +// } +// +// } + + public List<Object> getProperties(final URI s, final URI p) { + + try { + + final RepositoryResult<Statement> result = + cxn().getStatements(s, p, null, false); + + final List<Object> props = new LinkedList<Object>(); + + while (result.hasNext()) { + + final Value value = result.next().getObject(); + + if (!(value instanceof Literal)) { + throw new RuntimeException("not a property: " + value); + } + + final Literal lit = (Literal) value; + + props.add(factory.fromLiteral(lit)); + + } + + return props; + + } catch (Exception ex) { + throw new RuntimeException(ex); + } + + } + + public Set<String> getPropertyKeys(final URI s) { + + try { + + final RepositoryResult<Statement> result = + cxn().getStatements(s, null, null, false); + + final Set<String> properties = new LinkedHashSet<String>(); + + while (result.hasNext()) { + + final Statement stmt = result.next(); + + if (!(stmt.getObject() instanceof Literal)) { + continue; + } + + if (stmt.getPredicate().equals(RDFS.LABEL)) { + continue; + } + + final String p = + factory.fromPropertyURI(stmt.getPredicate()); + + properties.add(p); + + } + + return properties; + + } catch (Exception ex) { + throw new RuntimeException(ex); + } + + } + + public Object removeProperty(final URI s, final URI p) { + + try { + + final Object oldVal = getProperty(s, p); + + cxn().remove(s, p, null); + + return oldVal; + + } catch (Exception e) { + throw new RuntimeException(e); + } + + } + + public void setProperty(final URI s, final URI p, final Literal o) { + + try { + + cxn().remove(s, p, null); + + cxn().add(s, p, o); + + } catch (Exception e) { + throw new RuntimeException(e); + } + + } + + @Override + public Edge addEdge(final Object key, final Vertex from, final Vertex to, + final String label) { + + if (label == null) { + throw new IllegalArgumentException(); + } + + final String eid = key != null ? key.toString() : UUID.randomUUID().toString(); + + final URI edgeURI = factory.toEdgeURI(eid); + + if (key != null) { + + final Edge edge = getEdge(key); + + if (edge != null) { + if (!(edge.getVertex(Direction.OUT).equals(from) && + (edge.getVertex(Direction.OUT).equals(to)))) { + throw new IllegalArgumentException("edge already exists: " + key); + } + } + + } + + try { + +// if (cxn().hasStatement(edgeURI, RDF.TYPE, EDGE, false)) { +// throw new IllegalArgumentException("edge " + eid + " already exists"); +// } + + final URI fromURI = factory.toVertexURI(from.getId().toString()); + final URI toURI = factory.toVertexURI(to.getId().toString()); + + cxn().add(fromURI, edgeURI, toURI); + cxn().add(edgeURI, RDF.TYPE, EDGE); + cxn().add(edgeURI, RDFS.LABEL, factory.toLiteral(label)); + + return new BigdataEdge(new StatementImpl(fromURI, edgeURI, toURI), this); + + } catch (Exception ex) { + throw new RuntimeException(ex); + } + + } + + @Override + public Vertex addVertex(final Object key) { + + try { + + final String vid = key != null ? + key.toString() : UUID.randomUUID().toString(); + + final URI uri = factory.toVertexURI(vid); + +// if (cxn().hasStatement(vertexURI, RDF.TYPE, VERTEX, false)) { +// throw new IllegalArgumentException("vertex " + vid + " already exists"); +// } + + cxn().add(uri, RDF.TYPE, VERTEX); + + return new BigdataVertex(uri, this); + + } catch (Exception ex) { + throw new RuntimeException(ex); + } + + } + + @Override + public Edge getEdge(final Object key) { + + if (key == null) + throw new IllegalArgumentException(); + + try { + + final URI edge = factory.toEdgeURI(key.toString()); + + final RepositoryResult<Statement> result = + cxn().getStatements(null, edge, null, false); + + if (result.hasNext()) { + + final Statement stmt = result.next(); + + if (result.hasNext()) { + throw new RuntimeException( + "duplicate edge: " + key); + } + + return new BigdataEdge(stmt, this); + + } + + return null; + + } catch (Exception ex) { + throw new RuntimeException(ex); + } + + } + + @Override + public Iterable<Edge> getEdges() { + + final URI wild = null; + return getEdges(wild, wild); + + } + + public Iterable<Edge> getEdges(final URI s, final URI o, final String... labels) { + + try { + +// final RepositoryResult<Statement> result = +// cxn().getStatements(s, p, o, false); +// +// return new EdgeIterable(result); + + final StringBuilder sb = new StringBuilder(); + sb.append("construct { ?from ?edge ?to . } where {\n"); + sb.append("?edge rdf:type bd:Edge . ?from ?edge ?to .\n"); + if (labels != null && labels.length > 0) { + if (labels.length == 1) { + sb.append("?edge rdfs:label \"").append(labels[0]).append("\" .\n"); + } else { + sb.append("?edge rdfs:label ?label .\n"); + sb.append("filter(?label in ("); + for (String label : labels) { + sb.append("\""+label+"\", "); + } + sb.setLength(sb.length()-2); + sb.append(")) .\n"); + } + } + sb.append("}"); + + final String queryStr = sb.toString() + .replace("?from", s != null ? "<"+s+">" : "?from") + .replace("?to", o != null ? "<"+o+">" : "?to"); + + final org.openrdf.query.GraphQuery query = + cxn().prepareGraphQuery(QueryLanguage.SPARQL, queryStr); + + final GraphQueryResult stmts = query.evaluate(); + + return new EdgeIterable(stmts); + + } catch (Exception ex) { + throw new RuntimeException(ex); + } + + } + + public Iterable<Vertex> getVertices(final URI s, final URI o, + final String... labels) { + + if (s != null && o != null) { + throw new IllegalArgumentException(); + } + + if (s == null && o == null) { + throw new IllegalArgumentException(); + } + + try { + +// final RepositoryResult<Statement> result = +// cxn().getStatements(s, null, o, false); +// +// return new VertexIterable(result, s == null); + + final StringBuilder sb = new StringBuilder(); + sb.append("construct { ?from ?edge ?to . } where {\n"); + sb.append("?edge rdf:type bd:Edge . ?from ?edge ?to .\n"); + if (labels != null && labels.length > 0) { + if (labels.length == 1) { + sb.append("?edge rdfs:label \"").append(labels[0]).append("\" .\n"); + } else { + sb.append("?edge rdfs:label ?label .\n"); + sb.append("filter(?label in ("); + for (String label : labels) { + sb.append("\""+label+"\", "); + } + sb.setLength(sb.length()-2); + sb.append(")) .\n"); + } + } + sb.append("}"); + + final String queryStr = sb.toString() + .replace("?from", s != null ? "<"+s+">" : "?from") + .replace("?to", o != null ? "<"+o+">" : "?to"); + + final org.openrdf.query.GraphQuery query = + cxn().prepareGraphQuery(QueryLanguage.SPARQL, queryStr); + + final GraphQueryResult stmts = query.evaluate(); + + return new VertexIterable(stmts, s == null); + + } catch (Exception ex) { + throw new RuntimeException(ex); + } + + } + + public final <T> Iterable<T> fuse(final Iterable<T>... args) { + + return new FusedIterable<T>(args); + } + + + @Override + public Iterable<Edge> getEdges(final String prop, final Object val) { + + final URI p = factory.toPropertyURI(prop); + final Literal o = factory.toLiteral(val); + + try { + + final String queryStr = IOUtils.toString( + getClass().getResourceAsStream("edgesByProperty.rq")) + .replace("?prop", "<"+p+">") + .replace("?val", o.toString()); + + final org.openrdf.query.GraphQuery query = + cxn().prepareGraphQuery(QueryLanguage.SPARQL, queryStr); + + final GraphQueryResult stmts = query.evaluate(); + + return new EdgeIterable(stmts); + + } catch (Exception ex) { + throw new RuntimeException(ex); + } + + } + + @Override + public Features getFeatures() { + + return FEATURES; + + } + + @Override + public Vertex getVertex(final Object key) { + + if (key == null) + throw new IllegalArgumentException(); + + final URI uri = factory.toVertexURI(key.toString()); + try { + if (cxn().hasStatement(uri, RDF.TYPE, VERTEX, false)) { + return new BigdataVertex(uri, this); + } + return null; + } catch (Exception ex) { + throw new RuntimeException(ex); + } + + } + + @Override + public Iterable<Vertex> getVertices() { + + try { + final RepositoryResult<Statement> result = + cxn().getStatements(null, RDF.TYPE, VERTEX, false); + return new VertexIterable(result, true); + } catch (Exception ex) { + throw new RuntimeException(ex); + } + + } + + @Override + public Iterable<Vertex> getVertices(String prop, Object val) { + + final URI p = factory.toPropertyURI(prop); + final Literal o = factory.toLiteral(val); + try { + final RepositoryResult<Statement> result = + cxn().getStatements(null, p, o, false); + return new VertexIterable(result, true); + } catch (Exception ex) { + throw new RuntimeException(ex); + } + + } + + @Override + public GraphQuery query() { + return new DefaultGraphQuery(this); + } + + @Override + public void removeEdge(final Edge edge) { + try { + final URI uri = factory.toURI(edge); + if (!cxn().hasStatement(uri, RDF.TYPE, EDGE, false)) { + throw new IllegalStateException(); + } + final URI wild = null; + // remove the edge statement + cxn().remove(wild, uri, wild); + // remove its properties + cxn().remove(uri, wild, wild); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @Override + public void removeVertex(final Vertex vertex) { + try { + final URI uri = factory.toURI(vertex); + if (!cxn().hasStatement(uri, RDF.TYPE, VERTEX, false)) { + throw new IllegalStateException(); + } + final URI wild = null; + // remove outgoing links and properties + cxn().remove(uri, wild, wild); + // remove incoming links + cxn().remove(wild, wild, uri); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + +// @Override +// public void commit() { +// try { +// cxn().commit(); +// } catch (RepositoryException e) { +// throw new RuntimeException(e); +// } +// } +// +// @Override +// public void rollback() { +// try { +// cxn().rollback(); +// cxn.close(); +// cxn = repo.getUnisolatedConnection(); +// cxn.setAutoCommit(false); +// } catch (RepositoryException e) { +// throw new RuntimeException(e); +// } +// } +// +// @Override +// public void shutdown() { +// try { +// cxn.close(); +// repo.shutDown(); +// } catch (RepositoryException e) { +// throw new RuntimeException(e); +// } +// } +// +// @Override +// @Deprecated +// public void stopTransaction(Conclusion arg0) { +// } + + public class VertexIterable implements Iterable<Vertex>, Iterator<Vertex> { + + private final CloseableIteration<Statement, ? extends OpenRDFException> stmts; + + private final boolean subject; + + private final List<Vertex> cache; + + public VertexIterable( + final CloseableIteration<Statement, ? extends OpenRDFException> stmts, + final boolean subject) { + this.stmts = stmts; + this.subject = subject; + this.cache = new LinkedList<Vertex>(); + } + + @Override + public boolean hasNext() { + try { + return stmts.hasNext(); + } catch (OpenRDFException e) { + throw new RuntimeException(e); + } + } + + @Override + public Vertex next() { + try { + final Statement stmt = stmts.next(); + final URI v = (URI) + (subject ? stmt.getSubject() : stmt.getObject()); + if (!hasNext()) { + stmts.close(); + } + final Vertex vertex = new BigdataVertex(v, BigdataGraph.this); + cache.add(vertex); + return vertex; + } catch (OpenRDFException e) { + throw new RuntimeException(e); + } + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + + @Override + public Iterator<Vertex> iterator() { + return hasNext() ? this : cache.iterator(); + } + + } + + public class EdgeIterable implements Iterable<Edge>, Iterator<Edge> { + + private final CloseableIteration<Statement, ? extends OpenRDFException> stmts; + + private final List<Edge> cache; + + public EdgeIterable( + final CloseableIteration<Statement, ? extends OpenRDFException> stmts) { + this.stmts = stmts; + this.cache = new LinkedList<Edge>(); + } + + @Override + public boolean hasNext() { + try { + return stmts.hasNext(); + } catch (OpenRDFException e) { + throw new RuntimeException(e); + } + } + + @Override + public Edge next() { + try { + final Statement stmt = stmts.next(); + if (!hasNext()) { + stmts.close(); + } + final Edge edge = new BigdataEdge(stmt, BigdataGraph.this); + cache.add(edge); + return edge; + } catch (OpenRDFException e) { + throw new RuntimeException(e); + } + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + + @Override + public Iterator<Edge> iterator() { + return hasNext() ? this : cache.iterator(); + } + + } + + public class FusedIterable<T> implements Iterable<T>, Iterator<T> { + + private final Iterable<T>[] args; + + private transient int i = 0; + + private transient Iterator<T> curr; + + public FusedIterable(final Iterable<T>... args) { + this.args = args; + this.curr = args[0].iterator(); + } + + @Override + public boolean hasNext() { + if (curr.hasNext()) { + return true; + } + while (!curr.hasNext() && i < (args.length-1)) { + curr = args[++i].iterator(); + if (curr.hasNext()) { + return true; + } + } + return false; + } + + @Override + public T next() { + return curr.next(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + + @Override + public Iterator<T> iterator() { + return this; + } + + } + + protected static final Features FEATURES = new Features(); + + static { + + FEATURES.supportsSerializableObjectProperty = false; + FEATURES.supportsBooleanProperty = true; + FEATURES.supportsDoubleProperty = true; + FEATURES.supportsFloatProperty = true; + FEATURES.supportsIntegerProperty = true; + FEATURES.supportsPrimitiveArrayProperty = false; + FEATURES.supportsUniformListProperty = false; + FEATURES.supportsMixedListProperty = false; + FEATURES.supportsLongProperty = true; + FEATURES.supportsMapProperty = false; + FEATURES.supportsStringProperty = true; + + FEATURES.supportsDuplicateEdges = true; + FEATURES.supportsSelfLoops = true; + FEATURES.isPersistent = true; + FEATURES.isWrapper = false; + FEATURES.supportsVertexIteration = true; + FEATURES.supportsEdgeIteration = true; + FEATURES.supportsVertexIndex = false; + FEATURES.supportsEdgeIndex = false; + FEATURES.ignoresSuppliedIds = true; + FEATURES.supportsTransactions = false; + FEATURES.supportsIndices = true; + FEATURES.supportsKeyIndices = true; + FEATURES.supportsVertexKeyIndex = true; + FEATURES.supportsEdgeKeyIndex = true; + FEATURES.supportsEdgeRetrieval = true; + FEATURES.supportsVertexProperties = true; + FEATURES.supportsEdgeProperties = true; + FEATURES.supportsThreadedTransactions = false; + } + +} Property changes on: branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataGraph.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataGraphBulkLoad.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataGraphBulkLoad.java (rev 0) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataGraphBulkLoad.java 2014-05-07 20:24:56 UTC (rev 8223) @@ -0,0 +1,325 @@ +/** +Copyright (C) SYSTAP, LLC 2006-2014. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program 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; version 2 of the License. + +This program 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, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +package com.bigdata.blueprints; + +import java.util.UUID; + +import org.openrdf.model.Literal; +import org.openrdf.model.URI; +import org.openrdf.model.impl.StatementImpl; +import org.openrdf.model.vocabulary.RDF; +import org.openrdf.model.vocabulary.RDFS; +import org.openrdf.repository.RepositoryConnection; + +import com.bigdata.rdf.changesets.IChangeLog; +import com.bigdata.rdf.changesets.IChangeRecord; +import com.bigdata.rdf.sail.BigdataSailRepositoryConnection; +import com.tinkerpop.blueprints.Edge; +import com.tinkerpop.blueprints.GraphQuery; +import com.tinkerpop.blueprints.TransactionalGraph; +import com.tinkerpop.blueprints.Vertex; + +/** + * Simple bulk loader that will insert graph data without any consistency + * checking (won't check for duplicate vertex or edge identifiers). Currently + * does not overwrite old property values, but we may need to change this. + * <p> + * Implements {@link IChangeLog} so that we can report a mutation count. + * + * @author mikepersonick + * + */ +public class BigdataGraphBulkLoad extends BigdataGraph + implements TransactionalGraph, IChangeLog { + + private final BigdataSailRepositoryConnection cxn; + + public BigdataGraphBulkLoad(final BigdataSailRepositoryConnection cxn) { + this(cxn, BigdataRDFFactory.INSTANCE); + } + + public BigdataGraphBulkLoad(final BigdataSailRepositoryConnection cxn, + final BlueprintsRDFFactory factory) { + super(factory); + + this.cxn = cxn; + this.cxn.addChangeLog(this); + } + + protected RepositoryConnection cxn() throws Exception { + return cxn; + } + + @Override + public void commit() { + try { + cxn.commit(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @Override + public void rollback() { + try { + cxn.rollback(); + cxn.close(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @Override + public void shutdown() { + try { + cxn.close(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @Override + @Deprecated + public void stopTransaction(Conclusion arg0) { + } + + + static { + +// FEATURES.supportsSerializableObjectProperty = false; +// FEATURES.supportsBooleanProperty = true; +// FEATURES.supportsDoubleProperty = true; +// FEATURES.supportsFloatProperty = true; +// FEATURES.supportsIntegerProperty = true; +// FEATURES.supportsPrimitiveArrayProperty = false; +// FEATURES.supportsUniformListProperty = false; +// FEATURES.supportsMixedListProperty = false; +// FEATURES.supportsLongProperty = true; +// FEATURES.supportsMapProperty = false; +// FEATURES.supportsStringProperty = true; +// +// FEATURES.supportsDuplicateEdges = true; +// FEATURES.supportsSelfLoops = true; +// FEATURES.isPersistent = true; +// FEATURES.isWrapper = false; +// FEATURES.supportsVertexIteration = true; +// FEATURES.supportsEdgeIteration = true; +// FEATURES.supportsVertexIndex = false; +// FEATURES.supportsEdgeIndex = false; +// FEATURES.ignoresSuppliedIds = true; + BigdataGraph.FEATURES.supportsTransactions = true; +// FEATURES.supportsIndices = true; +// FEATURES.supportsKeyIndices = true; +// FEATURES.supportsVertexKeyIndex = true; +// FEATURES.supportsEdgeKeyIndex = true; +// FEATURES.supportsEdgeRetrieval = true; +// FEATURES.supportsVertexProperties = true; +// FEATURES.supportsEdgeProperties = true; +// FEATURES.supportsThreadedTransactions = false; + } + + + @Override + public Edge getEdge(Object arg0) { + throw new UnsupportedOperationException(); + } + + @Override + public Iterable<Edge> getEdges() { + throw new UnsupportedOperationException(); + } + + @Override + public Iterable<Edge> getEdges(String arg0, Object arg1) { + throw new UnsupportedOperationException(); + } + + @Override + public Vertex getVertex(Object arg0) { + throw new UnsupportedOperationException(); + } + + @Override + public Iterable<Vertex> getVertices() { + throw new UnsupportedOperationException(); + } + + @Override + public Iterable<Vertex> getVertices(String arg0, Object arg1) { + throw new UnsupportedOperationException(); + } + + @Override + public GraphQuery query() { + throw new UnsupportedOperationException(); + } + + @Override + public void removeEdge(Edge arg0) { + throw new UnsupportedOperationException(); + } + + @Override + public void removeVertex(Vertex arg0) { + throw new UnsupportedOperationException(); + } + + /** + * Set a property without removing the old value first. + */ + @Override + public void setProperty(final URI s, final URI p, final Literal o) { + + try { + +// cxn().remove(s, p, null); + + cxn().add(s, p, o); + + } catch (Exception e) { + throw new RuntimeException(e); + } + + } + + /** + * Add a vertex without consistency checking (does not check for a duplicate + * identifier). + */ + @Override + public Vertex addVertex(final Object key) { + + try { + + final String vid = key != null ? + key.toString() : UUID.randomUUID().toString(); + + final URI uri = factory.toVertexURI(vid); + +// if (cxn().hasStatement(vertexURI, RDF.TYPE, VERTEX, false)) { +// throw new IllegalArgumentException("vertex " + vid + " already exists"); +// } + + cxn().add(uri, RDF.TYPE, VERTEX); + + return new BigdataVertex(uri, this); + + } catch (Exception ex) { + throw new RuntimeException(ex); + } + + } + + /** + * Add an edge without consistency checking (does not check for a duplicate + * identifier). + */ + @Override + public Edge addEdge(final Object key, final Vertex from, final Vertex to, + final String label) { + + if (label == null) { + throw new IllegalArgumentException(); + } + + final String eid = key != null ? key.toString() : UUID.randomUUID().toString(); + + final URI edgeURI = factory.toEdgeURI(eid); + +// if (key != null) { +// +// final Edge edge = getEdge(key); +// +// if (edge != null) { +// if (!(edge.getVertex(Direction.OUT).equals(from) && +// (edge.getVertex(Direction.OUT).equals(to)))) { +// throw new IllegalArgumentException("edge already exists: " + key); +// } +// } +// +// } + + try { + +// if (cxn().hasStatement(edgeURI, RDF.TYPE, EDGE, false)) { +// throw new IllegalArgumentException("edge " + eid + " already exists"); +// } + + final URI fromURI = factory.toVertexURI(from.getId().toString()); + final URI toURI = factory.toVertexURI(to.getId().toString()); + + cxn().add(fromURI, edgeURI, toURI); + cxn().add(edgeURI, RDF.TYPE, EDGE); + cxn().add(edgeURI, RDFS.LABEL, factory.toLiteral(label)); + + return new BigdataEdge(new StatementImpl(fromURI, edgeURI, toURI), this); + + } catch (Exception ex) { + throw new RuntimeException(ex); + } + + } + + private transient long mutationCountTotal = 0; + private transient long mutationCountCurrentCommit = 0; + private transient long mutationCountLastCommit = 0; + + @Override + public void changeEvent(final IChangeRecord record) { + mutationCountTotal++; + mutationCountCurrentCommit++; + } + + @Override + public void transactionBegin() { + } + + @Override + public void transactionPrepare() { + } + + @Override + public void transactionCommited(long commitTime) { + mutationCountLastCommit = mutationCountCurrentCommit; + mutationCountCurrentCommit = 0; + } + + @Override + public void transactionAborted() { + } + + public long getMutationCountTotal() { + return mutationCountTotal; + } + + public long getMutationCountCurrentCommit() { + return mutationCountCurrentCommit; + } + + public long getMutationCountLastCommit() { + return mutationCountLastCommit; + } + + + +} Property changes on: branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataGraphBulkLoad.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataGraphClient.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataGraphClient.java (rev 0) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-blueprints/src/java/com/bigdata/blueprints/BigdataGraphClient.java 2014-05-07 20:24:56 UTC (rev 8223) @@ -0,0 +1,112 @@ +/** +Copyright (C) SYSTAP, LLC 2006-2014. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program 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; version 2 of the License. + +This program 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, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +package com.bigdata.blueprints; + +import com.bigdata.rdf.sail.remote.BigdataSailRemoteRepository; +import com.bigdata.rdf.sail.remote.BigdataSailRemoteRepositoryConnection; +import com.bigdata.rdf.sail.webapp.client.RemoteRepository; + +/** + * This is a thin-client implementation of a Blueprints wrapper around the + * client library that interacts with the NanoSparqlServer. This is a functional + * implementation suitable for writing POCs... [truncated message content] |