|
|
|
FILE OR DATABASE MAINTENANCE |
System and method for providing a persistent object framework for managing persistent objects6912520
Abstract
A system and method for managing persistent objects with a persistent object framework is disclosed. The persistent object framework receives queries and instructions from an application for data from the persistent objects. The persistent objects are stored in data sources, such as databases or repositories. The persistent object framework may create, save, update, access, search, and delete persistent objects. Further, the persistent object framework caches applicable persistent objects for the application. The persistent object framework provides the caching for the persistent objects. The persistent object framework supports both Lightweight Directory Access Protocol and relational databases.
Claims
1. A system for managing persistent objects for an application accessing data, wherein said persistent objects are stored in at least one data source, comprising:
a persistent object framework to provide data from and perform functions on said persistent objects in accordance with said application, wherein the persistent object framework is between the application and the data source and providing an interface for the application to query the data source; and
a cached set of persistent objects within said persistent object framework and managed by the persistent object framework, the persistent objects being identified for use by said application and corresponding to said stored persistent objects.
2. The system of claim 1, wherein said application is a Java servlet.
3. The system of claim 1, wherein said functions include a function to create a persistent object, the creation function comprising caching the newly-created persistent object in the cached set of persistent objects and then, inserting the newly-created persistent object into the data source after a save transaction has been committed or a flush method has been invoked.
4. The system of claim 1, wherein said functions include a function to cache a persistent object.
5. The system of claim 1, wherein said functions include a function to update a persistent object, wherein the update function comprises deferring comprises writing to a persistent object in the data source that is deferred until a transaction is committed, a flush method is invoked, or a query process is started.
6. The system of claim 1, wherein said persistent object framework includes a set of data models corresponding to said stored persistent objects.
7. The system of claim 1, further comprising an additional data source and wherein said persistent object framework includes an object space to map said persistent objects to the at least one data source or the additional data source based on a type definition for each of the persistent objects.
8. A system for managing persistent objects correlating to an application, comprising:
means for mapping a persistent object stored within a data source with a persistent object framework coupled to said application;
means for identifying said persistent object stored in said data source as applicable to said application;
means for caching said persistent object within said persistent object framework; and
means for creating a new persistent object according to a data model stored by the persistent object framework, the creating comprising caching the new persistent object in the persistent object cache and inserting the new persistent object in the data source after a save transaction has been committed or a flush method has been invoked.
9. A system for searching persistent objects stored in at least one data source, wherein an application accesses said persistent objects for data, comprising:
means for receiving a search query for a persistent object at a persistent object framework;
means for determining a query type for said search query, wherein said query type is selected from the group of query types consisting of a primary key, a handle, a unique key, a query filter, and a relationship between persistent objects;
when said query type is determined not to be a query filter, means for searching a cache within said persistent object framework for said persistent object according to said query type; and
means for searching said data source when said persistent object is not within said cache.
10. A system for managing persistent objects within an application system, wherein said persistent objects are stored within a first data source and a second data source and said persistent objects provide data to an application, comprising:
means for implementing a persistent object framework that caches said persistent objects correlating to said application comprising:
means for creating said persistent objects;
means for caching said persistent objects;
means for accessing said persistent objects;
means for updating said persistent objects;
means for searching said persistent objects:
means for deferring writes to said first and second data sources; and
means for controlling persistent storage of said persistent objects; and
means for retrieving said data from said first and second data sources when requested by said persistent object framework.
11. A method for managing persistent objects correlating to an application, comprising;
mapping a persistent object stored within a data source with a persistent object framework coupled to said application;
identifying said persistent object stored in said data source as applicable to said application;
caching said persistent object within a cache managed by said persistent object framework; and
with the persistent object framework, creating a new persistent object according to a data model stored by the persistent object framework, the creating comprising caching the new persistent object in the persistent object cache and inserting the new persistent object in the data source after a save transaction has been committed or a flush method has been invoked.
12. The method of claim 11, wherein said creating includes determining initial values for attributes within said data model.
13. The method of claim 11, wherein said creating includes updating a revision indicator within said data model.
14. The method of claim 11, wherein said creating includes determining a persistant object identify for said newly created persistent object.
15. The method of claim 11, wherein said creating includes defining subtypes for said newly created persistent object.
16. The method of claim 11, further comprising saving said persistent object by said persistent object framework.
17. The method of claim 11, further comprising accessing said persistent object by said persistent object framework.
18. The method of claim 11, further comprising updating said persistent object by said persistent object framework.
19. The method of claim 11, further comprising deleting said persistent object by said persistent object framework.
20. A method for searching persistent objects stored in at least one data source, wherein an application accesses said persistent objects for data, comprising:
receiving a search query for a persistent object at a persistent object framework;
determining a query type for said search query, wherein said query type is selected from the group of query types consisting of a primary key, a handle, a unique key, a query filter, and a relationship between persistent objects;
when said query type is determined not to be a query filter, searching a cache within said persistent object framework for said persistent object according to said query type; and
searching said data source when said persistent object is not within said cache or when said query type is determined to be a query filter.
21. The method of claim 20, wherein said searching of said data source includes enabling a lazy load state.
22. The method of claim 21, further comprising determining whether said persistent object data is needed by said application.
23. The method of claim 20, further comprising discarding said search query.
24. A method for managing persistent objects within an application system, wherein said persistent objects are stored within a first data source and a second data source and said persistent objects provide data to an application, comprising:
implementing a persistent object framework that caches said persistent objects correlating to said application by:
creating said persistent objects;
caching said persistent objects;
accessing said persistent objects;
updating said persistent objects;
searching said persistent objects;
deferring writes to said first and second data sources; and
controlling persistent storage of said persistent objects; and
retrieving said data from said first and second data sources when requested by said persistent object framework.
25. A computer program product comprising a computer useable medium having computer readable code embodied therein for managing persistent objects correlating to an application, the computer program product adapted when run on a computer to effect steps, including:
mapping a persistent object stored within a data source with a persistent object framework coupled to said application;
identifying said persistent object stored in said data source as applicable to said application;
caching said persistent object within said persistent object framework; and
creating a new persistent object according to a data model stored by the persistent object framework, the creating comprising caching the new persistent object in the persistent object cache and inserting the new persistent object in the data source after a save transaction has been committed or a flush method has been invoked.
26. A computer program product comprising a computer useable medium having computer readable code embodied therein for searching persistent objects stored in at least one data source, wherein an application accesses said persistent objects for data, the computer program product adapted when run on a computer to effect steps, including:
receiving a search query for a persistent object at a persistent object framework;
determining a query type for said search query, wherein said query type is selected from the group of query types consisting of a primary key, a handle, a unique key, a query filter, and a relationship between persistent objects;
when said query type is determined not to be a query filter, searching a cache within said persistent object framework for said persistent object according to said query type; and
searching said data source when said persistent object is not within said cache.
27. A computer program product comprising a computer useable medium having computer readable code embodied therein for managing persistent objects within an application system, wherein said persistent objects are stored within a first data source and a second data source and said persistent objects provide data to an application, the computer program product adapted when run on a computer to effect steps, including:
implementing a persistent object framework that caches said persistent objects correlating to said application comprising:
creating said persistent objects;
caching said persistent objects;
accessing said persistent objects;
updating said persistent objects;
searching said persistent objects;
deferring writes to said first and second data sources; and
controlling persistent storage of said persistent objects; and
retrieving said data from said first and second data sources when requested by said persistent object framework.
Description
BACKGROUND OF THE INVENTION
1. Field of the Invention
The present invention relates to a system and method for managing objects that are stored persistently. More particularly, the present invention relates to managing persistently stored objects within databases that are accessible by applications.
2. Discussion of the Related Art
A persistent object may be defined as an abstraction of data that represents an object that may be involved in a business process and is stored persistently. Examples of persistent objects include orders, customers, products and the like. Persistent objects may be stored in different types of persistent storage, such as relational databases, object-oriented databases, Lightweight Directory Access Protocol ("LDAP") enabled directories, flat files, and the like. In persistent object environments, the term "data source" may refer to persistent storage so as to be applicable to all forms of persistent storage. For example, "data source" may indicate a database.
In addition to being stored, persistent objects may be managed. An application programming interface ("API") may create, update, delete, and query the objects that are stored persistently. Managing persistent objects may become a priority as programs are written for any platform, such as Java applications. The application may look for the persistent objects or may create persistent objects to be used after the program has been completed. Therefore, a framework for persistent object API may be desired that is uniform and simple.
SUMMARY OF THE INVENTION
Accordingly, the embodiments of present invention are directed to a system and method for providing a persistent object framework for managing persistent objects.
According to an embodiment, a system for managing persistent objects for an application is disclosed. The persistent objects are stored in at least one data source. The system includes a persistent object framework to provide data from and perform functions on the persistent objects in accordance with the application. The system also includes a cached set of persistent objects within the persistent object framework and corresponding to the stored persistent objects.
According to another embodiment, an application system supported by a Java programming environment is disclosed. The application system includes a relational database storing a first set of persistent objects correlating to the application. The application system also includes a LDAP repository storing a second set of persistent objects correlating to the application. The application system also includes a persistent object framework to provide data to the application from the first and second sets of persistent objects. The persistent object framework caches a subset of the persistent objects from the relational and the LDAP repository.
According to another embodiment, a method for managing persistent objects correlating to an application is disclosed. The method includes mapping a persistent object stored within a data source with a persistent object framework coupled to the application. The method also includes identifying the persistent object stored in the data source as applicable to the application. The method also includes caching the persistent object within the persistent object framework.
According to another embodiment, a method for searching persistent objects stored in at least one data source is disclosed. An application accesses the persistent objects for data. The method includes receiving a search query for a persistent object at a persistent object framework. The method also includes determining a query type for the search query. The method also includes searching a cache within the persistent object framework for the persistent object. The method also includes searching the data source when the persistent object is not within the cache.
According to another embodiment, a method for managing persistent objects stored in at least one data source according to relationships between the persistent objects is disclosed. An application accesses the persistent objects for data. The method includes specifying a relationship between at least two objects. The method also includes retrieving the at least two objects according to the relationship. The method also includes performing a function on the relationship. The method also includes synchronizing another relationship between the at least two objects according to the result of the function.
According to another embodiment, a method for resolving a stale data state between a persistent object and an application accessing the persistent object for data is disclosed. The method also includes executing a process of the application accessing the persistent object. The persistent object includes a revision attribute. The method includes identifying the stale data state within the persistent object by a persistent object framework. The method also includes retrying the process of the application accessing the persistent object. The method also includes incrementing the revision attribute.
According to another embodiment, a method for managing persistent objects within an application system is disclosed. The persistent objects are stored within a first data source and a second data source. The persistent objects provide data to an application. The method includes implementing a persistent object framework that caches the persistent objects correlating to the application by creating the persistent objects, caching the persistent objects, accessing the persistent objects, updating the persistent objects, searching the persistent objects, deferring writes to the first and second data sources, and controlling persistent storage of the persistent objects. The method also includes retrieving the data from the first and second data sources when requested by the persistent object framework.
According to another embodiment, a system for managing persistent objects correlating to an application is disclosed. The system includes means for mapping a persistent object stored within a data source with a persistent object framework coupled to the application. The system also includes means for identifying the persistent object stored in the data source as applicable to the application. The system also includes means for caching the persistent object within the persistent object framework.
According to another embodiment, a computer program product comprising a computer useable medium having computer readable code embodied therein for managing persistent objects correlating to an application is disclosed. The computer program product is adapted to run on a computer to effect steps, including mapping a persistent object stored within a data source with a persistent object framework coupled to the application. The steps also include identifying the persistent object stored in the data source as applicable to the application. The steps also include caching the persistent object within the persistent object framework.
According to another embodiment, a system for searching persistent objects stored in at least one data source is disclosed. An application accesses the persistent objects for data. The system includes means for receiving a search query for a persistent object at a persistent object framework. The system also includes means for determining a query type for the search query. The system also includes means for searching a cache within the persistent object framework for the persistent object according to the query type. The system also includes means for searching the data source when the persistent object is not within the cache.
According to another embodiment, a computer program product comprising a computer useable medium having computer readable code embodied therein for searching persistent objects stored in at least one data source is disclosed. An application accesses the persistent objects for data. The computer program product is adapted to run on a computer to effect steps, including receiving a search query for a persistent object at a persistent object framework. The steps also include determining a query type for the search query. The steps also include searching a cache within the persistent object framework for the persistent object according to the query type. The steps also include searching the data source when the persistent object is not within the cache.
According to another embodiment, a system for managing persistent objects stored in at least one data source according to relationships between the persistent objects is disclosed. An application accesses the persistent objects for data. The system includes means for specifying a relationship between at least two objects. The system includes means for retrieving the two objects according to the relationship. The system includes means for performing a function on the relationship. The system includes means for synchronizing another relationship between the two objects according to the result of the function.
According to another embodiment, a computer program product comprising a computer useable medium having computer readable code embodied therein for managing persistent objects stored in at least one data source according to relationships between the persistent objects is disclosed. An application accesses the persistent objects for data. The computer program product is adapted to run on a computer to effect steps, including specifying a relationship between at least two objects. The steps also include retrieving the two objects according to the relationship. The steps also include performing a function on the relationship. The steps also include synchronizing another relationship between the two objects according to the result of the function.
According to another embodiment, a system for resolving a stale data state between a persistent object and an application accessing the persistent object for data is disclosed. The persistent object includes a revision attribute. The system also includes means for retrying the process of the application accessing the persistent object. The system includes means for identifying the stale data state within the persistent object by a persistent object framework. The system also includes means for executing a process of the application accessing the persistent object. The system also includes means for incrementing the revision attribute.
According to another embodiment, a computer program product comprising a computer useable medium having computer readable code embodied therein for resolving a stale data state between a persistent object and an application accessing the persistent object for data is disclosed. The computer program product is adapted to run on a computer to effect steps, including executing a first process of the application accessing the persistent object. The persistent object includes a revision attribute. The steps identifying the stale data state within the persistent object by a persistent object framework also include and incrementing the revision attribute. The steps also include retrying the process of the application accessing the persistent object. The steps also include incrementing the revision attribute.
According to another embodiment, a system for managing persistent objects within an application system is disclosed. The persistent objects are stored within a first data source and a second data source and the persistent objects provide data to an application. The system includes means for implementing a persistent object framework that caches the persistent objects correlating to the application comprising means for creating the persistent objects, means for caching the persistent objects, means for accessing the persistent objects, means for updating the persistent objects, means for searching the persistent objects, means for deferring writes to the first and second data sources, and means for controlling persistent storage of the persistent objects. The system also includes means for retrieving the data from the first and second data sources when requested by the persistent object framework.
According to another embodiment, a computer program product comprising a computer useable medium having computer readable code embodied therein for managing persistent objects within an application system is disclosed. The persistent objects are stored within a first data source and a second data source and the persistent objects provide data to an application. The computer program product is adapted to run on a computer to effect steps, including implementing a persistent object framework that caches the persistent objects correlating to the application comprising creating the persistent objects, caching the persistent objects, accessing the persistent objects, updating the persistent objects, searching the persistent objects, deferring writes to the first and second data sources, and controlling persistent storage of the persistent objects. The steps also include retrieving the data from the first and second data sources when requested by the persistent object framework.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory and are intended to provide further explanation of the invention as claimed.
BRIEF DESCRIPTION OF THE DRAWINGS
The accompanying drawings, which are included to provide a further understanding of the invention and are incorporated in and constitute a part of this specification, illustrate the disclosed embodiments and together with the description serve to explain the principles of the invention. In the drawings:
FIG. 1 illustrates a block diagram of a software application system in accordance with an embodiment of the present invention;
FIG. 2 illustrates a persistent object framework in accordance with an embodiment of the present invention;
FIG. 3 illustrates a flowchart for managing persistent objects within a persistent object framework in accordance with an embodiment of the present invention;
FIG. 4A illustrates a flowchart for determining initial values for attributes when creating a persistent object in accordance with an embodiment of the present invention;
FIG. 4B illustrates a flowchart for configuring a persistent object in accordance with an embodiment of the present invention;
FIG. 5 illustrates a flowchart for searching for objects within a persistent object framework in accordance with an embodiment of the present invention;
FIG. 6 illustrates a flowchart for managing objects through relationships in accordance with an embodiment of the present invention;
FIG. 7 illustrates a flowchart for stale data checking in accordance with an embodiment of the present invention; and
FIG. 8 illustrates a flowchart for persistent object framework maintenance functions in accordance with an embodiment of the present invention.
DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS
Reference will now be made in detail to the preferred embodiment of the present invention, examples of which are illustrated in the drawings.
Embodiments of the present invention include a persistent object framework that provides access to persistent objects in the form of a network of inter-relations that may appear to the application developer as memory resident. This feature may minimize the need for application developers to perform certain tasks. These tasks may include managing persistent object transactions, managing data source connections, composing query statements, mapping of query results to persistent objects and mapping back for data source inserts, updates, and deletes, and the like.
FIG. 1 depicts a system 100 for executing a software application in accordance with an embodiment of the present invention. System 100 may execute a program application on a platform, such as a computer. Preferably, system 100 includes a Java application 102 supported by a database 104 and a LDAP repository 106. Java application 102 may be a Java program or a software application. Java application 102 may run on all hardware platforms, preferably without modification. Java application 102 may be a Java program that contains source code that is compiled into bytecode. Bytecode may be an intermediate language that should run standing alone. The bytecode may be converted, or interpreted, into machine code when Java application 102 is launched. A Java interpreter, or Java Virtual Machine, is invoked. The Java Virtual Machine translates the bytecode into machine code and runs the program. Java application 102 may be Java servlet that is Java code running on the server side. Alternatively, Java application 102 may be a Java applet that is Java code down loaded and running on a client's computer by request.
Database 104 may be colocated with a web server. Database 104 may be a relational database, object-oriented database, and the like. Database 104 may store persistent objects. LDAP repository 106 may be a LDAP-enabled directory that stores persistent objects. Additional storage components, such as flat files, may be coupled to system 100 and accessible by Java application 102. The storage components should store persistent objects. Database 104 and LDAP repository 106 also may be known as data sources.
Java application 102 may use business objects 108 in executing. Business objects 108 may be those objects used in electronic commerce applications, such as buyer, seller, product, and the like. Business objects 108 may be stored within database 104 and LDAP repository 106. Business objects 108 also may be stored within additional data sources accessible by Java application 102.
Base architecture 110 includes those components that function to connect the storage components to Java application 102. Base architecture 110 includes application-server-Java-database-connectivity services 112, LDAP Java Software Development Kit ("SDK") 114, and other application server services 116. A SDK provides APIs, programming framework and the like for developers to use. LDAP Java SDK 114 provides the means to access the data in LDAP repository 106. Other application server services 116 may include logging, TX, EJB, and the like. Java-database-connectivity ("JDBC") services 112 provide an interface with database 104. LDAP Java SDK 114 provides an interface with LDAP repository 106.
Base architecture 110 also includes persistent object framework ("POF") 120. POF 120 provides a uniform, simple application program interface for creating, updating, deleting and querying the persistently stored objects. POF 120 may provide transparent mapping of objects between memory, and database 104 and LDAP repository 106. POF 120 may provide features such as object relationships, concurrency protection, caching, deferred writing, and the like.
FIG. 2 depicts a persistent object framework in accordance with an embodiment of the present invention. FIG. 2 depicts some of the POF components in order to illustrate embodiments of the present invention. FIG. 2, however, should not be considered as illustrating all POF functionalities. POF 120 may be comprised of data model files and persistent object configuration files. POF 120 may perform operations dynamically based upon a data model 210. Data model 210 may be one of a plurality of data models identified by POF 120. The data model 210 may be loaded at runtime initialization. For example, whenever a request to create a new object of type "Order" is received, the newly-created object may be initialized dynamically by examining the definition of the "Order" object type in terms of the attributes that an "Order" should contain. Alternatively, code generation may be implemented to generate an initialization method to improve the performance of object creation.
The data model 210 may specify the types of persistent objects available for use by applications, such as Java application 102. The data model 210 also may specify how each persistent object type maps to data source schemas. Each schema may represent a database table for persistent objects that are to be stored in database 104. Each schema may represent an LDAP schema for persistent objects that are to be stored in LDAP repository 106. The data model 210 may be specified in a file, and formatted as disclosed by the following example:
Data Model Name-Type-Valve ("NTV") File Format - DataModel: =NTV {
- DataElementStanza: ="data13 elements" NTV {"defaults" NTV {
- DataElements: ="
- DataType:=String|Integer|Long|Boolean|BigDecimal|Date
- SchemaStanza:="schema_elements" NTV {"schema" NTV {
- Schemas: ="
- LDAPSchemaAttrInitialValues: ="
- StringOrStringArray: =Str "
- SchemaType: =jdbc|ldap
- SchemaAttributes: ="
- ObjectTypeStanza: ="data_objects" NTV {
- ObjectTypes: ="
- CustomProperties: =" ObjectAttributes: ="
- ObjectTransientAttributes: ="
- NTVDataType: =Str|Int|Long|Bool|Dec|Date
- ObjectAttrSchemas: ={"schema" Str "
- RelationshipStanza: ="relationships" NTV {
- Relationships: ="
- RelationshipRole: ="cardinality" Str "
- RoleReferenceTypeSpecificlnfo: =
- ReferencingByForeignKey: ="data_object" Str "
ReferencedByForeignKey: ="data_object" Str " - ReferencingByTagPlusForeignKey: ="data_object" Str "
- ReferencedByTagPlusForeignKey: ="data_objects" NTV {
- ReferencingByHandle: ="data_object" Str "
- ReferencedByHandle: ="data_objects" NTV {
- AssocReference: ="assoc_rel" Str "
- SourceOrTarget: =source|target
- CommonAttributes: ="objectAttributeName" [,
- Cardinality: =0 . . . 1|1 . . . 1|0 . . . n|1 . . . n
- TagRelObjectTypes: ="
- FKObjectTypes: ="
- ObjectTypes: ="
- }[,
- Boolean: =true|false
POF 120 also includes an object space 212 to specify a mapping between persistent object types and the data sources into which they are to be stored, such as database 104 and LDAP repository 106. Preferably, the disclosed embodiments may allow for one data source to be specified per schema type. Thus, one data source may be specified for JDBC and another for LDAP. Every JDBC data source that is specified in object space 212 may be registered with the LDAP server that is used by the Java service to lookup the data source. The object space 212 may be specified in a file, and formatted as disclosed by the following example:
Object Space NTV Format - ObjectSpace: ="object_space" NTV {"data_sources" NTV {
- OSDataSources: ="
The data source may be formatted as disclosed by the following example:
Data Source NTV Format - DataSources: ="data_sources" NTV {
- DataSourceStanzas: ="
- DataSourceType: =jdbc|ldap
Persistent objects are dynamic such that to define a new persistent object type, one edits the files described above: data model, object space and data source. Any changes to the persistent objects, or defined new persistent object types, are available immediately for use without any compilation.
As noted above, data model 210 may include a value for data type. The data type specified by data model 210 may include: Data Java Data Oracle Database Type Type Data Type Str String VARCHAR2( ** The Long data type may be used for attributes that are designated in the schema as 'sequence' generated.
Attributes also may be defined by data model 210. An attribute may be a field within a record stored within a data source. Methods may be given to retrieve and to set the attribute values. The attribute values may be retrieved or set as their native types, or in a type-independent way using the method disclosed in the pseudo-code example given below: void sampleMethod(CXPObject order, CXPObject order2) throws CXException { String code, desc; BigDecimal grossQty; CXPObject buyerCo; Collection lines; // Get a couple of string values. code = order.getStr("code"); desc = order.getStr("description"); // Copy the value of "grossQuantity" from one order to another order. order2.setValue("grossQuantity", order.getValue("grossQuantity")); // Checking for null value if (order.getValue("description") == null) System.out.println("No description"); // Setting null value order.setValue("description", null); // Another way to set null value order.setStr("description", null); // Increment the order's grossQuantity by 10. grossQty = order.getDec("grossQuantity"); grossQty = grossQty.add(10.0); order.setDec("grossQuantity", grossQty); // Assuming that the 'id' attribute is the primary key for the order, // the following statement will throw an exception, // since the primary key attribute values cannot be changed. order.setLong("id", 1234); }
POF 120 may specify that an attribute have its value generated automatically as a globally unique identifier ("GUID"). The GUID may be globally unique such that no other GUID may have the same value. The GUID may be a string, and the attribute to store the GUID also may be declared a string. An example of a declaration in the data object section of data model 210 depicting how to declare an attribute as having its value generated automatically as a GUID is given by the following pseudo-code: "User" NTV { "class_name" Str "User", "attributes" NTV { "id" NTV { "schemas" NTVArr [ {"schema" Str "User", "schema_attr" Str "id" } // datatype must be String ], "guid" Bool "true", // Indicates that this is a 'GUID'- generated attribute }, // Add other attributes here... }, },
Alternatively, POF 120 also may specify that an attribute have its value generated automatically as a unique sequence value. The value may be unique for all attributes that use the same sequence name. The sequence value is a "long" and, therefore, the attribute also may be declared a "long." An example depicting how to declare an attribute as having its value generated automatically from a sequence is given by the following pseudo-code: "Order" NTV { "schema_type" Str "jdbc", "table_name" Str "Order", "attributes" NTV { "id" NTV { "data_element" Str "Long", // This *must* be 'Long' "column_name" Str "id", "required" Bool "true", "sequence" Str "Order_seq", // Indicates that value is generated // from the 'Order_seq' sequence. }, // Add other schema attributes here... }, }
Data model 210 also may define relationships. A relationship may express a link between two persistent objects. Relationships may be defined in terms of two roles where each role represents one of the two related objects. For example, a relationship named "Purchase" may be composed of the following roles: Role Name Object Type(s) Cardinality buyer Company or Person 1..1 orders Order 0..n
Each role in a relationship may define a cardinality that indicates the number of objects allowed to be in the relationship. Singular cardinality roles may be those that have a value of "0 . . . 1" or "1 . . . 1." A cardinality of "0 . . . 1" may indicate that for every object of one role in the relationship, there is either zero or one related object of this role. A cardinality of "1 . . . 1" may indicate that for every object of one role in the relationship, there may be only one related object of this role.
Multiple cardinality roles may be those that have a value of "0 . . . n" or "1 . . . n." A cardinality of "0 . . . n" may indicate that for every object of one role in the relationship, there may be any number of related objects of this role. A cardinality of "1 . . . n" may indicate that for every object of one role in the relationship, there may be at least one related object of this role.
According to the disclosed embodiments, the mechanism for defining relationships between persistent objects may be flexible and allows for different ways of specifying how the relationships are represented. Developers may access relationships in a representation-independent manner, and may not have to be aware of how the relationships are represented. Two categories may exist for relationships, reference-based and association-based.
A reference-based relationship may be a relationship wherein the objects of one role contain attribute values that reference the objects of another role. Reference-based relationships may be specified in data model 210 by the examples disclosed below.
A reference-based relationship using reference-by-foreign key may be shown in the following example pseudo-code: "data_objects" NTV { "Foo" NTV { "attributes" NTV { "id" NTV { ... }, "barID" NTV { ... }, }, }, "Bar" NTV { "attributes" NTV { "id" NTV { ... }, }, }, }, "relationships" NTV { "FooBar" NTV { "source" NTV { "data_object" Str "Foo", "access_name" Str "bar", "cardinality" Str "0..1", "foreign_key" Bool "true", "common_attribute" StrArr [ "barID" ], }, "target" NTV { "data_object" Str "Bar", "access_name" Str "foo", "cardinality" Str "0..1", "common_attribute" StrArr [ "id" ], }, }, },
A reference-based relationship using reference-by-type-tag-plus-foreign key may be shown in the following example pseudo-code: "data_objects" NTV { "Foo" NTV { "attributes" NTV { "barType" NTV { }, "barID" NTV { ... }, "barID2" NTV { ... }, }, }, "TypeA" NTV { "attributes" NTV { "id" NTV { ... }, }, }, "TypeB" NTV { "attributes" NTV { "id" NTV { ... }, "id2" NTV { ... }, }, }, }, "relationships" NTV { "FooBar" NTV { "source" NTV { "data_object" Str "Foo",
"access_name" Str "bar", "cardinality" Str "0..1", "rel_type_tag_attr" Str "barType", "rel_data_objects" NTV { "TypeA" NTV { "rel_type_tag_value" Str "TypeATag", "common_attribute" StrArr [ "barID" ], }, "TypeB" NTV { "rel_type_tag_value" Str "TypeBTag", "common_attribute" StrArr [ "barID", "barID2" ], }, }, }, "target" NTV { "access_name" Str "foo", "cardinality" Str "0..1", "data_objects" NTV { "TypeA" NTV { "common_attribute" StrArr [ "id" ], }, "TypeB" NTV { "common_attribute" StrArr [ "id", "id2" ], }, }, }, }, }
A reference-based relationship using reference-by-handle may be shown in the following example pseudo-code: "data_objects" NTV { "Foo" NTV { "attributes" NTV { "barHandle" NTV { ... }, }, }, }, "relationships" NTV { "FooBar" NTV { "source" NTV { "data_object" Str "Foo", "access_name" Str "bar", "cardinality" Str "0..1", "rel_obj_handle_attr" Str "barHandle", }, "target" NTV { "access_name" Str "foo", "cardinality" Str "0..1", "data_objects" NTV { "TypeA" NTV { }, "TypeB" NTV { }, }, }, }, }
An association-based relationship may be a relationship wherein a POF object exists that serves as an intermediary between the related objects. The intermediary object may be known as an association object. As association-based relationships are established and de-established between objects, POF 120 automatically creates and removes the association objects as necessary. The association objects automatically are stored and removed from the data source when the store method is invoked on either of the objects in the relationship and/or when the relationship is severed. Thus, the developer may not need to be aware of the existence of the association objects.
Relationships that have a many-to-many cardinality, and relationships wherein none of the related objects is fixed should always be association-based relationships because they desire the intermediary object. Association-based relationships also may be used for other types of relationships, however, it may not be required or recommended that they do so.
Every association-based relationship may be defined in terms of two reference-based relationships. One of the reference-based relationships may be defined as being between one of the related object types and the association object type, while the other reference-based relationship may be defined between the other related object type and the association object type. The association-based relationship also contains information that indicates how to automatically bridge the two reference-based relationships. Association-based relationships may be specified in data model 210 by the examples disclosed below.
An association-based relationship using reference-by-handle and reference-by-foreign-key may be shown in the following example pseudo-code: "data_objects" NTV { "FooBarAssoc" NTV { "attributes" NTV { "fooHandle" NTV { ... }, "barID" NTV { ... }, }, }, }, "relationships" NTV { "Foo-FooBarAssoc" NTV { "source" NTV { "data_objects" NTV { "Foo" NTV {}, "Foo2" NTV {}, }, "access_name" Str "fooBarAssocs", "cardinality" Str "0..n", }, "target" NTV { "data_object" Str "FooBarAssoc", "access_name" Str "foo", "cardinality" Str "1..1", "rel_obj_handle_attr" Str "fooHandle", }, }, "Bar-FooBarAssoc" NTV { "source" NTV { "data_object" Str "Bar", "access_name" Str "fooBarAssocs", "cardinality" Str "0..n", "common_attributes" StrArr [ "id" ], }, "target" NTV { "data_object" Str "FooBarAssoc", "access_name" Str "bar",
"cardinality" Str "1..1", "common_attributes" StrArr [ "barID" ], }, }, // Association-based relationships (e.g. "Foo-Bar") // must be specified in the configuration after // the specifications for the reference-based // relationships to which it refers // (i.e. "Foo-FooBarAssoc" and "Bar-FooBarAssoc"). "Foo-Bar" NTV { "source" NTV { "access_name" Str "bars", "cardinality" Str "0..n", "assoc_rel" Str "Foo-FooBarAssoc", "assoc_role" Str "source", }, "target" NTV { "access_name" Str "foos", "cardinality" Str "0..n", "assoc_rel" Str "Bar-FooBarAssoc", "assoc_role" Str "source", }, }, }
Properties may be named values that are specific to a persistent object type, attribute or relationship. These values may be specified in data model 210 and apply to all instances of the persistent object type. Two types of properties may exist: pre-defined and custom. POF 120 may include the following set of pre-defined properties: Pre-Defined Object Properties Symbolic String Value Name Name Type Description CXPObject.OBJ_PROP- "type_name" String The object TYPE_NAME type name. Pre-Defined Attribute Properties Symbolic Name String Name Value Type Description CXPObject.ATTR_PROP_DATA_TYPE "data_type" Class The Java Class representing the data type of the attribute. One of: String.class, Interger.class, Long.class, Boolean.class, java.math.BigDecimal.class, or java.util.Date.class. CXPObject.ATTR_PROP_REQUIRED "required" Boolean "true" if the attribute must have a value before the transaction is committed, "false" if the value is not required. CXPObject.ATTR_PROP_PRIMARY_KEY "primary_key" Boolean "true" if the attribute is part of the primary key of the object, "false" if the attribute is not part of the primary key. CXPObject.ATTR_PROP_TRANSIENT "transient" Boolean "true" if the attribute is transient (i.e. it's value is not saved), "false" if the attribute is persistent. CXPObject.ATTR_PROP_INITIAL_VALUE "initial_value" The initial value to assign to this attribute when first created. The value type should match the attribute's data type. Pre-Defined Relationship Properties Symbolic Name String Name Value Type Description CXPObject.REL_PROP_CARDINALITY_MULTIPLE "cardinality_multiple" Boolean true if relationship allows multiple values, false otherwise. CXPObject.REL_PROP_REL_OBJECT_TYPES "rel_object_types" Array of String Names of object types that are valid for related object.
Properties may be defined by the business objects that extends the POF base object. The properties may be specified as custom properties in data model 210. An example of specifying custom properties may be shown by the following pseudo-code: "data_objects" NTV { "SXOrder" NTV { "attributes" NTV { "xyz" NTV { "attr_name" Str "xyz", "custom_props" NTV { // Specify a custom property for attr "xyz" of object type "SXOrder" // with the String value "bar". "foo" Str "bar", // Specify a custom property for attr "abc" of object type "SXOrder" // with the Integer value of "100". "abc" Int "100", } } } } }
POF 120 also includes cache 214 that stores persistent objects for managing the persistent objects without accessing a data source. POF 120 may perform operations on persistent objects in cache 214. Persistent objects may be cached in cache 214 for the duration of the user session. When a user logs in the cached objects may be accessed until the session ends, usually the time when the user logs out. Cache 214 may be private to the session. Requests received during the session may be processed. When the session is complete, the existence of an exception, if it occurred, during the session is noted. By noting any exceptions, the proper resources may be freed from cache 214.
FIG. 3 depicts a flowchart for managing persistent objects within a persistent object framework in accordance with an embodiment of the present invention. Step 300 executes by creating a new persistent object. To create a new persistent object, initial values for the attributes are propogated. FIG. 4 refers to creating a new persistent object in greater detail below.
Step 301 executes by caching the persistent object within POF 120. The persistent object is stored within cache 214 of POF 120. Cached persistent objects may be limited to those persistent objects likely to be accessed during the user session.
Step 302 executes by saving the persistent object. Newly-created persistent objects may not be saved immediately. The object may be inserted into the data source when a save transaction has been committed, or a flush method has been invoked. The following example pseudo-code discloses how to save a new orders object. The pseudo-code indicates that the primary key for the "Order" object type is generated automatically by either sequence-generation or GUID-generation, and, that no initial values may be needed. void sampleMethod(CXPContext context) throws CXException { CXPObject order1, order2, order3; Object initVals[] = { "code", "Ord-ABC", "totalPrice", new BigDecimal(500.25) }; // Create a new order with // attribute "foo" set to "foo value". order1 = context.createObj("Order"); order1.setStr("foo", "foo value"); // Persistently save the new order. context.makePersistent(order1); // Create a new order, with the initial value of // the "code" attribute set to "Ord-ABC", // and the "totalPrice" attribute set to 500.25. order2 = context.createObj("Order", initVals); // Persistently save the new order. context.makePersistent(order2); // Create a new order, with initial values copied // from order1, overriding the initial value of // the "code" attribute to "Ord-ABC", // and the "totalPrice" attribute to 500.25. order3 = context.createObj(order1, initVals); context.makePersistent(order3); }
Step 304 executes by accessing persistent object information. This step also may be known as "introspection." POF 120 may access the persistent object for information on its type, attributes, relationships, and properties. The following example pseudo-code discloses how to access a persistent object: void sampleMethod(CXPObject obj) throws CXException { // Get the names of all attributes for this object. Collection anames = obj.getAttrNames( ); System.out.println("Number of Attrs = " + anames.size( )); // Check for the existence of an attribute named "xyz". if (anames.contains("xyz")) System.out.println("Attribute xyz exists."); else System.out.println("Attribute xyz does not exist."); // Print the attribute name and value and the name and value of all of the // properties for all persistent (i.e. non-transient) attributes of the object. Iterator aiter = anames.iterator( ); while (aiter.hasNext( )) { String aname = (String) aiter.next( ); if (!((Boolean)obj.getAttrProp(aname, CXPObject.ATTR_PROP_TRANSIENT)).booleanValue( )) { Object val = obj.getValue(aname); System.out.println("Attr Name = " + aname); System.out.println("Attr Value = " + val); Iterator piter = obj.getAttrPropNames(aname).iterator( ); while (piter.hasNext( )) { String pname = (String) piter.next( ); Object pval = obj.getAttrProp(aname, pname); System.out.println("Prop Name = " + pname); System.out.println("Prop Value = " + pval); } } } // Get the names of all relationships of this object. Collection rnames = obj.getRelNames( ); System.out.println("Number of Rels = " + rnames.size( )); // Print the name of all relationships of the object. Iterator riter = rnames.iterator( );
while (riter.hasNext( )) { String rname = (String) riter.next( ); System.out.println("Rel Name = " + rname); } } POF 120 also may access properties according to the following pseudo-code example: void sampleMethod(CXPObject obj) throws CXException { // Print the object type name and description. System.out.println("Type = " + (String)obj.getObjProp(CXPObject.OBJ_PROP_TYPE_NAME)); // Print the data type and "foo" custom property value for "xyz" attribute. System.out.println("Attr 'xyz' Data Type = " + ((Class)obj.getAttrProp("xyz", CXPObject.ATTR_PROP_DATA_TYPE)).getName( )); System.out.println("Attr 'xyz' 'foo' Property = " + (String)obj.getAttrProp("xyz", "foo")); // Print the description for the "pdq" relationship. System.out.println("Rel 'pdq' Allows multiple values = " + (Boolean)obj.getRelProp("pdq", CXPObject.REL_CARDINALITY_MULTIPLE)); }
Step 306 executes by querying the persistent object. The querying step is disclosed in greater detail with reference to FIG. 5.
Step 308 executes by updating the persistent object. Persistent objects may be updated, or modified, by invoking the persistent object set methods. The changes may be marked automatically to be stored persistently. The changes may not be saved in the data source, such as database 104, until the transaction is committed, or when a flush method is invoked.
Step 312 executes by deleting the persistent object. POF 120 may delete objects persistently in a straight-forward manner. Different methods may exist to delete persistent objects. First, persistent objects may be deleted by primary key, or by object type name and the primary key. Second, persistent objects may be deleted by handle. Third, persistent objects may be deleted by referencing the persistent object. When a persistent object is deleted, all relationships to the object may be automatically removed. The deletion of the object and removal of the relationships may not be changed in the data source until the transaction has been committed, or when a flush method is invoked. The following example pseudo-code discloses how to delete a persistent object according to each of the methods: void sampleMethod(CXPContext context, String orderPKey, String orderHdl, CXPObject order) throws CXException { CXPObject order2; // Delete the order with a given primary key. context.removeObj("Order", orderPKey); order2 = context.findByPrimaryKey("Order", orderPKey); if (order2 != null) System.out.println("You will never see this."); // Delete the order with a given handle. context.removeObj(orderHdl); order2 = context.findByHandle(orderHdl); if (order2 != null) System.out.printIn("You will never see this."); // Persistently delete an order. context.removeObj(order); }
FIG. 4A depicts a flowchart for determining initial values for attributes when creating a persistent object in accordance with an embodiment of the present invention. The initial values for attributes within data model 210 may be propogated to facilitate creating a new persistent object. The flowchart correlates with step 300 of FIG. 3. Step 300, however, is not limited to the steps disclosed by FIG. 4A.
Step 400 executes by determining the initial values for attributes that are specified in data model 210. The initial values are filled. Step 402 executes by copying the attributes of object parameters. Attributes that are part of a foreign key reference may be exempt from this step. Step 404 executes by determining the attributes defined as having sequence-generated values in data model 210. The initial values are filled with the newly generated sequence value. Step 406 executes by determining the attributes defined as having GUID-generated values in data model 210. The initial values are filled with the newly generated GUID value. Step 408 executes by updating those attributes having a revision indicator in data model 210. The revision indicator may be updated with a value of 1. Revision indicators are disclosed in greater detail below.
FIG. 4B depicts a flowchart for configuring a persistent object in accordance with an embodiment of the present invention. Certain values and configuration issues should be resolved when creating a persistent object. Again, the flowchart correlates with step 300 of FIG. 3. Step 300, however, is not limited to the steps disclosed in FIG. 4B.
Step 420 executes by determining a persistent object identity for the persistent object. Each type of persistent object may specify a set of attributes that correspond to a primary key for that object type so that each persistent object instance may be uniquely identified. POF 120 may guarantee that for each unique persistent object, there exists, at most, one instance of the persistent object in memory for a given context. Certain implications may arise. First, changes to every persistent object may be "seen" by every reference to the same persistent object. This implication may guarantee view consistency. Second, persistent object references may be compared to determine if the references are referring to the same object by using an "==" operator.
Copies of persistent objects may be made, however, the copies should have a primary key that differs from the copied object. The copies may be identified as separate objects, independent of the persistent objects from which they were copied.
Step 422 executes by defining subtypes and supertypes of a persistent object. POF 120 supports specifying object types that are subtypes of other object types. Subtypes of a given supertype may have certain commonalities. With regard to interfacing with POF 120, all attributes defined in the supertype may apply to all of the subtypes. For example, a type named "Order" may have subtypes named "SalesOrder" and "PurchaseOrder," where the "Order" type defines attributes common to all types of Orders. Further, all relationships defined for the supertype may apply to all of the subtypes. Moreover, if a different Java class is defined for each subtype, methods may be defined in the superclass that are either abstract or are implemented solely in terms of the common attributes. Subclasses may override these methods by using knowledge of the specific subtype, such as additional type-specific attributes in their implementation. For example, the type named "Order" may have a method named "cancel" that have a different implementation for objects of type "SalesOrder" than for objects of type "PurchaseOrder."
With regard to persistent storage, all attributes defined in the supertype may be stored persistently using the same schemas for the supertype and all of the subtypes. For example, all objects of type "Order" may have the attribute values stored in the "Order" table. Subtype-specific attributes may be defined as being stored either in the same table or in subtype-specific tables. With regard to properties, property values that may not have values specified in subtypes have their values inherited from the supertypes.
The attributes that compose the primary key may be the same for the base type and all of its subtypes. If a subtype specifies multiple inheritance, all inherited types may share a common base type. Attributes with the same name may have to be merged into one attribute in the subtypes. It may be an error if the attributes with the same name are not rooted in the same supertype. Further, properties may be merged. If a subtype inherits different values for a given property, it is an error if the subtype does not define a value for that property.
When objects are created, a type tag attribute value may fill automatically with the value of a type tag value for the type of object being created. If a type defines a value for type tag attribute or a subtype, and does not specify a value for type tag value, then the type is an abstract type. An abstract type indicates that concrete instances of this type may not be created. Instances of subtypes of the abstract type that are not themselves abstract may have instances of their subtype created. It may be an error for more than one subtype of a given type to have the same value for type tag value. Subtypes also may have subtypes.
If subtypes specify attributes with the same name as those defined in the supertype, the declarations augment the existing attribute rather than override the attribute as a new attribute. The augmentation may be performed for specifying the mapping of primary key attributes to subtype-specific schemas, overriding property values, and specifying a different default value for an attribute of the subtype.
Every object has its type defined at the time it is first created, and it may not change. Any attempt at changing the type tag attribute may result in an exception being thrown. Queries of the base type may produce all objects that match the query filter and that are of the base type or any of its subtypes. No objects may exist as instances of abstract types. Each object may be seen as an instance of the type denoted by the value of the type tag attribute.
When every object is first created, it may be known as its final type. The final type may not be changed for the lifetime of the object. There may be an attribute for every type that has subtypes or is a subtype itself, known as the type tag attribute whose value indicates the final type of the object. The attribute is set automatically, and any attempt to change its value may result in an exception being thrown.
An object of type query may return true if an object is of a specified type or any of its subtypes. Queries of a given type produce all objects that match the query filter that are of the queried type or any of its subtypes. Objects always appear as instances of their final type. Even if an object is found by way of a query of a supertype, the objects that match the query, but are of subtypes of the queried type, may appear as instances of their final type, and not the queried supertype. Any type that has subtypes or is a subtype itself and does not have a value for the type tag attribute specified may be abstract and may not have instances created of its type. Any attempt to do so may result in an exception being thrown.
The following pseudo-code example is a sample data model definition for a Transaction type with subtypes CreditCardTransaction and AccountTransaction: "data_objects" NTV { "Transaction" NTV { "class_name" Str "Transaction", "type_tag_attr" Str "txType", "attributes" NTV { "txType" NTV { "attr_name" Str "txType", ... }, ...// Specify attrs that all Transactions have here. }, }, "CreditCardTransaction" NTV { "class_name" Str "CreditCardTransaction", "inherits" StrArr [ "Transaction" ], "type_tag_value" Str "CC", "attributes" NTV { |