1. Field of the Invention
The present invention relates to a method, system, data structures, and article of manufacture for implementing a persistent object.
2. Description of the Related Art
An object is an entity with a set of possible states. The state of an object comprises the values of the attributes defined for the object. An application can apply methods to change the state of an object. For example, an application can change the state of an object by applying a method to change the value of an attribute defined for the object. When the application terminates, the object is destroyed and the state information is lost unless the application or the application environment saves the object in persistent storage such as files on a disk. When the state of an object outlives the execution of an application, the state of the object is called persistent, and the object is called a persistent object. When the application starts again, the application or the application environment restores the state of the persistent object from the persistent storage.
In an object-oriented system, a class is a collection of related objects and methods that operate on the objects.
The Java Vector class 400 implements a growable array of objects. Like an array, the Java Vector class 400 contains components that can be accessed using an integer index. However, the size of a vector can grow or shrink as needed to accommodate adding and removing items after the vector has been created. The constructor Vector( ) 402 constructs an empty vector. The method elementAt(int) 404 returns the component at the specified index. The method addElement(Object) 406 adds the specified component to the end of a vector, increasing the size of the vector by one. The method removeElementAt(int) 408 deletes the component at the specified index. The method setElementAt(Object, int) 410 updates the component at the specified index of a vector to be the specified object. The method insertElementAt(Object, int) 412 inserts the specified object as a component in this vector at the specified index.
In prior art, there are indirect ways to create and save the state of persistent objects via object serialization. For classes that implement the serializable 414 interface, such as the Java Vector class 400, a programmer can modify the source code of an application to write the complete state of an object to a file output stream, and then recreate the object at a later time by reading the state of the object from the file's input stream. If serialized objects are written to a file's output stream, persistent objects are created. However, the methods in the Java Vector class 400 do not directly create and manipulate persistent objects. Hence, there is a need in the art to provide improved technologies for making vector objects, such as Java Vector objects, persistent.
Provided are a method, system and article of manufacture for implementing an array of persistent elements. A class of the array of persistent elements has a constructor. A call is received from an application executing in a runtime environment to the constructor. The constructor is processed to create an empty array of persistent elements. A persistent element is included into the array of persistent elements within the runtime environment. In response to including the persistent element in to the array, persistent data of the added persistent element is stored in a data record and the address of the data record is stored at a corresponding index record.
In a further implementation the data record is stored in a data file, and the index record is stored in an index file. The data file stores a plurality of data records and the index file stores a plurality of index records. Further implementations are provided for adding, removing, accessing, inserting, and setting elements in objects of the persistent Java Vector class.
In still further implementations a method, system and article of manufacture are provided for manipulating objects in an object oriented database. An object data store includes a plurality of persistent objects, wherein each persistent object is associated with an object index. Each of the plurality of object oriented objects is an instance of a class. An application program calls methods of the class of persistent array elements. In response, the persistent objects are manipulated within a runtime environment. Any modifications to the persistent objects are persistent.
In one implementation, the persistent objects are instantiated from the class. Each object includes a key value. The object oriented database also provides a node data structure including nodes, wherein each node is a persistent object instantiated from the class. Each node represents one persistent object in the object store and includes one object index used to access the persistent object represented by the node in the object store. The nodes in the node data structure are organized according to the key values in the objects represented by the nodes. An application uses the node data structure to access the objects in the object store by applying methods of the class. In one implementation, the methods of the class are used to perform access operations, addition operations, insertion operations and deletion operations on the nodes and persistent objects.
If an application instantiates an object from a persistent vector class, the state of the object outlives the execution of the application. The methods of the class, such as the Java persistent vector class, maintain persistent objects. For example, database objects instantiated from the class and stored within an object oriented database in a database server can be manipulated either from within the database server or from a database client by using the methods of the persistent vector class. Not only are the database objects persistent but the methods of the persistent vector class can be applied to the database objects to perform database operations.
Referring now to the drawings in which like reference numbers represent corresponding parts throughout:
a, 6c, 7a, 7c illustrate block diagrams of index files and data files in accordance with certain described implementations of the invention;
b illustrates logic to process the method for adding an element in a persistent Java Vector object in accordance with certain described implementations of the invention;
b illustrates logic to remove an element from a persistent vector object in accordance with certain described implementations of the invention;
In the following description, reference is made to the accompanying drawings which form a part hereof and which illustrate several implementations. It is understood that other implementations may be utilized and structural and operational changes may be made without departing from the scope of the present implementations
The Java runtime environment 6 includes a Java interpreter 8 and a Java virtual machine (JVM) 10. The Java interpreter 8 generates platform-independent bytecodes that run inside the JVM 10. The Java application 12 can execute on any machine that supports a JVM 10. The JVM 10 is a program that interprets Java byte codes into machine code. The JVM 10 program allows as Java program to execute on different operating systems. The Java runtime environment 6 interacts with the Java class library 14 while executing the Java application 12. The Java class library 14 is a set of pre-compiled Java classes, such as classes for input/output and window management operations, that are available for instantiating objects within the Java application 12. In
The persistent Java Vector class 16 maintains information on persistent elements where the number of persistent elements is scalable. The persistent Java Vector class 16 may be implemented in a variety of ways, such as for example by implementing similar interfaces to the Java Vector class 400 or by extending the Java Vector class 400. The persistent Java Vector class 16 includes methods to insert persistent elements into an array, to delete persistent elements from the array, or to search for specified persistent elements within the array. The Java runtime environment 6 saves persistent Java Vector objects of the persistent Java Vector class 16 into the persistence storage 20, such as a file system, when the Java application 12 executes under the control of the Java runtime environment 6. The persistent storage 20 may be implemented with a variety of persistent software elements such as sequential files, databases, spreadsheets and so on. The data of the persistent software elements may be stored in a non-volatile storage device such as a disk drive, a tape drive, a CDRom drive, a Zip** drive etc. **JAVA is a trademark of Sun Microsystems, Inc.; and ** ZIP is a trademark of Iomega corporation.
If there are n elements 24 in the ith persistent vector object 23 then the index file 52 corresponding to the ith persistent vector object 23 contains n fixed length index records 0 through n−1, where in one implementation each index record is 4 bytes in length. Corresponding to the jth index record 60 (j=0, . . . ,n−1) in the index file 52, there is a jth data record 70 in the data file 54. The persistent data of the jth element 25 of the ith persistent vector object 23 is stored in a jth data record 70. The jth index record 60, where j=0 . . . ,(n−1), representing the jth element 25 of the ith persistent Java Vector object 23, contains the starting address of the jth data record 70. The starting address of the jth data record 70 can be provided in various ways, for example as an offset from the beginning of the data file 54.
As shown in the jth data record 70, each data record has a length field 112 that provides the length of the data record. Each data record also has an “in use bit” 114. If the “in use bit” 114 is zero, i.e. turned off, then the data record is not currently reserved for an element of a persistent Java Vector object and is available for reuse. If the “in use bit” 114 is one, i.e. turned on, then the data record is already reserved for an element of a persistent Java Vector object. For example, when a jth element 25 is deleted from the ith persistent Java Vector object 23, the jth data record 70 in the data file 54 may have the “in use bit” 114 turned off. Correspondingly, if a jth element 25 is inserted into the ith persistent Java Vector object 23 the jth data record 70 may have the “in use bit” 114 turned on.
The Java runtime environment 6 receives (at block 71) from Java application 12 the code that corresponds to the constructor for a Java Vector object. The Java runtime environment 6 creates (at block 72) an empty persistent Java Vector object 23. The Java runtime environment 6 determines (at block 74) whether the constructor has a pathname in the parameter. The pathname is a location in persistent storage, such as the filesystem 50 that stores the persistent data, i.e. the index file 52 and the data file 54 of the empty persistent vector object 23.
If the constructor does not have a pathname in the parameter then the Java runtime environment 6 creates (at block 78) a default index file 52 for the persistent vector object 23 in the current directory of the Java runtime environment 6. The Java runtime environment 6 then creates (at block 80) a default data file 54 for the persistent vector object 23 in the current directory of the Java runtime environment 6 and the process stops (at block 90).
If the constructor does have a pathname in the parameter then the Java runtime environment 6 determines (at block 76) whether index 52 and data 54 files already exist in the pathname in the parameter. If index and data files already exists (i.e. persistent data corresponding to the Java Vector object 23 was saved at an earlier execution of Java application 12) then the Java runtime environment 6 first reopens (at block 84) the index file 52 corresponding to the location given by the pathname, and then reopens (at block 88) the data file 54 corresponding to the location given by the pathname. Reopening a file involves retrieving the file from the file system 50 such that read/write operations can be performed on previously stored records within the file. Subsequently, the process stops (block 90).
If index file 52 and data file 54 do not exist, then the Java runtime environment 6 first creates (at block 82) an index file 52 for the persistent vector object 23 in the location given by the pathname and creates (at block 86) a data file 54 for the persistent vector object 23 in the location given by the pathname. Subsequently, the process stops (block 90).
a illustrates a block diagram of an index file 152 and a data file 154 corresponding to a persistent Java Vector object pb before an element objectX is added to the persistent Java Vector object pb. In
b illustrates logic implemented in a Java runtime environment 6 to process the method for adding an element objectX in the persistent Java Vector object pb in accordance with certain implementations of the invention. In the logic illustrated in
In
a illustrates a block diagram of an index file 252 and a data file 254 before removing an element in a persistent Java Vector object pb. The index file 252 for object pb has n index records 0 . . . (n−1) each containing the address of a data record 0 . . . (n−1) in the data file 254 for object pb.
b illustrates logic implemented in a Java runtime environment 6 to process the method for removing an element in a persistent Java Vector object. At block 200, the Java runtime environment 6 receives an instruction pb.removeElement(i) from the Java application 12. At block 202, the Java runtime environment 6 adjusts the index file 252 for pb to delete contents of index i and shifts downwards by four bytes the contents of all index records greater than i. Shifting downwards by four bytes means that index record k is moved to the location of index record k−1 where k varies from i+1 to n−1 (the result in shown in
c illustrates a block diagram of the index file and the data file after removing an element in a persistent Java Vector object. In
If at block 230, a data record with an “in use bit” of zero that is large enough to store the element “newelement” is not found control proceeds to block 232 where the Java runtime environment 6 appends the persistent data of the element “newelement” to a data record at the end of the data file. Subsequently, at block 233 the address of the data record appended in block 232 is stored at index record i in the index file and the process stops (at block 236).
If at block 222, the Java runtime determines that the length of the element “newelement” is less than or equal to the length of the data record corresponding to element i, then the Java runtime environment 6 stores (at block 226) the persistent data of the element “newelement” at the data record that corresponds to element i. The index files does not need to be updated and the process stops (at block 236).
Control proceeds to block 258, where the Java runtime environment 6 performs a best fit search in the data file for object pb to find a data record with a zero “not in use” bit, where the data record is large enough to store the persistent data of the element “newelement.” If the Java runtime environment 6 finds (at block 260) such a data record control proceeds to block 264. At block 264, the Java runtime environment 6 determines the address of the data record found within the data file and stores the persistent data of the element “newelement” in the data record found within the data file. Subsequently, the Java runtime environment 6 updates (at block 265) the index record i in the index file of object pb with the address of the data record found in block 264 and the process stops (at block 266). If a “not in use” data record is not found (at block 260), the Java runtime environment 6 appends (at block 262) the persistent data of the element “newelement” to a data record at the end of the data file and proceeds to update (at block 263) the index record i for the index file of object pb with the address of the appended data record at block 262. The process then stops.
An object-oriented data base management system (OODBMS) often provides persistent storage for objects. The OODBMS is implemented using the Java programming language, and stores objects of the persistent Java Vector class. The methods of the persistent Java Vector class are not limited to the methods described in
In
The database server program 316 manages the object oriented database 302, the object store 304, and the objects 0 . . . (n−1). The database server program 316 executes operations against the database 302, such as adding, updating and deleting objects in the object store 304 and executing queries against the object store 304 using the associated indices of the persistent Java Vector object that implements the object store 304. The database server 316, utilizes the constructors and methods in the Persistent Java Vector class 314 to instantiate the vector of persistent objects in the object store 304 and manipulate the objects therein, e.g. adding, inserting, deleting, updating etc. The database server program 316 thus includes the program components that perform database management and access operations.
In one implementation, a database client program 322 implemented on a computer 320 communicates with the server 300 over a network 318. The database client program 322 is capable of interfacing with a user of the database 302 and communicating database operation requests, such as adding, updating, and deleting records, to the database server program 316, to execute against the object store 304. In one implementation, the database client 322 comprises a Java application 324, where the Java application 324 directly manipulates the objects in the object store 304 via the methods of the Persistent Java Vector class 314.
A server 502 includes an object oriented database 504 that comprises an object store 506 and a balanced tree, “B-Tree”, object 508. The object store 506 includes a plurality of objects 510a, b . . . n, where each object comprises an object oriented object that is an instance of a class. Each object 510a, b . . . n in the object store 506 has an associated index value 512a, b . . . n that is used to access the object 510a, b . . . n in the object store 506. In certain implementations, the object store 506 may be implemented as a persistent Java Vector, using the interfaces of the persistent Java Vector class 528. In such cases, the objects 510a, b . . . n in the persistent Java Vector are accessed using the index value 512a, b . . . n of the object. In persistent Java Vector implementations, the index value 512a, b . . . n provides a unique identifier or handle for the object 510a, b . . . n in the object store 506.
The object oriented database 504 further includes an implementation of the B-Tree object 508, where each node 514a, b . . . n of the B-Tree object 508 represents one of the objects 510a, b . . . n in the object store 506. Each B-Tree node 514a, b . . . n has a corresponding index value 516a, b . . . n that comprises a unique identifier of the node 514a, b . . . n in the B-Tree object 508 that is used to access the node 514a, b . . . n in the B-Tree object 508. The B-Tree object 508 may be implemented as a persistent Java Vector using the persistent Java Vector class.
A database server program 520 comprises a program that manages the database objects within the object oriented database 504 and executes operations against the database 504, such as adding, updating, and deleting objects in the object store 506 and executing queries against the object store 506 using the object store 506 index derived from the B-tree object 508. In implementations where the database objects 506 and 508 comprise persistent Java Vectors, the database server 520 would utilize interfaces in the persistent Java Vector class 528 to instantiate the object store 506 and B-Tree object 508 and manipulate the elements therein. The database server program 520 thus includes the program components that perform the database management and access operations using the persistent Java Vector class 528.
A database client program 522 is capable of interfacing with a user of the database and communicating database operation requests, such as adding, updating, and deleting records, to the database server 520 to execute against the database objects 506 and 508.
A root node index value 530 comprises the index value of the root node in the B-Tree implemented in the B-tree object 508. The root node index value 530 (shown in
In the described implementations, the objects 510a, b . . . n in the object store 506 include a field that has the key value for that object 510a, b . . . n. The database server 520 or database client 522 may issue a Java elementAt(int) method identifying a persistent object and field to obtain the value for a particular field in the persistent objects 510a, b . . . n. In certain implementations, the key value may be maintained in a field within an object embedded in the object 510a, b . . . n. In such a case, the database server 520 or the database client 522 would issue the elementAt(int) method to the embedded object including the field that comprises the key value, and the embedded object would in turn issue the elementAt(int) method against the embedded object including the key value field.
The object index 512a, b . . . n in the object index value field 550 is then used (at block 608) to access the object 510a, b . . . n represented by the accessed node 514a, b . . . n. In persistent Java Vector implementations, the elementAt( ) function may be used to access the object 510a, b, . . . n in the object store 506 using the determined index value 512a, b . . . n. In persistent Java Vector implementations, a Java GET field request is issued (at block 610) to access the key value in the accessed object 510a, b . . . n. As discussed, if the key value is located within an object embedded in the object 510a, b . . . n, then the object 510a, b . . . n issues the GET request against the embedded object including the field that includes the key value.
If (at block 612) the search value is equal to the returned key value in the accessed object 510a, b . . . n, then the database server 520 returns (at block 614) the index value 512a, b . . . n of the object 510a, b . . . n having the matching key value. Otherwise, if (at block 612) the accessed key value does not match the search value, then the database server 520 determines (at block 616) whether the node 514a, b . . . n accessed at block 604 is a leaf node. A leaf node may be indicated by setting the left 552 and right 554 node index values to NULL. If the current accessed node 514a, b . . . n is a leaf node, then the database server 520 returns (at block 618) an error exception indicating that no object 510a, b . . . n includes a key value matching the query value. If the current node is not a leaf node, i.e., there are child nodes, and the determined key value is less (at block 620) than the search value, then the database server 520 determines (at block 622) the left child node index value 516a, b . . . n in the field 552 of the accessed node 514a, b . . . n. Otherwise, if the key value is greater (at block 620) than the query value, then the right child node index value 516a, b . . . n is determined from field 554 in the accessed node 514a, b . . . n. From block 622 or 624, control proceeds back to block 604 to access the node 514a, b . . . n at the determined index value 516a, b . . . n. Also, if there is only one child node, and the determination at blocks 622 and 624 identifies a NULL value for the left or right child node index value, respectively, then control proceeds to block 618 to return an error.
When reaching a leaf node when adding a new node object to the B-Tree object 508, the implementation can invoke the addElement( ) method in the persistent Java Vector class 528 to add a new node object to the B-Tree object 508 representing the B-tree structure. The new node object would be initialized by setting the index value field 50 to a new index value, determined by incrementing the last index value 12a . . . n in the object store 68, and setting the left child node Index 52 and right child node index 54 fields to NULL.
With the above implementations, a balanced or B-tree data structure may be used to index and search the object store 506 for an object 510a, b . . . n having a key value matching a search query without requiring the use of special object oriented database interfaces. Instead, standard interfaces from the Java persistent vector utility class may be used to access the objects 510a, b . . . n in the object store 506 using a B-Tree index of the object store 506 elements implemented in the B-Tree object 508. Thus, adding, deleting, and updating entries in the object oriented database 4 does not require that the objects 510a, b . . . n implement interfaces of a special database class or be extended to accommodate special object oriented database classes. In the above described implementations, all that is needed to determine the key value of the object 510a, b . . . n is knowledge of the object field that contains the key value. Additionally, the B-Tree object 508 may implement a multi-key B-tree index, in which case the database server 520 would have to use Java GET methods to access multiple key values from the object 510a, b . . . n.
With the above implementations, a balanced or B-tree data structure may be used to index and search the object store 506 for an object 510a, b . . . n having a key value matching a search query without requiring the use of special object oriented database interfaces. Instead, standard interfaces from the persistent Java Vector class may be used to access the objects 510a, b . . . n in the object store 506 using a B-Tree index of the object store 506 elements implemented in the B-Tree object 508. Thus, adding, deleting, and updating entries in the object oriented database 504 does not require that the objects 510a, b . . . n implement interfaces of a special database class or be extended to accommodate special object oriented database classes. In the above described implementations, all that is needed to determine the key value of the object 510a, b . . . n is knowledge of the object field that contains the key value. In persistent Java Vector implementations, the persistent Java Vector addElement( ) function is used to insert the add object at the end of the object store 506 Java Vector. If the object store 506 vector is full, then the database server 520 would have to grow the vector and reallocate additional space for further objects to add to the object store 6.
The database server 520 may also implement update, delete, insert operations of the objects 510a, b . . . n in the object store 6 by calling methods of the persistent Java Vector class. Update is performed by the setElementAt method, delete is performed by the removeElementAt method, and insert is performed by the insertElementAt method in the persistent Java Vector class.
The described vector objects, classes, and methods therein may be implemented as a method, apparatus or article of manufacture using standard programming and/or engineering techniques to produce software, firmware, hardware, or any combination thereof The term “article of manufacture” as used herein refers to code or logic implemented in hardware logic (e.g., an integrated circuit chip, Field Programmable Gate Array (FPGA), Application Specific Integrated Circuit (ASIC), etc.) or a computer readable medium (e.g., magnetic storage medium (hard disk drives, floppy disks, tape, etc.), optical storage (CD-ROMs, optical disks, etc.), volatile and non-volatile memory devices (EEPROMs, ROMs, PROMs, RAMs, DRAMs, SRAMs, firmware, programmable logic, etc.). Code in the computer readable medium is accessed and executed by a processor. The code in which implementations are made may further be accessible through a transmission media or from a file server over a network. In such cases, the article of manufacture in which the code is implemented may comprise a transmission media, such as a network transmission line, wireless transmission media, signals propagating through space, radio waves, infrared signals, etc. Of course, those skilled in the art will recognize that many modifications may be made to this configuration without departing from the scope of the implementations, and that the article of manufacture may comprise any information bearing medium known in the art.
While the implementations have been described with reference to the Java programming language they apply to any other object oriented programming language such as C++, Ada, Smalltalk etc. In addition to databases the persistent Java objects can also be used in any application where persistency of data needs to be maintained.
While the implementations have been described with a plurality of index and data files, alternative implementations are possible where the contents of index files and data files are merged in one or more files. Such a merger may involve the merging of several index files or several data files. The merger may also involve the merger of one or more data files with one or more index files.
In
The preferred logic of
Therefore, the foregoing description of the implementations has been presented for the purposes of illustration and description. It is not intended to be exhaustive or to limit the invention to the precise form disclosed. Many modifications and variations are possible in light of the above teaching. It is intended that the scope of the invention be limited not by this detailed description, but rather by the claims appended hereto. The above specification, examples and data provide a complete description of the manufacture and use of the composition of the invention. Since many embodiments of the invention can be made without departing from the spirit and scope of the invention, the invention resides in the claims hereinafter appended.
Number | Name | Date | Kind |
---|---|---|---|
6128771 | Tock et al. | Oct 2000 | A |
6223342 | George | Apr 2001 | B1 |
6505211 | Dessloch et al. | Jan 2003 | B1 |
6782538 | Copeland et al. | Aug 2004 | B1 |
Number | Date | Country |
---|---|---|
1 030 253 | Aug 2000 | EP |
Number | Date | Country | |
---|---|---|---|
20030182292 A1 | Sep 2003 | US |