1 7 8 package com.hp.hpl.jena.db.impl; 11 12 import java.sql.*; 15 16 import com.hp.hpl.jena.db.RDFRDBException; 17 import com.hp.hpl.jena.graph.*; 18 19 import org.apache.commons.logging.Log; 20 import org.apache.commons.logging.LogFactory; 21 22 29 public class ResultSetTripleIterator extends ResultSetIterator { 30 31 32 protected IDBID m_graphID; 33 34 35 protected IPSet m_pset; 36 37 38 protected Triple m_triple; 39 40 41 protected boolean m_isReif; 42 43 44 protected Node m_stmtURI; 45 46 47 protected boolean m_hasType; 48 49 static protected Log logger = LogFactory.getLog( ResultSetTripleIterator.class ); 50 51 public ResultSetTripleIterator(IPSet p, IDBID graphID) { 53 m_pset = p; 54 setGraphID(graphID); 55 m_isReif = false; 56 } 57 58 public ResultSetTripleIterator(IPSet p, boolean isReif, IDBID graphID) { 60 m_pset = p; 61 setGraphID(graphID); 62 m_isReif = isReif; 63 } 64 65 69 public void setGraphID(IDBID gid) { 70 m_graphID = gid; 71 } 72 73 80 public void reset(ResultSet resultSet, PreparedStatement sourceStatement, SQLCache cache, String opname) { 81 super.reset(resultSet, sourceStatement, cache, opname); 82 m_triple = null; 83 } 84 85 99 protected void extractRow() throws SQLException { 100 int rx = 1; 101 ResultSet rs = m_resultSet; 102 String subj = rs.getString(1); 103 String pred = rs.getString(2); 104 String obj = rs.getString(3); 105 106 if ( m_isReif ) { 107 m_stmtURI = m_pset.driver().RDBStringToNode(rs.getString(4)); 108 m_hasType = rs.getString(5).equals("T"); 109 } 110 111 Triple t = null; 112 113 try { 114 t = m_pset.extractTripleFromRowData(subj, pred, obj); 115 } catch (RDFRDBException e) { 116 logger.debug("Extracting triple from row encountered exception: ", e); 117 } 118 119 m_triple = t; 120 121 } 122 123 126 protected Object getRow() { 127 return m_triple; 128 } 129 130 133 protected Node getStmtURI() { 134 return m_stmtURI; 135 } 136 137 140 protected boolean getHasType() { 141 return m_hasType; 142 } 143 144 148 protected void deleteRow() { 149 try { 150 m_resultSet.deleteRow(); 151 } catch (SQLException e) { 152 throw new RDFRDBException("Internal sql error", e); 153 } 154 } 155 156 157 160 public void remove() { 161 if (m_triple == null) 162 throw new IllegalStateException (); 163 m_pset.deleteTriple(m_triple, m_graphID); 164 } 165 166 } 168 194 195 | Popular Tags |