Java Code Examples for org.eclipse.rdf4j.query.QueryLanguage#valueOf()

The following examples show how to use org.eclipse.rdf4j.query.QueryLanguage#valueOf() . 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: RepositoryModel.java    From semweb4j with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public ClosableIterable<Statement> queryConstruct(String query, String querylanguage)
		throws QueryLanguageNotSupportedException {
	assertModel();
	if (querylanguage.equalsIgnoreCase("SPARQL"))
		return sparqlConstruct(query);
	else {
		QueryLanguage ql = QueryLanguage.valueOf(querylanguage);
		if (ql == null) {
			throw new QueryLanguageNotSupportedException("Unsupported query language: '"
					+ querylanguage + "'");
		}
		try {
			GraphQuery prepared = this.connection.prepareGraphQuery(ql, query);
			GraphQueryResult graphQueryResult = prepared.evaluate();
			return new GraphIterable(graphQueryResult, this);
		} catch (MalformedQueryException | RepositoryException |
				UnsupportedQueryLanguageException | QueryEvaluationException e) {
			throw new ModelRuntimeException(e);
		}
	}
}
 
Example 2
Source File: QueryServlet.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void saveQuery(final WorkbenchRequest req, final HttpServletResponse resp)
		throws IOException, BadRequestException, RDF4JException {
	resp.setContentType("application/json");
	ObjectNode jsonObject = mapper.createObjectNode();
	jsonObject.put("queryText", getQueryText(req));

	final HTTPRepository http = (HTTPRepository) repository;
	final boolean accessible = storage.checkAccess(http);
	jsonObject.put("accessible", accessible);
	if (accessible) {
		final String queryName = req.getParameter("query-name");
		String userName = getUserNameFromParameter(req, SERVER_USER);
		final boolean existed = storage.askExists(http, queryName, userName);
		jsonObject.put("existed", existed);
		final boolean written = Boolean.valueOf(req.getParameter("overwrite")) || !existed;
		if (written) {
			final boolean shared = !Boolean.valueOf(req.getParameter("save-private"));
			final QueryLanguage queryLanguage = QueryLanguage.valueOf(req.getParameter(QUERY_LN));
			final String queryText = req.getParameter(QUERY);
			final boolean infer = req.isParameterPresent(INFER) ? Boolean.valueOf(req.getParameter(INFER)) : false;
			final int rowsPerPage = Integer.valueOf(req.getParameter(LIMIT));
			if (existed) {
				final IRI query = storage.selectSavedQuery(http, userName, queryName);
				storage.updateQuery(query, userName, shared, queryLanguage, queryText, infer, rowsPerPage);
			} else {
				storage.saveQuery(http, queryName, userName, shared, queryLanguage, queryText, infer, rowsPerPage);
			}
		}
		jsonObject.put("written", written);
	}
	final PrintWriter writer = new PrintWriter(new BufferedWriter(resp.getWriter()));
	writer.write(mapper.writeValueAsString(jsonObject));
	writer.flush();
}
 
Example 3
Source File: QueryEvaluator.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Evaluates the query submitted with the given request.
 *
 * @param builder   used to build the response
 * @param resp      the response object
 * @param out       the output writer
 * @param xslPath   style sheet path
 * @param con       connection to repository
 * @param queryText the query text, having been pulled using
 *                  {@link org.eclipse.rdf4j.workbench.commands.QueryServlet} from one of three request parameters:
 *                  "query", "queryhash" or "saved"
 * @param req       the request object
 * @param cookies   used to deal with browser cookies
 * @throws BadRequestException if there's a problem getting request parameters or issuing the repository query
 * @throws RDF4JException      if there's a problem preparing the query
 */
public void extractQueryAndEvaluate(final TupleResultBuilder builder, final HttpServletResponse resp,
		final OutputStream out, final String xslPath, final RepositoryConnection con, String queryText,
		final WorkbenchRequest req, final CookieHandler cookies) throws BadRequestException, RDF4JException {
	final QueryLanguage queryLn = QueryLanguage.valueOf(req.getParameter("queryLn"));
	Query query = QueryFactory.prepareQuery(con, queryLn, queryText);
	boolean evaluateCookie = false;
	int offset = req.getInt("offset");
	int limit = req.getInt("limit_query");
	boolean paged = limit > 0;
	if (query instanceof GraphQuery || query instanceof TupleQuery) {
		final int know_total = req.getInt("know_total");
		evaluateCookie = know_total <= 0;
		if (!evaluateCookie) {
			cookies.addTotalResultCountCookie(req, resp, know_total);
		}
		if (paged) {
			PagedQuery pagedQuery = new PagedQuery(queryText, queryLn, limit, offset);
			if (pagedQuery.isPaged()) {
				offset = pagedQuery.getOffset();
				limit = pagedQuery.getLimit();
			}
			if (!evaluateCookie) {
				query = QueryFactory.prepareQuery(con, queryLn, pagedQuery.toString());
			}
		}
	}
	if (req.isParameterPresent("infer")) {
		final boolean infer = Boolean.parseBoolean(req.getParameter("infer"));
		query.setIncludeInferred(infer);
	}
	this.evaluate(builder, out, xslPath, req, resp, cookies, query, evaluateCookie, paged, offset, limit);
}
 
Example 4
Source File: RepositoryModel.java    From semweb4j with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public QueryResultTable querySelect(String query, String queryLanguage) throws QueryLanguageNotSupportedException {
	assertModel();
	if (queryLanguage.equalsIgnoreCase("SPARQL")) {
		return sparqlSelect(query);
	} else {
		QueryLanguage ql = QueryLanguage.valueOf(queryLanguage);
		if (ql == null) {
			throw new QueryLanguageNotSupportedException("Unsupported query language: '" + queryLanguage + "'");
		}
		return new RepositoryQueryResultTable(query, ql, this.connection);
	}
}