org.openrdf.repository.Repository Java Examples

The following examples show how to use org.openrdf.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: GraphHandler.java    From cumulusrdf with Apache License 2.0 6 votes vote down vote up
/**
 * Delete data from the graph.
 * 
 * @param repository the Repository object
 * @param request the HttpServletRequest object
 * @param response the HttpServletResponse object
 * @return the EmptySuccessView if successes
 * @throws ClientHTTPException throws when there are errors in getting the name of the Graph
 * @throws ServerHTTPException throws when errors happens update the data
 */
private ModelAndView getDeleteDataResult(final Repository repository,
		final HttpServletRequest request, final HttpServletResponse response)
		throws ClientHTTPException, ServerHTTPException {
	ProtocolUtil.logRequestParameters(request);

	ValueFactory vf = repository.getValueFactory();

	URI graph = getGraphName(request, vf);

	try {
		RepositoryConnection repositoryCon = repository.getConnection();
		synchronized (repositoryCon) {
			repositoryCon.clear(graph);
		}
		repositoryCon.close();
		return new ModelAndView(EmptySuccessView.getInstance());
	} catch (RepositoryException e) {
		throw new ServerHTTPException("Repository update error: " + e.getMessage(), e);
	}
}
 
Example #2
Source File: LoadPdb.java    From database with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
		File file = new File("tmp-1Y26.jnl");

		Properties properties = new Properties();
		properties.setProperty(BigdataSail.Options.FILE, file.getAbsolutePath());

		BigdataSail sail = new BigdataSail(properties);
		Repository repo = new BigdataSailRepository(sail);
		repo.initialize();

        if(false) {
        sail.getDatabase().getDataLoader().loadData(
                "contrib/src/problems/alex/1Y26.rdf",
                new File("contrib/src/problems/alex/1Y26.rdf").toURI()
                        .toString(), RDFFormat.RDFXML);
        sail.getDatabase().commit();
        }
        
//		loadSomeDataFromADocument(repo, "contrib/src/problems/alex/1Y26.rdf");
		// readSomeData(repo);
		executeSelectQuery(repo, "SELECT * WHERE { ?s ?p ?o }");
	}
 
Example #3
Source File: SampleBlazegraphSesameEmbedded.java    From blazegraph-samples with GNU General Public License v2.0 6 votes vote down vote up
public static TupleQueryResult executeSelectQuery(final Repository repo, final String query,
		final QueryLanguage ql) throws OpenRDFException  {

	RepositoryConnection cxn;
	if (repo instanceof BigdataSailRepository) {
		cxn = ((BigdataSailRepository) repo).getReadOnlyConnection();
	} else {
		cxn = repo.getConnection();
	}

	try {

		final TupleQuery tupleQuery = cxn.prepareTupleQuery(ql, query);
		tupleQuery.setIncludeInferred(true /* includeInferred */);
		return tupleQuery.evaluate();
		
	} finally {
		// close the repository connection
		cxn.close();
	}
}
 
Example #4
Source File: BigdataRepositoryFactory.java    From database with GNU General Public License v2.0 6 votes vote down vote up
public Repository getRepository(final RepositoryImplConfig config)
	throws RepositoryConfigException {

	if (!TYPE.equals(config.getType())) {
		throw new RepositoryConfigException(
                   "Invalid type: " + config.getType());
	}
	
	if (!(config instanceof BigdataRepositoryConfig)) {
		throw new RepositoryConfigException(
                   "Invalid type: " + config.getClass());
	}
	
       try {
           
		final BigdataRepositoryConfig bigdataConfig = (BigdataRepositoryConfig)config;
		final Properties properties = bigdataConfig.getProperties();
   		final BigdataSail sail = new BigdataSail(properties);
   		return new BigdataSailRepository(sail);
           
       } catch (Exception ex) {
           throw new RepositoryConfigException(ex);
       }
       
}
 
Example #5
Source File: SPARQLQueryTest.java    From database with GNU General Public License v2.0 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().createURI(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 #6
Source File: BigdataSparqlTest.java    From database with GNU General Public License v2.0 6 votes vote down vote up
@Override
    protected Repository newRepository() throws RepositoryException {

        if (true) {
            final Properties props = getProperties();
            
            if (cannotInlineTests.contains(testURI)){
            	// The test can not be run using XSD inlining.
                props.setProperty(Options.INLINE_XSD_DATATYPE_LITERALS, "false");
            	props.setProperty(Options.INLINE_DATE_TIMES, "false");
            }
            
            if(unicodeStrengthIdentical.contains(testURI)) {
            	// Force identical Unicode comparisons.
            	props.setProperty(Options.COLLATOR, CollatorEnum.JDK.toString());
            	props.setProperty(Options.STRENGTH, StrengthEnum.Identical.toString());
            }
            
            final BigdataSail sail = new BigdataSail(props);
//            return new DatasetRepository(new BigdataSailRepository(sail));
            return new BigdataSailRepository(sail);
        } else {
            return new DatasetRepository(new SailRepository(new MemoryStore()));
        }
    }
 
Example #7
Source File: SPARQLUpdateConformanceTest.java    From database with GNU General Public License v2.0 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().createURI(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 #8
Source File: GraphHandler.java    From cumulusrdf with Apache License 2.0 6 votes vote down vote up
/**
 * Get all statements and export them as RDF.
 * 
 * @param repository the Repository object
 * @param request the HttpServletRequest object
 * @param response the HttpServletResponse object
 * @return a model and view for exporting the statements.
 * @throws ClientHTTPException throws when errors in parameters 
 */
private ModelAndView getExportStatementsResult(final Repository repository, final HttpServletRequest request,
		final HttpServletResponse response)
		throws ClientHTTPException {
	ProtocolUtil.logRequestParameters(request);

	ValueFactory vf = repository.getValueFactory();

	URI graph = getGraphName(request, vf);

	RDFWriterFactory rdfWriterFactory = ProtocolUtil.getAcceptableService(request, response,
			RDFWriterRegistry.getInstance());

	Map<String, Object> model = new HashMap<String, Object>();

	model.put(ExportStatementsView.CONTEXTS_KEY, new Resource[] { graph });
	model.put(ExportStatementsView.FACTORY_KEY, rdfWriterFactory);
	model.put(ExportStatementsView.USE_INFERENCING_KEY, true);
	model.put(ExportStatementsView.HEADERS_ONLY, METHOD_HEAD.equals(request.getMethod()));
	return new ModelAndView(ExportStatementsView.getInstance(), model);
}
 
Example #9
Source File: TripleStoreBlazegraph.java    From powsybl-core with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void add(TripleStore source) {
    Objects.requireNonNull(source);
    Repository sourceRepository;
    if (source instanceof TripleStoreBlazegraph) {
        sourceRepository = ((TripleStoreBlazegraph) source).repo;
        RepositoryConnection sourceConn = null;
        try {
            sourceConn = sourceRepository.getConnection();
            copyFrom(sourceConn);
        } catch (RepositoryException e) {
            LOG.error("Connecting to the source repository : {}", e.getMessage());
        } finally {
            if (sourceConn != null) {
                closeConnection(sourceConn, "Copying from source");
            }
        }
    } else {
        throw new TripleStoreException(String.format("Add to %s from source %s is not supported",
            getImplementationName(), source.getImplementationName()));
    }
}
 
Example #10
Source File: NamespaceHandler.java    From cumulusrdf with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param repository the Repository object
 * @param request the HttpServletRequest object
 * @param prefix the prefix
 * @return the SimpleResponseView which will return the namesapce
 * @throws ServerHTTPException throws when there is error about the repository
 * @throws ClientHTTPException throws when there is undefined prefix
 */
private ModelAndView getExportNamespaceResult(final Repository repository, final HttpServletRequest request, final String prefix)
		throws ServerHTTPException, ClientHTTPException {
	try {
		String namespace = null;

		RepositoryConnection repositoryCon = repository.getConnection();
		synchronized (repositoryCon) {
			namespace = repositoryCon.getNamespace(prefix);
		}

		if (namespace == null) {
			throw new ClientHTTPException(SC_NOT_FOUND, "Undefined prefix: " + prefix);
		}

		Map<String, Object> model = new HashMap<String, Object>();
		model.put(SimpleResponseView.CONTENT_KEY, namespace);
		repositoryCon.close();
		return new ModelAndView(SimpleResponseView.getInstance(), model);
	} catch (RepositoryException e) {
		throw new ServerHTTPException("Repository error: " + e.getMessage(), e);
	}
}
 
Example #11
Source File: ListTest.java    From anno4j with Apache License 2.0 6 votes vote down vote up
private int getSize(Repository repository) throws RepositoryException {
	int size = 0;
	RepositoryConnection connection = null;
	RepositoryResult<Statement> iter = null;
	try {
		connection = repository.getConnection();
		iter = connection.getStatements(null, null, null, false);
		while (iter.hasNext()) {
			iter.next();
			++size;
		}
	} finally {
		if (iter != null)
			iter.close();
		if (connection != null)
			connection.close();
	}
	return size;
}
 
Example #12
Source File: SPARQLUpdateTestv2.java    From database with GNU General Public License v2.0 5 votes vote down vote up
protected Repository newRepository() throws RepositoryException {

        final Properties props = getProperties();
        
        final BigdataSail sail = new BigdataSail(props);
        
        backend = sail.getIndexManager();

        return new BigdataSailRepository(sail);

//        if (true) {
//            final Properties props = getProperties();
//            
//            if (cannotInlineTests.contains(testURI)){
//                // The test can not be run using XSD inlining.
//                props.setProperty(Options.INLINE_XSD_DATATYPE_LITERALS, "false");
//                props.setProperty(Options.INLINE_DATE_TIMES, "false");
//            }
//            
//            if(unicodeStrengthIdentical.contains(testURI)) {
//                // Force identical Unicode comparisons.
//                props.setProperty(Options.COLLATOR, CollatorEnum.JDK.toString());
//                props.setProperty(Options.STRENGTH, StrengthEnum.Identical.toString());
//            }
//            
//            final BigdataSail sail = new BigdataSail(props);
//            return new DatasetRepository(new BigdataSailRepository(sail));
//        } else {
//            return new DatasetRepository(new SailRepository(new MemoryStore()));
//        }

    }
 
Example #13
Source File: SPARQLQueryTest.java    From database with GNU General Public License v2.0 5 votes vote down vote up
protected Repository createRepository()
	throws Exception
{
	Repository repo = newRepository();
	repo.initialize();
	RepositoryConnection con = repo.getConnection();
	try {
		con.clear();
		con.clearNamespaces();
	}
	finally {
		con.close();
	}
	return repo;
}
 
Example #14
Source File: SPARQLUpdateTest.java    From database with GNU General Public License v2.0 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 #15
Source File: RepositoryModelSet.java    From semweb4j with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void setUnderlyingModelSetImplementation(Repository repository) {
	// get rid of any connections
	boolean open = this.isOpen();
	if(open) {
		this.close();
	}
	
	// setup access to the new repository
	this.init(repository);
	
	// make sure the ModelSet is in the same "opened" state as before
	if(open) {
		this.open();
	}
}
 
Example #16
Source File: BigdataSPARQLUpdateTest.java    From database with GNU General Public License v2.0 5 votes vote down vote up
@Override
    protected Repository newRepository() throws RepositoryException {

        final Properties props = getProperties();
        
        final BigdataSail sail = new BigdataSail(props);
        
        backend = sail.getIndexManager();

        return new BigdataSailRepository(sail);

//        if (true) {
//            final Properties props = getProperties();
//            
//            if (cannotInlineTests.contains(testURI)){
//                // The test can not be run using XSD inlining.
//                props.setProperty(Options.INLINE_XSD_DATATYPE_LITERALS, "false");
//                props.setProperty(Options.INLINE_DATE_TIMES, "false");
//            }
//            
//            if(unicodeStrengthIdentical.contains(testURI)) {
//                // Force identical Unicode comparisons.
//                props.setProperty(Options.COLLATOR, CollatorEnum.JDK.toString());
//                props.setProperty(Options.STRENGTH, StrengthEnum.Identical.toString());
//            }
//            
//            final BigdataSail sail = new BigdataSail(props);
//            return new DatasetRepository(new BigdataSailRepository(sail));
//        } else {
//            return new DatasetRepository(new SailRepository(new MemoryStore()));
//        }

    }
 
Example #17
Source File: BigdataFederationSparqlTest.java    From database with GNU General Public License v2.0 5 votes vote down vote up
protected BigdataSailRepositoryConnection getQueryConnection(Repository dataRep)
			throws Exception {
		// return dataRep.getConnection();
		final BigdataSailRepositoryConnection con = new BigdataSailRepositoryConnection(new BigdataSailRepository(
				_sail), _sail.getReadOnlyConnection());
//		System.err.println(_sail.getDatabase().dumpStore());
		return con;
	}
 
Example #18
Source File: RepositoryModel.java    From semweb4j with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public RepositoryModel(URI context, Repository repository) throws ModelRuntimeException {
	if(repository == null) {
		throw new IllegalArgumentException("Repository cannot be null");
	}
	
	this.repository = repository;
	this.context = context;
	init();
}
 
Example #19
Source File: SPARQLUpdateConformanceTest.java    From database with GNU General Public License v2.0 5 votes vote down vote up
protected Repository createRepository()
	throws Exception
{
	Repository repo = newRepository();
	repo.initialize();
	RepositoryConnection con = repo.getConnection();
	try {
		con.clear();
		con.clearNamespaces();
	}
	finally {
		con.close();
	}
	return repo;
}
 
Example #20
Source File: RepositoryHandler.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
/**
 * @param repository the Repository object
 * @param graphURI the String the graphURI to be created
 * @return the created URI for the input graphURI
 */
private URI createURIOrNull(final Repository repository, final String graphURI) {
	if ("null".equals(graphURI)) {
		return null;
	}
	return repository.getValueFactory().createURI(graphURI);
}
 
Example #21
Source File: SampleCode.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Execute a "construct" query.
 * 
 * @param repo
 * @param query
 * @param ql
 * @throws Exception
 */
public void executeConstructQuery(Repository repo, String query, 
    QueryLanguage ql) throws Exception {
    
    /*
     * With MVCC, you read from a historical state to avoid blocking and
     * being blocked by writers.  BigdataSailRepository.getQueryConnection
     * gives you a view of the repository at the last commit point.
     */
    RepositoryConnection cxn;
    if (repo instanceof BigdataSailRepository) { 
        cxn = ((BigdataSailRepository) repo).getReadOnlyConnection();
    } else {
        cxn = repo.getConnection();
    }
    
    try {

        // silly construct queries, can't guarantee distinct results
        final Set<Statement> results = new LinkedHashSet<Statement>();
        final GraphQuery graphQuery = cxn.prepareGraphQuery(ql, query);
        graphQuery.setIncludeInferred(true /* includeInferred */);
        graphQuery.evaluate(new StatementCollector(results));
        // do something with the results
        for (Statement stmt : results) {
            log.info(stmt);
        }

    } finally {
        // close the repository connection
        cxn.close();
    }
    
}
 
Example #22
Source File: SampleCode.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Execute a "select" query.
 * 
 * @param repo
 * @param query
 * @param ql
 * @throws Exception
 */
public void executeSelectQuery(Repository repo, String query, 
    QueryLanguage ql) throws Exception {
    
    /*
     * With MVCC, you read from a historical state to avoid blocking and
     * being blocked by writers.  BigdataSailRepository.getQueryConnection
     * gives you a view of the repository at the last commit point.
     */
    RepositoryConnection cxn;
    if (repo instanceof BigdataSailRepository) { 
        cxn = ((BigdataSailRepository) repo).getReadOnlyConnection();
    } else {
        cxn = repo.getConnection();
    }
    
    try {

        final TupleQuery tupleQuery = cxn.prepareTupleQuery(ql, query);
        tupleQuery.setIncludeInferred(true /* includeInferred */);
        TupleQueryResult result = tupleQuery.evaluate();
        // do something with the results
        while (result.hasNext()) {
            BindingSet bindingSet = result.next();
            log.info(bindingSet);
        }
        
    } finally {
        // close the repository connection
        cxn.close();
    }
    
}
 
Example #23
Source File: ContextsHandler.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
@Override
public ModelAndView serve(final Repository repository, final HttpServletRequest request, final HttpServletResponse response)
		throws Exception {
	Map<String, Object> model = new HashMap<String, Object>();
	TupleQueryResultWriterFactory factory = ProtocolUtil.getAcceptableService(request, response,
			TupleQueryResultWriterRegistry.getInstance());

	if (METHOD_GET.equals(request.getMethod())) {
		List<String> columnNames = Arrays.asList("contextID");
		List<BindingSet> contexts = new ArrayList<BindingSet>();
		RepositoryConnection repositoryCon = repository.getConnection();
		synchronized (repositoryCon) {
			try {
				CloseableIteration<? extends Resource, RepositoryException> contextIter = repositoryCon.getContextIDs();

				try {
					while (contextIter.hasNext()) {
						BindingSet bindingSet = new ListBindingSet(columnNames, contextIter.next());
						contexts.add(bindingSet);
					}
				} finally {
					contextIter.close();
				}
			} catch (RepositoryException e) {
				throw new ServerHTTPException("Repository error: " + e.getMessage(), e);
			}
		}
		model.put(QueryResultView.QUERY_RESULT_KEY, new TupleQueryResultImpl(columnNames, contexts));
	}

	model.put(QueryResultView.FILENAME_HINT_KEY, "contexts");
	model.put(QueryResultView.FACTORY_KEY, factory);
	model.put(QueryResultView.HEADERS_ONLY, METHOD_HEAD.equals(request.getMethod()));
	return new ModelAndView(TupleQueryResultView.getInstance(), model);
}
 
Example #24
Source File: NamespacesHandler.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
/**
 * clear the namespaces
 * 
 * @param repository the Repository object
 * @param request the HttpServletRequest object 
 * @param response the HttpServletResponse oject
 * @return EmptySuccessView object if success
 * @throws ServerHTTPException throws when errors in repository
 * @throws RepositoryException throws when errors in closing the RepositoryConnection 
 */
private ModelAndView getClearNamespacesResult(final Repository repository, final HttpServletRequest request, final HttpServletResponse response)
		throws ServerHTTPException, RepositoryException {
	RepositoryConnection repositoryCon = repository.getConnection();
	synchronized (repositoryCon) {
		try {
			repositoryCon.clearNamespaces();
		} catch (RepositoryException e) {
			throw new ServerHTTPException("Repository error: " + e.getMessage(), e);
		}
	}
	repositoryCon.close();
	return new ModelAndView(EmptySuccessView.getInstance());
}
 
Example #25
Source File: StatementHandler.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
/**
 * Get all statements and export them as RDF.
 * 
 * @param repository the Repository object
 * @param request the HttpServletRequest object
 * @param response the HttpServletResponse object
 * @return a model and view for exporting the statements.
 * @throws ClientHTTPException throws when there errors in parsing the request
 */
private ModelAndView getExportStatementsResult(final Repository repository, final HttpServletRequest request,
		final HttpServletResponse response)
		throws ClientHTTPException {
	ProtocolUtil.logRequestParameters(request);

	ValueFactory vf = repository.getValueFactory();

	Resource subj = ProtocolUtil.parseResourceParam(request, SUBJECT_PARAM_NAME, vf);
	URI pred = ProtocolUtil.parseURIParam(request, PREDICATE_PARAM_NAME, vf);
	Value obj = ProtocolUtil.parseValueParam(request, OBJECT_PARAM_NAME, vf);
	Resource[] contexts = ProtocolUtil.parseContextParam(request, CONTEXT_PARAM_NAME, vf);
	boolean useInferencing = ProtocolUtil.parseBooleanParam(request, INCLUDE_INFERRED_PARAM_NAME, true);

	RDFWriterFactory rdfWriterFactory = ProtocolUtil.getAcceptableService(request, response,
			RDFWriterRegistry.getInstance());

	Map<String, Object> model = new HashMap<String, Object>();
	model.put(ExportStatementsView.SUBJECT_KEY, subj);
	model.put(ExportStatementsView.PREDICATE_KEY, pred);
	model.put(ExportStatementsView.OBJECT_KEY, obj);
	model.put(ExportStatementsView.CONTEXTS_KEY, contexts);
	model.put(ExportStatementsView.USE_INFERENCING_KEY, Boolean.valueOf(useInferencing));
	model.put(ExportStatementsView.FACTORY_KEY, rdfWriterFactory);
	model.put(ExportStatementsView.HEADERS_ONLY, METHOD_HEAD.equals(request.getMethod()));
	model.put(ExportStatementsView.REPO_KEY, repository);
	return new ModelAndView(ExportStatementsView.getInstance(), model);
}
 
Example #26
Source File: LoadPdb.java    From database with GNU General Public License v2.0 5 votes vote down vote up
public static void loadSomeDataFromADocument(Repository repo, String documentPath) throws Exception {
	int counter = 0;
	File file = new File(documentPath);
	StatementCollector collector = new StatementCollector();
	InputStream in = new FileInputStream(file);
	try {
           final RDFParser parser = RDFParserRegistry.getInstance()
                   .get(RDFFormat.RDFXML).getParser();
		parser.setRDFHandler(collector);
		parser.parse(in, file.toURI().toString());
	} finally {
		in.close();
	}

	RepositoryConnection cxn = repo.getConnection();
	cxn.setAutoCommit(false);

	Statement stmt = null;
	try {
		for (Iterator<Statement> i = collector.getStatements().iterator(); i.hasNext();) {
			stmt = i.next();
			cxn.add(stmt);
			counter++;
		}
		LOG.info("Loaded " + counter + " triples");
		cxn.commit();
	} catch (Exception e) {
		LOG.error("error inserting statement: " + stmt, e);
		cxn.rollback();
	} finally {
		cxn.close();
	}

}
 
Example #27
Source File: StatementHandler.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
@Override
public ModelAndView serve(final Repository repository, final HttpServletRequest request, final HttpServletResponse response)
		throws Exception {
	ModelAndView result;

	String reqMethod = request.getMethod();

	if (METHOD_GET.equals(reqMethod)) {
		_logger.info("GET statements");
		result = getExportStatementsResult(repository, request, response);
	} else if (METHOD_HEAD.equals(reqMethod)) {
		_logger.info("HEAD statements");
		result = getExportStatementsResult(repository, request, response);
	} else if (METHOD_POST.equals(reqMethod)) {
		String mimeType = HttpServerUtil.getMIMEType(request.getContentType());

		if (Protocol.TXN_MIME_TYPE.equals(mimeType)) {
			_logger.info("POST transaction to repository");
			result = getTransactionResultResult(repository, request, response);
		} else if (request.getParameterMap().containsKey(Protocol.UPDATE_PARAM_NAME)) {
			_logger.info("POST SPARQL update request to repository");
			result = getSparqlUpdateResult(repository, request, response);
		} else {
			_logger.info("POST data to repository");
			result = getAddDataResult(repository, request, response, false);
		}
	} else if ("PUT".equals(reqMethod)) {
		_logger.info("PUT data in repository");
		result = getAddDataResult(repository, request, response, false);
	} else if ("DELETE".equals(reqMethod)) {
		_logger.info("DELETE data from repository");
		result = getDeleteDataResult(repository, request, response);
	} else {
		throw new ClientHTTPException(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "Method not allowed: "
				+ reqMethod);
	}

	return result;
}
 
Example #28
Source File: ListTest.java    From anno4j with Apache License 2.0 5 votes vote down vote up
@Override
protected Repository getRepository() throws Exception {
	ObjectRepositoryFactory factory = new ObjectRepositoryFactory();
	ObjectRepositoryConfig config = factory.getConfig();
	config.addConcept(List.class);
	return factory.createRepository(config, super.getRepository());
}
 
Example #29
Source File: SesameUtils.java    From ldp4j with Apache License 2.0 5 votes vote down vote up
public static RepositoryConnection getConnection(Repository repository) throws SesameRepositoryFailure {
	Objects.requireNonNull(repository, "Repository cannot be null");
	if(!repository.isInitialized()) {
		throw new IllegalStateException("Template support has been disposed");
	}
	try {
		return repository.getConnection();
	} catch(RepositoryException e) {
		throw new SesameRepositoryFailure(COULD_NOT_CONNECT_TO_THE_REPOSITORY,e);
	}
}
 
Example #30
Source File: RepositoryManager.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
/**
 * Closes all the repositories.
 */
public void shutDownAll() {
	synchronized (_repoMap) {
		for (String id : _repoMap.keySet()) {
			Repository repo = _repoMap.remove(id);
			if (repo != null) {
				shutdown(repo);
			}
		}
		_repoMap.clear();
	}
}