protected SolutionSet unitSolution() { SolutionList unit = new SolutionList(); PatternSolutionImpl emptySolution = new PatternSolutionImpl(); unit.add(emptySolution); return unit; }
public Glitter2BasicResultSetAdaptor(QueryResults glitterResults) { this.size = glitterResults.getSelectResults().size(); this.results = glitterResults.getSelectResults().iterator(); this.qc = glitterResults.getQueryController(); }
public boolean isDistinct() { return ((Projection) this.qc.getQueryResultForm()).isDistinct(); }
/** * If the QueryResults are from a SELECT query, getSelectResult() * will be created with a Glitter2BasicResultSetAdaptor. * * @param results */ public QueryResult(QueryResults results ) { queryType = results.getQueryController().getQueryType(); if (queryType == QueryType.ASK) { resultObject=results.getAskResults(); } else if (queryType == QueryType.CONSTRUCT) { resultObject=results.getConstructResults(); } else if (queryType == QueryType.DESCRIBE){ resultObject=results.getDescribeResults(); } else { resultObject=createSelectResults(results); } } public Object createSelectResults(QueryResults results) {
Iterator<URI> iter = null; if (namedGraphVariable == null) { iter = queryInformation.getSolutionGenerator().getRDFDataset().getDefaultGraphs(); } else { iter = queryInformation.getSolutionGenerator().getRDFDataset().getNamedGraphs(); SolutionGenerator sg = queryInformation.getSolutionGenerator(); SolutionSet ss = new SolutionList(); if (! noSolutions){ if (sg instanceof BocaServerSolutionGenerator) { for (StatementWrapper s : results) { BocaQuad quad = new BocaQuad(bssg.getConnection().getNodeLayout().getNodeConverter(), s.getGraphId(), s.getSubjectId(), s.getPredicateId(), s.getObjectId()); PatternSolution sol = new PatternSolutionImpl(); sol.setBinding(var, quad.getObjId()); if (includePattern && subjBindable != null) { sol.setBinding(subjBindable, quad.getSubjId()); sol.setBinding(predBindable, quad.getPredId()); sol.setBinding(namedGraphVariable, quad.getNamedGraphId()); ss.add(sol);
Value s = ((gs != null) ? this.converter.convert(gs, true) : null), p = ((gp != null) ? this.converter.convert(gp, true) : null), o = ((go != null) ? this.converter.convert(go, true) : null); Resource context = (Resource)((namedGraph != null) ? this.converter.convert(namedGraph, true) : null); SolutionSet solutions = new SolutionList(); if (namedGraph == null) { int i = 0; PatternSolution sol = triple.entails(tp); if (sol != null) { sol.setBinding(namedGraphVariable, uri); solutions.add(sol); PatternSolution sol = triple.entails(tp); if (sol != null) solutions.add(sol); if (sol != null) { if (namedGraphVariable != null) sol.setBinding(namedGraphVariable, uri); solutions.add(sol);
protected void addBindings(BocaServerBGPQuery query, ResultSet rs, SolutionSet bindings) throws SQLException, GlitterException { try { ResultSetMetaData meta = rs.getMetaData(); HashMap<Integer, Bindable> columns = new HashMap<Integer, Bindable>(); int lastColumn = meta.getColumnCount(); for (int i = 1; i <= lastColumn; i++) { // TODO @@ do I want getColumnLabel or getColumnName // String name = meta.getColumnName(i); String name = meta.getColumnLabel(i); if (!name.equals(BocaServerSQL.glitterIgnoredVariable)) { // 2) columns.put(new Integer(i), query.getBindableForAlias(name)); // 1) } } while (rs.next()) { PatternSolutionImpl solution = new PatternSolutionImpl(); for (Entry<Integer, Bindable> e : columns.entrySet()) { long id = rs.getLong(e.getKey()); RDFTerm value = this.connection.getNodeLayout().getNodeConverter().getGlitterNode(id); // 3) solution.setBinding(e.getValue(), value); } bindings.add(solution); } } finally { if (rs != null) { rs.close(); } } }
com.ibm.adtech.glitter.query.QueryResults results = glitter.executeQuery(query, defaultGraphs, namedGraphs); QueryResult qr = null; switch (results.getQueryController().getQueryType()) { case SELECT : qr = new QueryResult(new Glitter2BocaResultSetAdaptor(results, nodeLayout));
public List<String> getBindingNames() { Projection proj = (Projection) qc.getQueryResultForm(); ArrayList<Variable> vars = new ArrayList<Variable>(); CollectionUtils.addAll(vars, proj.getProjectedVariables()); ArrayList<String> varnames = new ArrayList<String>(); for (Variable v : vars) varnames.add(v.getName()); return varnames; }
commit(); result = results.getAskResults(); } catch (ParseException e) { throw BocaException.createException(ExceptionConstants.SERVER.CODES.SEARCH_ERROR, ExceptionConstants.SERVER.SUBCODES.GLITTER_PARSE_EXCEPTION, e, query);
public Value getValue(String varName) { RDFTerm term = this.solution.getBinding(Variable.createVariable(varName)); Value value = null; if (term != null) value = this.converter.convert(term, false); return value; }
public boolean isOrdered() { return this.qc.isOrdered(); }
protected void ensureVariableNames() { if (this.variableNames == null) { Iterable<Variable> vars = this.solution.getBoundVariables(); this.variableNames = new HashSet<String>(); for (Variable v : vars) { this.variableNames.add(v.getName()); this.bindings.put(v.getName(), createBinding(v)); } } } private GlitterBinding createBinding(Variable variable) {
com.ibm.adtech.glitter.query.QueryResults results = glitter.executeQuery(query, defaultGraphs, namedGraphs); RDFXMLWriter writer = null; switch (results.getQueryController().getQueryType()) { case ASK : writer = new RDFXMLWriter(outputStream); writer.startRDF(); writer.handleStatement(Constants.valueFactory.createStatement(Constants.valueFactory.createBNode(), Predicates.SparqlQueryResults.BOOLEAN_TAG, Constants.valueFactory.createLiteral(results.getAskResults()))); writer.endRDF(); return QueryType.ASK.ordinal(); case CONSTRUCT : resultSet = results.getConstructResults(); writer = new RDFXMLWriter(outputStream); writer.startRDF(); return QueryType.CONSTRUCT.ordinal(); case DESCRIBE : resultSet = results.getDescribeResults(); writer = new RDFXMLWriter(outputStream); writer.startRDF(); return QueryType.DESCRIBE.ordinal(); case SELECT : Glitter2BocaResultSetAdaptor adaptor = new Glitter2BocaResultSetAdaptor(results, getNodeLayout()); return QueryType.SELECT.ordinal(); default : throw new GlitterException("Not a valid query type");
SolutionGenerator sg = queryInformation.getSolutionGenerator(); SolutionSet ss = new SolutionList(); if (sg instanceof BocaServerSolutionGenerator) { BocaServerSolutionGenerator bssg = (BocaServerSolutionGenerator) sg; List<Long> ids=bssg.getConnection().getLiteralIndexer().query(textMatch); for(Long id:ids) { PatternSolution sol = new PatternSolutionImpl(); sol.setBinding(var, bssg.getConnection().getNodeLayout().getNodeConverter().getGlitterNode( id)); ss.add(sol); while (results.hasNext()) { long id=results.next(); PatternSolution sol = new PatternSolutionImpl(); sol.setBinding(var, bssg.getConnection().getNodeLayout().getNodeConverter().getGlitterNode( id)); ss.add(sol);
TriplePatternComponent gs = tp.getSubject(), gp = tp.getPredicate(), go = tp.getObject(); Value s = ((gs != null) ? this.converter.convert(gs, true) : null), p = ((gp != null) ? this.converter.convert(gp, true) : null), o = ((go != null) ? this.converter.convert(go, true) : null); SolutionSet solutions = new SolutionList(); if (namedGraph == null) { int i = 0; PatternSolution sol = triple.entails(tp); if (sol != null) { sol.setBinding(namedGraphVariable, uri); solutions.add(sol); PatternSolution sol = triple.entails(tp); if (sol != null) solutions.add(sol); if (sol != null) { if (namedGraphVariable != null) sol.setBinding(namedGraphVariable, uri); solutions.add(sol);
private GlitterBinding createBinding(Variable variable) { RDFTerm term = this.solution.getBinding(variable); return new GlitterBinding(variable.getName(),this.converter.convert(term, false)); } public Binding getBinding(String varName) {
logSql(sql, new String[]{}); ResultSet rs = stmt.executeQuery(); SolutionList bindings = new SolutionList(); addBindings(query, rs, bindings); log.debug("QueryTime:"+(System.currentTimeMillis()-start)); org.openrdf.model.URI ng = (org.openrdf.model.URI) this.connection.getNodeLayout().getNodeConverter().convert(namedGraph, false, null); ITemporalGraph graph = RepositoryDataSet.getTemporalGraph(ng, connection, transactionTime, null, null); SolutionSet solutions = new SolutionList(); if (graph != null) { TriplePattern tp = ((TriplePatternNode) node).getTriplePattern(); PatternSolution sol = triple.entails(tp); if (namedGraphVariable != null) sol.setBinding(namedGraphVariable, namedGraph); solutions.add(sol); return new SolutionList(); SolutionSet solutions = new SolutionList(); RDFDataset dataset = getRDFDataset(); Iterator<URI> dgIter = dataset.getDefaultGraphs(); Triple triple = new Triple(quint.getSubjId(), quint.getPredId(), quint.getObjId()); PatternSolution sol = triple.entails(tp); solutions.add(sol); PatternSolution sol = triple.entails(tp); if (namedGraphVariable != null)