Java源码示例:org.eclipse.rdf4j.repository.config.RepositoryImplConfig

示例1
@Transactional
@Override
public void registerKnowledgeBase(KnowledgeBase aKB, RepositoryImplConfig aCfg)
    throws RepositoryException, RepositoryConfigException
{
    // Obtain unique repository id
    String baseName = "pid-" + Long.toString(aKB.getProject().getId()) + "-kbid-";
    String repositoryId = repoManager.getNewRepositoryID(baseName);
    aKB.setRepositoryId(repositoryId);
    
    // We want to have a separate Lucene index for every local repo, so we need to hack the
    // index dir in here because this is the place where we finally know the repo ID.
    setIndexDir(aKB, aCfg);

    repoManager.addRepositoryConfig(new RepositoryConfig(repositoryId, aCfg));
    entityManager.persist(aKB);
}
 
示例2
private void reconfigureLocalKnowledgeBase(KnowledgeBase aKB)
{
    /*
    log.info("Forcing update of configuration for {}", aKB);
    Model model = new TreeModel();
    ValueFactory vf = SimpleValueFactory.getInstance();
    IRI root = vf
            .createIRI("http://inception-project.github.io/kbexport#" + aKB.getRepositoryId());
    repoManager.getRepositoryConfig(aKB.getRepositoryId()).export(model, root);
    StringWriter out = new StringWriter();
    Rio.write(model, out, RDFFormat.TURTLE);
    log.info("Current configuration: {}", out.toString());
    */
    
    RepositoryImplConfig config = getNativeConfig();
    setIndexDir(aKB, config);
    repoManager.addRepositoryConfig(new RepositoryConfig(aKB.getRepositoryId(), config));
}
 
示例3
private void setIndexDir(KnowledgeBase aKB, RepositoryImplConfig aCfg)
{
    assertRegistration(aKB);
    
    // We want to have a separate Lucene index for every local repo, so we need to hack the
    // index dir in here because this is the place where we finally know the repo ID.
    if (aCfg instanceof SailRepositoryConfig) {
        SailRepositoryConfig cfg = (SailRepositoryConfig) aCfg;
        if (cfg.getSailImplConfig() instanceof LuceneSailConfig) {
            LuceneSailConfig luceneSailCfg = (LuceneSailConfig) cfg.getSailImplConfig();
            luceneSailCfg.setIndexDir(
                    new File(kbRepositoriesRoot, "indexes/" + aKB.getRepositoryId())
                            .getAbsolutePath());
        }
    }
}
 
示例4
@BeforeClass
public static void setUpClass() throws Exception {
	System.setProperty("org.eclipse.rdf4j.repository.debug", "true");

	server = new HTTPMemServer();
	try {
		server.start();
	} catch (Exception e) {
		server.stop();
		throw e;
	}

	setRepositoryFactory(new HTTPRepositoryFactory() {

		@Override
		public RepositoryImplConfig getConfig() {
			return new HTTPRepositoryConfig(HTTPMemServer.REPOSITORY_URL);
		}

	});
}
 
示例5
@Override
public Repository getRepository(RepositoryImplConfig config) throws RepositoryConfigException {

	if (!(config instanceof FedXRepositoryConfig)) {
		throw new RepositoryConfigException("Unexpected configuration type: " + config.getClass());
	}

	FedXRepositoryConfig fedXConfig = (FedXRepositoryConfig) config;

	log.info("Configuring FedX for the RDF4J repository manager");

	// wrap the FedX Repository in order to allow lazy initialization
	// => RDF4J repository manager requires control over the repository instance
	// Note: data dir is handled by RDF4J repository manager and used as a
	// base directory.
	return new FedXRepositoryWrapper(fedXConfig);
}
 
示例6
@Test
public final void testGetRepository() throws RDF4JException, IOException {
	Model graph = Rio.parse(this.getClass().getResourceAsStream("/proxy.ttl"), RepositoryConfigSchema.NAMESPACE,
			RDFFormat.TURTLE);
	RepositoryConfig config = RepositoryConfig.create(graph,
			Models.subject(graph.getStatements(null, RDF.TYPE, RepositoryConfigSchema.REPOSITORY))
					.orElseThrow(() -> new RepositoryConfigException("missing Repository instance in config")));
	config.validate();
	assertThat(config.getID()).isEqualTo("proxy");
	assertThat(config.getTitle()).isEqualTo("Test Proxy for 'memory'");
	RepositoryImplConfig implConfig = config.getRepositoryImplConfig();
	assertThat(implConfig.getType()).isEqualTo("openrdf:ProxyRepository");
	assertThat(implConfig).isInstanceOf(ProxyRepositoryConfig.class);
	assertThat(((ProxyRepositoryConfig) implConfig).getProxiedRepositoryID()).isEqualTo("memory");

	// Factory just needs a resolver instance to proceed with construction.
	// It doesn't actually invoke the resolver until the repository is
	// accessed. Normally LocalRepositoryManager is the caller of
	// getRepository(), and will have called this setter itself.
	ProxyRepository repository = (ProxyRepository) factory.getRepository(implConfig);
	repository.setRepositoryResolver(mock(RepositoryResolver.class));
	assertThat(repository).isInstanceOf(ProxyRepository.class);
}
 
示例7
@Override
public Repository getRepository(RepositoryImplConfig configuration) throws RepositoryConfigException {
	if (configuration instanceof ContextAwareConfig) {
		ContextAwareConfig config = (ContextAwareConfig) configuration;

		ContextAwareRepository repo = new ContextAwareRepository();

		repo.setIncludeInferred(config.isIncludeInferred());
		repo.setMaxQueryTime(config.getMaxQueryTime());
		repo.setQueryLanguage(config.getQueryLanguage());
		repo.setBaseURI(config.getBaseURI());
		repo.setReadContexts(config.getReadContexts());
		repo.setAddContexts(config.getAddContexts());
		repo.setRemoveContexts(config.getRemoveContexts());
		repo.setArchiveContexts(config.getArchiveContexts());
		repo.setInsertContext(config.getInsertContext());

		return repo;
	}

	throw new RepositoryConfigException("Invalid configuration class: " + configuration.getClass());
}
 
示例8
public Repository createMetadataRepository(RepositoryImplConfig config)
        throws RepositoryConfigException
{
    RepositoryRegistry registry = RepositoryRegistry.getInstance();
    RepositoryFactory factory = registry.get(config.getType()).get();

    if (factory != null) {
        if (factory instanceof RepositoryResolverClient) {
            ((RepositoryResolverClient)factory).setRepositoryResolver(repositoryResolver);
        }
        return factory.getRepository(config);
    }
    else {
        throw new RepositoryConfigException("Unable to find repository factory for type " + config.getType());
    }
}
 
示例9
public Repository getRepository(RepositoryImplConfig repositoryImplConfig)
        throws RepositoryConfigException {

    assert repositoryImplConfig instanceof SemagrowRepositoryConfig;

    SemagrowRepositoryConfig config = (SemagrowRepositoryConfig) repositoryImplConfig;
    Optional<SailFactory> sailFactory = SailRegistry.getInstance().get(config.getSemagrowSailConfig().getType());
    if (sailFactory.isPresent()) {

        try {

            SemagrowSail sail = (SemagrowSail) sailFactory.get().getSail(config.getSemagrowSailConfig());
            return new SemagrowSailRepository(sail);
        } catch (SailConfigException e) {
            throw new RepositoryConfigException(e);
        }
    }

    throw new RepositoryConfigException();
}
 
示例10
@Transactional
@Override
public void updateKnowledgeBase(KnowledgeBase kb, RepositoryImplConfig cfg)
    throws RepositoryException, RepositoryConfigException
{
    assertRegistration(kb);
    repoManager.addRepositoryConfig(new RepositoryConfig(kb.getRepositoryId(), cfg));
    entityManager.merge(kb);
}
 
示例11
@Override
public RepositoryImplConfig getNativeConfig()
{
    // See #221 - Disabled because it is too slow during import
    // return new SailRepositoryConfig(
    //   new ForwardChainingRDFSInferencerConfig(new NativeStoreConfig()));

    LuceneSailConfig config = new LuceneSailConfig(new NativeStoreConfig());
    // NOTE: We do not set the index dir here but when the KB is registered because we want each
    // repo to have its own index folder and we don't know the repo ID until it is registered
    return new SailRepositoryConfig(config);
}
 
示例12
@Override
public RepositoryImplConfig getKnowledgeBaseConfig(KnowledgeBase kb)
    throws RepositoryConfigException, RepositoryException
{
    assertRegistration(kb);
    return repoManager.getRepositoryConfig(kb.getRepositoryId()).getRepositoryImplConfig();
}
 
示例13
@Override
public void apply(CandidateEntity aCandidate)
{
    KnowledgeBase kb = aCandidate.getHandle().getKB();

    // For UKP Wikidata
    if (kb.getType() == REMOTE && FTS_VIRTUOSO.equals(kb.getFullTextSearchIri())) {
        RepositoryImplConfig cfg = kbService.getKnowledgeBaseConfig(kb);
        if (UKP_WIKIDATA_SPARQL_ENDPOINT
                .equals(((SPARQLRepositoryConfig) cfg).getQueryEndpointUrl())) {
            String wikidataId = aCandidate.getIRI().replace(PREFIX_WIKIDATA_ENTITY, "");
            aCandidate.put(KEY_ID_RANK, Math.log(Double.parseDouble(wikidataId.substring(1))));
        }
    }
}
 
示例14
@Override
public Repository getRepository(RepositoryImplConfig config) throws RepositoryConfigException {
    log.info("getting repository");
    try {
        if (config instanceof CostFedRepositoryConfig) {
            CostFedRepositoryConfig cfg = (CostFedRepositoryConfig)config;
            log.info("config: " + cfg.getConfigFile());
            return FedXFactory.initializeFederation(cfg.getConfigFile());
        }
        log.info("no repository");
        return null;
    } catch (Exception e) {
        throw new RepositoryConfigException(e.getMessage(), e);
    }
}
 
示例15
/**
 * Regression test for adding new repositories when legacy SYSTEM repository is still present See also GitHub issue
 * 1077
 */
@Test
public void testAddWithExistingSysRepository() {
	new File(datadir, "repositories/SYSTEM").mkdir();
	try {
		RepositoryImplConfig cfg = new SailRepositoryConfig(new MemoryStoreConfig());
		subject.addRepositoryConfig(new RepositoryConfig("test-01", cfg));
		subject.addRepositoryConfig(new RepositoryConfig("test-02", cfg));
	} catch (RepositoryConfigException e) {
		fail(e.getMessage());
	}
}
 
示例16
private void verifySuccess(boolean readonly, boolean distinct, String... memberTypes) throws Exception {
	assertThat(manager.hasRepositoryConfig(FED_ID)).isTrue();
	verify(mockConsoleIO, times(1)).readln("Federation Description (optional): ");
	verify(mockConsoleIO, times(1)).writeln("Federation created.");
	verify(mockConsoleIO, never()).writeError(anyString());
	assertThat(manager.getRepositoryInfo(FED_ID).getDescription()).isEqualTo(FED_DESCRIPTION);
	SailRepositoryConfig sailRepoConfig = (SailRepositoryConfig) manager.getRepositoryConfig(FED_ID)
			.getRepositoryImplConfig();
	FederationConfig fedSailConfig = (FederationConfig) sailRepoConfig.getSailImplConfig();
	assertThat(fedSailConfig.isReadOnly()).isEqualTo(readonly);
	assertThat(fedSailConfig.isDistinct()).isEqualTo(distinct);
	List<RepositoryImplConfig> members = fedSailConfig.getMembers();
	assertThat(members).hasSameSizeAs(memberTypes);
	int i = 0;
	for (RepositoryImplConfig ric : members) {
		String memberType = memberTypes[i];
		i++;
		assertThat(ric.getType()).isEqualTo(memberType);
		Class<? extends RepositoryImplConfig> implType;
		if (HTTPRepositoryFactory.REPOSITORY_TYPE.equals(memberType)) {
			implType = HTTPRepositoryConfig.class;
		} else if (SPARQLRepositoryFactory.REPOSITORY_TYPE.equals(memberType)) {
			implType = SPARQLRepositoryConfig.class;
		} else {
			implType = ProxyRepositoryConfig.class;
		}
		assertThat(ric).isInstanceOf(implType);
	}
}
 
示例17
@Override
public Repository getRepository(RepositoryImplConfig config) throws RepositoryConfigException {
	if (config instanceof ConfigurableSailRepositoryConfig) {
		ConfigurableSailRepositoryConfig sailRepConfig = (ConfigurableSailRepositoryConfig) config;

		try {
			Sail sail = createSailStack(sailRepConfig.getSailImplConfig());
			return new ConfigurableSailRepository(sail, true);
		} catch (SailConfigException e) {
			throw new RepositoryConfigException(e.getMessage(), e);
		}
	}

	throw new RepositoryConfigException("Invalid configuration class: " + config.getClass());
}
 
示例18
protected void addMemoryStoreWithRDFS(String repoId) throws Exception {

		RepositoryImplConfig implConfig = new SailRepositoryConfig(
				new SchemaCachingRDFSInferencerConfig(new MemoryStoreConfig()));
		RepositoryConfig config = new RepositoryConfig(repoId, implConfig);
		repoManager.addRepositoryConfig(config);
	}
 
示例19
@BeforeClass
public static void setUpClass() throws Exception {
	setRepositoryFactory(new SailRepositoryFactory() {
		@Override
		public RepositoryImplConfig getConfig() {
			return new SailRepositoryConfig(new NativeStoreFactory().getConfig());
		}
	});
}
 
示例20
@BeforeClass
public static void setUpClass() throws Exception {
	System.setProperty("org.eclipse.rdf4j.repository.debug", "true");
	setRepositoryFactory(new SailRepositoryFactory() {
		@Override
		public RepositoryImplConfig getConfig() {
			return new SailRepositoryConfig(new MemoryStoreFactory().getConfig());
		}
	});
}
 
示例21
@Override
public Resource export(Model model) {
	ValueFactory valueFactory = SimpleValueFactory.getInstance();
	Resource self = super.export(model);
	model.setNamespace("sf", NAMESPACE);
	for (RepositoryImplConfig member : getMembers()) {
		model.add(self, MEMBER, member.export(model));
	}
	for (String space : getLocalPropertySpace()) {
		model.add(self, LOCALPROPERTYSPACE, valueFactory.createIRI(space));
	}
	model.add(self, DISTINCT, valueFactory.createLiteral(distinct));
	model.add(self, READ_ONLY, valueFactory.createLiteral(readOnly));
	return self;
}
 
示例22
@Override
public void validate() throws SailConfigException {
	super.validate();
	if (members.isEmpty()) {
		throw new SailConfigException("No federation members specified");
	}
	for (RepositoryImplConfig member : members) {
		try {
			member.validate();
		} catch (RepositoryConfigException e) {
			throw new SailConfigException(e);
		}
	}
}
 
示例23
@Override
public Repository getRepository(RepositoryImplConfig config) throws RepositoryConfigException {
	if (config instanceof DatasetRepositoryConfig) {
		return new DatasetRepository();
	}

	throw new RepositoryConfigException("Invalid configuration class: " + config.getClass());
}
 
示例24
@Override
public Repository getRepository(RepositoryImplConfig config) throws RepositoryConfigException {
	ProxyRepository result = null;

	if (config instanceof ProxyRepositoryConfig) {
		result = new ProxyRepository(((ProxyRepositoryConfig) config).getProxiedRepositoryID());
	} else {
		throw new RepositoryConfigException("Invalid configuration class: " + config.getClass());
	}
	return result;
}
 
示例25
@Override
public Repository getRepository(RepositoryImplConfig config) throws RepositoryConfigException {
	if (config instanceof SailRepositoryConfig) {
		SailRepositoryConfig sailRepConfig = (SailRepositoryConfig) config;

		try {
			Sail sail = createSailStack(sailRepConfig.getSailImplConfig());
			return new SailRepository(sail);
		} catch (SailConfigException e) {
			throw new RepositoryConfigException(e.getMessage(), e);
		}
	}

	throw new RepositoryConfigException("Invalid configuration class: " + config.getClass());
}
 
示例26
private Repository createDelegate() {
	RepositoryConfig repoConfig = getSystemConfig();
	if (repoConfig == null) {
		throw new RepositoryConfigException("Could not find SYSTEM configuration");
	}
	repoConfig.validate();
	RepositoryImplConfig config = repoConfig.getRepositoryImplConfig();
	RepositoryFactory factory = RepositoryRegistry.getInstance()
			.get(config.getType())
			.orElseThrow(
					() -> new RepositoryConfigException("Repository type not in classpath: " + config.getType()));
	return factory.getRepository(config);
}
 
示例27
/**
 * Creates the stack of Repository objects for the repository represented by the specified
 * {@link org.eclipse.rdf4j.repository.config.RepositoryImplConfig}. Uses a
 * {@link org.eclipse.rdf4j.repository.config.RepositoryFactory} to create the repository and initialize it.
 *
 * @param config The node representing the to-be-created repository in the configuration.
 * @return The created repository, or <tt>null</tt> if no such repository exists.
 * @throws RepositoryConfigException If no repository could be created due to invalid or incomplete configuration
 *                                   data.
 */
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;
}
 
示例28
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;
}
 
示例29
private static RepositoryImplConfig getConfig() {
    RyaAccumuloSailConfig c = new RyaAccumuloSailConfig();
    c.setUser("root");
    c.setPassword("");
    c.setInstance("mock-instance");
    c.setMock(true);
    return new SailRepositoryConfig(c);
}
 
示例30
public RepositoryImplConfig getMetadataConfig() {
    /*
    SailImplConfig sailConfig = new SEVODInferencerConfig(
                                    new ForwardChainingRDFSInferencerConfig(
                                        new MemoryStoreConfig()));


    return new SailRepositoryConfig(sailConfig);
    */
    return new ProxyRepositoryConfig("semagrow_metadata");
}