View Javadoc

1   /*
2    * Copyright James Leigh (c) 2006, 2007.
3    *
4    * Licensed under the Aduna BSD-style license.
5    */
6   package org.openrdf.repository.augur.helpers;
7   
8   import info.aduna.iteration.FilterIteration;
9   import info.aduna.iteration.Iteration;
10  
11  import org.openrdf.model.Resource;
12  import org.openrdf.model.Statement;
13  import org.openrdf.model.Value;
14  import org.openrdf.repository.augur.model.AResource;
15  import org.openrdf.repository.augur.model.CachableAugurNode;
16  
17  /**
18   * Passed all the results to the AugurNode for caching.
19   * 
20   * @author James Leigh
21   * 
22   */
23  public class ConsumeStatementIterator<X extends Exception> extends
24  		FilterIteration<Statement, X> {
25  
26  	private AResource carried;
27  
28  	private CachableAugurNode node;
29  
30  	public ConsumeStatementIterator(Iteration<Statement, X> iter,
31  			AResource carried, CachableAugurNode node, int version) {
32  		super(iter);
33  		this.carried = carried;
34  		this.node = node;
35  		node.initCache(version);
36  	}
37  
38  	@Override
39  	protected boolean accept(Statement stmt) {
40  		node.cacheStatement(stmt);
41  		Resource subj = stmt.getSubject();
42  		Value obj = stmt.getObject();
43  		Resource r = node.getCarriedOverResource(subj, obj);
44  		return carried.equals(r);
45  	}
46  
47  	@Override
48  	protected void handleClose() throws X {
49  		while (hasNext()) {
50  			next();
51  		}
52  
53  		super.handleClose();
54  		node.enableCache();
55  	}
56  }