1 16 package scriptella; 17 18 import scriptella.execution.EtlExecutor; 19 import scriptella.execution.EtlExecutorException; 20 import scriptella.jdbc.QueryHelper; 21 import scriptella.spi.ParametersCallback; 22 import scriptella.spi.QueryCallback; 23 24 import java.sql.Connection ; 25 import java.util.Arrays ; 26 import java.util.HashSet ; 27 import java.util.Set ; 28 29 30 33 public class NestedQueryTest extends DBTestCase { 34 public void test() throws EtlExecutorException { 35 getConnection("nestedquerytestdb1"); final Connection con = getConnection("nestedquerytestdb2"); 37 38 final EtlExecutor se = newEtlExecutor(); 39 se.execute(); 40 41 QueryHelper s = new QueryHelper("select * from result"); 42 final Set <Integer > ids = new HashSet <Integer >(); 43 Set <Integer > expectedIds = new HashSet <Integer >(Arrays.asList( 44 new Integer []{1, 3})); 45 final Set <String > texts = new HashSet <String >(); 46 Set <String > expectedTexts = new HashSet <String >(Arrays.asList( 47 new String []{"One", "Three"})); 48 49 s.execute(con, 50 new QueryCallback() { 51 public void processRow(final ParametersCallback evaluator) { 52 final Integer id = (Integer ) evaluator.getParameter("id"); 53 ids.add(id); 54 55 final String text = (String ) evaluator.getParameter("text"); 56 texts.add(text); 57 assertEquals("!tst", evaluator.getParameter("text2")); 58 } 59 }); 60 assertEquals(ids, expectedIds); 61 assertEquals(texts, expectedTexts); 62 } 63 64 public void test2() throws EtlExecutorException { 65 getConnection("nestedquerytest2db1"); final Connection con = getConnection("nestedquerytest2db2"); 67 68 final EtlExecutor se = newEtlExecutor("NestedQueryTest2.xml"); 69 se.execute(); 70 71 QueryHelper s = new QueryHelper("select * from test"); 72 final Set <Integer > ids = new HashSet <Integer >(); 73 Set <Integer > expectedIds = new HashSet <Integer >(Arrays.asList( 74 new Integer []{5, 7, 13, 15, 2, 6})); 75 76 s.execute(con, 77 new QueryCallback() { 78 public void processRow(final ParametersCallback evaluator) { 79 final Integer id = (Integer ) evaluator.getParameter("id"); 80 ids.add(id); 81 } 82 }); 83 assertEquals(ids, expectedIds); 84 } 85 86 89 public void testRownum() throws EtlExecutorException { 90 final Connection con = getConnection("nestedquerytestrownum"); 91 92 final EtlExecutor se = newEtlExecutor("NestedQueryTestRownum.xml"); 93 se.execute(); 94 95 QueryHelper s = new QueryHelper("select * from Result"); 96 final Set <Integer > ids = new HashSet <Integer >(); 97 Set <Integer > expectedIds = new HashSet <Integer >(Arrays.asList( 98 new Integer []{1, 2, 3, 11, 12, 13})); 99 100 s.execute(con, 101 new QueryCallback() { 102 public void processRow(final ParametersCallback evaluator) { 103 final Integer id = (Integer ) evaluator.getParameter("id"); 104 ids.add(id); 105 } 106 }); 107 assertEquals(expectedIds, ids); 108 } 109 110 } 111 | Popular Tags |