View Javadoc
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 org.apache.commons.rdf.api.AbstractGraphTest;
21  import org.apache.commons.rdf.api.BlankNodeOrIRI;
22  import org.apache.commons.rdf.api.Dataset;
23  import org.apache.commons.rdf.api.IRI;
24  import org.apache.commons.rdf.api.Literal;
25  import org.apache.commons.rdf.api.Quad;
26  import org.apache.commons.rdf.api.RDFTerm;
27  import org.apache.commons.rdf.api.RDF;
28  import org.eclipse.rdf4j.repository.Repository;
29  import org.eclipse.rdf4j.repository.sail.SailRepository;
30  import org.eclipse.rdf4j.sail.Sail;
31  import org.eclipse.rdf4j.sail.memory.MemoryStore;
32  import org.eclipse.rdf4j.sail.memory.model.MemValueFactory;
33  
34  public class MemoryGraphTest extends AbstractGraphTest {
35  
36      public static final class MemoryStoreRDF implements RDF {
37  
38          RDF4J rdf4jFactory = new RDF4J(new MemValueFactory());
39  
40          @Override
41          public RDF4JBlankNode createBlankNode() {
42              return rdf4jFactory.createBlankNode();
43          }
44  
45          @Override
46          public RDF4JBlankNode createBlankNode(final String name) {
47              return rdf4jFactory.createBlankNode(name);
48          }
49  
50          @Override
51          public Dataset createDataset() {
52              return rdf4jFactory.createDataset();
53          }
54  
55          @Override
56          public RDF4JIRI createIRI(final String iri) throws IllegalArgumentException, UnsupportedOperationException {
57              return rdf4jFactory.createIRI(iri);
58          }
59  
60          @Override
61          public RDF4JLiteral createLiteral(final String lexicalForm) {
62              return rdf4jFactory.createLiteral(lexicalForm);
63          }
64  
65          @Override
66          public Literal createLiteral(final String lexicalForm, final IRI dataType) {
67              return rdf4jFactory.createLiteral(lexicalForm, dataType);
68          }
69  
70          @Override
71          public Literal createLiteral(final String lexicalForm, final String languageTag) {
72              return rdf4jFactory.createLiteral(lexicalForm, languageTag);
73          }
74  
75          @Override
76          public RDF4JTriple createTriple(final BlankNodeOrIRI subject, final IRI predicate, final RDFTerm object) {
77              return rdf4jFactory.createTriple(subject, predicate, object);
78          }
79  
80          @Override
81          public Quad createQuad(final BlankNodeOrIRI graphName, final BlankNodeOrIRI subject, final IRI predicate, final RDFTerm object) {
82              return rdf4jFactory.createQuad(graphName, subject, predicate, object);
83          }
84  
85          @Override
86          public RDF4JGraph createGraph() {
87              final Sail sail = new MemoryStore();
88              final Repository repository = new SailRepository(sail);
89              repository.initialize();
90              return rdf4jFactory.asGraph(repository);
91          }
92      }
93  
94      @Override
95      public RDF createFactory() {
96          return new MemoryStoreRDF();
97      }
98  
99  }