1 16 package scriptella.driver.xpath; 17 18 import org.w3c.dom.Document ; 19 import org.w3c.dom.Element ; 20 import scriptella.AbstractTestCase; 21 import scriptella.configuration.MockConnectionEl; 22 import scriptella.configuration.StringResource; 23 import scriptella.spi.AbstractConnection; 24 import scriptella.spi.Connection; 25 import scriptella.spi.ConnectionParameters; 26 import scriptella.spi.IndexedQueryCallback; 27 import scriptella.spi.MockDriverContext; 28 import scriptella.spi.MockParametersCallbacks; 29 import scriptella.spi.ParametersCallback; 30 31 import javax.xml.parsers.ParserConfigurationException ; 32 import java.util.HashMap ; 33 import java.util.Map ; 34 35 41 public class XPathConnectionPerfTest extends AbstractTestCase { 42 46 public void testQuery() { 47 Map <String , String > props = new HashMap <String , String >(); 49 ConnectionParameters cp = new ConnectionParameters(new MockConnectionEl(props, getClass().getResource("excel.xml").toString()), MockDriverContext.INSTANCE); 50 51 Connection con = new Driver().connect(cp); 52 IndexedQueryCallback queryCallback = new IndexedQueryCallback() { 53 protected void processRow(final ParametersCallback parameters, final int rowNumber) { 54 parameters.getParameter("Cell"); 55 } 56 }; 57 for (int i = 0; i < 200; i++) { 59 con.executeQuery(new StringResource("/$Workbook/Worksheet/Table/Row"), MockParametersCallbacks.NAME, queryCallback); 60 } 61 assertEquals(600, queryCallback.getRowsNumber()); 62 } 63 64 68 public void testQueryLargeDOM() throws ParserConfigurationException { 69 Document doc = XPathConnection.DBF.newDocumentBuilder().newDocument(); 71 Element root = doc.createElement("table"); 72 doc.appendChild(root); 73 for (int i = 0; i < 4000; i++) { 74 Element row = doc.createElement("row"); 75 row.setAttribute("id", String.valueOf(i)); 76 root.appendChild(row); 77 } 78 XPathQueryExecutor qe = new XPathQueryExecutor(doc, new StringResource("/table/row[@id mod 2=0]"), new XPathExpressionCompiler(), new AbstractConnection.StatementCounter()); 80 for (int i = 0; i < 20; i++) { 81 IndexedQueryCallback queryCallback = new IndexedQueryCallback() { 82 protected void processRow(final ParametersCallback parameters, final int rowNumber) { 83 assertTrue(Integer.parseInt((String ) parameters.getParameter("id")) % 2 == 0); 84 } 85 }; 86 qe.execute(queryCallback, MockParametersCallbacks.NULL); 87 assertEquals(2000, queryCallback.getRowsNumber()); 88 } 89 90 91 } 92 93 94 } 95 | Popular Tags |