Try this link http://coenraets.org/blog/category/lcds/
On Wed, Dec 17, 2008 at 12:35 PM, meteatamel <meteata...@yahoo.com> wrote: > Hi Bonny, > > Here's a reply from Ed Solovey, one of our engineers in the LCDS team: > > The first thing you want to do is enable Server-to-data-source paging, > also referred to as paged-fill, by implementing the useFillPage method > in your extension of AbstractAssembler: > > @Override > public boolean useFillPage(List fillParameters) > { > // enabling paged-fill for all fills > return true; > } > > LCDS will call this method when a fill request comes in to the server > to determine whether to call the Assembler fill method variant with > just a fill parameters argument or the fill method variant with > additional startIndex, and numberOfRows parameters. You can enable it > for a subset of fills by returning true/false based on the > fillParameters argument. Above, I've enabled it for all fills. > > Next, you'll want to implement the paged-fill variant of the fill method: > > @Override > public Collection fill(List fillParameters, int startIndex, int > numberOfRows) > { > System.out.println("paged fill called with: " + startIndex + ", " > + numberOfRows); > > ArrayList<Person> people = new ArrayList<Person>(); > Connection c = null; > > c = getConnection(); > Statement s = c.createStatement(); > // use the startIndex and numItems parameters to limit the result set > // returned by your data source. Details will depend on your > datasource; > // we are using MySQL here which supports a "LIMIT" clause > // to do exactly what we want > ResultSet rs = s.executeQuery("SELECT * FROM people LIMIT" > + startIndex + ", " + numberOfRows); > while (rs.next()) > { > Person person = new Person(); > person.lastName = rs.getString("lastName"); > person.firstName = rs.getString("firstName"); > person.id = rs.getInt("id"); > people.add(person); > } > > return people; > } > > (error handling is not included above, I'll include a full version of > the assembler at the bottom). > > I am using MySQL in this sample and the line of interest above is > "ResultSet rs = s.executeQuery("SELECT * FROM people LIMIT " + > startIndex + ", " + numberOfRows);". Here I am using the startIndex > and numberOfRows parameters to limit the result set fetched by MySQL > thus extending paging all the way to the datasource. The exact syntax > here will depend on your specific datasource. > > When you use paged-fill, LCDS can no longer determine the size of the > fill collection from the result of the first fill request because it > only returns the first page of your collection. So it is required > that the count method is implemented when paged-fill is used. Here is > my method: > > @Override > public int count(List countParameters) > { > // when fill paging is enabled, this method will be called > // after the first fill request comes in because the size of > // the collection is no longer known from the result of that > // initial fill request. However, in the cases where a count > // query is almost as expensive as a full fill query, you may > // avoid it and return -1. In this case the client's notion of > // the size will be incremented with each page request causing > // UI components such as the DataGrid to adjust with each page request > > boolean countQueryExpensive = false; > int count = -1; > > if (!countQueryExpensive) > { > Connection c = null; > > c = getConnection(); > Statement s = c.createStatement(); > ResultSet rs = s.executeQuery("SELECT COUNT(*) count FROM > people"); > rs.next(); > count = rs.getInt("count"); > } > System.out.println("count returning: " + count); > return count; > } > > (again, error handling is not included above, I'll include a full > version of the assembler at the bottom). > > Note the comment at the top of the implementation, if count is > expensive you may return -1 and LCDS will adjust the collection size > dynamically. > > At this point you should be ready to go. You can configure this > destination in data-management-config.xml just as you would any other: > > <adapters> > <adapter-definition class="flex.data.adapters.JavaAdapter" > id="java-dao"></adapter-definition> > </adapters> > > <destination adapter="java-dao" id="PagingDestination"> > <properties> > <source>paging.PagingAssembler</source> > <scope>application</scope> > <network> > <paging enabled="true" pageSize="5"></paging> > </network> > <metadata> > <identity property="id"></identity> > </metadata> > </properties> > </destination> > > As you would expect, to use server-to-data-source paging, > client-to-server paging must also be enabled. Note above that I've > set my page size to 5. You can now hit access your destination with a > simple client: > > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" > layout="absolute" applicationComplete="myDS.fill(myCollection)"> > <mx:DataService id="myDS" destination="PagingDestination"/> > <mx:ArrayCollection id="myCollection"/> > <mx:DataGrid id="myDG" dataProvider="{myCollection}"/> > </mx:Application> > > In your server output you should initially see: > > paged fill called with: 0, 6 > count returning: 25 (or count returning: -1, depending on whether > your count > is implemented or you are using dynamic sizing) > paged fill called with: 5, 6 > > as you scroll down on your DataGrid you'll see paged fill called with: > 10, 6 > > etc... > > The documentation regarding this feature is here: > > http://livedocs.adobe.com/livecycle/8.2/programLC/programmer/lcds/index.html > > Hope this helps, > Ed > > package paging; > > import java.sql.Connection; > import java.sql.DriverManager; > import java.sql.ResultSet; > import java.sql.SQLException; > import java.sql.Statement; > import java.util.ArrayList; > import java.util.Collection; > import java.util.List; > > import flex.data.PropertySpecifier; > import flex.data.assemblers.AbstractAssembler; > > public class PagingAssembler extends AbstractAssembler > { > public PagingAssembler() > { > super(); > } > > private Connection getConnection() throws SQLException > { > try > { > Class.forName("com.mysql.jdbc.Driver"); > return > DriverManager.getConnection("jdbc:mysql://localhost:3306/paging","root", > "adobe"); > } > catch (Exception e) > { > e.printStackTrace(); > return null; > } > } > > @Override > public int count(List countParameters) > { > // when fill paging is enabled, this method will be called > // after the first fill request comes in because the size of > // the collection is no longer known from the > // result of that initial fill request. However, in the cases > // where a count query is almost as expensive as a full fill > query, > // you may avoid it and return -1. In this case the client's > notion of > // the size will be incremented with each page request causing > // UI components such as the DataGrid to adjust with each page > request > > boolean countQueryExpensive = true; > int count = -1; > > if (!countQueryExpensive) > { > Connection c = null; > try > { > c = getConnection(); > Statement s = c.createStatement(); > ResultSet rs = s.executeQuery("SELECT COUNT(*) count > FROM people"); > rs.next(); > count = rs.getInt("count"); > } > catch (Exception e) > { > e.printStackTrace(); > } > finally > { > if (c != null) > { > try > { > c.close(); > } > catch (Exception e) > { > e.printStackTrace(); > } > } > } > } > > System.out.println("count returning: " + count); > return count; > } > > @Override > public Collection fill(List fillParameters, int startIndex, int > numberOfRows) > { > System.out.println("paged fill called with: " + startIndex + > ", " + numberOfRows); > > ArrayList<Person> people = new ArrayList<Person>(); > > Connection c = null; > try > { > c = getConnection(); > Statement s = c.createStatement(); > // use the startIndex and numItems parameters to limit the > result set returned by your data source. > // Details will depend on your datasource; we are using > MySQL here which supports a "LIMIT" clause > // to do exactly what we want > ResultSet rs = s.executeQuery("SELECT * FROM people LIMIT > " + startIndex + ", " + numberOfRows); > while (rs.next()) > { > Person person = new Person(); > person.lastName = rs.getString("lastName"); > person.firstName = rs.getString("firstName"); > person.id = rs.getInt("id"); > people.add(person); > } > } > catch (Exception e) > { > e.printStackTrace(); > } > finally > { > if (c != null) > { > try > { > c.close(); > } > catch (Exception e) > { > e.printStackTrace(); > } > } > } > > return people; > } > > @Override > public boolean useFillPage(List fillParameters) > { > // enabling paged-fill for all fills > return true; > } > > public static class Person > { > public String lastName; > public String firstName; > public int id; > > } > > } > --- In flexcoders@yahoogroups.com, "bonny_us" <patelnirv...@...> wrote: >> >> Hi All, >> I am Bonny working as Flex Developer. I want to know about paging in >> LCDS. So please if you have any example for LCDS paging for server to >> datasource. Then please let me know about that. It is very helpful to >> me. >> Right now we are using client-server paging and want to move on server >> to datasource paging. >> Please help me if you have any Example or POC for this. >> >> Thanks & Regards, >> Bonny >> > >