1 15 package org.josql.contrib; 16 17 import java.util.List ; 18 19 import net.sf.jasperreports.engine.JRRewindableDataSource; 20 import net.sf.jasperreports.engine.JRField; 21 22 import org.josql.QueryExecutionException; 23 import org.josql.QueryParseException; 24 import org.josql.Query; 25 import org.josql.QueryResults; 26 27 55 public class JoSQLJRDataSource extends Query implements JRRewindableDataSource 56 { 57 58 private int row = 0; 59 private List results = null; 60 61 public JoSQLJRDataSource () 62 { 63 64 } 65 66 76 public QueryResults executeQuery (List l) 77 throws QueryExecutionException 78 { 79 80 if (this.isWantObjects ()) 81 { 82 83 throw new QueryExecutionException ("Only SQL statements that return columns (not the objects passed in) can be used."); 84 85 } 86 87 QueryResults qr = super.execute (l); 88 89 this.results = qr.getResults (); 90 91 return qr; 92 93 } 94 95 public List getResults () 96 { 97 98 return this.results; 99 100 } 101 102 public void clearResults () 103 { 104 105 this.results = null; 106 107 } 108 109 public Object getFieldValue (JRField field) 110 { 111 112 List res = (List ) this.results.get (this.row); 114 115 Integer ind = (Integer ) this.getAliases ().get (field.getName ()); 116 117 int i = -1; 118 119 if (ind != null) 120 { 121 122 i = ind.intValue (); 123 124 if (i > (res.size () - 1)) 125 { 126 127 return null; 128 129 } 130 131 } 132 133 return res.get (i); 135 136 } 137 138 public boolean next () 139 { 140 141 if (this.row < (this.results.size () - 1)) 142 { 143 144 this.row++; 145 146 return true; 147 148 } 149 150 return false; 151 152 } 153 154 public void moveFirst () 155 { 156 157 this.row = 0; 158 159 } 160 161 } 162 | Popular Tags |