Skip to content
Snippets Groups Projects
Commit c9303ed8 authored by Andreas Schärtl's avatar Andreas Schärtl
Browse files

graphcli: establish connection to GraphDB server

parent 8c7822ad
No related branches found
No related tags found
No related merge requests found
......@@ -3,10 +3,19 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>me.schaertl</groupId>
<artifactId>graphcli</artifactId>
<version>indev</version>
<properties>
<maven.compiler.source>1.11</maven.compiler.source>
<maven.compiler.target>1.11</maven.compiler.target>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.ontotext.graphdb/graphdb-free-runtime -->
<dependency>
<groupId>com.ontotext.graphdb</groupId>
<artifactId>graphdb-free-runtime</artifactId>
<version>9.2.0</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package me.schaertl.graphcli;
import org.eclipse.rdf4j.model.Resource;
import org.eclipse.rdf4j.model.impl.TreeModel;
import org.eclipse.rdf4j.model.vocabulary.RDF;
import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.RepositoryConnection;
import org.eclipse.rdf4j.repository.config.RepositoryConfig;
import org.eclipse.rdf4j.repository.config.RepositoryConfigSchema;
import org.eclipse.rdf4j.repository.manager.LocalRepositoryManager;
import org.eclipse.rdf4j.repository.manager.RemoteRepositoryManager;
import org.eclipse.rdf4j.repository.manager.RepositoryManager;
import org.eclipse.rdf4j.rio.RDFFormat;
import org.eclipse.rdf4j.rio.RDFParser;
import org.eclipse.rdf4j.rio.Rio;
import org.eclipse.rdf4j.rio.helpers.StatementCollector;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
public class Main {
public static void main(String[] args) {
System.out.println("Hello, World!");
private static void hello() throws IOException {
// Code taken from http://graphdb.ontotext.com/documentation/standard/using-graphdb-with-the-rdf4j-api.html
// Instantiate a local repository manager and initialize it
final RepositoryManager repositoryManager = new RemoteRepositoryManager("http://rdf:7200");
repositoryManager.initialize();
// Instantiate a repository graph model
// final TreeModel graph = new TreeModel();
// Read repository configuration file
// InputStream config = EmbeddedGraphDB.class.getResourceAsStream("/repo-defaults.ttl");
// RDFParser rdfParser = Rio.createParser(RDFFormat.TURTLE);
// rdfParser.setRDFHandler(new StatementCollector(graph));
// rdfParser.parse(config, RepositoryConfigSchema.NAMESPACE);
// config.close();
// Retrieve the repository node as a resource
// Resource repositoryNode = GraphUtil.getUniqueSubject(graph, RDF.TYPE, RepositoryConfigSchema.REPOSITORY);
// Create a repository configuration object and add it to the repositoryManager
// RepositoryConfig repositoryConfig = RepositoryConfig.create(graph, repositoryNode);
// repositoryManager.addRepositoryConfig(repositoryConfig);
// Get the repository from repository manager, note the repository id set in configuration .ttl file
final Repository repository = repositoryManager.getRepository("chem");
// Open a connection to this repository
final RepositoryConnection repositoryConnection = repository.getConnection();
// ... use the repository
// Shutdown connection, repository and manager
repositoryConnection.close();
repository.shutDown();
repositoryManager.shutDown();
}
public static void main(String[] args) throws IOException {
Main.hello();
System.out.println("done running the program");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment