By: K. Brown, B. Whitenack
Published in: Object Magazine, Sept. 1996
Pages: 51-55
When and how to define a database schema to support an object model. The identity of the objects, their relationships, and their state must be preserved in the tables of a relational database; a continuation of Crossing Chasms: A Pattern Language for Object-RDBMS Integration###Crossing Chasms
Category: Architectural, Database
Summary: When and how to define a database schema to support an object model. The identity of the objects, their relationships, and their state must be preserved in the tables of a relational database, a continuation of [Brown+96b]
Pages: 53
What is the appropriate structure for classes in a Smalltalk client-server system? Use a four-layer architecture: View, Application Model, Domain Model, and Supporting Infrastructure. Determine interfaces between layers in advance and keep communication paths well defined.
Category: Architectural, Client-Server
Pages: 53
Design a relational database schema after a first-pass object model done with a behavioral modeling technique. It may be prudent to wait until after an architectural prototype has been built. Doing things in reverse order often leads to a poorly factored OO design with separate function and data objects.
Pages: 53
To map objects into a relational database, start with a table for each persistent object. Determine the type of each instance variable and create a column in the table. If the instance variable contains a collection,
Pages: 53
To preserve an object's identity in a relational database, assign an object identifier to each persistent object, typically a long integer guaranteed to be unique for a class of objects.
Pages: 53
To represent object relationships in a relational database, one-to-one mappings become Foreign Key References. One-to-many mappings can use a relationship table. Many-to-many relationships become relationship tables.
Category: Database
Pages: 53
To represent Smalltalk collections in a relational database, create a relationship table for each collection. A relationship table maps the primary keys of the containing objects to the primary keys of the contained objects. The relationship table may store other information as well.
Pages: 53
To represent objects in a relational database that reference other objects that are not base datatypes, assign each object a unique identifier. Add a column for each instance variable that is not a base datatype or a collection. Store the identifier of the referenced object in the column. Declare the column a foreign key.
Pages: 54
To separate the domain-specific parts of an application from the database-specific parts, connect the database-specific classes and the domain-specific classes with an intermediate layer of broker objects.
Category: Database
Pages: 54
To define the mapping between the elements of an object class and the corresponding parts of a relational scheme, reify the mapping into a set of map classes that map object relationships into relational equivalents. Map classes also map column names to instance variable selectors in domain objects.
Category: Database
Pages: 54
To handle the generation and execution of common SQL statements and minimize the amount of duplicated code between broker classes, define a set of generic classes that generate SQL statements from common data. A hierarchy of classes representing SQL statements can generate the appropriate SQL given a domain object and its map object metadata representation.
Category: Database
Pages: 54-55
To handle client image and database synchronization when there are errors, mark objects as "deleted," "added," or "updated" during the session. If the database update succeeds, then remove the mark. If it fails, retry the transaction. If it continually fails, note the error and flush the cache. When changed objects are marked, you can return to the original state by storing changed objects locally and performing recovery later.
Category: Client-Server, Database, Transaction Processing
Pages: 55
To manage the lifetime of persistent objects in a relational database, use a session object that has a bounded lifetime and is responsible for identity cache management of a limited set of objects. Balance speed versus space by flushing the cache as appropriate. Use a query-before-write (timestamp) technique to keep caches accurate.
Category: Client-Server, Database