6 Replies Latest reply: Nov 20, 2012 8:42 AM by KevinAngus RSS

    Asynchronously execute a View Object query

    KevinAngus
      Hi,

      ADF Essentials 11.1.2.3

      Use case: the user initiates a long running query to populate a table in an ADF page. The request is submitted as a partial request. The query may take a few minutes so I would like a wait mechanism in the page that polls and refreshes the table to load the data when it is available. The solution should avoid any potential timeouts for the http request submitting the request for the data.

      For the wait mechanism I will likely use Active Data Services (ADS) or an af:poll component to check the status of the query.

      What I'm not sure about is how to initiate the view object query asynchronously.

      I have come across various potential solutions but none seems to be quite right:

      <li>separate Java thread/ExecutorService: most suggest that this will not work as the thread will have no access to the application module.
      <li>work managers: tied to Weblogic (will be deploying on Glassfish), same problem as separate thread accessing the app module connection?
      <li>web service: the only reference I can find in ADF to asynchronous execution is to do with loading data via a web service. This would involve quite a big architecture change and seems like overkill.

      Are there any other methods that I haven't considered yet?

      My instinct is that the separate Java thread would be the most straightforward way to go, has anyone been able to successfully use this to execute a query in an application module?

      The other possibly relevant information is that the application uses dynamic JDBC for database connectivity so I need to use the same connection from the app module rather than access an app server data source.

      Many thanks,

      Kevin
        • 1. Re: Asynchronously execute a View Object query
          codigoadf
          Hi,
          another sugestion is a JMS:http://jobinesh.blogspot.com.es/2011/04/using-jms-with-adf-business-components.html

          but I recommend minimize the time of query, because is not a best practice having to wait minutes in a web application
          • 2. Re: Asynchronously execute a View Object query
            Timo Hahn
            Kevin,
            I would try the asynchrous WS to trigger the long running query and then use a af:poll to update the table on the UI.
            You don't have to populate the results but only have to start the query via the WS. You then wait for hte query to finish and the poll component will eventually show the data.

            Timo
            • 3. Re: Asynchronously execute a View Object query
              KevinAngus
              Hi Timo,

              That idea sounds promising, thanks. Would you mind expanding on it slightly please?

              You say the asynchronous WS does not populate the data but simply triggers the query - how does it achieve this? Can it interact with the view object? Also, what mechanism would it use to indicate that the query has finished?

              Cheers,

              Kevin.
              • 4. Re: Asynchronously execute a View Object query
                KevinAngus
                Hi codigoadf,

                Thanks for the reply.

                I knew someone would say make the query quicker ;) Assuming it is already as quick as it can be and an acceptable speed for the application...

                I've not come across JMS before but looking at the link, will it have a similar problem to the threaded approaches in accessing the application module? Also, the example uses Weblogic features, I'd need to check Glassfish has similar.

                Cheers,

                Kevin
                • 5. Re: Asynchronously execute a View Object query
                  kdario
                  If your backend is db, there is no such thing as asynchronous jdbc call.
                  So, you will need to use thread(or to use some technology which will use thread instead of you :) )
                  But, problem is that threads and webapps don't play nicely.

                  Maybe you can generate some token(or use username) and trigger some background app which will execute long running query and populate some table with query result(and add token to each row - or you can use two tables: master which contain token, and detail which contain results for this token)
                  Then in your app, you can use af:poll to periodically check this new table (query will be restricted by given token - and this should be fast because this will be simple select)

                  Dario
                  • 6. Re: Asynchronously execute a View Object query
                    KevinAngus
                    Hi,

                    It seems that plans are afoot through [url http://jcp.org/en/jsr/detail?id=236]JSR 236 to add this functionality to Java EE in the form of container managed concurrency facilities. See the [url http://download.oracle.com/otndocs/jcp/concurrency_utilities-1_0-edr-spec/index.html]Early Draft Review.

                    In the meantime I've implemented a bean to manage query threads and an af:poll component to check for their completion.

                    Thanks to all for your suggestions.

                    Kevin