i think its proper to have a Dataprovider for each table. why i enjoy
dataprovider in wicket is that it gives me this feeling that SELECT * FROM
TABLE will not return 1 million records and crash my application, its gives
you a simple way to fetch the data you want to display per time and you can
create a many dataprovider as possible or even implement some internal
session state logic to tell IDataprovider which table to fetch. its up to
your implementation.

you will also loose the flexibility you have with yur models if you avoid
IDataProvider

however actually i think i makes sense for someone to donate a robust
JDBCDataProvider to wicket stuff
because attempting to do this for criteria matter, you can only hope you are
not dealing with complex data types

private class JDBCQueryDataProvider implements IDataProvider
{
private Connection c;
private String query;

private String[] columns;
public ResultSetDataProvider (Connection _c){
c = _c;
}
public ResultSetDataProvider (Connection _c, Query _q){
c = _c;
q = _q;
}

public void setColumnsToFetch(String ... cols){
columns = cols;
}


public void setQuery(String query){this.query = query;}
public String getQuery(){return this.query;}

public Iterator iterator(int start, int count) {
String compiledquery = getQuery + " LIMIT " + start + "," +  count;
PrepareStatement pq = c.createStatement(compiledquery );
ResultSet set = pq.executeQuery();

List<List<String>> dataList = new LinkedList<List<String>>();
while(set.next()){

List<String> rowList = new LinkedList<String>();
//iterate over column array
for(columns)
rowList.add(set.getString(column));

//i think the only hell here is the conversions, null to string, timestamp
to string, :)


dataList.add(rowList);
}
return dataList.iterator();
}
public int size() {
String countQ = "SELECT COUNT(ID) FROM TABLE";
PrepareStatement pq = c.createStatement(countQ);
ResultSet set = pq.executeQuery();
if(set.next())
return set.getInt(1);
else
return 0;
}
public IModel model(Object arg0) {
return new Model((List)arg);
}
}




On 8/23/07, dtoffe <[EMAIL PROTECTED]> wrote:
>
>
>     Done, I've offered to write some example of use for the wiki or
> example
> page.
>
> Thanks !!
>
> Daniel
>
>
> igor.vaynberg wrote:
> >
> > perhaps you can email frank and ask him, it is unfortunate he did not
> post
> > his code on a wiki page somewhere.
> >
> >
> http://www.nabble.com/displaying-java.sql.Timestamp-tf1333211.html#a3561689
> >
> > -igor
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Question-regarding-old-post-%28ResultSet-and-DataTable%29-tf4314874.html#a12297009
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

Reply via email to