1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18 package org.apache.commons.rdf.rdf4j;
19
20 import java.util.Optional;
21 import java.util.stream.Stream;
22
23 import org.apache.commons.rdf.api.BlankNodeOrIRI;
24 import org.apache.commons.rdf.api.Dataset;
25 import org.apache.commons.rdf.api.IRI;
26 import org.apache.commons.rdf.api.Quad;
27 import org.apache.commons.rdf.api.RDFTerm;
28
29 /**
30 * Marker interface for RDF4J implementations of Dataset.
31 *
32 * @see RDF4J#createDataset()
33 * @see RDF4J#asDataset(org.eclipse.rdf4j.repository.Repository, Option...)
34 */
35 public interface RDF4JDataset extends Dataset, RDF4JGraphLike<Quad> {
36
37 /**
38 * {@inheritDoc}
39 * <p>
40 * Note that for datasets backed by a repository ({@link #asRepository()} is
41 * present), the stream <strong>must be closed</strong> with
42 * {@link Stream#close()}.
43 * <p>
44 * This can generally achieved using a try-with-resources block, e.g.:
45 *
46 * <pre>
47 * int subjects;
48 * try (Stream<RDF4JQuad> s : graph.stream()) {
49 * subjects = s.map(RDF4JQuad::getSubject).distinct().count()
50 * }
51 * </pre>
52 */
53 @Override
54 Stream<RDF4JQuad> stream();
55
56 /**
57 * {@inheritDoc}
58 * <p>
59 * Note that for datasets backed by a repository ({@link #asRepository()} is
60 * present), the stream <strong>must be closed</strong> with
61 * {@link Stream#close()}.
62 * <p>
63 * This can generally achieved using a try-with-resources block, e.g.:
64 *
65 * <pre>
66 * int subjects;
67 * try (Stream<RDF4JQuad> s : graph.stream()) {
68 * subjects = s.map(RDF4JQuad::getSubject).distinct().count()
69 * }
70 * </pre>
71 */
72 @Override
73 Stream<RDF4JQuad> stream(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
74
75 /**
76 * {@inheritDoc}
77 * <p>
78 * Note that for datasets backed by a repository ({@link #asRepository()} is
79 * present), the stream <strong>must be closed</strong> with
80 * {@link Stream#close()}.
81 * <p>
82 * This can generally achieved using a try-with-resources block, e.g.:
83 *
84 * <pre>
85 * int graphs;
86 * try (Stream<BlankNodeOrIRI> s : graph.stream()) {
87 * graphs = s.count()
88 * }
89 * </pre>
90 */
91 @Override
92 Stream<BlankNodeOrIRI> getGraphNames();
93
94 /**
95 * {@inheritDoc}
96 * <p>
97 * Note that for datasets backed by a repository ({@link #asRepository()} is
98 * present), the iterable <strong>must be closed</strong> with
99 * {@link ClosableIterable#close()}.
100 * <p>
101 * This can generally achieved using a try-with-resources block, e.g.:
102 *
103 * <pre>
104 * try (ClosableIterable<Quad> s : graph.iterate()) {
105 * for (Quad q : quads) {
106 * return q; // OK to terminate for-loop early
107 * }
108 * }
109 * </pre>
110 *
111 * If you don't use a try-with-resources block, the iterator will attempt to
112 * close the ClosableIterable when reaching the end of the iteration.
113 */
114 @Override
115 ClosableIterable<Quad> iterate();
116
117 /**
118 * {@inheritDoc}
119 * <p>
120 * Note that for datasets backed by a repository ({@link #asRepository()} is
121 * present), the iterable <strong>must be closed</strong> with
122 * {@link ClosableIterable#close()}.
123 * <p>
124 * This can generally achieved using a try-with-resources block, e.g.:
125 *
126 * <pre>
127 * try (ClosableIterable<Quad> s : graph.iterate(g,s,p,o)) {
128 * for (Quad q : quads) {
129 * return q; // OK to terminate for-loop early
130 * }
131 * }
132 * </pre>
133 *
134 * If you don't use a try-with-resources block, the iterator will attempt to
135 * close the ClosableIterable when reaching the end of the iteration.
136 */
137 @Override
138 ClosableIterable<Quad> iterate(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate,
139 RDFTerm object);
140
141 }