Ganesan.Sankara> I believe most of applications will have the following requirement:
Ganesan.Sankara> 
Ganesan.Sankara> 1. Screen which fetches data from databases such as ORACLE
Ganesan.Sankara> 2. The screen has a limitation to show maximum number of records, 
let's say
Ganesan.Sankara> 20.
Ganesan.Sankara> 3. The fetched rows exceed > 20. So the main screen shows a pointers 
for
Ganesan.Sankara> page 1 , 2 , 3 ...
Ganesan.Sankara> 
Ganesan.Sankara> To code this the developer has to write a cache function for each 
screen
Ganesan.Sankara> and mechanism to store and retrieve. JDBC functions to skip result 
set rows
Ganesan.Sankara> may not work since the query may be returning rows in random order. 
Also
Ganesan.Sankara> the cache has to be designed in such a way it does not eat too much 
memory.
Ganesan.Sankara> 
Ganesan.Sankara> One of my projects , we did a slow cache with small memory foot 
print. The
Ganesan.Sankara> main query will retrieve ROWIDs(ORACLE) and cache , each page hit will
Ganesan.Sankara> slice through ROWIDs cache and user ROWIDs to retrieve from ORACLE ( 
WHERE
Ganesan.Sankara> ROWID IN ( 'xx.xx.xx.xx','yy.yyy.yy.yy') ).
Ganesan.Sankara> 
Ganesan.Sankara> If turbine includes a base class for the mulit-page screen it will 
very
Ganesan.Sankara> useful. Is anyone out there has done any similar work??

I rewrote  org.apache.turbine.util.db.LargeSelect for this purposes.
I splitted it to two classes and one interface:

LargeSelect - interacts with UI,
RecordFetcher - objects of this type do actual database operations,
RecordFetcherFactory - constructs RecordFetchers for different Object
database adapters( now for Castor only).

If you are interested in it I can put code on ftp.

Psevdocode of usage looks like this

For screen:

protected void doBuildTemplate( RunData data,  WebContext context ) throws Exception
{ 
 ...    
   context.put("SelectResults", data.getUser().getTemp("selected_block"));
 ...
}

For action:

public void doQuery (RunData data, WebContext context) throws Exception
{
 ...
    RecordFetcher fetcher = RecordFetcherFactory.createRecordFetcher(query, 
bind_params);
    LargeSelect sel = new LargeSelect("Select", fetcher, MEMORY_LIMIT, PAGE_SIZE);
    data.getUser().setTemp("select", sel);
    doNextchunk (data, context);

}

public void doAdd (RunData data, WebContext context) throws Exception
{
...
    LargeSelect sel = (LargeSelect)data.getUser().getTemp("select");
    sel.insertRecord(record);
    doCurrentchunk(data, context);
}

public void doDelete (RunData data, WebContext context) throws Exception
{
...
    LargeSelect sel = (LargeSelect)data.getUser().getTemp("select");
    sel.deleteRecord(record_num);
    doCurrentchunk(data, context);
}

public void doUpdate (RunData data, WebContext context) throws Exception
{
...
    LargeSelect sel = (LargeSelect)data.getUser().getTemp("select");
    sel.updateRecord(record_num, edited_record);
    doCurrentchunk(data, context);
}

public void doNextchunk (RunData data, WebContext context) throws Exception
{
   LargeSelect sel = (LargeSelect)data.getUser().getTemp("select");

   if (sel.isLastBlock())
       data.setMessage("No more results for this query.");
   else
       data.getUser().setTemp("selected_block", sel.getNextResults());

}

public void doPrevchunk (RunData data, WebContext context) throws Exception
{
    LargeSelect sel = (LargeSelect)data.getUser().getTemp("select");
    if (sel.isFirstBlock())
        data.setMessage("At first record.");
    else
        data.getUser().setTemp("selected_block", sel.getPreviousResults());

}

public void doFirstchunk (RunData data, WebContext context) throws Exception
{
    LargeSelect sel = (LargeSelect)data.getUser().getTemp("select");
    data.getUser().setTemp("selected_block", sel.getResults(0));
}

public void doCurrentchunk (RunData data, WebContext context) throws Exception
{
    LargeSelect sel = (LargeSelect)data.getUser().getTemp("select");
    data.getUser().setTemp("select_block", sel.getCurrentResults());
}


------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
Problems?:           [EMAIL PROTECTED]

Reply via email to