next up previous contents
Next: Remote Proxy Pattern: Distributed Up: Patterns Previous: Observer Pattern: Update Notification   Contents

Snapshot Pattern: Persistent Objects [62]



$\bullet$ Problem: How to make an object persistent on the disk?

$\bullet$ Solution: Snapshot Pattern

$\bullet$ Outline: An in-memory object ``lives'' only as long as the application program is running. But an object might contain important data that needs to be retained essentially forever, in particular, objects which represent information in a database.


\begin{picture}(385,216)(35,584)\thicklines
\put( 35,720){\framebox (105,80){...
...x(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm at each construction}}}
\end{picture}

$\bullet$ Alternative 1: Use Java's serialization mechanism to implement Snapshot Pattern

$\bullet$ Alternative 2: Use an SQL Relational database to implement Snapshot Pattern

$\bullet$ For example, a relational table has a row per object:

mysql> select * from S;
+------+-------+--------+--------+
| S_NO | SNAME | STATUS | CITY   |
+------+-------+--------+--------+
| S1   | Smith |     20 | London |  ======> S1  Smith  30  Paris
| S2   | Jones |     10 | Paris  |
| S3   | Blake |     30 | Paris  |
| S4   | Clark |     20 | London |
| S5   | Adams |     30 | Athens |
+------+-------+--------+--------+

$\bullet$ When ``S1'' is constructed by Application, read the associated fields from the row

$\bullet$ When ``S1'' mutates, modify the row to the new values

$\bullet$ SEE CASE STUDY



Ted Billard 2006-09-26