3 Replies Latest reply on Jul 23, 2007 12:23 AM by Na_Tha_Lie

    LCDS and paging

      Hello everybody,

      First, excuse me for the mistakes I may have made.

      I am a trainee and the enterprise I work for is planning to change the presentation layer (and maybe all the layers) of their software packages for Flex (at the present time they use the .NET platform). But in order to ensure that Flex can answer their needs, they have asked me to make a model using Flex together with Java, Hibernate, LCDS, SQL Server and Tomcat.

      I am currently using those versions :
      - jdk 1.5.0_12
      - Hibernate 3 (I use the jars provided with LCDS)
      - LCDS 2.5
      - SQL Server 2005
      - Tomcat 5.5

      As far as some of the tables from their databases are quite big (they can reach 2.000.000 rows) I need to implement paging. The table I currently use for my example is "only" 10.000 rows.

      I must confess that I am new to n-tiers architectures and that there are many concepts I misunderstand.

      What I want to do is make the user able to choose how many rows a page he wants to display (This could look a bit like this). And the server would only send this number of rows for each page (which is not the case for the page I linked).

      I have noticed that the implementation of the fill method for the HibernateAssembler had changed between FDS ( public Collection fill(List fillArgs)) and LCDS ( public Collection fill(List fillArgs, int startIndex, int numItems)).
      You are now able to specify a start index and the number of rows to display. This is the method I would like to use.

      To do so, I have tried to refer to LCDS documentation but I find it quite confusing. Here it is :

      Using on-demand paging

      There are two ways in which the Data Management Service implements on-demand paging of data by Flex clients. In the default approach, the fill method returns the entire collection of objects. The server sends the first page of items to the client as part of the initial fill request.
      As the client code tries to access ArrayCollection elements which are not resident, additional pages are retrieved from the server. If the cache-items property is set to true, these pages are sent directly by the Data Management Service. If the cache-items property is set to false, the Data Management Service calls the getItem() method for each item it needs to send to the client.
      When the original query is too large to be held in the server's memory, it is desirable for the Assembler to only return a single page of items at a time. In this mode, each time the client requests a page, the Assembler is asked for that page of items and they are sent directly to the client. Currently this mode is not supported when the autoSyncEnabled property is set to true for the paged collection. You must set the autoSyncEnabled property to false before executing the code. This configuration is not supported for the SQLAssembler. It is supported for the HibernateAssembler and you can implement it with your own Java Assembler implementation.
      To enable this second mode, you set the custom="true" attribute on the paging element in your network settings on the server and ensure paging is enabled with a reasonable pageSize value.
      If you are using the fill-method approach in your Assembler, you specify a fill method that matches the fill parameters used by your client with two additional parameters: the startIndex and the number of items requested. The Data Management Service calls this method once for each page requested by the client.
      If you are using the Assembler interface approach, you override the useFillPage() method for the appropriate fill method to return true for the fill parameters you want paged using custom paging. When the client requests a page, it calls the fill variant in the Assembler interface which takes the additional startIndex and number of items parameters. You return
      just those items and they are returned to the client.
      When you use custom paging in either the fill-method or Assembler approach, there are two ways that the client can determine the size of the collection. When you have enabled the custom paging mode, on the initial fill request made by the client, the Data Management Service invokes the count method with the parameters the client passed to fill. If the count
      method returns -1, a dynamic sizing algorithm is used for this filled collection. In this approach, the assembler's paged fill method is called with startIndex of 0 and number of items set to the pageSize + 1. If the assembler method returns less than the number requested, the size of the fill is known. If it returns the pageSize+1 items requested, pageSize items are
      returned to the client but the client sets the collection size to pageSize + 1 - with one empty slot at the end. When that empty item is requested by the client, the next pageSize+1 items are requested and the process repeats until the assembler returns less than pageSize+1 items.
      The HibernateAssembler implements this dynamic paging mechanism when you set the page-queries-from-database attribute to true in the destination's server properties. If you are using an HQL query sent from the client and the query is a simple query, the Hibernate assembler attempts to implement a count query by modifying the query sent from the client.
      If you are using a named query, the Hibernate assembler looks for a query named <original-query-name>.count. If that query exists, it uses it to compute the size of the paged collection. Otherwise, it uses the dynamic-sized approach.

      I guess I should change <params>java.util.List</params> for <params>java.util.List,int,int</params>.
      But I don't know which properties to add or modify.
      It also talks about the custom attribute of the paging element. Is it a new attribute that replaces "enabled" ? Or does it come in addition to it ?

      The following files are working and allow me to retrieve the datas I expect (but without paging).

      My data-management-config.xml looks like this :

      <?xml version="1.0" encoding="UTF-8"?>

      <service id="data-service" class="flex.data.DataService" messageTypes="flex.data.messages.DataMessage">

      ....<adapter-definition id="java-adapter" class="flex.data.adapters.JavaAdapter" default="true"/>

      ....<channel ref="my-rtmp"/>

      <destination id="refacteur.hibernate">
      ....<adapter ref="java-adapter" />


      ............<identity property="cleacteur"/>

      ............<paging enabled="false" pageSize="20"/>
      ............<throttle-inbound policy="ERROR" max-frequency="500"/>
      ............<throttle-outbound policy="REPLACE" max-frequency="500"/>





      This is the named query definition I use, found in Refacteur.hbm.xml :

      <query name="refacteur.where.ville.order.by.libacteur">
      ........from Refacteur as refacteur
      ........where refacteur.villeActeur = ?
      ........order by libacteur

      And here is the call to the fill method, found in my mxml application file Acteurs.mxml :

      globalFilter.dataService.fill(globalFilter.arrayCollection, "refacteur.where.ville.order.by.libacteur", ["VANNES"]);

      I have tried to modify several things, but nothing works.

      I would be most grateful if someone could tell me what to change in my files in order to make the paging work.

        • 1. Re: LCDS and paging
          Robert Hirst Level 1

          Have you seen the part of the example configs where it talks about what is required for data paging to work?


          Indicates whether data paging is enabled for the destination and if you wish to override the

          pageSize set for the channel.

          Setting the custom flag to true indicates that the associated assembler has a paged-fill method

          corresponding to each method specified via the <fill-mathod> tag. The paged-fill method

          should have two additional java.lang.Integer params at the end of the parameters specified

          via the <params> tag. The first param specifes the index in the fill collection from which this

          method will start retrieving records. And the second param specifies the number of records to be

          retrieved by each paged-fill call.

          Default enabled value is false. Default pageSize value is 10. Default custom value is false.

          <paging enabled="true" pageSize="5" custom="true"/>


          It seems to imply to me that you need the paged fill methods in your config in addition to the regular ones.

          I admit I have not got as far as getting a working paging setup yet, although this is something I will need to get working in the near future.
          • 2. Re: LCDS and paging
            Ed Solovey (adobe)
            There are two types of paging supported by LCDS,
            1) Paging between server and client
            2) Paging between LCDS server and your data source

            To enable the first type of paging all you need to do is set

            <paging enabled="true" pageSize="X" >

            and do not need to define fill methods with two extra Integer parameters.

            If you do want to enable the second type of paging then you add the custom="true" property to the above config line and need to define those extra fill methods.

            Note that this custom paging feature is available in the current release only if the atuoSync property for your destination is set to false. It will be available regardless of autoSync value in the next release.

            Hope this clears things up,
            • 3. Re: LCDS and paging
              Na_Tha_Lie Level 1

              As we were waiting for answers to my post, they have told me to start looking at another aspect of the model. So I don't have tested your suggestions yet but I will tell you if they solve my problem as soon as I will work on paging again.

              Thanks a lot for your answers :) .