当前位置: 首页>>代码示例>>Java>>正文


Java TupleQueryResultWriterFactory类代码示例

本文整理汇总了Java中org.openrdf.query.resultio.TupleQueryResultWriterFactory的典型用法代码示例。如果您正苦于以下问题:Java TupleQueryResultWriterFactory类的具体用法?Java TupleQueryResultWriterFactory怎么用?Java TupleQueryResultWriterFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TupleQueryResultWriterFactory类属于org.openrdf.query.resultio包,在下文中一共展示了TupleQueryResultWriterFactory类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: SPARQLTupleStreamingOutput

import org.openrdf.query.resultio.TupleQueryResultWriterFactory; //导入依赖的package包/类
/**
 * Creates a new sparql tuple streaming output that executes a SPARQL
 * SELECT query and streams the result.
 * @param query the SELECT query to execute
 * @param writerFactory a result writer factory used to serialise the
 * results
 * @param conn the connection to use for query execution
 */
public SPARQLTupleStreamingOutput(
	TupleQuery query,
	TupleQueryResultWriterFactory writerFactory,
	RepositoryConnection conn) {
	super(conn);
	this.query = query;
	this.factory = writerFactory;
}
 
开发者ID:lszeremeta,项目名称:neo4j-sparql-extension-yars,代码行数:17,代码来源:SPARQLTupleStreamingOutput.java

示例2: getTupleWriterFactory

import org.openrdf.query.resultio.TupleQueryResultWriterFactory; //导入依赖的package包/类
/**
 * Returns a {@link TupleQueryResultWriterFactory} that returns a writer
 * that writes SPARQL query results in the format of a given MIME-Type.
 *
 * @param mimetype the mimetype
 * @return the corresponding query result writer factory
 */
private TupleQueryResultWriterFactory getTupleWriterFactory(String mimetype) {
	switch (mimetype) {
		default:
		case RDFMediaType.SPARQL_RESULTS_JSON:
			return new SPARQLResultsJSONWriterFactory();
		case RDFMediaType.SPARQL_RESULTS_XML:
			return new SPARQLResultsXMLWriterFactory();
		case RDFMediaType.SPARQL_RESULTS_CSV:
			return new SPARQLResultsCSVWriterFactory();
		case RDFMediaType.SPARQL_RESULTS_TSV:
			return new SPARQLResultsTSVWriterFactory();
	}
}
 
开发者ID:lszeremeta,项目名称:neo4j-sparql-extension-yars,代码行数:21,代码来源:SPARQLQuery.java

示例3: serve

import org.openrdf.query.resultio.TupleQueryResultWriterFactory; //导入依赖的package包/类
@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);
}
 
开发者ID:cumulusrdf,项目名称:cumulusrdf,代码行数:36,代码来源:ContextsHandler.java

示例4: serve

import org.openrdf.query.resultio.TupleQueryResultWriterFactory; //导入依赖的package包/类
@Override
public ModelAndView serve(final Repository repository, final HttpServletRequest request, final HttpServletResponse response)
		throws Exception {
	Map<String, Object> model = new HashMap<String, Object>();

	if (METHOD_GET.equals(request.getMethod())) {
		Repository systemRepository = _repositoryManager.getSystemRepository();
		ValueFactory vf = systemRepository.getValueFactory();

		try {
			RepositoryConnection con = systemRepository.getConnection();
			try {
				// connection before returning. Would be much better to stream the query result directly to the client.

				List<String> bindingNames = new ArrayList<String>();
				List<BindingSet> bindingSets = new ArrayList<BindingSet>();

				TupleQueryResult queryResult = con.prepareTupleQuery(QueryLanguage.SERQL,
						REPOSITORY_LIST_QUERY).evaluate();
				try {
					// Determine the repository's URI
					StringBuffer requestURL = request.getRequestURL();
					if (requestURL.charAt(requestURL.length() - 1) != '/') {
						requestURL.append('/');
					}
					String namespace = requestURL.toString();

					while (queryResult.hasNext()) {
						QueryBindingSet bindings = new QueryBindingSet(queryResult.next());

						String id = bindings.getValue("id").stringValue();
						bindings.addBinding("uri", vf.createURI(namespace, id));

						bindingSets.add(bindings);
					}

					bindingNames.add("uri");
					bindingNames.addAll(queryResult.getBindingNames());
				} finally {
					queryResult.close();
				}
				model.put(QueryResultView.QUERY_RESULT_KEY,
						new TupleQueryResultImpl(bindingNames, bindingSets));

			} finally {
				con.close();
			}
		} catch (RepositoryException e) {
			throw new ServerHTTPException(e.getMessage(), e);
		}
	}

	TupleQueryResultWriterFactory factory = ProtocolUtil.getAcceptableService(request, response,
			TupleQueryResultWriterRegistry.getInstance());

	model.put(QueryResultView.FILENAME_HINT_KEY, "repositories");
	model.put(QueryResultView.FACTORY_KEY, factory);
	model.put(QueryResultView.HEADERS_ONLY, METHOD_HEAD.equals(request.getMethod()));

	return new ModelAndView(TupleQueryResultView.getInstance(), model);
}
 
开发者ID:cumulusrdf,项目名称:cumulusrdf,代码行数:62,代码来源:RepositoryListHandler.java

示例5: getExportNamespacesResult

import org.openrdf.query.resultio.TupleQueryResultWriterFactory; //导入依赖的package包/类
/**
 * 
 * @param repository the Repository object
 * @param request the HttpServletRequest object 
 * @param response the HttpServletResponse oject
 * @return QueryResultView object include the namespaces
 * @throws ClientHTTPException throws when errors in the request
 * @throws ServerHTTPException throws when errors in the Repository
 * @throws RepositoryException throws when errors in closing the RepositoryConnection 
 */
private ModelAndView getExportNamespacesResult(final Repository repository, final HttpServletRequest request, final HttpServletResponse response)
		throws ClientHTTPException, ServerHTTPException, RepositoryException {
	final boolean headersOnly = METHOD_HEAD.equals(request.getMethod());

	Map<String, Object> model = new HashMap<String, Object>();
	if (!headersOnly) {
		List<String> columnNames = Arrays.asList("prefix", "namespace");
		List<BindingSet> namespaces = new ArrayList<BindingSet>();

		RepositoryConnection repositoryCon = repository.getConnection();
		synchronized (repositoryCon) {
			try {
				CloseableIteration<? extends Namespace, RepositoryException> iter = repositoryCon.getNamespaces();

				try {
					while (iter.hasNext()) {
						Namespace ns = iter.next();

						Literal prefix = new LiteralImpl(ns.getPrefix());
						Literal namespace = new LiteralImpl(ns.getName());

						BindingSet bindingSet = new ListBindingSet(columnNames, prefix, namespace);
						namespaces.add(bindingSet);
					}
				} finally {
					iter.close();
				}
			} catch (RepositoryException e) {
				throw new ServerHTTPException("Repository error: " + e.getMessage(), e);
			}
		}
		model.put(QueryResultView.QUERY_RESULT_KEY, new TupleQueryResultImpl(columnNames, namespaces));
		repositoryCon.close();
	}

	TupleQueryResultWriterFactory factory = ProtocolUtil.getAcceptableService(request, response,
			TupleQueryResultWriterRegistry.getInstance());

	model.put(QueryResultView.FILENAME_HINT_KEY, "namespaces");
	model.put(QueryResultView.HEADERS_ONLY, headersOnly);
	model.put(QueryResultView.FACTORY_KEY, factory);

	return new ModelAndView(TupleQueryResultView.getInstance(), model);
}
 
开发者ID:cumulusrdf,项目名称:cumulusrdf,代码行数:55,代码来源:NamespacesHandler.java


注:本文中的org.openrdf.query.resultio.TupleQueryResultWriterFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。