System for enabling access to a relational database from an object oriented program5937402Abstract Logical tables and logical keys are employed to facilitate interaction between user applications and a relational database. Each logical table is a group of at least one column from a table or view associated with a relational database, and can be utilized like a relational table or view. Each logical primary or foreign key is a key between logical and physical tables that behaves like an actual primary or foreign key. A normalization process allows creation of integrator relational schema objects from existing captured tables. Once a denormalized table is captured from a database the normalization process allows the user to define different logical tables using subsets of the columns of the table. One or more columns of the logical table are designated as primary key. The logical tables interact with the mapping process in the same manner as physical tables. Claims What is claimed: Description CORSS REFERENCE TO RELATED APPLICATIONS
TABLE 1
______________________________________
Division
NAMES
______________________________________
American East
New England
American Midwest
______________________________________
Tables 6 and 7 are denormalized schema tables. A single normal structure can be denormalized in a number of different ways. We consider two possibilities in these examples. The denormalization achieved by Tables 6 & 7 is termed as FORM I denormalization. The table structure provides the same object model as the Normalized Schema structure described earlier. In a denormalized schema structure a single table may contain more than one user object. In such case it is essential to understand which column belongs to which object.
TABLE 6
__________________________________________________________________________
Team.sub.-- Division.sub.-- Ball.sub.-- Park
TEAM.sub.-- NAME
CITY SEASON.sub.-- LOSSES
SEASON.sub.-- WINS
BALL.sub.-- PARK.sub.-- NAME
OWNER
DIVISION.sub.-- NAME
__________________________________________________________________________
Tigers Darlington
7 25 Darlington City of
American
Stadium Darlington
East
Red Sox Boston
1 31 Boston City of
New
Garden Boston
England
New Sox Boston
4 28 Boston City of
American
Garden Boston
East
NY Stadium City of
New York
American
Midwest
__________________________________________________________________________
Table 6 contains three distinct objects, namely `Team,` `Division` and `Ball.sub.-- Park.` The `DIVISION NAME` column belongs to the `Division` object. The `BALL.sub.-- PARK.sub.-- NAME` and `OWNER` columns belong to the `Ball.sub.-- Park` object and the `TEAM.sub.-- NAME,` `CITY,``SEASON.sub.-- LOSSES` and `SEASON.sub.-- WINS` columns belong to the `Team` object. The `Team` object has relationships to the `Ball.sub.-- Park` object; however, since the `Ball.sub.-- Park` objects are present in the same table, no separate foreign key column is required as in the case of the normalized schema structure.
TABLE 7
______________________________________
Player.sub.-- Pitcher
CURRENT CURRENT
PLAYS PITCHER
SEASON SEASON
NAME FOR AGE NUMBER LOSSES WINS
______________________________________
John Tigers 22 22 7 25
Andrews
Keith Tigers 31 48 5 27
McSally
John Adams
Red Sox 24 39 1 31
Mike Red Sox 30
Wallace
Terry Stone
New Sox 30 54 10 22
______________________________________
Tables 8-9 and FIG. 23 are denormalized schema tables. These tables describe a different way of denormalizing the same normal schema and the structure is referenced as denormalization FORM II.
TABLE 8
______________________________________
Division
NAME
______________________________________
American East
New England
American Midwest
______________________________________
Data integrity constraints are mechanisms provided by the database system that can be used by users to declare and maintain the object model being stored in the database. A significant contribution of the integrator product to the technology is its support of the different database storage models to provide the same object model. In the normalized form, the identity of an object in the relational table is provided and supported by a primary key constraint that is provided and supported by the relational database. The primary key constraint specifies a set of one or more columns of a table and imposes that the designated columns can contain values whose combination must be unique in the table. This ensures that for each unique object, only one row is created in the database. In order to ensure uniqueness of objects, a user must declare a primary key on a table in the columns that represent the identifying attributes(s) of the object. For example, since the name of the `Ball.sub.-- Park` object is its identifying characteristic, the normalized schema contains a primary key over the `Name` column of the `Ball.sub.-- Park` table. In the denormalized form, however, it may not be possible to define a primary key as the identifying attribute of an object, as more than one row could contain the same object. Refer to the `Team Division Ball Park` table structure (Table 6). More than one row of the table contains the same `Ball.sub.-- Park` object, which gets repeated due to its relationship with the `Team` Objects. Hence, no primary key can be defined on the "Ball.sub.-- Park.sub.-- Name` column. Even though more than one row contains values of `Boston Garden`) there exists in the system only one unique `Boston Garden` Ball.sub.-- Park object. This constraint, however, can no longer be enforced by the relational database itself, as no primary key can be defined for the identifying column. In a normalized schema, relationship between two objects is specified by a foreign key. A foreign key specifies one or more columns of a source table and a target table. The relational database ensures that the source table column contains a value that matches exactly with any one primary key value in the target table. Thus a relationship between the objects from the two tables is established. For example, the normalized schema table `Team` contains a foreign key to the `Division` table on the `In.sub.-- Division` column. This establishes a relationship that the `Team` object has a reference to a `Division` object. The object model stipulates that the `Team` and `Division` objects have a one to many relationship, i.e., one division has many teams associated with it. This relationship has no direct representation in the relational structure. A single foreign key constraint serves to establish the relationship for both the objects. The `Team` object has a direct reference to a `Division` object and all the `Team` objects associated with a `Division` object can be established in the relational system by a simple query by searching in the Team table for the values of the `In.sub.-- Division` column. In a denormalized schema, the relationship between the two objects is established by existence of the two objects in the same row of the table. Referring to the `Team.sub.-- Division.sub.-- Ball.sub.-- Park` Table 6: the relationship between `Red Sox` and `Boston Garden` Objects is established by entering them in the same row, whereas since `NY Stadium` has no team associated with its row, it contains no values in columns other than the ones associated with the `Ball.sub.-- Park` object itself. The illustrated example uses only a one to many relationship for illustrations, however many to many relationship can also be easily supported using relational constructs and can be similarly denormalized. The many to many relationship denormalization is also supported by integrator. FIG. 10 illustrates integrator mapping schema. The TypeMap object is the major object in the integrator Mapping Schema. A single TypeMap object refers to the integrator Relational Schema object created for the table. Other significant objects in the mapping schema (not shown) are AttributeMap which hold the mapping information between an object property and a relational column. Related TypeMap objects also refer to each other. As described earlier, the integrator Mapping Process provides tools to create, change and maintain the TypeMap objects. The Mapping Process can not, however, change the Relational Schema Objects. The integrator normalization process provides mechanisms to create logical tables from a physical table. The capture process creates the relational schema for the physical table. To create a logical table from a physical table in integrator, one or more columns must be chosen from a single physical table, some of those columns must be designated as the primary key of the logical table, and a discriminator must be provided to identity rows of the physical table that can be considered part of the logical table. For example, in the denormalized schema form described above, the following command provided by integrator will create logical tables: oratab +t +sTEAM.sub.-- DIVISION.sub.-- BALL.sub.-- PARK +1BALL.sub.-- PARK-logical +kBall.sub.-- Park.sub.-- Name +cOwner +d"Ball.sub.-- Park.sub.-- Name is not NULL." That command will create a `BALL.sub.-- PARK.sub.-- logical` table that has the same column and key structure as the normal `BALL.sub.-- PARK` table, in the integrator Relational Schema that can be used by the TypeMap objects in the Mapping Schema. Similarly, oratab +t +sTEAM.sub.-- DIVISION.sub.-- BALL.sub.-- PARK +1TEAM.sub.-- logical +kTEAM.sub.-- Name +cCity +CSEASON.sub.-- Losses +cSeason.sub.-- WIns +cBall.sub.-- Park.sub.-- Name +cDivision.sub.-- Name +d"Team.sub.-- Name is not NULL" will create a logical table `TEAM.sub.-- logical` in integrator Relational Schema that will be similar in structure to the normalized form `TEAM` table. The following command creates a logical foreign key from the table `TEAM.sub.-- logical` to table `BALL.sub.-- PARK.sub.-- logical`: oratab +f +STEAM.sub.-- logical+tBALL.sub.-- PARK.sub.-- logical+cBall.sub.-- Park.sub.-- Name FIG. 11 illustrates integrator mapping schema with logical tables. In the integrator Relational Schema, the logical and physical table objects maintain references to each other. Control flows are sensitive to the use of logical tables in the integrator. A major part of the control flows described in this section handle the normalized schema structure. Denormalized schema structures are handled in a separate branch with the main control flow. This branch is denoted as a single box in each figure, which is described in greater detail in separate figures in subsequent sections. Activation is the integrator process through which an object in the relational database is converted into a C++ object in a user program. FIG. 12 is a flow chart which illustrates the control flow for the process. The following SQL statements are generated while activating the Pitcher object `John Andrews` from the database. The first two statements establish the tables that the data needs to be read from. If the object `John Andrews` is not found in the PITCHER table, that table will be ignored from the third statement. SELECT count(*) FROM PLAYER WHERE NAME=`John Andrews`; SELECT count(*) FROM PITCHER WHERE NAME=`John Andrews`; SELECT a.Name,a.Plays.sub.-- For,a.Age, b.Pitcher.sub.-- Number, b.Current.sub.-- Season.sub.-- Losses, b.Current.sub.-- Season.sub.-- Wins FROM PLAYER a, PITCHER b WHERE a.Name+b.Name AND b.Name =`John Andrews`; Referring to FIGS. 13 and 14, a create object operation in integrator corresponds to inserting rows into one or more tables in the relational database. FIG. 13 is a flow chart which illustrates the control flow when a new object is being created in the database. For example, when a team object with properties (name: `White Sox`, city: `Chicago`, season losses: `2` season wins: `29`) and a reference to a new Ball Park object with properties (name: `Chicago Central`, owner: `City of Chicago`, and has a reference to an existing Division object with properties (name: `American MidWest`) is being created new in the database, the following SQL is generated and executed in the given sequence. FIG. 14 illustrates control flow for updating an object in normalized schema. UPDATE PITCHER SET PITCHER.sub.-- NUMBER = 39,CURRENT.sub.-- SEASON.sub.-- LOSSES =1, CURRENT.sub.-- SEASON.sub.-- WINS =32 WHERE NAME=`John Adams` UPDATE PLAYER SET PLAYS.sub.-- FOR=`Red Sox`, AGE=25 WHERE NAME=`John Adams`; FIG. 15 illustrates control flow for deleting an object from normalized schema. The delete operation removes an already persistent object from the database. In relational terms, the operation corresponds to deleting rows from one or more tables. When the `John Adams` Pitcher object is being deleted from the database, the following SQL will be generated in given sequence. DELETE FROM PITCHER WHERE NAME=`John Adams` DELETE FROM PLAYER WHERE NAME=`John Adams` FIG. 16 illustrates control flow for inserting object in a normalized schema collection. The insert operation refers to manipulations of the one to many or many to many relationships. While only the one to many case is illustrated in the examples, the many to many case is supported by the integrator system. As described above, the many side of a one to many relationship does not have a direct representation in the relational database. Manipulation of the set in the object model, i.e., insert or remove from the set, is effected in the database by setting or unsetting an appropriate foreign key in the database. For example, if a `Team` object is inserted into the teams set of a `Division` object, the foreign key column of the `Team` object is changed to contain the primary key value of the Division object. For the purposes of the illustrated flow chart, the owner object of the set, i.e., the Division object in this example, is termed as the `host` object, and the object being inserted into the set, i.e., the `Team` object in the illustrated example, is termed as the `member` object. The operation is effected by the `host` object. When the `Team` object `New Sox` is inserted into the `Division` object `New England` and the types are mapped to tables in normalized schema form, the following SQL statement is generated and executed by integrator: UPDATE TEAM SET IN.sub.-- DIVISION=`New England` WHERE NAME =`New Sox` FIG. 17 illustrates control flow for removing an object from a normalized schema collection. Considerations for the remove operation are the same as the insert. However, for the remove operation, the corresponding foreign key in the database is set to NULL. Considering the example as above: If the `Team` object `New Sox` is now removed from the `Division, object `New England,` the following SQL statement will be generated and executed when tables are in normalized schema form. UPDATE TEAM SET IN.sub.-- DIVISION=NULL WHERE NAME= `New Sox`; FIG. 18 illustrates control flow for activating an object from denormalized schema. As described earlier, the denormalization process may result in many different relational table structures. The integrator runtime system control flow is not sensitive to specifics of the table structure, but only to the concept of denormalization. Hence only one control flow chart is required for the denormalized processing to describe control flows for any form of denormalization. Referring to FIG. 19, a significant point of the denormalized schema processing is that the SQL generated is designed to provide the data integrity support. As explained earlier, the relational database itself may not provide any means to ensure data integrity for a denormalized table structure. The integrator runtime system takes that responsibility. The data integrity of a denormalized table structure is ensured by integrator through generation of correct SQL statements for all object requests generated by users. Also, as denoted in the flow charts of the normalized schema processing, the two streams have some common parts. The activation process using logical tables in denormalized schema is quite similar to the one for tables in normalized schema. The process of `searching` and `reading` an object from a physical table in the normalized schema involves one or more SQL select statements to search for the object's identifying attributes in the primary key columns of the physical table. The process of `searching` and `reading` objects from logical tables involves one or more SQL select statements that search over the columns specified by the user as primary keys of the logical table using the discriminator clause specified by the user in the logical table definition. For example, the following SQL statement is generated to read Pitcher object `John Andrews` from the database table `PLAYER.sub.-- PITCHER`: SELECT count(*)FROM PLAYER.sub.-- PITCHER WHERE NAME=`John Andrews` and NAME is not NULL; SELECT count(*)FROM PLAYER.sub.-- PITCHER WHERE NAME=`John Andrews` AND NAME is not NULL AND PITCHER.sub.-- NUMBER is not NULL; SELECT DISTINCT (a.Name), aPlays.sub.-- For, a.Age, a.Pitcher.sub.-- Number, a.Current.sub.-- Season.sub.-- Losses, a.Current.sub.-- Season.sub.-- Wins FROM PLAYER.sub.-- PITCHER a WHERE a.Name=`John Andrews` AND a.Name is not NULL AND a.PITCHER.sub.-- NUMBER is not NULL; As explained earlier, more than one row in a denormalized table could contain data for the same object in the columns in the database that comprise the logical table. To illustrate the flow chart, two examples are given which refer to the two denormalized schema described earlier. Consider the example above with some extensions: a Team object with properties (name: `White Sox`, city: `Chicago` season losses: `2` season wins: `29`) and a reference to a new Ball Park object with properties (name: `American MidWest`) is being created in the database. For the purpose of this example, also consider that a new Pitcher object with properties (name: `John Clayton`, Age:25, Pitcher.sub.-- Number: 31, Current.sub.-- Season.sub.-- Losses: 2, Current.sub.-- Season.sub.-- Wins: 30) is added to the Team object. If the Team, Division and Ball.sub.-- Park are mapped through logical tables to the same physical table `Team.sub.-- Division Ball Park`, i.e. if the denormalized FORM I described earlier is used, the following SQL is generated and executed in given sequence: INSERT INTO TEAM.sub.-- DIVISION.sub.-- BALL (BALL.sub.-- PARK.sub.-- NAME, OWNER, TEAM.sub.-- NAME, CITY, SEASON.sub.-- LOSSES, SEASON.sub.-- WINS, DIVISION.sub.-- NAME) VALUES (`Chicago Central`, `City of Chicago`, `White Sox`, `Chicago`, 2, 29, `American MidWest`); INSERT INTO PLAYER.sub.-- PITCHER (NAME PLAYS.sub.-- FOR, AGE, PITCHER.sub.-- NUMBER, CURRENT SEASON.sub.-- LOSSES, CURRENT SEASON.sub.-- WINS VALUES (`John Clayton`, `White Sox`, 25, 31,2,30); If the types, however, are mapped using the denormalized FORM II described earlier, the following SQL is generated: INSERT INTO BALL.sub.-- PARK (NAME, OWNER) VALUES (`City of Chicago`, `Chicago Central`); INSERT INTO TEAM.sub.-- PLAYER.sub.-- PITCHER (TEAM.sub.-- NAME, CITY, SEASON.sub.-- LOSSES, SEASON.sub.-- WINS, IN.sub.-- DIVISION, PLAYER.sub.-- NAME,AGE,PITCHER.sub.-- NUMBER, CURRENT.sub.-- SEASON.sub.-- LOSSES, CURRENT.sub.-- SEASON.sub.-- WINS) VALUES (`White Sox`, `Chicago` ,2,29, `American Midwest`, `John Clayton`,25,31,2,30); Referring to FIG. 19 and Item D in FIG. 13, in the control flow descriptions the object being saved directly by the user, i.e., the object that the create message is started on, is referred to as the `main object` and all object references properties of the `main object` are referred to as `property object`. Correspondingly, the types of the objects are termed as `main type` and `property type`. Control flow for generating the denormalized schema SQL for updating an object, Box D in FIG. 14, is substantially similar to the control flow for creating an object as shown in FIG. 19. The difference in the SQL statement generated is that the `INSERT`. . . `SQL statement is generated for creating the object whereas `UPDATE. . . ` SQL statement is generated for updating the object. For instance, if the properties of the objects created in the example above are changed as follows: SEASON.sub.-- LOSSES of Team object `White Sox` is changed to 3 and `Current.sub.-- Season.sub.-- Losses` property of the `John Clayton` `Pitcher` object is changed to 3, the SQL statement below will be generated, or if the Team Division and Ball.sub.-- Park objects are mapped through logical tables to the same physical table `Team.sub.-- Division.sub.-- Ball.sub.-- Park`, i.e., if the denormalized FORM I described earlier is used, the following respective SQL is generated and executed. UPDATE TEAM DIVISION.sub.-- BALL.sub.-- PARK SET OWNER=`City of Chicago`, CITY=`Chicago`, SEASON.sub.-- LOSSES=3, SEASON.sub.-- WINS=29, DIVISION NAME=`American MidWest` WHERE TEAM.sub.-- NAME=`White Sox` and a TEAM.sub.-- NAME is not NULL; UPDATE PLAYER.sub.-- PITCHER SET PLAYS.sub.-- FOR=`White Sox`, AGE=25, PITCHER.sub.-- NUMBER=31, CURRENT.sub.-- SEASON.sub.-- LOSSES=3, CURRENT SEASON WINS=30 WHERE NAME=`John Clayton` and NAME is not NULL; Since both the objects are independent and already persistent, the order of execution is not important in the case of update. However, if the types are mapped using the denormalized FORM II described above, then the following SQL is generated: UPDATE TEAM.sub.-- PLAYER.sub.-- PITCHER CITY=`Chicago`, SEASON.sub.-- LOSSES=3 SEASON.sub.-- WINS=29, IN.sub.-- DIVISION=`AmericanMidWest` WHERE TEAM NAME=`White Sox` and PLAYER.sub.-- NAME is not NULL; UPDATE TEAM.sub.-- PLAYER.sub.-- PITCHER, CITY=`Chicago`, SEASON.sub.-- LOSSES=3, SEASON.sub.-- WINS=29, IN.sub.-- DIVISION=`American MidWest`, AGE=25, PITCHER NUMBER=31, CURRENT.sub.-- SEASON.sub.-- LOSSES=3, CURRENT.sub.-- SEASON.sub.-- WINS=30 WHERE PLAYER NAME=`White Sox` and PLAYER.sub.-- NAME is not NULL and PITCHER.sub.-- NUMBER is not NULL; Referring to FIG. 20, the delete object operation in integrator corresponds to setting appropriate columns in one or more tables in the relational database to NULL when the object type is mapped to tables in a denormalized schema form. Only some of the columns in a denormalized table may belong to the object being deleted. Also, the object may be repeated in more than one row. In order to effectively `delete` the object, all the columns belonging to the object must be set to NULL in all the rows the object is repeated in. The following figure describes the control flow employed to create appropriate SQL to delete an object. This control flow diagram essentially contains the details of the Box D, FIG. 15. To illustrate with an example, when `Team` object `New Sox` is deleted, the following SQL statement is generated and executed by integrator: Denormalized Schema Form I: UPDATE TEAM.sub.-- DIVISION.sub.-- BALL.sub.-- PARK SET TEAM.sub.-- NAME=NULL, CITY=NULL, SEASON.sub.-- LOSSES=NULL,SEASON.sub.-- WINS=NULL WHERE TEAM.sub.-- TEAM=`New Sox` and TEAM.sub.-- NAME is not NULL; Denormalized Schema Form II: UPDATE TEAM.sub.-- PITCHER.sub.-- PLAYER SET TEAM.sub.-- NAME=NULL,CITY=NULL, SEASON.sub.-- LOSSES=NULL, SEASON.sub.-- LOSSES=NULL, HOME.sub.-- FIELD=NULL, IN.sub.-- DIVISION=NULL WHERE TEAM.sub.-- NAME=`New Sox` and TEAM.sub.-- NAME is not NULL; Referring to FIG. 21, the relationship between two objects is signified in a denormalized schema structure by the existence of the two objects in the same row of the table. Hence, the insert operation in integrator corresponds to creating a new row in the table and filling appropriate columns of the tables with the property values from the two objects. To illustrate with an example, when a new `Pitcher` object with properties name: `John Clayton`, Age: 25, Pitcher.sub.-- Number: 31, Current.sub.-- Season.sub.-- Losses: 2, Current.sub.-- Season.sub.-- Wins: 30 is added to an existing `Team` object `Red Sox,` the following SQL statement is generated. INSERT INTO PLAYER.sub.-- PITCHER ( NAME,PLAYS.sub.-- FOR,AGE,PITCHER.sub.-- NUMBER, CURRENT.sub.-- SEASON.sub.-- LOSSES, CURRENT.sub.-- SEASON.sub.-- WINS) VALUES (`John Clayton`, `Red Sox`, 25,31,2,30); Denormalized Schema Form II: INSERT INTO TEAM.sub.-- PLAYER.sub.-- PITCHER (TEAM.sub.-- NAME,CITY,SEASON.sub.-- LOSSES, SEASON.sub.-- WINS, IN.sub.-- DIVISION, PLAYER.sub.-- NAME,AGE,PITCHER.sub.-- NUMBER, CURRENT.sub.-- SEASON.sub.-- LOSSES,CURRENT.sub.-- SEASON.sub.-- WINS) VALUES (`Red Sox`, `Boston`,1,31, `New England`, `John Clayton`,25,31,2,30); The SQL statement generated looks the same as the one generated for `Create` object; however, the difference is that for an `Insert` operation only one table needs to be updated, whereas for `Create` all the tables in the type hierarchy are updated. FIG. 21 illustrates the control flow employed to generate appropriate SQL statements. The object with the set property, the `Team` object in this case, is termed as the `host` object and the object being inserted into the set, `Pitcher,` is termed as the `member` object. Referring to FIG. 22, the relationship between two objects is signified in a denormalized schema structure by the existence of the two objects in the same row of the table. Hence, the remove operation in integrator corresponds to moving the two objects into separate rows of the table. This can be effected in a number of ways. Considering the object with set property as the `host` object and the object being inserted as the `member` object: integrator effects the remove operation by creating a new row in the table with only the columns belonging to the `host` object and then setting the same columns to NULL in the row that contains both objects. To illustrate with an example, when `Team` object `Red Sox` is removed from `Division` object `New England,` the following SQL statement are generated and executed in given sequence for denormalized schema form I. INSERT INTO TEAM.sub.-- DIVISION.sub.-- BALL.sub.-- PARK (DIVISION.sub.-- NAME) VALUES (`New England`); UPDATE TEAM.sub.-- DIVISION.sub.-- BALL.sub.-- PARK SET DIVISION.sub.-- NAME=NULL, SEASON.sub.-- LOSSES=NULL, IN.sub.-- DIVISION=NULL WHERE PLAYER.sub.-- NAME=`John Adams; and PLAYER.sub.-- NAME is not NULL and PITCHER.sub.-- NUMBER is not NULL FIG. 22 illustrates the control flow integrator employs to generate appropriate SQL statements for the `Remove` operation. The control flow is quite similar to the one used in the `Insert` operation with a few differences. The `Insert` operation requires column and property values from both objects, whereas the `Remove` operation requires the column names and property values form the host object and only the object property values from the member object. It should be understood that various changes and modifications may be made from the embodiments herein disclosed. Accordingly, the invention is not to be viewed as limited except by the scope and spirit of the appended claims.
|
Same subclass Same class Consider this |
||||||||||
