1. Technical Field
The present invention relates to databases in general, and in particular to relational databases. Still more particularly, the present invention relates to a method and apparatus for generating a transaction-bound sequence of records in a database table within a relational database.
2. Description of Related Art
Database tables are commonly utilized by database programmers during database development. A database programmer can add a numerical field, such as an ORDER field, to a database table for tracking the order in which records are entered into the database table. For example, an ORDER field can be added to an EMPLOYEE database table having a NAME field, an EMPLOYEE_NUMBER field, and a STATE field for keeping track of the order of records being inserted in the EMPLOYEE database table. Records added into the EMPLOYEE database table are typically managed by a global mechanism of a relational database. Each time a new record is added to the EMPLOYEE database table, a number is generated in the ORDER field by the global mechanism of the relational database. The value of the number in a corresponding entry of the ORDER field is automatically incremented by 1 for each new record entered, thus allowing all records in the EMPLOYEE database table to be tracked, as shown in Table I.
Quite often, multiple records within a database table may be related or belong to a common transaction. However, global mechanisms of existing relational databases do not support numbering of the records within a database table in a transaction-bound order such that records are numbered based upon common transactions.
Consequently, it would be desirable to provide a method and system for generating a transaction-bound sequence of records in a database table within a relational database.
In accordance with a preferred embodiment of the present invention, a transaction-bound tracking table, which includes a transaction_id column, a table_name column and a last_order_number column, is provided to a relational database. In response to an transaction attempting to insert a record to a database table within the relational database, an identification (ID) of the transaction and the name of the associated database table are initially obtained. A determination is then made whether or not the obtained transaction ID and the associated database table name are found within the corresponding columns of the transaction-bound tracking table. If the obtained transaction ID and the database table name are not found in the transaction-bound tracking table, a new entry is generated in the transaction-bound tracking table for the obtained transaction ID and database table name, and a value in the last_order_number column associated with the entry is set to 1. Otherwise, if the obtained transaction ID and the database table name are found in the transaction-bound tracking table, a value in the last_order_number column associated with the entry is incremented by 1. The value in the last_order_number column associated with the entry is subsequently copied to the corresponding order tracking field associated with the record entry in the database table for the transaction.
All features and advantages of the present invention will become apparent in the following detailed written description.
The invention itself, as well as a preferred mode of use, further objects, and advantages thereof, will best be understood by reference to the following detailed description of an illustrative embodiment when read in conjunction with the accompanying drawings, wherein:
In order for a relational database to have the capability to track transaction-bound sequences for database tables, a transaction-bound tracking table is initially provided within the relational database. With reference now to the drawings, and in particular to
With reference now to
The relational database can obtain the transaction ID by utilizing a database Application Program Interface (API). For example, a callable database procedure that knows how to obtain the transaction ID can be invoked. The callable database procedure then uses the database API to obtain the transaction ID and returns the transaction ID to the caller. If the relational database does not have an API for obtaining the current transaction ID, then the relational database can query the database transaction logs to determine the transaction ID.
If the transaction ID and database table name are not found in the TRANSACTION_ID and TABLE_NAME columns, respectively, of the transaction-bound tracking table, a new entry is generated in the TRANSACTION_ID column for the transaction ID, the database table name is inserted into the TABLE_NAME column of the same entry, and a value in the LAST_ORDER_NUMBER column of the same entry is set to 1, as shown in block 23.
Otherwise, if the transaction ID and database table name are found in the TRANSACTION_ID and TABLE_NAME columns, respectively, of the transaction-bound tracking table, the value in the LAST_ORDER_NUMBER column of the associated entry is incremented by 1, as depicted in block 24.
Finally, the value in the LAST_ORDER_NUMBER column of the entry associated with the transaction is copied to an ORDER field of the database table for the record associated the transaction, as shown in block 25, and the process returns to block 21.
For all records of the database table that are processed as discussed above, the order of insertion of the records will be numbered according to a transaction-bound sequential order. For example, in the above-mentioned Table I, if the first four records belong to a first transaction, the fifth and sixth records belong to a second transaction, and the last three records belong to a third transaction, the values in the ORDER field of the database table are entered by the method of the present invention as shown in Table II:
For all those transactions that have “completed,” corresponding entries can be removed from the transaction-bound tracking table. The transaction removal can be performed by, for example, a pre-scheduled daemon or background process that uses API of the relational database or the transaction log records to determine whether or not certain transactions in the transaction-bound tracking table have been completed. This process basically queries the transaction-bound tracking table to get all transaction IDs and then determines which of those transactions have completed such that entries of the completed transactions can be removed from the transaction-bound tracking table.
As has been described, the present invention provides a method for generating transaction-bound sequences for numbering records in a database table of a relational database. The present invention allows transaction-insensitive global mechanisms to be extended for numbering records in database tables to the generation of sequences that number the records within particular transactions.
Referring now to
While an illustrative embodiment of the present invention has been described in the context of a fully functional data processing system, those skilled in the art will appreciate that the software aspects of an illustrative embodiment of the present invention are capable of being distributed as a program product in a variety of forms, and that an illustrative embodiment of the present invention applies equally regardless of the particular type of media used to actually carry out the distribution. Examples of the types of media include recordable type media such as thumb drives, floppy disks, hard drives, CD ROMs, DVDs, and transmission type media such as digital and analog communication links.
While the invention has been particularly shown and described with reference to a preferred embodiment, it will be understood by those skilled in the art that various changes in form and detail may be made therein without departing from the spirit and scope of the invention.
Number | Name | Date | Kind |
---|---|---|---|
5799305 | Bortvedt et al. | Aug 1998 | A |
5930806 | Taira et al. | Jul 1999 | A |
5995980 | Olson et al. | Nov 1999 | A |
7167858 | Naeymi-Rad et al. | Jan 2007 | B2 |
20010044834 | Bradshaw et al. | Nov 2001 | A1 |
20030200212 | Benson et al. | Oct 2003 | A1 |
20030204420 | Wilkes et al. | Oct 2003 | A1 |
20040193655 | Miyata et al. | Sep 2004 | A1 |
20040267809 | East et al. | Dec 2004 | A1 |
20050027725 | Kagalwala et al. | Feb 2005 | A1 |
20050038671 | Naeymi-Rad et al. | Feb 2005 | A1 |
20050071341 | Chkodrov et al. | Mar 2005 | A1 |
20050131966 | Lou | Jun 2005 | A1 |
20070115738 | Emaru et al. | May 2007 | A1 |
20070203910 | Ferguson et al. | Aug 2007 | A1 |
20080098045 | Radhakrishnan et al. | Apr 2008 | A1 |
20090024871 | Emaru et al. | Jan 2009 | A1 |
Number | Date | Country | |
---|---|---|---|
20090216813 A1 | Aug 2009 | US |