1 5 6 package com.hp.hpl.jena.rdql; 7 8 import java.util.*; 9 10 23 24 public class QueryResultsStream implements QueryResults 25 { 26 Iterator queryExecutionIter ; 27 QueryExecution queryExecution ; 28 List resultVars ; 29 ResultBinding currentEnv ; 30 int rowNumber ; 31 volatile boolean finished = false ; 32 33 34 public QueryResultsStream(Query query, QueryExecution qe, Iterator iter) 35 { 36 queryExecutionIter = iter ; 37 queryExecution = qe ; 38 resultVars = query.getResultVars() ; 40 currentEnv = null ; 41 rowNumber = 0 ; 42 } 43 44 47 48 public void remove() throws java.lang.UnsupportedOperationException 49 { 50 throw new java.lang.UnsupportedOperationException ("com.hp.hpl.jena.rdf.query.QueryResults.remove") ; 51 } 52 53 56 public boolean hasNext() 57 { 58 return queryExecutionIter.hasNext() ; 59 } 60 61 67 public Object next() 68 { 69 currentEnv = (ResultBinding)queryExecutionIter.next() ; 70 if ( currentEnv != null ) 71 rowNumber++ ; 72 return currentEnv ; 73 } 74 75 77 78 public void close() 79 { 80 if ( ! finished ) 81 { 82 queryExecution.abort() ; 83 finished = true ; 84 } 85 else 86 queryExecution.close() ; 87 } 88 89 92 93 public String getBinding(String name) 94 { 95 return getBindingWorker(name, false) ; 97 } 98 99 102 103 public int getRowNumber() 104 { 105 return rowNumber ; 106 } 107 108 110 111 public List getResultVars() { return resultVars ; } 112 113 119 120 public List getAll() 121 { 122 List all = new ArrayList() ; 123 while(this.hasNext()) 124 { 125 all.add(next()); 126 } 127 close() ; 128 return all ; 129 } 130 131 private String getBindingWorker(String name, boolean projectResultVars) 132 { 133 if ( ! projectResultVars || resultVars.contains(name) ) 134 { 135 Object v = currentEnv.get(name) ; 136 if ( v == null ) return null ; 137 return v.toString() ; 138 } 139 return null ; 140 } 141 } 142 143 169 | Popular Tags |