org.eclipse.rdf4j.repository.Repository Java Examples

The following examples show how to use org.eclipse.rdf4j.repository.Repository. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProxyRepository.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private Repository getProxiedRepository() {
	Repository result = proxiedRepository;
	if (result == null) {
		synchronized (this) {
			result = proxiedRepository;
			if (result == null) {
				assert null != resolver : "Expected resolver to be set.";
				assert null != proxiedID : "Expected proxiedID to be set.";
				try {
					result = proxiedRepository = resolver.getRepository(proxiedID);
				} catch (RDF4JException ore) {
					throw new IllegalStateException(ore);
				}
			}
		}
	}
	return result;
}
 
Example #2
Source File: Load.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Add data from a URL or local file. If the dataURL is null, then the datafile will be used.
 *
 * @param repository repository
 * @param baseURI    base URI
 * @param context    context (can be null)
 * @param dataURL    url of the data
 * @param dataFile   file containing data
 * @throws RepositoryException
 * @throws IOException
 * @throws RDFParseException
 */
private void addData(Repository repository, String baseURI, String context, URL dataURL, File dataFile)
		throws RepositoryException, IOException, RDFParseException {
	Resource[] contexts = getContexts(repository, context);
	writeln("Loading data...");

	final long startTime = System.nanoTime();
	try (RepositoryConnection con = repository.getConnection()) {
		if (dataURL == null) {
			con.add(dataFile, baseURI, null, contexts);
		} else {
			con.add(dataURL, baseURI, null, contexts);
		}
	}
	final long endTime = System.nanoTime();
	writeln("Data has been added to the repository (" + (endTime - startTime) / 1_000_000 + " ms)");
}
 
Example #3
Source File: SPARQLQueryTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected static String getManifestName(Repository manifestRep, RepositoryConnection con, String manifestFileURL)
		throws QueryEvaluationException, RepositoryException, MalformedQueryException {
	// Try to extract suite name from manifest file
	TupleQuery manifestNameQuery = con.prepareTupleQuery(QueryLanguage.SERQL,
			"SELECT ManifestName FROM {ManifestURL} rdfs:label {ManifestName}");
	manifestNameQuery.setBinding("ManifestURL", manifestRep.getValueFactory().createIRI(manifestFileURL));
	TupleQueryResult manifestNames = manifestNameQuery.evaluate();
	try {
		if (manifestNames.hasNext()) {
			return manifestNames.next().getValue("ManifestName").stringValue();
		}
	} finally {
		manifestNames.close();
	}

	// Derive name from manifest URL
	int lastSlashIdx = manifestFileURL.lastIndexOf('/');
	int secLastSlashIdx = manifestFileURL.lastIndexOf('/', lastSlashIdx - 1);
	return manifestFileURL.substring(secLastSlashIdx + 1, lastSlashIdx);
}
 
Example #4
Source File: SizeController.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
		throws Exception {
	ProtocolUtil.logRequestParameters(request);

	Map<String, Object> model = new HashMap<>();
	final boolean headersOnly = METHOD_HEAD.equals(request.getMethod());

	if (!headersOnly) {
		Repository repository = RepositoryInterceptor.getRepository(request);

		ValueFactory vf = repository.getValueFactory();
		Resource[] contexts = ProtocolUtil.parseContextParam(request, Protocol.CONTEXT_PARAM_NAME, vf);

		long size = -1;

		try (RepositoryConnection repositoryCon = RepositoryInterceptor.getRepositoryConnection(request)) {
			size = repositoryCon.size(contexts);
		} catch (RepositoryException e) {
			throw new ServerHTTPException("Repository error: " + e.getMessage(), e);
		}
		model.put(SimpleResponseView.CONTENT_KEY, String.valueOf(size));
	}

	return new ModelAndView(SimpleResponseView.getInstance(), model);
}
 
Example #5
Source File: ContextAwareConnectionTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testQuery() throws Exception {
	RepositoryConnection stub = new RepositoryConnectionStub() {

		@Override
		public Query prepareQuery(QueryLanguage ql, String query, String baseURI)
				throws MalformedQueryException, RepositoryException {
			assertEquals(SPARQL, ql);
			assertEquals(queryString, query);
			return new QueryStub() {

				@Override
				public void setDataset(Dataset dataset) {
					Set<IRI> contexts = Collections.singleton(context);
					assertEquals(contexts, dataset.getDefaultGraphs());
					super.setDataset(dataset);
				}
			};
		}
	};
	Repository repo = stub.getRepository();
	ContextAwareConnection con = new ContextAwareConnection(repo, stub);
	con.setReadContexts(context);
	con.setQueryLanguage(SERQL);
	con.prepareQuery(SPARQL, queryString, null);
}
 
Example #6
Source File: ContextAwareConnectionTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testTupleQuery() throws Exception {
	RepositoryConnection stub = new RepositoryConnectionStub() {

		@Override
		public TupleQuery prepareTupleQuery(QueryLanguage ql, String query, String baseURI)
				throws MalformedQueryException, RepositoryException {
			assertEquals(SPARQL, ql);
			assertEquals(queryString, query);
			return new TupleQueryStub() {

				@Override
				public void setDataset(Dataset dataset) {
					Set<IRI> contexts = Collections.singleton(context);
					assertEquals(contexts, dataset.getDefaultGraphs());
					super.setDataset(dataset);
				}
			};
		}
	};
	Repository repo = stub.getRepository();
	ContextAwareConnection con = new ContextAwareConnection(repo, stub);
	con.setReadContexts(context);
	con.setQueryLanguage(SERQL);
	con.prepareTupleQuery(SPARQL, queryString, null);
}
 
Example #7
Source File: ShaclValidationReportTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testSparqlUpdate() throws IOException {

	Repository systemRepo = new HTTPRepository(
			Protocol.getRepositoryLocation(TestServer.SERVER_URL, TestServer.TEST_SHACL_REPO_ID));
	try (RepositoryConnection connection = systemRepo.getConnection()) {
		connection.begin();
		connection.add(new StringReader(shacl), "", RDFFormat.TURTLE, RDF4J.SHACL_SHAPE_GRAPH);
		connection.commit();

		try {
			connection.begin();
			connection.prepareUpdate("INSERT DATA {[] a rdfs:Resource}").execute();
			connection.commit();
			fail();
		} catch (Throwable e) {
			assertExceptionIsShaclReport(e);
		}
	}

}
 
Example #8
Source File: TypeFilteringRepositoryManager.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public Collection<Repository> getInitializedRepositories() {
	List<Repository> result = new ArrayList<>();

	for (String id : getInitializedRepositoryIDs()) {
		try {
			Repository repository = getRepository(id);

			if (repository != null) {
				result.add(repository);
			}
		} catch (RepositoryConfigException | RepositoryException e) {
			logger.error("Failed to verify repository type", e);
		}
	}

	return result;
}
 
Example #9
Source File: Show.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Show namespaces
 */
private void showNamespaces() {
	Repository repository = state.getRepository();
	if (repository == null) {
		writeUnopenedError();
		return;
	}

	try (RepositoryConnection con = repository.getConnection()) {
		try (CloseableIteration<? extends Namespace, RepositoryException> namespaces = con.getNamespaces()) {
			if (namespaces.hasNext()) {
				writeln(OUTPUT_SEPARATOR);
				while (namespaces.hasNext()) {
					final Namespace namespace = namespaces.next();
					writeln("|" + namespace.getPrefix() + "  " + namespace.getName());
				}
				writeln(OUTPUT_SEPARATOR);
			} else {
				writeln("No namespaces found");
			}
		}
	} catch (RepositoryException e) {
		writeError("Failed to show namespaces", e);
	}
}
 
Example #10
Source File: SPARQLQueryBuilderTest.java    From inception with Apache License 2.0 6 votes vote down vote up
public void __testWithLabelMatchingExactlyAnyOf_subproperty(Repository aRepository)
    throws Exception
{
    importDataFromString(aRepository, TURTLE, TURTLE_PREFIX, LABEL_SUBPROPERTY);
    
    // The label "Green Goblin" is not assigned directly via rdfs:label but rather via a
    // subproperty of it. Thus, this test also checks if the label sub-property support works.
    List<KBHandle> results = asHandles(aRepository, SPARQLQueryBuilder.forItems(kb)
                .withLabelMatchingExactlyAnyOf("Green Goblin"));
    
    assertThat(results).extracting(KBHandle::getUiLabel)
            .allMatch(label -> label.equals("Green Goblin"));
    assertThat(results).extracting(KBHandle::getIdentifier).doesNotHaveDuplicates();
    assertThat(results)
            .usingElementComparatorOnFields(
                    "identifier", "name", "language")
            .containsExactlyInAnyOrder(
                    new KBHandle("http://example.org/#green-goblin", "Green Goblin"));
}
 
Example #11
Source File: SPARQLQueryBuilderTest.java    From inception with Apache License 2.0 6 votes vote down vote up
public void __testWithLabelMatchingAnyOf_withLanguage(Repository aRepository)
    throws Exception
{
    importDataFromString(aRepository, TURTLE, TURTLE_PREFIX,
            DATA_LABELS_AND_DESCRIPTIONS_WITH_LANGUAGE);

    List<KBHandle> results = asHandles(aRepository, SPARQLQueryBuilder
            .forItems(kb)
            .withLabelMatchingAnyOf("Gobli"));
    
    assertThat(results).extracting(KBHandle::getUiLabel)
            .allMatch(label -> label.contains("Goblin"));
    assertThat(results).extracting(KBHandle::getIdentifier).doesNotHaveDuplicates();
    assertThat(results)
            .usingElementComparatorOnFields(
                    "identifier", "name", "language")
            .containsExactlyInAnyOrder(
                    new KBHandle("http://example.org/#red-goblin", "Red Goblin"),
                    new KBHandle("http://example.org/#green-goblin", "Green Goblin",
                            null, "en"));
}
 
Example #12
Source File: SPARQLQueryBuilderGenericTest.java    From inception with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("resource")
private void importData(Repository aRepo, String aUrl) throws IOException
{
    try (InputStream aIS = openAsStream(aUrl)) {
        InputStream is = new BufferedInputStream(aIS);
        try {
            // Stream is expected to be closed by caller of importData
            is = new CompressorStreamFactory().createCompressorInputStream(is);
        }
        catch (CompressorException e) {
            // Probably not compressed then or unknown format - just try as is.
        }

        // Detect the file format
        RDFFormat format = Rio.getParserFormatForFileName(aUrl).orElse(RDFFormat.RDFXML);
        
        try (RepositoryConnection conn = aRepo.getConnection()) {
            // If the RDF file contains relative URLs, then they probably start with a hash.
            // To avoid having two hashes here, we drop the hash from the base prefix configured
            // by the user.
            String prefix = StringUtils.removeEnd(kb.getBasePrefix(), "#");
            conn.add(is, prefix, format);
        }
    }
}
 
Example #13
Source File: SPARQLQueryBuilderAsserts.java    From inception with Apache License 2.0 6 votes vote down vote up
public static List<KBHandle> asHandles(Repository aRepo, SPARQLQuery aBuilder)
{
    try (RepositoryConnection conn = aRepo.getConnection()) {
        printQuery(aBuilder);
        
        long startTime = System.currentTimeMillis();

        List<KBHandle> results = aBuilder.asHandles(conn, true);

        System.out.printf("Results : %d in %dms%n", results.size(),
                System.currentTimeMillis() - startTime);
        results.stream().limit(10).forEach(r -> System.out.printf("          %s%n", r));
        if (results.size() > 10) {
            System.out.printf("          ... and %d more ...%n", results.size() - 10);
        }
        
        return results;
    }
    catch (MalformedQueryException e) {
        throw handleParseException(aBuilder, e);
    }
}
 
Example #14
Source File: SPARQLQueryBuilderAsserts.java    From inception with Apache License 2.0 6 votes vote down vote up
public static void assertThatChildrenOfExplicitRootCanBeRetrieved(KnowledgeBase aKB,
        Repository aRepository, String aRootClass)
{
    List<KBHandle> results = asHandles(aRepository, SPARQLQueryBuilder
            .forClasses(aKB)
            .childrenOf(aRootClass)
            .retrieveLabel()
            .retrieveDescription());
    
    assertThat(results).isNotEmpty();
    
    assertThat(results).allMatch(_child -> {
        try (RepositoryConnection conn = aRepository.getConnection()) {
            return SPARQLQueryBuilder.forClasses(aKB).parentsOf(_child.getIdentifier())
                    .asHandles(conn, true)
                    .stream()
                    .map(KBHandle::getIdentifier)
                    .anyMatch(iri -> iri.equals(aRootClass));
        }
    });
}
 
Example #15
Source File: SPARQLUpdateTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Creates, initializes and clears a repository.
 *
 * @return an initialized empty repository.
 * @throws Exception
 */
protected Repository createRepository() throws Exception {
	Repository repository = newRepository();
	repository.initialize();
	RepositoryConnection con = repository.getConnection();
	con.clear();
	con.clearNamespaces();
	con.close();
	return repository;
}
 
Example #16
Source File: Close.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Close repository
 *
 * @param verbose print more information
 */
protected void closeRepository(final boolean verbose) {
	final Repository repository = this.state.getRepository();

	if (repository == null) {
		if (verbose) {
			writeln("There are no open repositories that can be closed");
		}
	} else {
		writeln("Closing repository '" + this.state.getRepositoryID() + "'...");
		this.state.setRepository(null);
		this.state.setRepositoryID(null);
	}
}
 
Example #17
Source File: SemagrowSailFactory.java    From semagrow with Apache License 2.0 5 votes vote down vote up
public void initializeMetadata( Repository metadata, List<String> files )
{
    for( String file : files ) {
        try { initializeMetadata(metadata, file); }
        catch( IOException | RDFParseException | RepositoryException ex ) {
            logger.warn( "Failed reading default metadata from file {}: ", ex.getMessage() );
        }
    }
}
 
Example #18
Source File: NoReificationTest.java    From inception with Apache License 2.0 5 votes vote down vote up
public List<KBStatement> listStatements(Repository aRepo, KBHandle aItem)
    throws Exception
{
    try (RepositoryConnection conn = aRepo.getConnection()) {
        long startTime = System.currentTimeMillis();
  
        List<KBStatement> results = sut.listStatements(conn, kb, aItem, true);
  
        System.out.printf("Results : %d in %dms%n", results.size(),
                System.currentTimeMillis() - startTime);
        results.forEach(r -> System.out.printf("          %s%n", r));
  
        return results;
    }
}
 
Example #19
Source File: WorkbenchServlet.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void service(final String repoID, final HttpServletRequest req, final HttpServletResponse resp)
		throws RepositoryConfigException, RepositoryException, ServletException, IOException {
	LOGGER.info("Servicing repository: {}", repoID);
	setCredentials(req, resp);
	final DynamicHttpRequest http = new DynamicHttpRequest(req);
	final String path = req.getPathInfo();
	final int idx = path.indexOf(repoID) + repoID.length();
	http.setServletPath(http.getServletPath() + path.substring(0, idx));
	final String pathInfo = path.substring(idx);
	http.setPathInfo(pathInfo.length() == 0 ? null : pathInfo);
	if (repositories.containsKey(repoID)) {
		repositories.get(repoID).service(http, resp);
	} else {
		final Repository repository = manager.getRepository(repoID);
		if (repository == null) {
			final String noId = config.getInitParameter(NO_REPOSITORY);
			if (noId == null || !noId.equals(repoID)) {
				resp.setHeader("Cache-Control", "no-cache, no-store");
				throw new BadRequestException("No such repository: " + repoID);
			}
		}
		final ProxyRepositoryServlet servlet = new ProxyRepositoryServlet();
		servlet.setRepositoryManager(manager);
		if (repository != null) {
			servlet.setRepositoryInfo(manager.getRepositoryInfo(repoID));
			servlet.setRepository(repository);
		}
		servlet.init(new BasicServletConfig(repoID, config));
		repositories.putIfAbsent(repoID, servlet);
		repositories.get(repoID).service(http, resp);
	}
}
 
Example #20
Source File: AbstractFederationConnection.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private TupleExpr optimize(TupleExpr parsed, Dataset dataset, BindingSet bindings, boolean includeInferred,
		EvaluationStrategy strategy) throws SailException {
	LOGGER.trace("Incoming query model:\n{}", parsed);

	// Clone the tuple expression to allow for more aggressive optimisations
	TupleExpr query = new QueryRoot(parsed.clone());

	new BindingAssigner().optimize(query, dataset, bindings);
	new ConstantOptimizer(strategy).optimize(query, dataset, bindings);
	new CompareOptimizer().optimize(query, dataset, bindings);
	new ConjunctiveConstraintSplitter().optimize(query, dataset, bindings);
	new DisjunctiveConstraintOptimizer().optimize(query, dataset, bindings);
	new SameTermFilterOptimizer().optimize(query, dataset, bindings);
	new QueryModelPruner().optimize(query, dataset, bindings);

	new QueryMultiJoinOptimizer().optimize(query, dataset, bindings);
	// new FilterOptimizer().optimize(query, dataset, bindings);

	// prepare bloom filters
	RepositoryBloomFilter defaultBloomFilter = new AccurateRepositoryBloomFilter(includeInferred);
	Map<Repository, RepositoryBloomFilter> bloomFilters = federation.getBloomFilters();
	java.util.function.Function<Repository, RepositoryBloomFilter> bloomFilterFunction = c -> bloomFilters
			.getOrDefault(c, defaultBloomFilter);

	new EmptyPatternOptimizer(members, bloomFilterFunction).optimize(query, dataset, bindings);
	boolean distinct = federation.isDistinct();
	PrefixHashSet local = federation.getLocalPropertySpace();
	new FederationJoinOptimizer(members, distinct, local, bloomFilterFunction).optimize(query, dataset, bindings);
	new OwnedTupleExprPruner().optimize(query, dataset, bindings);
	new QueryModelPruner().optimize(query, dataset, bindings);
	new QueryMultiJoinOptimizer().optimize(query, dataset, bindings);

	new PrepareOwnedTupleExpr().optimize(query, dataset, bindings);

	LOGGER.trace("Optimized query model:\n{}", query);
	return query;
}
 
Example #21
Source File: RepositoryUtil.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Compares the models in the default contexts of the two supplied repositories and returns true if they are equal.
 * Models are equal if they contain the same set of statements. bNodes IDs are not relevant for model equality, they
 * are mapped from one model to the other by using the attached properties. Note that the method pulls the entire
 * default context of both repositories into main memory. Use with caution.
 */
public static boolean equals(Repository rep1, Repository rep2) throws RepositoryException {
	// Fetch statements from rep1 and rep2
	Set<Statement> model1, model2;

	try (RepositoryConnection con1 = rep1.getConnection()) {
		model1 = Iterations.asSet(con1.getStatements(null, null, null, true));
	}

	try (RepositoryConnection con2 = rep2.getConnection()) {
		model2 = Iterations.asSet(con2.getStatements(null, null, null, true));
	}

	return Models.isomorphic(model1, model2);
}
 
Example #22
Source File: ContextAwareConnection.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public ContextAwareConnection(Repository repository, RepositoryConnection connection) throws RepositoryException {
	super(repository, connection);
	ContextAwareConnection next = null;
	RepositoryConnection up = connection;
	while (up instanceof RepositoryConnectionWrapper) {
		if (up instanceof ContextAwareConnection) {
			next = (ContextAwareConnection) up;
			break;
		} else {
			up = ((RepositoryConnectionWrapper) up).getDelegate();
		}
	}
	this.next = next;
}
 
Example #23
Source File: Load.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Get context as resource
 *
 * @param repository
 * @param context
 * @return array of size one, or null
 */
private Resource[] getContexts(Repository repository, String context) {
	Resource[] contexts = new Resource[0];
	if (context != null) {
		Resource contextURI;
		if (context.startsWith("_:")) {
			contextURI = repository.getValueFactory().createBNode(context.substring(2));
		} else {
			contextURI = repository.getValueFactory().createIRI(context);
		}
		contexts = new Resource[] { contextURI };
	}
	return contexts;
}
 
Example #24
Source File: SPARQLEmbeddedServer.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void stop() throws Exception {
	Repository systemRepo = new HTTPRepository(Protocol.getRepositoryLocation(getServerUrl(), SystemRepository.ID));
	RepositoryConnection con = systemRepo.getConnection();
	try {
		con.clear();
	} finally {
		con.close();
		systemRepo.shutDown();
	}

	jetty.stop();
	System.clearProperty("org.mortbay.log.class");
}
 
Example #25
Source File: HBaseRepositoryManager.java    From Halyard with Apache License 2.0 5 votes vote down vote up
private Repository createRepositoryStack(RepositoryImplConfig config) throws RepositoryConfigException {
    RepositoryFactory factory = RepositoryRegistry.getInstance()
        .get(config.getType())
        .orElseThrow(() -> new RepositoryConfigException("Unsupported repository type: " + config.getType()));
    Repository repository = factory.getRepository(config);
    if (repository instanceof RepositoryResolverClient) {
        ((RepositoryResolverClient) repository).setRepositoryResolver(this);
    }
    if (repository instanceof FederatedServiceResolverClient) {
        ((FederatedServiceResolverClient) repository).setFederatedServiceResolver(getFederatedServiceResolver());
    }
    if (repository instanceof SessionManagerDependent) {
        ((SessionManagerDependent) repository).setHttpClientSessionManager(client);
    } else if (repository instanceof HttpClientDependent) {
        ((HttpClientDependent) repository).setHttpClient(getHttpClient());
    }
    if (config instanceof DelegatingRepositoryImplConfig) {
        RepositoryImplConfig delegateConfig = ((DelegatingRepositoryImplConfig) config).getDelegate();
        Repository delegate = createRepositoryStack(delegateConfig);
        try {
            ((DelegatingRepository) repository).setDelegate(delegate);
        } catch (ClassCastException e) {
            throw new RepositoryConfigException("Delegate specified for repository that is not a DelegatingRepository: " + delegate.getClass(), e);
        }
    }
    return repository;
}
 
Example #26
Source File: RepositoryManager.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Gets the repository that is known by the specified ID from this manager.
 *
 * @param identity A repository ID.
 * @return An initialized Repository object, or <tt>null</tt> if no repository was known for the specified ID.
 * @throws RepositoryConfigException If no repository could be created due to invalid or incomplete configuration
 *                                   data.
 */
@Override
public Repository getRepository(String identity) throws RepositoryConfigException, RepositoryException {
	synchronized (initializedRepositories) {
		updateInitializedRepositories();
		Repository result = initializedRepositories.get(identity);

		if (result != null && !result.isInitialized()) {
			// repository exists but has been shut down. throw away the old
			// object so we can re-read from the config.
			initializedRepositories.remove(identity);
			result = null;
		}

		if (result == null && SystemRepository.ID.equals(identity)) {
			result = getSystemRepository();
		}
		if (result == null) {
			// First call (or old object thrown away), create and initialize the
			// repository.
			result = createRepository(identity);

			if (result != null) {
				initializedRepositories.put(identity, result);
			}
		}

		return result;
	}
}
 
Example #27
Source File: DatasetRepository.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void setDelegate(Repository delegate) {
	if (delegate instanceof SailRepository) {
		super.setDelegate(delegate);
	} else {
		throw new IllegalArgumentException("delegate must be a SailRepository, is: " + delegate.getClass());
	}
}
 
Example #28
Source File: AbstractQueryController.java    From semagrow with Apache License 2.0 5 votes vote down vote up
private RepositoryConnection getRepositoryConnection(HttpServletRequest request) {

        if (connection == null) {
            Repository repository = getRepository(request);
            connection = repository.getConnection();
        }

        return connection;
    }
 
Example #29
Source File: HBaseRepositoryManager.java    From Halyard with Apache License 2.0 5 votes vote down vote up
@Override
protected Repository createRepository(String id) throws RepositoryConfigException, RepositoryException {
    Repository repository = null;
    RepositoryConfig repConfig = getRepositoryConfig(id);
    if (repConfig != null) {
        repConfig.validate();
        repository = createRepositoryStack(repConfig.getRepositoryImplConfig());
        repository.init();
    }
    return repository;
}
 
Example #30
Source File: SchemaCachingRDFSInferencerRDFSchemaMemoryRepositoryConnectionTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected Repository createRepository() {
	SchemaCachingRDFSInferencer sail = new SchemaCachingRDFSInferencer(new MemoryStore(), true);
	sail.setAddInferredStatementsToDefaultContext(false);

	return new SailRepository(sail);
}