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

uloimport: setup of repository connection

parent 93501309
No related branches found
No related tags found
No related merge requests found
...@@ -11,4 +11,27 @@ ...@@ -11,4 +11,27 @@
<maven.compiler.source>1.11</maven.compiler.source> <maven.compiler.source>1.11</maven.compiler.source>
<maven.compiler.target>1.11</maven.compiler.target> <maven.compiler.target>1.11</maven.compiler.target>
</properties> </properties>
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>29.0-jre</version>
</dependency>
<dependency>
<groupId>com.ontotext.graphdb</groupId>
<artifactId>graphdb-free-runtime</artifactId>
<version>9.2.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.30</version>
</dependency>
</dependencies>
</project> </project>
\ No newline at end of file
package info.kwarc.uloimport.importer;
import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.RepositoryConnection;
import org.eclipse.rdf4j.repository.manager.RemoteRepositoryManager;
import org.eclipse.rdf4j.repository.manager.RepositoryManager;
import java.io.InputStream;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* {@link Importer} that uploads imported data to a GraphDB instance.
*/
public class GraphDbImporter implements Importer {
private final String serverUrl;
private final String repository;
/**
* Construct a new GraphDbImporter that imports its data to a remote
* GraphDB instance.
*
* @param serverUrl The URL under which GraphDB is running.
* @param repository The name of the repository to dump to.
*/
public GraphDbImporter(String serverUrl, String repository) {
this.serverUrl = checkNotNull(serverUrl);
this.repository = checkNotNull(repository);
}
@Override
public void importRdfFile(InputStream is) throws ImportException {
final RepositoryManager manager;
final Repository repository;
final RepositoryConnection connection;
try {
manager = new RemoteRepositoryManager(this.serverUrl);
manager.init();
repository = manager.getRepository(this.repository);
if (repository == null) {
throw new ImportException("could not connect to repository=%s", this.repository);
}
connection = repository.getConnection();
} catch (Exception e) {
throw new ImportException("could not initialize database connection", e);
}
// TODO: Handle errors during initialization. This is quite annoying
// to do with this API.
}
}
package info.kwarc.uloimport; package info.kwarc.uloimport.importer;
/** /**
* An Exception caused by an import of ULO/RDF data. * An Exception caused by an import of ULO/RDF data.
...@@ -13,6 +13,16 @@ public class ImportException extends RuntimeException { ...@@ -13,6 +13,16 @@ public class ImportException extends RuntimeException {
super(message); super(message);
} }
/**
* Construct a new {@link ImportException} with a formatted message.
*
* @param format Format string of the message.
* @param args Arguments for the format string.
*/
public ImportException(String format, Object... args) {
super(String.format(format, args));
}
/** /**
* Construct a new {@link ImportException} with a message and a cause * Construct a new {@link ImportException} with a message and a cause
* that caused this exception. * that caused this exception.
......
package info.kwarc.uloimport; package info.kwarc.uloimport.importer;
import java.io.InputStream; import java.io.InputStream;
...@@ -10,5 +10,5 @@ public interface Importer { ...@@ -10,5 +10,5 @@ public interface Importer {
* @param is The stream from which to read a single ULO/RDF file. * @param is The stream from which to read a single ULO/RDF file.
* @throws ImportException When the import failed. * @throws ImportException When the import failed.
*/ */
void importUlo(InputStream is) throws ImportException; void importRdfFile(InputStream is) throws ImportException;
} }
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