A portion of the disclosure of this patent document contains material which is subject to copyright protection. The copyright owner has no objection to the facsimile reproduction by anyone of the patent document of the patent disclosure, as it appears in the Patent and Trademark Office patent file or records, but otherwise reserves all copyright rights whatsoever.
The following applications are cross-referenced and incorporated herein by reference: U.S. Provisional Application No. 60/349,432 entitled “System and Method for Dynamic Queries,” by Matthew Shinn et al., filed Jan. 18, 2002.
The present invention relates to the execution of queries against a database.
The Enterprise JavaBean (EJB) specification from Sun Microsystems, Inc. of Palo Alto, Calif., defines a way to do multi-platform transaction processing in Java. The EJB spec utilizes containers in which transaction-oriented applications can be written. The EJB architecture includes several elements, including session beans that control work flow and client interaction, as well as entity beans that interact with external resources such as databases and other enterprise servers. Entity beans can represent data elements, such as database elements that are represented to an application.
Access is gained to an EJB through a Home interface, using an EJB server and relevant EJB container. The EJB container provides access to an entity bean under “managed persistence,” whereby the entity bean does not need to be loaded into memory. The loading is done by the container through Container Managed Persistence (CMP), or by the entity bean itself using Bean Managed Persistence (BMP). Each entity bean can provide at least one finder method, which provides a user with a way to look up the bean when needed.
The EJB specification describes ways to execute queries against a database, as well as ways for a user to communicate queries to an EJB container. A user develops a query before deploying an EJB. Once the EJB is deployed, the user can execute the query. When executing a query, the component executing the query will iterate through all the results of the query. These results will then be used to populate other EJBs. All these EJBs are then handed back to the user in one big collection. This can waste system resources unnecessarily, as a user may only be interested in certain results and does not need to be sent the entire result set.
Systems and methods in accordance with one embodiment of the present invention can overcome these and other deficiencies of the prior art. A client can generate a query request using a finder method and sending the query request to a Home interface in an EJB container. The Home interface can do a security check, then contact the relevant bean manager. The bean manager can pass the query request in a call to a persistence manager. The persistence manager can receive the request and generate the appropriate SQL for the query. The persistence manager can execute the SQL query on the database and receive back a result set from the database.
The persistence manager can populate a set of EJBs with the result set. This can be a full result set, or a subset of the full result set. A bean manager is able to provide the client with access to any populated EJBs, which can be stored in local cache. The bean manager can allow the user to access all the EJBs or a subset of the EJBs. The bean manager can also provide the user with a list of EJBs and let the client select the EJBs to access. The client can iterate through the result set, either by viewing different subsets or selecting different EJBs from the list. This iterative process can continue until all the results have been viewed or the client does not wish to access any more results.
Other features, aspects, and objects of the invention can be obtained from a review of the specification, the figures, and the claims.
Systems and methods in accordance with one embodiment of the present invention change how results of a query are handled. Such a system can iterate through only those results for which a user asks, instead of every result matching the query. A user can execute a finder method, and the system will give the user back a cursored collection. A cursored collection allows a user to have the finder results processed on an as-needed, or as-requested, basis. Previously, all finder results were processed in batch before control was passed back to the user. In some situations, this can result in unnecessary work being done, costing the user both time and CPU cycles. With cursored collections, users can choose how finder results are processed.
A “cursored” collection can be thought of as a collection that keeps a pointer at the present location of the user in the collection of query results. This pointer can be maintained by the database or a persistence manager, for example. In one embodiment, the system gets the data from the database at each step as the user iterates through the collection. In another embodiment, the system stores all the results of the query in local cache and sends only those results to the user that correspond to the current iteration. These approaches can avoid the wasting of resources associated with pulling all the results and sending them to the user, since the user might only be interested in the first five results, for example.
If a user executes a query that generates 100 results, for example, 100 EJBs can each be populated with one of those results. In one embodiment, a user is shown a list of the results, and is allowed to choose which results the user wishes to receive. In another embodiment, the user could be send 20 results at a time. If the user gets the result being sought, there is no need to send the remaining 80 results.
Cursored collections can be implemented with a simple API. There may be no impact on users unless they opt to make use of this feature. To enable the use of cursored collections, users can simply add an element to a relevant CMP deployment descriptor. This element can be as follows:
<!ELEMENT return-cursored-collection (#PCDATA)>
This return-cursored-collection element can be a sub-element of a query function, such that it can be specified on a per-method basis. The value of the return-cursored-collection element can be either ‘True’ or ‘False’. Cursored collections may only be available for finders on the local Home interface, as cursored collections are not serializable in some embodiments.
In addition to adding an element such as a return-cursored-collection element to the deployment descriptor, a cursored collection interface can be created to provide the user with a method that can be used to close the underlying result set. It may be imperative that the user invokes this method when they are finished with the cursored collection to release the database, as well as any associated JDBC resources.
Currently, when multi-object finders return a collection of primary keys, EJB objects are materialized for each primary key. This is not necessary, however, unless each of the EJBs will be invoked. If it is reasonably certain that not all finder results will be used, it may be more efficient to create the EJB objects as they are needed. The efficiency can be further improved when an option such as finders-load-bean is enabled, in which case the EJB objects are created and their fields are loaded into cache.
A cursored collection interface to external entities, such as Javadocs, MBeans, Objects, and classes, can be implemented as:
The application can make use of this interface as follows:
The persistence manager 108 can return a list of results from which the client 100 can choose, or can return a certain subset of results for each iteration through the result set. As shown in
Methods of the present invention can be implemented on a computer-readable medium, a computer program product, computer system and/or computer data signal embodiment in transmission medium.
The foregoing description of preferred embodiments of the present invention has been provided for the purposes of illustration and description. It is not intended to be exhaustive or to limit the invention to the precise forms disclosed. Many modifications and variations will be apparent to one of ordinary skill in the art. The embodiments were chosen and described in order to best explain the principles of the invention and its practical application, thereby enabling others skilled in the art to understand the invention for various embodiments and with various modifications that are suited to the particular use contemplated. It is intended that the scope of the invention be defined by the following claims and their equivalence.
This application claims priority to U.S. Provisional Patent Application No. 60/358,655, filed Feb. 21, 2002, entitled “SYSTEM AND METHOD FOR CURSORED COLLECTIONS,” which is hereby incorporated herein by reference.
Number | Name | Date | Kind |
---|---|---|---|
5499371 | Henninger et al. | Mar 1996 | A |
6085198 | Skinner et al. | Jul 2000 | A |
6199195 | Goodwin et al. | Mar 2001 | B1 |
6266666 | Ireland et al. | Jul 2001 | B1 |
6442541 | Clark et al. | Aug 2002 | B1 |
6453321 | Hill et al. | Sep 2002 | B1 |
6466933 | Huang et al. | Oct 2002 | B1 |
6505200 | Ims et al. | Jan 2003 | B1 |
6539396 | Bowman-Amuah | Mar 2003 | B1 |
6571282 | Bowman-Amuah | May 2003 | B1 |
6591272 | Williams | Jul 2003 | B1 |
6640244 | Bowman-Amuah | Oct 2003 | B1 |
6694328 | Bennett | Feb 2004 | B1 |
6760719 | Hanson et al. | Jul 2004 | B1 |
6823329 | Kirk et al. | Nov 2004 | B2 |
6836889 | Chan et al. | Dec 2004 | B1 |
6971085 | Alcorn | Nov 2005 | B1 |
6985912 | Mullins et al. | Jan 2006 | B2 |
6996565 | Skufca et al. | Feb 2006 | B2 |
20020042789 | Michalewicz et al. | Apr 2002 | A1 |
20030014552 | Vaitheeswaran et al. | Jan 2003 | A1 |
20030050932 | Pace et al. | Mar 2003 | A1 |
Number | Date | Country |
---|---|---|
2339036 | Jan 2000 | GB |
Number | Date | Country | |
---|---|---|---|
20040002965 A1 | Jan 2004 | US |
Number | Date | Country | |
---|---|---|---|
60358655 | Feb 2002 | US |