The present application claims the priority of Chinese patent application, Serial No. 200410068290.X, titled “Globalized Database System and Method for Accessing the Same,” which was filed on Aug. 27, 2004, and which is incorporated herein by reference.
The present invention relates to a globalized database system for managing locale sensitive data and a corresponding method for accessing the locale sensitive data on the globalized database.
When developing globalized applications, especially Web applications, some data sensitive with respect to locale are stored in the database other than in property files. This type of database is a globalized database. Developers need to design extra tables to store these locale-sensitive data and implement specific database access functions to handle them. Since the globalization concern mingles with the core business concerns in this way, a database access code using JDBC (Java DataBase Connectivity) or other frameworks like Hibernate (a type of software product) are more complicated and require more maintenance than conventional database access codes that do not have globalization capability. A locale acts as an identification of a user's preference for a certain local language; the locale can be composed from a regional ID and a language ID.
Currently, developers use application ad hoc solutions for this problem to capture the globalization requirement early in the design stage. For newly developed systems, developers should follow these steps to implement the globalization feature in a conventional database access layer:
Developers expend a large effort to generate a globalization data access layer. Once developed, the globalized data access layer is expensive to modify. Furthermore, when a designer wishes to provide globalization features in an existing system, modifying the data storage layer requires a tremendous effort. The newly added localized data in the database causes many changes to the schema of the database table and all the access codes of the database table.
Using a conventional approach, developers typically modify the DB access layer by following these steps:
Furthermore, if the source code of the system is unavailable, then the migration is even more difficult. A practical conventional approach is rewriting the views, controllers and models, respectively:
What is therefore needed is a globalized database system and method for accessing the same that provides in the data storage layer a way to separate the globalization concern from the core business concerns. The globalized database system provides the developer with a transparent globalization data storage feature and eases development and maintenance work. The need for such a solution has heretofore remained unsatisfied.
The present invention satisfies this need, and presents a system, a computer program product, and an associated method (collectively referred to herein as “the system” or “the present system”) for providing a globalized database system and a method for accessing the globalized database. The present system provides a common and reusable solution for managing and accessing multilingual data in a database. The present system separates globalization concerns from core business concerns, thereby freeing developers from the repetitive work necessary for the implementation of the globalization feature in a database access layer.
The present system provides a globalized database system comprising a locale determining system that determines a locale identification from an application. The present system further comprises a database for storing a globalized database table. The globalized database table comprises a globalized column corresponding to a user query. Each of the globalized columns comprises data values related to different locales. The present system comprises a database access driver for intercepting a database query command of the user. Based on the locale identification retrieved from the locale determining system, the present system retrieves the locale sensitive data value that corresponds to the locale identification from the globalized columns in the globalized database table.
To access the globalized database, the present system intercepts a database query command of the user; retrieves a locale identification of a user; and based on the retrieved locale identification, retrieves the locale sensitive data value that corresponds to the locale identification from the globalized column in the globalized database table.
The present system provides a globalized database system that comprises a method to input data constituting the database. The present system further provides a method for generating a globalized database table. This method extracts locale sensitive data from the input data, generates a globalized database table that comprises a globalized column, and places similar data values corresponding to different locales into at least one globalized column for later database query.
The present system uses a globalized database table (GTable) and build-time and run-time locale models to provide a transparent locale sensitive data access mechanism in the database. The present system enables features comprising:
The various features of the present invention and the manner of attaining them will be described in greater detail with reference to the following description, claims, and drawings, wherein reference numerals are reused, where appropriate, to indicate a correspondence between the referenced items, and wherein:
System 10 utilizes a globalized table (a GTable) as a database table. The Gtable comprises one or more globalized column(s) (a GColumn). For each GColumn, different localized values corresponding to respective locale can exist in a GTable record. Normal database tables can be changed to the GTable type, and normal non-key columns of a GTable can be transformed into a GColumn type to store locale sensitive data. In an implementation, system 10 provides a globalization database driver that comprises a thin layer upon an existing database driver to support system 10.
In a build-time database locale model concept, a system table is used to record the supported locales in the relational database, and the GTable appears like a conventional database table. Developers can use the same codes to access the conventional database table and the GTables. To achieve this, system 10 obtains the run-time locale of a GTable access operation from a global locale repository rather than directly from parameters in the access codes.
System 10 uses a global locale repository to manage the current locale of each request. Developers register the current locale at a proper place (usually at the beginning of some services). In this way, locale is an environment variable in one process. For distributed systems, other methods are used to propagate locales between different processes. In a GTable access operation, both run-time locale and build-time locale models assist in determining the target of the locale sensitive data.
Using the GTable of system 10, build-time and run-time locale models used in the database can be implemented in different platforms using different technologies. In one embodiment, Java technology and DB2 (a kind of database management system software product from IBM corporation) database management system are used. While system 10 is described for illustration purpose only in terms of Java and DB2, it should be clear that the invention is applicable as well to, for example, any object-oriented programming language that is platform independent and any relational database.
Referring to
The run-time scenario (
The globalization driver 2 adds a GTable enhancement layer (GTable core) 21 on a normal driver 22. The globalization driver 2 intercepts a query command from the application 93, such as, for example, an SQL query statement, and converts the query command into a form capable of accessing the GTable. While system 10 is described in terms of SQL for illustration purpose only, it should be clear that the invention is applicable as well to, for example, any query language. During the conversion, the GTable enhancement layer 21 incorporates the current locale retrieved from a run-time locale model library 5 into the converted query command (the SQL query statement containing more parameters), and the current locale is registered by the specific application 93 at a proper time (usually at a start time) into the run-time locale model library 5.
The GTable enhancement layer 21 delegates the converted query command to a normal driver 22, thereby accessing directly the underlying database according to the converted query command and retrieving from a GTable 6 the multilingual data to be queried, corresponding to the current locale. For the query command querying database table(s) 7, the GTable enhancement layer 21 does no conversion, and delegates the query directly to the driver 22 so as to access the database table 7. Database table 7 is a normal database table without GTable capability. In
For the programmer 92, system 10 provides a globalization driver 2. The programmer 92 transparently obtains the features that Gtable 6 provides. System 10 provides a thin layer upon the existing driver 22 to enable the concept of the GTable 6. For example, one embodiment uses a DB2 JDBC driver as the driver 22.
A table 61 illustrates an internal structure of system 10 under the point of view of a programmer 92 at the build-time for an exemplary core business concern. Table 61 shows an example of a ScenicSpot table 61, whose primary key is a globalized table ID SCENICSPOT_ID 305, and the table comprises globalized columns as SCENICSPOT_NAME 310 and SPOT_INTRODUCTION 315 as well as a non-globalized column SCENICSPOT_TYPE 320. Each of the globalized columns SCENICSPOT_NAME 310 and SPOT_INTRODUCTION 215 has the respective multilingual data corresponding to each locale. For example, when SCENICSPOT_ID 305=1, SCENICSPOT_NAME 310 may be names such as “” or “west lake” etc., corresponding to various languages.
Applications that interact with database management systems typically use the SQL language. The GTable Enhancement layer 21 intercepts the SQL queries that are related to the G-Main table 62 and the G-Extra table 63. The GTable enhancement layer 21 modifies the intercepted SQL query to access the corresponding hidden table, the G-Extra table 63, and also add other locale conditions based on the current thread environment locale. After making modifications (conversions) to the SQL commands, the GTable Enhancement Layer 21 delegates the functions to the underlying driver 22 by passing the modified SQL commands to the driver 22. To the application 93, all these are transparent.
The behavior of the GTable enhancement layer 21 is configured to meet the various existing requirements. In practice, programmer 92 may need both locale sensitive and locale insensitive operations on the GTable 6. Consequently, system 10 provides a switch on the GTable 6 to enable and disable the globalization feature. States of the switch are ON, STRICT-ON, and OFF. In Table 1, the respective behaviors these switch states are described.
Providing such a switch allows programmer 92 to customize the GTable enhancement layer 21. For example, when converting an SQL command from a client code, the ON state representing the join type of the FROM clause in the SQL command is left join or right join; the STRICT-ON state representing the join type of the FROM clause in the SQL command is inner join; and the OFF state representing all the operations in the SQL command are only on values corresponding to the default locale in the G-Main table 6.
The switch states can be changed in the run-time via the APIs (Application Programming Interfaces) that system 10 provides. Programmer 92 can also perform locale insensitive operations on the GTable 6. For existing systems, after changing some normal tables to Gtables 6, the programmer 92 may find some operations on some Gtables 6 are still locale insensitive. Consequently, the programmer 92 can add code to close this switch before the database access operation so that the database access operations do not change before and after the application of GTable 6.
The semantics of the SQLs after introducing the GTable 6 and GColumn are the same, while the underlying operations on GColumns change somewhat from the operations on normal columns. A record of GTable 6 may have many possible values in its GColumns. However, after the environment locale is decided, a record of the GTable 6 can be viewed just as a normal record and have an SQL command executed on it. This approach is transparent to the client code, and separates the globalization concern from the core business logic. In one embodiment, configuration files are used to maintain the settings on the database and the GTable 6. These configurations are be used by the GTable enhancement layer 21.
Introduction of system 10 to a database system has little impact on performance of the database system. Metadata of the GTable 6 are installed at the beginning. For Gtable 6, operations that were previously handled by the programmer 92 are now handled by the GTable enhancement layer 21: when involving the GColumns, to execute SQL conversion and delegate to the underlying driver 22; and when not involving the GColumns, to directly delegate to the underlying driver 22. Operations on database table 7 are just delegated to the underlying driver 22 without any notable impact on performance. Therefore, introducing system 10 only introduces some checking and SQL transformation works, which does not have great impact on performance.
The GTable enhancement layer 21 retrieves the current locale from a locale repository 51 and transforms the SQL statement 405 into a transformed SQL statement 410:
The internal structure of the GTable 6 shown in
In one embodiment, the GTable 6 can adopt a structure column, in which a data structure is maintained to replace the simple data type. The structure column can be used to maintain all multilingual information in one column, such that only the G-Main table 62 is used to support the GTable 6 without needing an additional extra table.
The locale model provided by system 10 provides transparent support of GTable 6 and designs the locale as an environment attribute instead of an interface parameter of a function. In the build-time, system 10 introduces a system locale table for managing the supported locales in the database. A management tool handles these locale settings. A default locale attribute is associated with a database and a table. A default locale of a table can be inherited from the default locale of the database if the default locale of the table is not set specifically. The default locale of the table determines which locale sensitive values are stored in the GColumns of the G-Main table 62.
The run-time locale model library 5 enables the programmer 92 to register/retrieve the current locale and mark the call level (change the switch state that is introduced in Table 1). This run-time locale model library 5 can use different technologies to implement the defined common interfaces in various environments. The programmer 92 can customize application 93 to implement the given interface. The interfaces comprise the following:
In a typical process, programmer 92 calls the “register the locale” interface after receiving a request from the user. The GTable enhancement layer 21 invokes the ‘retrieve the locale’ interface to automatically obtain the run-time locale. All of the existing code of the user need not be changed to transfer the locale information. The ‘mark the call level’ interface is optional for programmer 92 to adjust the switch state in Table 1 of the introduced GTable 6 according to the practical need of an application. For example, as described above, some operations of the GTables 6 in some specific applications 93 may still be locale insensitive, so some codes can be added to turn off the switch (OFF) of the GTable 6 before the database accessing operations, allowing the accessing operations of the specific database to have no impact on the G-Extra table 63.
For example, in
A thread 95 in
As described above, the globalized database 61 and the database 62 in
For a distributed environment, a different implementation of the run-time locale model is required. For instance,
Referring to
The request handler 96 retrieves the locale setting (locale ID) of a user from the request of the user such as an HTTP (Hypertext Transfer Protocol) request with a locale handle, and invokes the “register the locale” interface at ST51 to place the information related to the locale of the user (locale handle or ID) into the locale repository 51. Internationalization service(s) 98 of the WAS V5 can automatically synchronize the local locale repository 51 of the request handler 96 with the local locale repository 52 of data object(s) 97 (e.g., the globalization driver 2 coupled directly to the data object 97). This enables the globalization driver 2, at ST54, to invoke the “retrieve the locale” interface, automatically extract the locale ID registered at ST51, and incorporate the locale ID into a database query (SQL command) of an application, i.e. contain it in an SQL command converted by the globalization driver 2. The globalization driver 2 thereby retrieves a globalized data value corresponding to the locale ID from the underlying GTable 6.
The invoking of the “mark the call level” interface shown in ST52 and ST53 in
A GTable manager 3 shown in
The GTable manager 3 comprises the following functions:
At step 703, the globalization driver 2 intercepts the data query command (SQL command) from the application. At step 704, the globalization driver 2 retrieves the locale ID registered by the application by using the proper modes for different application environments as shown in
If selecting not to change the switch state of the GTable (No) at step 705 or after completing the step 706, the flow proceeds to the main flow, i.e., step 707. Step 705 and step 706 are shown after step 704 in
At step 707, the globalization driver 2 transforms the SQL command in the application to a form capable of direct access of the globalized database table, i.e., the G-Main table 62 and the G-Extra table 63. The transformed SQL command comprises the locale ID registered by the application (retrieved at step 704) and the switch state parameter transferred at step 706. At step 708, through the transformed SQL command, the values of the locale sensitive data corresponding to the registered locale IDs are retrieved from the globalized columns of the G-Main table 62 and the G-Extra table 63. Then the flow ends.
It is to be understood that the specific embodiments of the invention that have been described are merely illustrative of certain applications of the principle of system 10. Numerous modifications may be made to the globalized database and methods of accessing the same described herein without departing from the spirit and scope of the present invention.
| Number | Date | Country | Kind |
|---|---|---|---|
| 200410068290.X | Aug 2004 | CN | national |