├── .gitignore
├── LICENSE
├── README.md
├── RELEASE.md
├── crew.rdf
├── images
└── blazegraph-gremlin.png
├── pom.xml
├── scripts
└── publishDocs.sh
└── src
├── main
├── java
│ └── com
│ │ └── blazegraph
│ │ └── gremlin
│ │ ├── console
│ │ └── BlazeGremlinPlugin.java
│ │ ├── embedded
│ │ ├── BasicRepositoryProvider.java
│ │ ├── BlazeGraphEmbedded.java
│ │ ├── BlazeGraphFactory.java
│ │ └── BlazeGraphReadOnly.java
│ │ ├── internal
│ │ ├── BlazeSailListener.java
│ │ ├── ListIndexExtension.java
│ │ ├── Tinkerpop3CoreVocab_v10.java
│ │ ├── Tinkerpop3ExtensionFactory.java
│ │ └── Tinkerpop3InlineURIFactory.java
│ │ ├── listener
│ │ ├── BlazeGraphAtom.java
│ │ ├── BlazeGraphEdit.java
│ │ └── BlazeGraphListener.java
│ │ ├── structure
│ │ ├── AbstractBlazeElement.java
│ │ ├── BlazeBindingSet.java
│ │ ├── BlazeEdge.java
│ │ ├── BlazeElement.java
│ │ ├── BlazeGraph.java
│ │ ├── BlazeGraphFeatures.java
│ │ ├── BlazeProperty.java
│ │ ├── BlazeReifiedElement.java
│ │ ├── BlazeValueFactory.java
│ │ ├── BlazeVertex.java
│ │ ├── BlazeVertexProperty.java
│ │ ├── EmptyBlazeProperty.java
│ │ ├── EmptyBlazeVertexProperty.java
│ │ └── SparqlGenerator.java
│ │ └── util
│ │ ├── CloseableIterator.java
│ │ ├── Code.java
│ │ ├── LambdaLogger.java
│ │ ├── Lambdas.java
│ │ ├── Memoizer.java
│ │ └── Streams.java
└── resources
│ └── META-INF
│ └── services
│ └── org.apache.tinkerpop.gremlin.groovy.plugin.GremlinPlugin
└── test
├── java
└── com
│ └── blazegraph
│ └── gremlin
│ └── structure
│ ├── BlazeGraphStructureStandardTest.java
│ ├── EmbeddedBlazeGraphProvider.java
│ ├── SampleCode.java
│ ├── StructureStandardSuite.java
│ ├── TestBasicOperations.java
│ ├── TestBlazeGraph.java
│ ├── TestBulkLoad.java
│ ├── TestHistory.java
│ ├── TestListeners.java
│ ├── TestRepositoryProvider.java
│ └── TestSearch.java
└── resources
└── log4j.properties
/.gitignore:
--------------------------------------------------------------------------------
1 | *.class
2 |
3 | # Mobile Tools for Java (J2ME)
4 | .mtj.tmp/
5 |
6 | # Package Files #
7 | *.jar
8 | *.war
9 | *.ear
10 |
11 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
12 | hs_err_pid*
13 |
14 | .classpath
15 | .project
16 | .settings/
17 | target/
18 | file:/
19 |
--------------------------------------------------------------------------------
/RELEASE.md:
--------------------------------------------------------------------------------
1 | ##Javadocs
2 | [Javadocs](https://blazegraph.github.io/BlazegraphBasedTPFServer/apidocs/)
3 |
4 | ##Building a release
5 |
6 | * Make sure the pom is at the latest version-SNAPSHOT, i.e. 1.0.0-SNAPSHOT
7 | * Setup your environment for Sonatype [See here](http://central.sonatype.org/pages/apache-maven.html#other-prerequisites).
8 | * Make sure to set the blazegraph version to the latest release in Maven Central.
9 | * Add and commit all changes.
10 | * `mvn -Pmaven-central release:clean release:prepare -Darguments="-DskipTests"` [See here](http://central.sonatype.org/pages/apache-maven.html#performing-a-release-deployment-with-the-maven-release-plugin). You will be prompted to enter the next version number, which should be in the form X.Y.X, i.e. 0.1.1. It's OK to accept the defaults.
11 | * `mvn -Pmaven-central release:perform -Darguments="-DskipTests"` [See here](http://central.sonatype.org/pages/apache-maven.html#performing-a-release-deployment-with-the-maven-release-plugin).
12 | * Checkout the release tag, `git checkout blazegraph-gremlin-1.0.0`, and publish the javadocs: `./scripts/publishDocs.sh`.
13 | * Reverse merge into master and commit the changes: `git checkout master`, `git merge blazegraph-gremlin-1.0.0`; `git push origin master`
14 | * Push the release branch and tag to https://github.com/blazegraph/tinkerpop3.
15 | * Got to [Github](https://github.com/blazegraph/tinkerpop3/releases) and update the release tag.
16 |
17 |
--------------------------------------------------------------------------------
/crew.rdf:
--------------------------------------------------------------------------------
1 | blaze:tinkergraph rdf:type blaze:software ;
2 | blaze:name "tinkergraph" .
3 |
4 | blaze:gremlin rdf:type blaze:software ;
5 | blaze:name "gremlin" ;
6 | blaze:48f63 blaze:tinkergraph .
7 |
8 | <> rdf:type blaze:traverses .
9 |
10 | blaze:daniel rdf:type blaze:person ;
11 | blaze:name "daniel" ;
12 | blaze:81056 blaze:tinkergraph ;
13 | blaze:e09ac blaze:gremlin ;
14 | blaze:location "spremberg" ;
15 | blaze:location "kaiserslautern" ;
16 | blaze:location "aachen" .
17 |
18 | <> rdf:type blaze:uses ;
19 | blaze:skill "3"^^xsd:int .
20 | <> rdf:type blaze:uses ;
21 | blaze:skill "5"^^xsd:int .
22 | <> blaze:startTime "1982"^^xsd:int ;
23 | blaze:endTime "2005"^^xsd:int .
24 | <> blaze:startTime "2005"^^xsd:int ;
25 | blaze:endTime "2009"^^xsd:int .
26 | <> blaze:startTime "2009"^^xsd:int .
27 |
28 | blaze:marko rdf:type blaze:person ;
29 | blaze:name "marko" ;
30 | blaze:42af2 blaze:gremlin ;
31 | blaze:4edec blaze:gremlin ;
32 | blaze:61d50 blaze:tinkergraph ;
33 | blaze:68c12 blaze:tinkergraph ;
34 | blaze:location "san diego" ;
35 | blaze:location "santa cruz" ;
36 | blaze:location "brussels" ;
37 | blaze:location "santa fe" .
38 |
39 | <> rdf:type blaze:develops ;
40 | blaze:since "2009"^^xsd:int .
41 | <> rdf:type blaze:uses ;
42 | blaze:skill "4"^^xsd:int .
43 | <> rdf:type blaze:develops ;
44 | blaze:since "2010"^^xsd:int .
45 | <> rdf:type blaze:uses ;
46 | blaze:skill "5"^^xsd:int .
47 | <> blaze:startTime "1997"^^xsd:int ;
48 | blaze:endTime "2001"^^xsd:int .
49 | <> blaze:startTime "2001"^^xsd:int ;
50 | blaze:endTime "2004"^^xsd:int .
51 | <> blaze:startTime "2004"^^xsd:int ;
52 | blaze:endTime "2005"^^xsd:int .
53 | <> blaze:startTime "2005"^^xsd:int .
54 |
55 | blaze:stephen rdf:type blaze:person ;
56 | blaze:name "stephen" ;
57 | blaze:15869 blaze:tinkergraph ;
58 | blaze:1e9c3 blaze:gremlin ;
59 | blaze:bf48d blaze:tinkergraph ;
60 | blaze:bff3c blaze:gremlin ;
61 | blaze:location "centreville" ;
62 | blaze:location "dulles" ;
63 | blaze:location "purcellville" .
64 |
65 | <> rdf:type blaze:develops ;
66 | blaze:since "2011"^^xsd:int .
67 | <> rdf:type blaze:develops ;
68 | blaze:since "2010"^^xsd:int .
69 | <> rdf:type blaze:uses ;
70 | blaze:skill "4"^^xsd:int .
71 | <> rdf:type blaze:uses ;
72 | blaze:skill "5"^^xsd:int .
73 | <> blaze:startTime "1990"^^xsd:int ;
74 | blaze:endTime "2000"^^xsd:int .
75 | <> blaze:startTime "2000"^^xsd:int ;
76 | blaze:endTime "2006"^^xsd:int .
77 | <> blaze:startTime "2006"^^xsd:int .
78 |
79 | blaze:matthias rdf:type blaze:person ;
80 | blaze:name "matthias" ;
81 | blaze:7373e blaze:gremlin ;
82 | blaze:e5a5d blaze:gremlin ;
83 | blaze:ef89a blaze:tinkergraph ;
84 | blaze:location "bremen" ;
85 | blaze:location "baltimore" ;
86 | blaze:location "oakland" ;
87 | blaze:location "seattle" .
88 |
89 | <> rdf:type blaze:develops ;
90 | blaze:since "2012"^^xsd:int .
91 | <> rdf:type blaze:uses ;
92 | blaze:skill "3"^^xsd:int .
93 | <> rdf:type blaze:uses ;
94 | blaze:skill "3"^^xsd:int .
95 | <> blaze:startTime "2004"^^xsd:int ;
96 | blaze:endTime "2007"^^xsd:int .
97 | <> blaze:startTime "2007"^^xsd:int ;
98 | blaze:endTime "2011"^^xsd:int .
99 | <> blaze:startTime "2011"^^xsd:int ;
100 | blaze:endTime "2014"^^xsd:int .
101 | <> blaze:startTime "2014"^^xsd:int .
--------------------------------------------------------------------------------
/images/blazegraph-gremlin.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/blazegraph/tinkerpop3/4b6feff7ecceed453a2f7158a394c35a3ad3ba51/images/blazegraph-gremlin.png
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
26 |
27 | 4.0.0
28 | com.blazegraph
29 | blazegraph-gremlin
30 | jar
31 | 1.0.1-SNAPSHOT
32 | blazegraph-gremlin
33 | Welcome to the Blazegraph/TinkerPop3 project. The TP3 implementation has some significant differences from the TP2 version. The data model has been changed to use RDF*, an RDF reification framework described here: https://wiki.blazegraph.com/wiki/index.php/Reification_Done_Right.
34 |
35 | The concept behind blazegraph-gremlin is that property graph (PG) data can be loaded and accessed via the TinkerPop3 API, but underneath the hood the data will be stored as RDF using the PG data model described in this document. Once PG data has been loaded you can interact with it just like you would interact with ordinary RDF - you can run SPARQL queries or interact with the data via the SAIL API. It just works. The PG data model is also customizable via a round-tripping interface called the BlazeValueFactory, also described in detail in this document.
36 |
37 | https://www.blazegraph.com/
38 |
39 | SYSTAP, LLC DBA Blazegraph
40 | http://www.systap.com/
41 |
42 | 2015
43 |
44 |
45 | GNU General Public License Version 2 (GPLv2)
46 | http://www.gnu.org/licenses/gpl-2.0.html
47 |
48 |
49 |
50 |
51 | Developer
52 | https://lists.sourceforge.net/lists/listinfo/bigdata-developers
53 | https://lists.sourceforge.net/lists/listinfo/bigdata-developers
54 | https://sourceforge.net/p/bigdata/mailman/bigdata-developers/
55 |
56 |
57 |
58 | JIRA
59 | https://jira.blazegraph.com/
60 |
61 |
62 | scm:git:https://github.com/blazegraph/tinkerpop3.git
63 | scm:git:git@github.com:blazegraph/tinkerpop3.git
64 | https://github.com/blazegraph/tinkerpop3.git
65 |
66 |
67 | UTF-8
68 | 9.2.3.v20140905
69 | 3.1.0-incubating
70 | 2.0.0
71 | 1.3.1
72 | 3.4.6
73 |
74 |
75 |
76 | Mike Personick
77 | mike@blazegraph.com
78 | SYSTAP, LLC DBA Blazegraph DBA Blazegraph
79 | http://www.blazegraph.com
80 |
81 |
82 | Bryan Thompson
83 | bryan@blazegraph.com
84 | SYSTAP, LLC DBA Blazegraph DBA Blazegraph
85 | http://www.blazegraph.com
86 |
87 |
88 | Brad Bebee
89 | beebs@blazegraph.com
90 | SYSTAP, LLC DBA Blazegraph DBA Blazegraph
91 | http://www.blazegraph.com
92 |
93 |
94 |
95 |
96 | maven-central
97 |
101 |
102 |
103 |
104 | org.apache.maven.plugins
105 | maven-gpg-plugin
106 | 1.6
107 |
108 |
109 | sign-artifacts
110 | verify
111 |
112 | sign
113 |
114 |
115 | ${gpg.keyname}
116 | ${gpg.keyname}
117 |
118 |
119 |
120 |
121 |
122 | org.sonatype.plugins
123 | nexus-staging-maven-plugin
124 | 1.6.3
125 | true
126 |
127 | ossrh
128 | https://oss.sonatype.org/
129 | true
130 |
131 |
132 |
133 | org.apache.maven.plugins
134 | maven-source-plugin
135 | 2.2.1
136 |
137 |
138 | attach-sources
139 |
140 | jar-no-fork
141 |
142 |
143 |
144 |
145 |
146 | org.apache.maven.plugins
147 | maven-javadoc-plugin
148 | 2.9.1
149 |
150 |
151 | attach-javadocs
152 |
153 | jar
154 |
155 |
156 |
157 |
158 |
159 |
160 | org.apache.maven.plugins
161 | maven-release-plugin
162 | 2.5
163 |
164 | true
165 | false
166 | maven-central
167 | deploy
168 |
169 |
170 |
171 |
172 |
173 |
174 | ossrh
175 | https://oss.sonatype.org/content/repositories/snapshots
176 |
177 |
178 |
179 |
180 | local-deploy
181 |
182 |
183 | bigdata.snapshots
184 | bigdata(R) snapshots
185 | scpexe://www.systap.com/srv/www/htdocs/systap.com/maven/snapshots
186 | true
187 |
188 |
189 |
190 |
191 | bigdata.releases
192 | http://www.systap.com/maven/releases/
193 |
194 |
195 | bigdata.snapshots
196 | http://www.systap.com/maven/snapshots/
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 | org.apache.maven.plugins
205 | maven-compiler-plugin
206 | 3.1
207 |
208 | 1.8
209 | 1.8
210 |
211 |
212 |
213 | org.apache.maven.plugins
214 | maven-deploy-plugin
215 | 2.8.1
216 |
217 |
218 |
219 |
220 | org.apache.maven.wagon
221 | wagon-ssh-external
222 | 1.0-beta-6
223 |
224 |
225 |
226 |
227 |
228 |
229 | apache.snapshots
230 | http://repository.apache.org/snapshots/
231 |
232 |
233 |
234 | maven.snapshots
235 | https://oss.sonatype.org/content/repositories/snapshots/
236 |
237 |
238 |
239 |
242 |
243 | org.hamcrest
244 | hamcrest-core
245 | 1.3
246 | test
247 |
248 |
249 | org.hamcrest
250 | hamcrest-library
251 | 1.3
252 | test
253 |
254 |
255 |
256 | org.apache.tinkerpop
257 | gremlin-core
258 | ${tp3.version}
259 |
260 |
261 | org.apache.tinkerpop
262 | gremlin-groovy
263 | ${tp3.version}
264 |
265 |
266 | org.apache.tinkerpop
267 | tinkergraph-gremlin
268 | ${tp3.version}
269 |
270 |
271 |
272 | org.apache.tinkerpop
273 | gremlin-test
274 | ${tp3.version}
275 | test
276 |
277 |
278 | org.hamcrest
279 | hamcrest-all
280 |
281 |
282 |
283 |
284 | org.apache.tinkerpop
285 | gremlin-groovy-test
286 | ${tp3.version}
287 | test
288 |
289 |
290 |
291 | com.blazegraph
292 | bigdata-core
293 | ${blaze.version}
294 |
295 |
296 | junit
297 | junit
298 | 4.13.1
299 | test
300 |
301 |
302 | org.hamcrest
303 | hamcrest-core
304 |
305 |
306 |
307 |
308 |
309 |
--------------------------------------------------------------------------------
/scripts/publishDocs.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #Script to publish javadoc to https://blazegraph.github.com/
3 | BASE_DIR=`dirname $0`
4 | PARENT_POM="${BASE_DIR}/../pom.xml"
5 | DEST_DIR=tinkerpop3/apidocs/
6 | #You must have cloned https://github.com/blazegraph/blazegraph.github.io into a directory at the same level as where tinkerpop3 is checked out
7 | GITHUB_PAGES="${BASE_DIR}/../../blazegraph.github.io"
8 |
9 | if [ ! -d "${GITHUB_PAGES}" ] ; then
10 |
11 | echo "${GITHUB_PAGES} does not exist."
12 | echo "You must have cloned https://github.com/blazegraph/blazegraph.github.io into a directory at the same level as where bigdata is checked out."
13 | exit 1
14 |
15 | fi
16 |
17 | mvn -f "${PARENT_POM}" javadoc:javadoc
18 |
19 | echo "Javadoc is located in ${BASE_DIR}/../target/site/apidocs/"
20 |
21 | pushd `pwd`
22 | mkdir -p "${GITHUB_PAGES}/${DEST_DIR}"
23 | echo cp -rf "${BASE_DIR}"/../target/site/apidocs/* "${GITHUB_PAGES}/${DEST_DIR}"
24 | cp -rf "${BASE_DIR}"/../target/site/apidocs/* "${GITHUB_PAGES}/${DEST_DIR}"
25 | cd $"${GITHUB_PAGES}"
26 | git pull
27 | git add --all
28 | git commit -m "Update for Blazegraph $DEST_DIR Javadocs"
29 | git push origin master
30 |
31 | popd
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/src/main/java/com/blazegraph/gremlin/console/BlazeGremlinPlugin.java:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright (C) SYSTAP, LLC DBA Blazegraph 2006-2016. All rights reserved.
3 |
4 | Contact:
5 | SYSTAP, LLC DBA Blazegraph
6 | 2501 Calvert ST NW #106
7 | Washington, DC 20008
8 | licenses@blazegraph.com
9 |
10 | This program is free software; you can redistribute it and/or modify
11 | it under the terms of the GNU General Public License as published by
12 | the Free Software Foundation; version 2 of the License.
13 |
14 | This program is distributed in the hope that it will be useful,
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | GNU General Public License for more details.
18 |
19 | You should have received a copy of the GNU General Public License
20 | along with this program; if not, write to the Free Software
21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 | */
23 | package com.blazegraph.gremlin.console;
24 |
25 | import java.util.HashSet;
26 | import java.util.Set;
27 |
28 | import org.apache.tinkerpop.gremlin.groovy.plugin.AbstractGremlinPlugin;
29 | import org.apache.tinkerpop.gremlin.groovy.plugin.IllegalEnvironmentException;
30 | import org.apache.tinkerpop.gremlin.groovy.plugin.PluginAcceptor;
31 | import org.apache.tinkerpop.gremlin.groovy.plugin.PluginInitializationException;
32 |
33 | /**
34 | * Plugin for gremlin console.
35 | *
36 | * @author mikepersonick
37 | */
38 | public final class BlazeGremlinPlugin extends AbstractGremlinPlugin {
39 |
40 | private static final Set IMPORTS = new HashSet() {{
41 | add(IMPORT_SPACE + "com.blazegraph.gremlin.embedded" + DOT_STAR);
42 | add(IMPORT_SPACE + "com.blazegraph.gremlin.listener" + DOT_STAR);
43 | add(IMPORT_SPACE + "com.blazegraph.gremlin.structure" + DOT_STAR);
44 | add(IMPORT_SPACE + "com.blazegraph.gremlin.util" + DOT_STAR);
45 | }};
46 |
47 | @Override
48 | public String getName() {
49 | return "tinkerpop.blazegraph";
50 | }
51 |
52 | @Override
53 | public void pluginTo(final PluginAcceptor pluginAcceptor)
54 | throws PluginInitializationException, IllegalEnvironmentException {
55 | pluginAcceptor.addImports(IMPORTS);
56 | }
57 |
58 | @Override
59 | public void afterPluginTo(final PluginAcceptor pluginAcceptor)
60 | throws IllegalEnvironmentException, PluginInitializationException {
61 | }
62 |
63 | @Override
64 | public boolean requireRestart() {
65 | return true;
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/com/blazegraph/gremlin/embedded/BasicRepositoryProvider.java:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright (C) SYSTAP, LLC DBA Blazegraph 2006-2016. All rights reserved.
3 |
4 | Contact:
5 | SYSTAP, LLC DBA Blazegraph
6 | 2501 Calvert ST NW #106
7 | Washington, DC 20008
8 | licenses@blazegraph.com
9 |
10 | This program is free software; you can redistribute it and/or modify
11 | it under the terms of the GNU General Public License as published by
12 | the Free Software Foundation; version 2 of the License.
13 |
14 | This program is distributed in the hope that it will be useful,
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | GNU General Public License for more details.
18 |
19 | You should have received a copy of the GNU General Public License
20 | along with this program; if not, write to the Free Software
21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 | */
23 | package com.blazegraph.gremlin.embedded;
24 |
25 | import java.util.Properties;
26 |
27 | import com.bigdata.journal.BufferMode;
28 | import com.bigdata.journal.Journal;
29 | import com.bigdata.rdf.axioms.NoAxioms;
30 | import com.bigdata.rdf.sail.BigdataSail;
31 | import com.bigdata.rdf.sail.BigdataSailRepository;
32 | import com.bigdata.rdf.sail.RDRHistory;
33 | import com.bigdata.rdf.store.AbstractTripleStore;
34 | import com.blazegraph.gremlin.internal.Tinkerpop3CoreVocab_v10;
35 | import com.blazegraph.gremlin.internal.Tinkerpop3ExtensionFactory;
36 | import com.blazegraph.gremlin.internal.Tinkerpop3InlineURIFactory;
37 | import com.blazegraph.gremlin.util.Code;
38 |
39 | /**
40 | * This utilty class is provided as a convenience for getting started with
41 | * Blazegraph. You will eventually want to create your own custom configuration
42 | * specific to your application. Visit our online
43 | * user guide for more information
44 | * on configuration and performance optimization, or contact us for more direct
45 | * developer support.
46 | *
47 | * @author mikepersonick
48 | */
49 | public class BasicRepositoryProvider {
50 |
51 | /**
52 | * Open and initialize a BigdataSailRepository using the supplied journal
53 | * file location. If the file does not exist or is empty, the repository
54 | * will be created using the default property configuration below.
55 | *
56 | * @param journalFile
57 | * absolute path of the journal file
58 | * @return
59 | * an open and initialized repository
60 | */
61 | public static BigdataSailRepository open(final String journalFile) {
62 | return open(getProperties(journalFile));
63 | }
64 |
65 | /**
66 | * Open and initialize a BigdataSailRepository using the supplied config
67 | * properties. You must specify a journal file in the properties.
68 | *
69 | * @param props
70 | * config properties
71 | * @return
72 | * an open and initialized repository
73 | */
74 | public static BigdataSailRepository open(final Properties props) {
75 | if (props.getProperty(Journal.Options.FILE) == null) {
76 | throw new IllegalArgumentException();
77 | }
78 |
79 | final BigdataSail sail = new BigdataSail(props);
80 | final BigdataSailRepository repo = new BigdataSailRepository(sail);
81 | Code.wrapThrow(() -> repo.initialize());
82 | return repo;
83 | }
84 |
85 | /**
86 | * Grab the default properties and set the location of the journal file.
87 | *
88 | * @param journalFile
89 | * absolute path of the journal file
90 | * @return
91 | * config properties
92 | */
93 | public static Properties getProperties(final String journalFile) {
94 |
95 | final Properties props = getDefaultProperties();
96 |
97 | // journal file
98 | props.setProperty(Journal.Options.FILE, journalFile);
99 |
100 | return props;
101 |
102 | }
103 |
104 | /**
105 | * Some reasonable defaults to get us up and running. Visit our online
106 | * user guide for more information
107 | * on configuration and performance optimization, or contact us for more direct
108 | * developer support.
109 | *
110 | * @return
111 | * config properties
112 | */
113 | public static Properties getDefaultProperties() {
114 |
115 | final Properties props = new Properties();
116 |
117 | /*
118 | * Use the RW store for persistence.
119 | */
120 | props.setProperty(Journal.Options.BUFFER_MODE, BufferMode.DiskRW.toString());
121 |
122 | /*
123 | * Turn off all RDFS/OWL inference.
124 | */
125 | props.setProperty(BigdataSail.Options.AXIOMS_CLASS, NoAxioms.class.getName());
126 | props.setProperty(BigdataSail.Options.TRUTH_MAINTENANCE, "false");
127 | props.setProperty(BigdataSail.Options.JUSTIFY, "false");
128 |
129 | /*
130 | * Turn on the text index.
131 | */
132 | props.setProperty(BigdataSail.Options.TEXT_INDEX, "true");
133 |
134 | /*
135 | * Turn off quads and turn on statement identifiers.
136 | */
137 | props.setProperty(BigdataSail.Options.QUADS, "false");
138 | props.setProperty(BigdataSail.Options.STATEMENT_IDENTIFIERS, "true");
139 |
140 | /*
141 | * We will manage the grounding of sids manually.
142 | */
143 | props.setProperty(AbstractTripleStore.Options.COMPUTE_CLOSURE_FOR_SIDS, "false");
144 |
145 | /*
146 | * Inline string literals up to 10 characters (avoids dictionary indices
147 | * for short strings).
148 | */
149 | props.setProperty(AbstractTripleStore.Options.INLINE_TEXT_LITERALS, "true");
150 | props.setProperty(AbstractTripleStore.Options.MAX_INLINE_TEXT_LENGTH, "10");
151 |
152 | /*
153 | * Custom core Tinkerpop3 vocabulary. Applications will probably want
154 | * to extend this.
155 | */
156 | props.setProperty(AbstractTripleStore.Options.VOCABULARY_CLASS,
157 | Tinkerpop3CoreVocab_v10.class.getName());
158 |
159 | /*
160 | * Use a multi-purpose inline URI factory that will auto-inline URIs
161 | * in the namespace.
162 | */
163 | props.setProperty(AbstractTripleStore.Options.INLINE_URI_FACTORY_CLASS,
164 | Tinkerpop3InlineURIFactory.class.getName());
165 |
166 | /*
167 | * Custom Tinkerpop3 extension factory for the ListIndexExtension IV,
168 | * used for Cardinality.list.
169 | */
170 | props.setProperty(AbstractTripleStore.Options.EXTENSION_FACTORY_CLASS,
171 | Tinkerpop3ExtensionFactory.class.getName());
172 |
173 | /*
174 | * Turn on history. You can turn history off by not setting this
175 | * property.
176 | */
177 | props.setProperty(AbstractTripleStore.Options.RDR_HISTORY_CLASS,
178 | RDRHistory.class.getName());
179 |
180 | return props;
181 |
182 | }
183 |
184 | }
185 |
--------------------------------------------------------------------------------
/src/main/java/com/blazegraph/gremlin/embedded/BlazeGraphFactory.java:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright (C) SYSTAP, LLC DBA Blazegraph 2006-2016. All rights reserved.
3 |
4 | Contact:
5 | SYSTAP, LLC DBA Blazegraph
6 | 2501 Calvert ST NW #106
7 | Washington, DC 20008
8 | licenses@blazegraph.com
9 |
10 | This program is free software; you can redistribute it and/or modify
11 | it under the terms of the GNU General Public License as published by
12 | the Free Software Foundation; version 2 of the License.
13 |
14 | This program is distributed in the hope that it will be useful,
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | GNU General Public License for more details.
18 |
19 | You should have received a copy of the GNU General Public License
20 | along with this program; if not, write to the Free Software
21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 | */
23 | package com.blazegraph.gremlin.embedded;
24 |
25 | import com.bigdata.rdf.sail.BigdataSailRepository;
26 |
27 | /**
28 | * Helper class for the gremlin console.
29 | *
30 | * @author mikepersonick
31 | */
32 | public class BlazeGraphFactory {
33 |
34 | public static final BlazeGraphEmbedded open(final String journal) {
35 | final BigdataSailRepository repo = BasicRepositoryProvider.open(journal);
36 | return BlazeGraphEmbedded.open(repo);
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/blazegraph/gremlin/embedded/BlazeGraphReadOnly.java:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright (C) SYSTAP, LLC DBA Blazegraph 2006-2016. All rights reserved.
3 |
4 | Contact:
5 | SYSTAP, LLC DBA Blazegraph
6 | 2501 Calvert ST NW #106
7 | Washington, DC 20008
8 | licenses@blazegraph.com
9 |
10 | This program is free software; you can redistribute it and/or modify
11 | it under the terms of the GNU General Public License as published by
12 | the Free Software Foundation; version 2 of the License.
13 |
14 | This program is distributed in the hope that it will be useful,
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | GNU General Public License for more details.
18 |
19 | You should have received a copy of the GNU General Public License
20 | along with this program; if not, write to the Free Software
21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 | */
23 | package com.blazegraph.gremlin.embedded;
24 |
25 | import org.apache.commons.configuration.Configuration;
26 |
27 | import com.bigdata.rdf.sail.BigdataSailRepository;
28 | import com.bigdata.rdf.sail.BigdataSailRepositoryConnection;
29 | import com.blazegraph.gremlin.util.Code;
30 |
31 | /**
32 | * BlazeGraphReadOnly extends BlazeGraphEmbedded and thus offers all the same
33 | * operations, except write operations will not be permitted
34 | * (BlazeGraphReadOnly.tx() will throw an exception). You can open as many
35 | * read-only views as you like, but we recommend you use a connection pool so as
36 | * not to overtax system resources. Applications should be written with the
37 | * one-writer many-readers paradigm front of mind.
38 | *
39 | * Important: Make sure to close the read-only view as soon as you are done with
40 | * it.
41 | *
42 | *
43 | * @author mikepersonick
44 | */
45 | public class BlazeGraphReadOnly extends BlazeGraphEmbedded {
46 |
47 | /**
48 | * Unlike the unisolated version (superclass), the read-only version
49 | * holds the read connection open for the duration of its lifespan, until
50 | * close() is called.
51 | */
52 | private final BigdataSailRepositoryConnection cxn;
53 |
54 | /**
55 | * Never publicly instantiated - only by another {@link BlazeGraphEmbedded}
56 | * instance.
57 | */
58 | BlazeGraphReadOnly(final BigdataSailRepository repo,
59 | final BigdataSailRepositoryConnection cxn,
60 | final Configuration config) {
61 | super(repo, config);
62 |
63 | this.cxn = cxn;
64 | }
65 |
66 | /**
67 | * Write operations not supported by this class.
68 | */
69 | @Override
70 | public BlazeTransaction tx() {
71 | throw new UnsupportedOperationException("Transactions not allowed on read-only view");
72 | }
73 |
74 | /**
75 | * Return the read-only SAIL connection.
76 | */
77 | @Override
78 | public BigdataSailRepositoryConnection cxn() {
79 | if (closed) throw new IllegalStateException();
80 |
81 | return cxn;
82 | }
83 |
84 | /**
85 | * Close the read-only SAIL connection.
86 | */
87 | @Override
88 | public synchronized void close() {
89 | if (closed)
90 | return;
91 |
92 | Code.wrapThrow(() -> cxn.close());
93 | closed = true;
94 | }
95 |
96 |
97 | }
98 |
--------------------------------------------------------------------------------
/src/main/java/com/blazegraph/gremlin/internal/BlazeSailListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright (C) SYSTAP, LLC DBA Blazegraph 2006-2016. All rights reserved.
3 |
4 | Contact:
5 | SYSTAP, LLC DBA Blazegraph
6 | 2501 Calvert ST NW #106
7 | Washington, DC 20008
8 | licenses@blazegraph.com
9 |
10 | This program is free software; you can redistribute it and/or modify
11 | it under the terms of the GNU General Public License as published by
12 | the Free Software Foundation; version 2 of the License.
13 |
14 | This program is distributed in the hope that it will be useful,
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | GNU General Public License for more details.
18 |
19 | You should have received a copy of the GNU General Public License
20 | along with this program; if not, write to the Free Software
21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 | */
23 | package com.blazegraph.gremlin.internal;
24 |
25 | import com.bigdata.rdf.changesets.IChangeLog;
26 | import com.bigdata.rdf.changesets.IChangeRecord;
27 |
28 | /**
29 | * Turn IChangeLog (Java 7) into a Java 8 functional interface.
30 | *
31 | * @author mikepersonick
32 | */
33 | @FunctionalInterface
34 | public interface BlazeSailListener extends IChangeLog {
35 |
36 | @Override
37 | void changeEvent(IChangeRecord changeRecord);
38 |
39 | /**
40 | * Default no-op.
41 | */
42 | @Override
43 | default void transactionAborted() {
44 | }
45 |
46 | /**
47 | * Default no-op.
48 | */
49 | @Override
50 | default void transactionBegin() {
51 | }
52 |
53 | /**
54 | * Default no-op.
55 | */
56 | @Override
57 | default void transactionCommited(long commitTime) {
58 | }
59 |
60 | /**
61 | * Default no-op.
62 | */
63 | @Override
64 | default void transactionPrepare() {
65 | }
66 |
67 | /**
68 | * Default no-op.
69 | */
70 | @Override
71 | default void close() {
72 | }
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/src/main/java/com/blazegraph/gremlin/internal/ListIndexExtension.java:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright (C) SYSTAP, LLC DBA Blazegraph 2006-2016. All rights reserved.
3 |
4 | Contact:
5 | SYSTAP, LLC DBA Blazegraph
6 | 2501 Calvert ST NW #106
7 | Washington, DC 20008
8 | licenses@blazegraph.com
9 |
10 | This program is free software; you can redistribute it and/or modify
11 | it under the terms of the GNU General Public License as published by
12 | the Free Software Foundation; version 2 of the License.
13 |
14 | This program is distributed in the hope that it will be useful,
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | GNU General Public License for more details.
18 |
19 | You should have received a copy of the GNU General Public License
20 | along with this program; if not, write to the Free Software
21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 | */
23 | package com.blazegraph.gremlin.internal;
24 |
25 | import java.util.Collections;
26 | import java.util.Set;
27 |
28 | import org.openrdf.model.Literal;
29 | import org.openrdf.model.URI;
30 | import org.openrdf.model.Value;
31 | import org.openrdf.model.impl.URIImpl;
32 |
33 | import com.bigdata.rdf.internal.IDatatypeURIResolver;
34 | import com.bigdata.rdf.internal.IExtension;
35 | import com.bigdata.rdf.internal.impl.literal.AbstractLiteralIV;
36 | import com.bigdata.rdf.internal.impl.literal.LiteralExtensionIV;
37 | import com.bigdata.rdf.internal.impl.literal.PackedLongIV;
38 | import com.bigdata.rdf.model.BigdataURI;
39 | import com.bigdata.rdf.model.BigdataValue;
40 | import com.bigdata.rdf.model.BigdataValueFactory;
41 |
42 | /**
43 | * Effective, packed representation of property graph list index typed as
44 | * {@code }
45 | * Builds on the {@link PackedLongIV} datatype for representing timestamps,
46 | * thus supporting the range [0;72057594037927935L]. Used for Cardinality.list
47 | * vertex properties.
48 | */
49 | @SuppressWarnings("rawtypes")
50 | public class ListIndexExtension implements IExtension {
51 |
52 | private final BigdataURI datatype;
53 |
54 | public static final URI DATATYPE =
55 | new URIImpl("http://www.blazegraph.com/rdf/datatype#listIndex");
56 |
57 |
58 | public ListIndexExtension(final IDatatypeURIResolver resolver) {
59 | datatype = resolver.resolve(DATATYPE);
60 | }
61 |
62 | public Set getDatatypes() {
63 | return Collections.singleton(datatype);
64 | }
65 |
66 | /**
67 | * Convert the supplied value into an internal representation as
68 | * PackedLongIV.
69 | */
70 | @SuppressWarnings("unchecked")
71 | public LiteralExtensionIV createIV(final Value value) {
72 |
73 | if (value instanceof Literal == false)
74 | throw new IllegalArgumentException();
75 |
76 | final Literal lit = (Literal) value;
77 |
78 | final AbstractLiteralIV delegate =
79 | new PackedLongIV(Long.parseLong(lit.getLabel()));
80 | return new LiteralExtensionIV(delegate, datatype.getIV());
81 |
82 | }
83 |
84 | @SuppressWarnings("unchecked")
85 | public V asValue(final LiteralExtensionIV iv, final BigdataValueFactory vf) {
86 |
87 | AbstractLiteralIV delegate = iv.getDelegate();
88 | if (delegate == null || !(delegate instanceof PackedLongIV)) {
89 | throw new IllegalArgumentException();
90 | }
91 |
92 | final PackedLongIV pIv = (PackedLongIV) delegate;
93 | return (V) vf.createLiteral(
94 | String.valueOf(pIv.getInlineValue()), DATATYPE);
95 |
96 | }
97 |
98 | }
99 |
--------------------------------------------------------------------------------
/src/main/java/com/blazegraph/gremlin/internal/Tinkerpop3CoreVocab_v10.java:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright (C) SYSTAP, LLC DBA Blazegraph 2006-2016. All rights reserved.
3 |
4 | Contact:
5 | SYSTAP, LLC DBA Blazegraph
6 | 2501 Calvert ST NW #106
7 | Washington, DC 20008
8 | licenses@blazegraph.com
9 |
10 | This program is free software; you can redistribute it and/or modify
11 | it under the terms of the GNU General Public License as published by
12 | the Free Software Foundation; version 2 of the License.
13 |
14 | This program is distributed in the hope that it will be useful,
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | GNU General Public License for more details.
18 |
19 | You should have received a copy of the GNU General Public License
20 | along with this program; if not, write to the Free Software
21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 | */
23 | package com.blazegraph.gremlin.internal;
24 |
25 | import com.bigdata.rdf.store.AbstractTripleStore;
26 | import com.bigdata.rdf.vocab.BaseVocabularyDecl;
27 | import com.bigdata.rdf.vocab.core.BigdataCoreVocabulary_v20151210;
28 | import com.blazegraph.gremlin.structure.BlazeValueFactory;
29 |
30 | /**
31 | * Custom core Tinkerpop3 vocabulary. Applications should extend this
32 | * vocabulary to include known constants that can be inlined into the
33 | * vocabulary, avoiding the dictionary indices for higher performance. A good
34 | * place to start for identifying these constants are known property keys in
35 | * the application space.
36 | */
37 | public class Tinkerpop3CoreVocab_v10 extends BigdataCoreVocabulary_v20151210 {
38 |
39 | /**
40 | * Tinkerpop3 URIs to be inlined.
41 | */
42 | private static final Object[] uris = new Object[]{
43 | BlazeValueFactory.Defaults.NAMESPACE,
44 | ListIndexExtension.DATATYPE,
45 | };
46 |
47 | /**
48 | * De-serialization ctor.
49 | */
50 | public Tinkerpop3CoreVocab_v10() {
51 | super();
52 | }
53 |
54 | /**
55 | * Used by {@link AbstractTripleStore#create()}.
56 | *
57 | * @param namespace
58 | * The namespace of the KB instance.
59 | */
60 | public Tinkerpop3CoreVocab_v10(final String namespace) {
61 | super(namespace);
62 | }
63 |
64 | @Override
65 | protected void addValues() {
66 | super.addValues();
67 | addDecl(new BaseVocabularyDecl(uris));
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/src/main/java/com/blazegraph/gremlin/internal/Tinkerpop3ExtensionFactory.java:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright (C) SYSTAP, LLC DBA Blazegraph 2006-2016. All rights reserved.
3 |
4 | Contact:
5 | SYSTAP, LLC DBA Blazegraph
6 | 2501 Calvert ST NW #106
7 | Washington, DC 20008
8 | licenses@blazegraph.com
9 |
10 | This program is free software; you can redistribute it and/or modify
11 | it under the terms of the GNU General Public License as published by
12 | the Free Software Foundation; version 2 of the License.
13 |
14 | This program is distributed in the hope that it will be useful,
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | GNU General Public License for more details.
18 |
19 | You should have received a copy of the GNU General Public License
20 | along with this program; if not, write to the Free Software
21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 | */
23 | package com.blazegraph.gremlin.internal;
24 |
25 | import java.util.Collection;
26 |
27 | import com.bigdata.rdf.internal.DefaultExtensionFactory;
28 | import com.bigdata.rdf.internal.IDatatypeURIResolver;
29 | import com.bigdata.rdf.internal.IExtension;
30 | import com.bigdata.rdf.internal.ILexiconConfiguration;
31 | import com.bigdata.rdf.model.BigdataLiteral;
32 | import com.bigdata.rdf.model.BigdataValue;
33 |
34 | /**
35 | * Extension factory for Tinkerpop3. Currently the only extension in use
36 | * is the {@link ListIndexExtension} for Cardinality.list.
37 | */
38 | public class Tinkerpop3ExtensionFactory extends DefaultExtensionFactory {
39 |
40 | protected void _init(final IDatatypeURIResolver resolver,
41 | final ILexiconConfiguration lex,
42 | final Collection extensions) {
43 |
44 | /*
45 | * Add ListIndexExtension for Cardinality.list.
46 | */
47 | extensions.add(new ListIndexExtension(resolver));
48 |
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/com/blazegraph/gremlin/internal/Tinkerpop3InlineURIFactory.java:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright (C) SYSTAP, LLC DBA Blazegraph 2006-2016. All rights reserved.
3 |
4 | Contact:
5 | SYSTAP, LLC DBA Blazegraph
6 | 2501 Calvert ST NW #106
7 | Washington, DC 20008
8 | licenses@blazegraph.com
9 |
10 | This program is free software; you can redistribute it and/or modify
11 | it under the terms of the GNU General Public License as published by
12 | the Free Software Foundation; version 2 of the License.
13 |
14 | This program is distributed in the hope that it will be useful,
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | GNU General Public License for more details.
18 |
19 | You should have received a copy of the GNU General Public License
20 | along with this program; if not, write to the Free Software
21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 | */
23 | package com.blazegraph.gremlin.internal;
24 |
25 | import com.bigdata.rdf.internal.InlineURIFactory;
26 | import com.bigdata.rdf.internal.MultipurposeIDHandler;
27 | import com.blazegraph.gremlin.structure.BlazeValueFactory;
28 |
29 | /**
30 | * Use a multi-purpose inline URI factory that will auto-inline URIs
31 | * in the {@code } namespace.
32 | *
33 | * @author mikepersonick
34 | */
35 | public class Tinkerpop3InlineURIFactory extends InlineURIFactory {
36 |
37 | public Tinkerpop3InlineURIFactory() {
38 | addHandler(new MultipurposeIDHandler(BlazeValueFactory.Defaults.NAMESPACE, 10));
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/com/blazegraph/gremlin/listener/BlazeGraphAtom.java:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright (C) SYSTAP, LLC DBA Blazegraph 2006-2016. All rights reserved.
3 |
4 | Contact:
5 | SYSTAP, LLC DBA Blazegraph
6 | 2501 Calvert ST NW #106
7 | Washington, DC 20008
8 | licenses@blazegraph.com
9 |
10 | This program is free software; you can redistribute it and/or modify
11 | it under the terms of the GNU General Public License as published by
12 | the Free Software Foundation; version 2 of the License.
13 |
14 | This program is distributed in the hope that it will be useful,
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | GNU General Public License for more details.
18 |
19 | You should have received a copy of the GNU General Public License
20 | along with this program; if not, write to the Free Software
21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 | */
23 | package com.blazegraph.gremlin.listener;
24 |
25 | /**
26 | * An atomic unit of information about a property graph. Analogous to an RDF
27 | * statement- the atomic unit of information about an RDF graph. This is the
28 | * unit of graph information used by the listener and history APIs.
29 | *
30 | * @author mikepersonick
31 | */
32 | public abstract class BlazeGraphAtom {
33 |
34 | /**
35 | * All atoms refer back to an element (Vertex, Edge, or VertexProperty).
36 | */
37 | protected final String id;
38 |
39 | /**
40 | * All atoms refer back to an element (Vertex, Edge, or VertexProperty).
41 | */
42 | protected BlazeGraphAtom(final String id) {
43 | this.id = id;
44 | }
45 |
46 | /**
47 | * The element id (Vertex, Edge, or VertexProperty) this atom refers to.
48 | */
49 | public String elementId() {
50 | return id;
51 | }
52 |
53 | /**
54 | * Abstract base class for VertexAtom and EdgeAtom. Adds the element label.
55 | *
56 | * @author mikepersonick
57 | */
58 | private static abstract class ElementAtom extends BlazeGraphAtom {
59 |
60 | /**
61 | * Element label.
62 | */
63 | protected final String label;
64 |
65 | private ElementAtom(final String id, final String label) {
66 | super(id);
67 |
68 | this.label = label;
69 | }
70 |
71 | /**
72 | * Element label.
73 | */
74 | public String label() {
75 | return label;
76 | }
77 |
78 | }
79 |
80 | /**
81 | * Vertex atom describes a vertex - id and label.
82 | *
83 | * @author mikepersonick
84 | */
85 | public static class VertexAtom extends ElementAtom {
86 |
87 | /**
88 | * Full construct a vertex atom.
89 | */
90 | public VertexAtom(final String id, final String label) {
91 | super(id, label);
92 | }
93 |
94 | /**
95 | * Return the vertex id.
96 | */
97 | public String vertexId() {
98 | return id;
99 | }
100 |
101 | @Override
102 | public String toString() {
103 | return "VertexAtom [id=" + id + ", label=" + label + "]";
104 | }
105 |
106 | }
107 |
108 | /**
109 | * Edge atom describes an edge - id, label, and from/to (vertex ids).
110 | *
111 | * @author mikepersonick
112 | */
113 | public static class EdgeAtom extends ElementAtom {
114 |
115 | /**
116 | * From vertex id.
117 | */
118 | private final String fromId;
119 |
120 | /**
121 | * To vertex id.
122 | */
123 | private final String toId;
124 |
125 | /**
126 | * Fully construct an edge atom.
127 | */
128 | public EdgeAtom(final String id, final String label,
129 | final String fromId, final String toId) {
130 | super(id, label);
131 |
132 | this.fromId = fromId;
133 | this.toId = toId;
134 | }
135 |
136 | /**
137 | * Return the edge id.
138 | */
139 | public String edgeId() {
140 | return id;
141 | }
142 |
143 | /**
144 | * From vertex id.
145 | */
146 | public String fromId() {
147 | return fromId;
148 | }
149 |
150 | /**
151 | * To vertex id.
152 | */
153 | public String toId() {
154 | return toId;
155 | }
156 |
157 | @Override
158 | public String toString() {
159 | return "EdgeAtom [id=" + id + ", label=" + label + ", from=" + fromId + ", to=" + toId + "]";
160 | }
161 |
162 | }
163 |
164 | /**
165 | * Property atom describes a property on an Edge or VertexProperty -
166 | * element id, key, and value.
167 | *
168 | * @author mikepersonick
169 | */
170 | public static class PropertyAtom extends BlazeGraphAtom {
171 |
172 | /**
173 | * Property key (name).
174 | */
175 | protected final String key;
176 |
177 | /**
178 | * Property value (primitive).
179 | */
180 | protected final Object val;
181 |
182 | /**
183 | * Fully construct a property atom.
184 | */
185 | public PropertyAtom(final String id, final String key, final Object val) {
186 | super(id);
187 |
188 | this.key = key;
189 | this.val = val;
190 | }
191 |
192 | /**
193 | * Property key (name).
194 | */
195 | public String getKey() {
196 | return key;
197 | }
198 |
199 | /**
200 | * Property value (primitive).
201 | */
202 | public Object getVal() {
203 | return val;
204 | }
205 |
206 | @Override
207 | public String toString() {
208 | return "PropertyAtom [elementId=" + id + ", key=" + key + ", val=" + val + "]";
209 | }
210 |
211 | }
212 |
213 | /**
214 | * VertexProperty atom describes a property on a Vertex - vertex id, vertex
215 | * property id, key, value.
216 | *
217 | * @author mikepersonick
218 | */
219 | public static class VertexPropertyAtom extends PropertyAtom {
220 |
221 | /**
222 | * Vertex property id.
223 | */
224 | private final String vpId;
225 |
226 | /**
227 | * Fully construct a vertex property atom.
228 | */
229 | public VertexPropertyAtom(final String vertexId,
230 | final String key, final Object val, final String vpId) {
231 | super(vertexId, key, val);
232 |
233 | this.vpId = vpId;
234 | }
235 |
236 | /**
237 | * Return the vertex id.
238 | */
239 | public String vertexId() {
240 | return id;
241 | }
242 |
243 | /**
244 | * Return the vertex property id.
245 | */
246 | public String vertexPropertyId() {
247 | return vpId;
248 | }
249 |
250 | @Override
251 | public String toString() {
252 | return "VertexPropertyAtom [vertexId=" + id + ", key=" + key + ", val=" + val + ", vertexPropertyId=" + vpId + "]";
253 | }
254 |
255 | }
256 |
257 | }
258 |
--------------------------------------------------------------------------------
/src/main/java/com/blazegraph/gremlin/listener/BlazeGraphEdit.java:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright (C) SYSTAP, LLC DBA Blazegraph 2006-2016. All rights reserved.
3 |
4 | Contact:
5 | SYSTAP, LLC DBA Blazegraph
6 | 2501 Calvert ST NW #106
7 | Washington, DC 20008
8 | licenses@blazegraph.com
9 |
10 | This program is free software; you can redistribute it and/or modify
11 | it under the terms of the GNU General Public License as published by
12 | the Free Software Foundation; version 2 of the License.
13 |
14 | This program is distributed in the hope that it will be useful,
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | GNU General Public License for more details.
18 |
19 | You should have received a copy of the GNU General Public License
20 | along with this program; if not, write to the Free Software
21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 | */
23 | package com.blazegraph.gremlin.listener;
24 |
25 | /**
26 | * An edit consists of an edit action (add or remove), the atomic unit of graph
27 | * information that was edited ({@link BlazeGraphAtom}), and the commit time of
28 | * the edit. This is the unit of graph information used by the listener and
29 | * history APIs. Listeners will get edits with no timestamp information, that
30 | * is because the edits are happening prior to a commit. Listeners will
31 | * eventually get a commit notification with a timestamp (or a rollback).
32 | * The history API will provide timestamps, since it is dealing with committed
33 | * edits that happened in the past.
34 | *
35 | * @author mikepersonick
36 | */
37 | public class BlazeGraphEdit {
38 |
39 | /**
40 | * Edit action - add or remove.
41 | *
42 | * @author mikepersonick
43 | */
44 | public static enum Action {
45 |
46 | /**
47 | * Graph atom added.
48 | */
49 | Add,
50 |
51 | /**
52 | * Graph atom removed.
53 | */
54 | Remove;
55 |
56 | }
57 |
58 | /**
59 | * Edit action.
60 | */
61 | private final Action action;
62 |
63 | /**
64 | * Atomic unit of graph information edited.
65 | */
66 | private final BlazeGraphAtom atom;
67 |
68 | /**
69 | * The commit time of the edit action.
70 | */
71 | private final long timestamp;
72 |
73 | /**
74 | * Construct an edit with an unknown commit time (listener API).
75 | */
76 | public BlazeGraphEdit(final Action action, final BlazeGraphAtom atom) {
77 | this(action, atom, 0l);
78 | }
79 |
80 | /**
81 | * Construct an edit with an known commit time (history API).
82 | */
83 | public BlazeGraphEdit(final Action action, final BlazeGraphAtom atom,
84 | final long timestamp) {
85 | this.action = action;
86 | this.atom = atom;
87 | this.timestamp = timestamp;
88 | }
89 |
90 | /**
91 | * Return the edit action.
92 | */
93 | public Action getAction() {
94 | return action;
95 | }
96 |
97 | /**
98 | * Return the atomic unit of graph information edited.
99 | */
100 | public BlazeGraphAtom getAtom() {
101 | return atom;
102 | }
103 |
104 | /**
105 | * Return the commit time of the edit action or 0l if this is an
106 | * uncommitted edit.
107 | */
108 | public long getTimestamp() {
109 | return timestamp;
110 | }
111 |
112 | @Override
113 | public String toString() {
114 | return "BlazeGraphEdit [action=" + action + ", atom=" + atom
115 | + (timestamp > 0 ? ", timestamp=" + timestamp : "") + "]";
116 | }
117 |
118 | }
119 |
120 |
--------------------------------------------------------------------------------
/src/main/java/com/blazegraph/gremlin/listener/BlazeGraphListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright (C) SYSTAP, LLC DBA Blazegraph 2006-2016. All rights reserved.
3 |
4 | Contact:
5 | SYSTAP, LLC DBA Blazegraph
6 | 2501 Calvert ST NW #106
7 | Washington, DC 20008
8 | licenses@blazegraph.com
9 |
10 | This program is free software; you can redistribute it and/or modify
11 | it under the terms of the GNU General Public License as published by
12 | the Free Software Foundation; version 2 of the License.
13 |
14 | This program is distributed in the hope that it will be useful,
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | GNU General Public License for more details.
18 |
19 | You should have received a copy of the GNU General Public License
20 | along with this program; if not, write to the Free Software
21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 | */
23 | package com.blazegraph.gremlin.listener;
24 |
25 | import com.blazegraph.gremlin.embedded.BlazeGraphEmbedded;
26 |
27 | /**
28 | * Listener interface for a {@link BlazeGraphEmbedded}.
29 | *
30 | * @see BlazeGraphEmbedded#addListener(BlazeGraphListener)
31 | *
32 | * @author mikepersonick
33 | */
34 | @FunctionalInterface
35 | public interface BlazeGraphListener {
36 |
37 | /**
38 | * Notification of an edit to the graph.
39 | *
40 | * @param edit
41 | * the {@link BlazeGraphEdit}
42 | * @param rdfEdit
43 | * toString() version of the raw RDF mutation
44 | */
45 | void graphEdited(BlazeGraphEdit edit, String rdfEdit);
46 |
47 | /**
48 | * Notification of a transaction committed.
49 | *
50 | * @param commitTime
51 | * the timestamp on the commit
52 | */
53 | default void transactionCommited(long commitTime) {
54 | // noop default impl
55 | }
56 |
57 | /**
58 | * Notification of a transaction abort.
59 | */
60 | default void transactionAborted() {
61 | // noop default impl
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/com/blazegraph/gremlin/structure/AbstractBlazeElement.java:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright (C) SYSTAP, LLC DBA Blazegraph 2006-2016. All rights reserved.
3 |
4 | Contact:
5 | SYSTAP, LLC DBA Blazegraph
6 | 2501 Calvert ST NW #106
7 | Washington, DC 20008
8 | licenses@blazegraph.com
9 |
10 | This program is free software; you can redistribute it and/or modify
11 | it under the terms of the GNU General Public License as published by
12 | the Free Software Foundation; version 2 of the License.
13 |
14 | This program is distributed in the hope that it will be useful,
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | GNU General Public License for more details.
18 |
19 | You should have received a copy of the GNU General Public License
20 | along with this program; if not, write to the Free Software
21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 | */
23 | package com.blazegraph.gremlin.structure;
24 |
25 | import java.util.Objects;
26 |
27 | import org.apache.tinkerpop.gremlin.structure.Element;
28 | import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
29 | import org.openrdf.model.URI;
30 |
31 | import com.bigdata.rdf.model.BigdataURI;
32 |
33 | /**
34 | * Abstract base class for {@link BlazeVertex} and {@link BlazeEdge}.
35 | *
36 | * @author mikepersonick
37 | */
38 | abstract class AbstractBlazeElement implements BlazeElement {
39 |
40 | /**
41 | * {@link BlazeGraph} instance this element belongs to.
42 | */
43 | protected final BlazeGraph graph;
44 |
45 | /**
46 | * The {@link BlazeValueFactory} provided by the graph for round-tripping
47 | * values.
48 | */
49 | protected final BlazeValueFactory vf;
50 |
51 | /**
52 | * The URI representation of the element id.
53 | */
54 | protected final BigdataURI uri;
55 |
56 | /**
57 | * The Literal representation of the element label.
58 | */
59 | protected final BigdataURI label;
60 |
61 | AbstractBlazeElement(final BlazeGraph graph, final BigdataURI uri,
62 | final BigdataURI label) {
63 | Objects.requireNonNull(graph);
64 | Objects.requireNonNull(uri);
65 | Objects.requireNonNull(label);
66 |
67 | this.graph = graph;
68 | this.uri = uri;
69 | this.label = label;
70 | this.vf = graph.valueFactory();
71 | }
72 |
73 | /**
74 | * Return element id. Tinkerpop3 interface method.
75 | *
76 | * @see Element#id()
77 | */
78 | @Override
79 | public String id() {
80 | return vf.fromURI(uri);
81 | }
82 |
83 | /**
84 | * Return element label. Tinkerpop3 interface method.
85 | *
86 | * @see Element#label()
87 | */
88 | @Override
89 | public String label() {
90 | return (String) vf.fromURI(label);
91 | }
92 |
93 | /**
94 | * Return the RDF representation of the label.
95 | *
96 | * @see BlazeElement#rdfLabel()
97 | */
98 | @Override
99 | public URI rdfLabel() {
100 | return label;
101 | }
102 |
103 | /**
104 | * Return the {@link BlazeGraph} instance.
105 | */
106 | @Override
107 | public BlazeGraph graph() {
108 | return graph;
109 | }
110 |
111 | /**
112 | * Delegates to {@link ElementHelper#hashCode(Element)}
113 | */
114 | @Override
115 | public int hashCode() {
116 | return ElementHelper.hashCode(this);
117 | }
118 |
119 | /**
120 | * Delegates to {@link ElementHelper#areEqual(Element, Object)}
121 | */
122 | @Override
123 | public boolean equals(final Object object) {
124 | return ElementHelper.areEqual(this, object);
125 | }
126 |
127 | }
128 |
--------------------------------------------------------------------------------
/src/main/java/com/blazegraph/gremlin/structure/BlazeBindingSet.java:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright (C) SYSTAP, LLC DBA Blazegraph 2006-2016. All rights reserved.
3 |
4 | Contact:
5 | SYSTAP, LLC DBA Blazegraph
6 | 2501 Calvert ST NW #106
7 | Washington, DC 20008
8 | licenses@blazegraph.com
9 |
10 | This program is free software; you can redistribute it and/or modify
11 | it under the terms of the GNU General Public License as published by
12 | the Free Software Foundation; version 2 of the License.
13 |
14 | This program is distributed in the hope that it will be useful,
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | GNU General Public License for more details.
18 |
19 | You should have received a copy of the GNU General Public License
20 | along with this program; if not, write to the Free Software
21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 | */
23 | package com.blazegraph.gremlin.structure;
24 |
25 | import java.util.Collections;
26 | import java.util.Iterator;
27 | import java.util.Map;
28 | import java.util.Set;
29 |
30 | /**
31 | * A property graph version of a tuple query result binding set. Instead of
32 | * variable names to RDF values, this does variable names to PG values (element
33 | * ids, property keys, property values).
34 | *
35 | * @author mikepersonick
36 | */
37 | public class BlazeBindingSet implements Iterable> {
38 |
39 | /**
40 | * The variable bindings - variable name to PG value.
41 | */
42 | private final Map vals;
43 |
44 | /**
45 | * Construct an instance.
46 | */
47 | BlazeBindingSet(final Map vals) {
48 | this.vals = vals;
49 | }
50 |
51 | /**
52 | * Get the PG value (element id, property key, or property value) for the
53 | * specified variable.
54 | */
55 | public Object get(final String var) {
56 | return vals.get(var);
57 | }
58 |
59 | /**
60 | * True if the binding set has a PG value for the specified variable.
61 | */
62 | public boolean isBound(final String var) {
63 | return vals.containsKey(var);
64 | }
65 |
66 | /**
67 | * A unmodifiable set of variables bound in this binding set.
68 | */
69 | public Set vars() {
70 | return Collections.unmodifiableSet(vals.keySet());
71 | }
72 |
73 | /**
74 | * An unmodifiable map of variable bindings - variable name to PG value.
75 | */
76 | public Map map() {
77 | return Collections.unmodifiableMap(vals);
78 | }
79 |
80 | /**
81 | * An iterator of variable bindings - variable name to PG value.
82 | */
83 | @Override
84 | public Iterator> iterator() {
85 | return vals.entrySet().iterator();
86 | }
87 |
88 | @Override
89 | public String toString() {
90 | return "BlazeBindingSet [vals=" + vals + "]";
91 | }
92 |
93 | }
94 |
--------------------------------------------------------------------------------
/src/main/java/com/blazegraph/gremlin/structure/BlazeEdge.java:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright (C) SYSTAP, LLC DBA Blazegraph 2006-2016. All rights reserved.
3 |
4 | Contact:
5 | SYSTAP, LLC DBA Blazegraph
6 | 2501 Calvert ST NW #106
7 | Washington, DC 20008
8 | licenses@blazegraph.com
9 |
10 | This program is free software; you can redistribute it and/or modify
11 | it under the terms of the GNU General Public License as published by
12 | the Free Software Foundation; version 2 of the License.
13 |
14 | This program is distributed in the hope that it will be useful,
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | GNU General Public License for more details.
18 |
19 | You should have received a copy of the GNU General Public License
20 | along with this program; if not, write to the Free Software
21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 | */
23 | package com.blazegraph.gremlin.structure;
24 |
25 | import java.util.Iterator;
26 | import java.util.stream.Stream;
27 |
28 | import org.apache.tinkerpop.gremlin.structure.Direction;
29 | import org.apache.tinkerpop.gremlin.structure.Edge;
30 | import org.apache.tinkerpop.gremlin.structure.Property;
31 | import org.apache.tinkerpop.gremlin.structure.Vertex;
32 | import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
33 |
34 | import com.bigdata.rdf.model.BigdataBNode;
35 | import com.bigdata.rdf.model.BigdataStatement;
36 | import com.bigdata.rdf.model.BigdataURI;
37 | import com.bigdata.rdf.model.BigdataValueFactory;
38 | import com.blazegraph.gremlin.structure.BlazeGraphFeatures.Graph;
39 | import com.blazegraph.gremlin.util.CloseableIterator;
40 |
41 | /**
42 | * Concrete edge implementation for Blazegraph.
43 | *
44 | * Edge existence is represented as two triples as follows:
45 | *
252 | * Return a graph property from a datatyped literal using its
253 | * XSD datatype.
254 | *
255 | * Supports: Float, Double, Integer, Long, Boolean, Short, Byte, and String.
256 | */
257 | default Object fromLiteral(final Literal l) {
258 |
259 | final URI datatype = l.getDatatype();
260 |
261 | if (datatype == null) {
262 | return l.getLabel();
263 | } else if (datatype.equals(XSD.FLOAT)) {
264 | return l.floatValue();
265 | } else if (datatype.equals(XSD.DOUBLE)) {
266 | return l.doubleValue();
267 | } else if (datatype.equals(XSD.INT)) {
268 | return l.intValue();
269 | } else if (datatype.equals(XSD.LONG)) {
270 | return l.longValue();
271 | } else if (datatype.equals(XSD.BOOLEAN)) {
272 | return l.booleanValue();
273 | } else if (datatype.equals(XSD.SHORT)) {
274 | return l.shortValue();
275 | } else if (datatype.equals(XSD.BYTE)) {
276 | return l.byteValue();
277 | } else {
278 | return l.getLabel();
279 | }
280 |
281 | }
282 |
283 | }
284 |
--------------------------------------------------------------------------------
/src/main/java/com/blazegraph/gremlin/structure/BlazeVertex.java:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright (C) SYSTAP, LLC DBA Blazegraph 2006-2016. All rights reserved.
3 |
4 | Contact:
5 | SYSTAP, LLC DBA Blazegraph
6 | 2501 Calvert ST NW #106
7 | Washington, DC 20008
8 | licenses@blazegraph.com
9 |
10 | This program is free software; you can redistribute it and/or modify
11 | it under the terms of the GNU General Public License as published by
12 | the Free Software Foundation; version 2 of the License.
13 |
14 | This program is distributed in the hope that it will be useful,
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | GNU General Public License for more details.
18 |
19 | You should have received a copy of the GNU General Public License
20 | along with this program; if not, write to the Free Software
21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 | */
23 | package com.blazegraph.gremlin.structure;
24 |
25 | import org.apache.tinkerpop.gremlin.structure.Direction;
26 | import org.apache.tinkerpop.gremlin.structure.Edge;
27 | import org.apache.tinkerpop.gremlin.structure.Graph;
28 | import org.apache.tinkerpop.gremlin.structure.Vertex;
29 | import org.apache.tinkerpop.gremlin.structure.VertexProperty;
30 | import org.apache.tinkerpop.gremlin.structure.VertexProperty.Cardinality;
31 | import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
32 | import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
33 | import org.openrdf.model.Literal;
34 |
35 | import com.bigdata.rdf.model.BigdataURI;
36 | import com.blazegraph.gremlin.util.CloseableIterator;
37 |
38 | /**
39 | * Concrete vertex implementation for BlazeGraph.
40 | *
41 | * Vertex existence is represented as one triples as follows:
42 | *
43 | *
44 | * :vertexId rdf:type :label .
45 | *
46 | *
47 | * Vertex properties are represented as follows:
48 | *
49 | *
50 | * :vertexId :key "val" .
51 | *
52 | *
53 | * @author mikepersonick
54 | */
55 | public class BlazeVertex extends AbstractBlazeElement implements Vertex, BlazeElement {
56 |
57 | /**
58 | * Construct an instance.
59 | */
60 | BlazeVertex(final BlazeGraph graph, final BigdataURI uri,
61 | final BigdataURI label) {
62 | super(graph, uri, label);
63 | }
64 |
65 | /**
66 | * Strengthen return type. Vertex RDF id is its URI.
67 | */
68 | @Override
69 | public BigdataURI rdfId() {
70 | return uri;
71 | }
72 |
73 | /**
74 | * Pass through to {@link StringFactory#vertexString(Vertex)}
75 | */
76 | @Override
77 | public String toString() {
78 | return StringFactory.vertexString(this);
79 | }
80 |
81 | /**
82 | * Strengthen return type to {@link BlazeVertexProperty}.
83 | *
84 | * @see Vertex#property(String)
85 | * @see BlazeVertex#properties(String...)
86 | */
87 | @Override
88 | public BlazeVertexProperty property(final String key) {
89 | try (CloseableIterator> it = this.properties(key)) {
90 | if (it.hasNext()) {
91 | final VertexProperty property = it.next();
92 | if (it.hasNext())
93 | throw Vertex.Exceptions.multiplePropertiesExistForProvidedKey(key);
94 | else
95 | return (BlazeVertexProperty) property;
96 | } else {
97 | return EmptyBlazeVertexProperty.instance();
98 | }
99 | }
100 | }
101 |
102 | /**
103 | * Strengthen return type to {@link BlazeVertexProperty} and use
104 | * Cardinality.single by default.
105 | */
106 | @Override
107 | public BlazeVertexProperty property(final String key, final V val) {
108 | return property(Cardinality.single, key, val);
109 | }
110 |
111 | /**
112 | * Strengthen return type to {@link BlazeVertexProperty}.
113 | *
114 | * @see BlazeGraph#vertexProperty(BlazeVertex, Cardinality, String, Object, Object...)
115 | */
116 | @Override
117 | public BlazeVertexProperty property(final Cardinality cardinality,
118 | final String key, final V val, final Object... kvs) {
119 | ElementHelper.validateProperty(key, val);
120 | if (ElementHelper.getIdValue(kvs).isPresent())
121 | throw Vertex.Exceptions.userSuppliedIdsNotSupported();
122 |
123 | return graph.vertexProperty(this, cardinality, key, val, kvs);
124 | }
125 |
126 | /**
127 | * Strength return type to {@link CloseableIterator}. You MUST close this
128 | * iterator when finished.
129 | */
130 | @Override
131 | public CloseableIterator> properties(String... keys) {
132 | return graph.properties(this, keys);
133 | }
134 |
135 | /**
136 | * @see Vertex#addEdge(String, Vertex, Object...)
137 | * @see BlazeGraph#addEdge(BlazeVertex, BlazeVertex, String, Object...)
138 | */
139 | @Override
140 | public BlazeEdge addEdge(final String label, final Vertex to, final Object... kvs) {
141 | if (to == null) throw Graph.Exceptions.argumentCanNotBeNull("vertex");
142 | return graph.addEdge(this, (BlazeVertex) to, label, kvs);
143 | }
144 |
145 | /**
146 | * Strength return type to {@link CloseableIterator}. You MUST close this
147 | * iterator when finished.
148 | *
149 | * @see Vertex#edges(Direction, String...)
150 | * @see BlazeGraph#edgesFromVertex(BlazeVertex, Direction, String...)
151 | */
152 | @Override
153 | public CloseableIterator edges(final Direction direction,
154 | final String... edgeLabels) {
155 | return graph.edgesFromVertex(this, direction, edgeLabels);
156 | }
157 |
158 | /**
159 | * Strength return type to {@link CloseableIterator}. You MUST close this
160 | * iterator when finished.
161 | *
162 | * @see Vertex#vertices(Direction, String...)
163 | */
164 | @Override
165 | public CloseableIterator vertices(final Direction direction,
166 | final String... edgeLabels) {
167 | return CloseableIterator.of(edges(direction, edgeLabels)
168 | .stream()
169 | .map(e -> {
170 | final BlazeEdge be = (BlazeEdge) e;
171 | return be.outVertex().equals(this) ? be.inVertex() : be.outVertex();
172 | }));
173 | }
174 |
175 | /**
176 | * @see Vertex#remove()
177 | * @see BlazeGraph#remove(BlazeVertex)
178 | */
179 | @Override
180 | public void remove() {
181 | graph.remove(this);
182 | }
183 |
184 | }
185 |
--------------------------------------------------------------------------------
/src/main/java/com/blazegraph/gremlin/structure/BlazeVertexProperty.java:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright (C) SYSTAP, LLC DBA Blazegraph 2006-2016. All rights reserved.
3 |
4 | Contact:
5 | SYSTAP, LLC DBA Blazegraph
6 | 2501 Calvert ST NW #106
7 | Washington, DC 20008
8 | licenses@blazegraph.com
9 |
10 | This program is free software; you can redistribute it and/or modify
11 | it under the terms of the GNU General Public License as published by
12 | the Free Software Foundation; version 2 of the License.
13 |
14 | This program is distributed in the hope that it will be useful,
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | GNU General Public License for more details.
18 |
19 | You should have received a copy of the GNU General Public License
20 | along with this program; if not, write to the Free Software
21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 | */
23 | package com.blazegraph.gremlin.structure;
24 |
25 | import java.util.NoSuchElementException;
26 |
27 | import org.apache.tinkerpop.gremlin.structure.Element;
28 | import org.apache.tinkerpop.gremlin.structure.Property;
29 | import org.apache.tinkerpop.gremlin.structure.VertexProperty;
30 | import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
31 | import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
32 | import org.openrdf.model.Literal;
33 | import org.openrdf.model.URI;
34 |
35 | import com.bigdata.rdf.model.BigdataBNode;
36 | import com.blazegraph.gremlin.util.CloseableIterator;
37 |
38 | /**
39 | * Concrete vertex property implementation for Blazegraph.
40 | *
41 | *
42 | * Vertex properties can be represented in one of two ways depending on the
43 | * cardinality of the key. Cardinality.single and Cardinality.set are
44 | * represented the same way, as follows:
45 | *
46 | *
47 | *
48 | * :vertexId :key "val" .
49 | *
50 | *
51 | * For Cardinality.list, a list index literal with a special datatype is used
52 | * to manage duplicate list items and ordering. Cardinality.list requires two
53 | * triples instead of one:
54 | *