1 5 6 package com.hp.hpl.jena.db.impl; 7 8 import com.hp.hpl.jena.db.GraphRDB; 9 import com.hp.hpl.jena.graph.*; 10 import com.hp.hpl.jena.graph.impl.*; 11 import com.hp.hpl.jena.graph.query.*; 12 import com.hp.hpl.jena.shared.*; 13 import com.hp.hpl.jena.util.iterator.*; 14 15 import java.util.*; 16 17 29 public class DBReifierGraph implements Graph { 30 31 protected List m_specializedGraphs = null; protected GraphRDB m_parent = null; 34 40 public DBReifierGraph( GraphRDB parent, List reifiers) { 41 42 m_parent = parent; 43 m_specializedGraphs = reifiers; 44 45 } 46 47 50 public void add( Triple t ) { 51 throw new AddDeniedException( "cannot add to DB reifier", t ); 52 } 53 54 57 public void delete(Triple t) { 58 throw new DeleteDeniedException( "cannot delete from a DB reifier", t ); 59 } 60 61 64 public int size() { 65 checkUnclosed(); 66 int result =0; 67 Iterator it = m_specializedGraphs.iterator(); 68 while( it.hasNext() ) { 69 SpecializedGraph sg = (SpecializedGraph) it.next(); 70 result += sg.tripleCount(); 71 } 72 return result; 73 } 74 75 public boolean isEmpty() 76 { return size() == 0; } 77 78 private void checkUnclosed() 79 { 80 if (m_specializedGraphs == null) 81 throw new ClosedException( "this DB Reifier has been closed", this ); 82 } 83 84 87 public boolean contains(Triple t) { 88 checkUnclosed(); 89 SpecializedGraph.CompletionFlag complete = newComplete(); 90 Iterator it = m_specializedGraphs.iterator(); 91 while( it.hasNext() ) { 92 SpecializedGraph sg = (SpecializedGraph) it.next(); 93 boolean result = sg.contains( t, newComplete() ); 94 if (result || complete.isDone()) return result; 95 } 96 return false; 97 } 98 99 protected SpecializedGraph.CompletionFlag newComplete() 100 { return new SpecializedGraph.CompletionFlag(); } 101 102 105 public boolean contains(Node s, Node p, Node o) { 106 return contains( Triple.create( s, p, o ) ); 107 } 108 109 110 113 public ExtendedIterator find(TripleMatch m) { 114 checkUnclosed(); 115 ExtendedIterator result = new NiceIterator(); 116 SpecializedGraph.CompletionFlag complete = newComplete(); 117 Iterator it = m_specializedGraphs.iterator(); 118 while( it.hasNext() ) { 119 SpecializedGraph sg = (SpecializedGraph) it.next(); 120 ExtendedIterator partialResult = sg.find( m, complete); 121 result = result.andThen(partialResult); 122 if( complete.isDone()) 123 break; 124 } 125 return result; 126 } 127 128 131 public PrefixMapping getPrefixMapping() { 132 return m_parent.getPrefixMapping(); 133 } 134 135 136 139 public TransactionHandler getTransactionHandler() { 140 return m_parent.getTransactionHandler(); 141 } 142 143 146 public void close() { 147 m_specializedGraphs = null; 148 m_parent = null; 149 } 150 151 public GraphEventManager getEventManager() 152 { throw new BrokenException( "DB reifiers do not yet implement getEventManager" ); } 153 154 157 public boolean dependsOn(Graph other) { 158 return m_parent.dependsOn(other); 159 } 160 161 164 public QueryHandler queryHandler() { 165 return new SimpleQueryHandler(this); 166 } 167 168 171 public BulkUpdateHandler getBulkUpdateHandler() { 172 return m_parent.getBulkUpdateHandler(); 173 } 174 175 178 public Capabilities getCapabilities() { 179 return null; 180 } 181 182 185 public Reifier getReifier() { 186 throw new JenaException( "DB Reifier graphs have no reifiers" ); 187 } 188 189 192 public ExtendedIterator find(Node s, Node p, Node o) { 193 return find( Triple.createMatch( s, p, o ) ); 194 } 195 196 199 public boolean isIsomorphicWith(Graph g) { 200 return g != null && GraphMatcher.equals( this, g ); 201 } 202 203 206 public int capabilities() { 207 return 0; 208 } 209 210 public String toString() 211 { return GraphBase.toString( "DBReifier ", this ); } 212 } 213 214 | Popular Tags |