1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package org.objectledge.database.persistence;
29
30 /***
31 * Implemented by objects that are made persistent using a relational
32 * database.
33 *
34 * @author <a href="mailto:rafal@caltha.pl">Rafal Krzewski</a>
35 * @version $Id: Persistent.java,v 1.2 2004/02/23 09:05:01 fil Exp $
36 */
37 public interface Persistent
38 {
39 /***
40 * Returns the name of the table this type is mapped to.
41 *
42 * @return the name of the table.
43 */
44 public String getTable();
45
46 /***
47 * Returns the names of the key columns.
48 *
49 * @return the names of the key columns.
50 */
51 public String[] getKeyColumns();
52
53 /***
54 * Stores the fields of the object into the specified record.
55 *
56 * <p>You need to call <code>getData</code> of your superclasses if they
57 * are <code>Persistent</code>.</p>
58 *
59 * @param record the record to store state into.
60 * @throws PersistenceException if something goes wrong.
61 */
62 public void getData(OutputRecord record)
63 throws PersistenceException;
64
65 /***
66 * Loads the fields of the object from the specified record.
67 *
68 * <p>You need to call <code>setData</code> of your superclasses if they
69 * are <code>Persistent</code>.</p>
70 *
71 * @param record the record to read state from.
72 * @throws PersistenceException if something goes wrong.
73 */
74 public void setData(InputRecord record)
75 throws PersistenceException;
76
77 /***
78 * Returns the 'saved' flag for the object.
79 *
80 * <p>The flag is off for objects that haven't been saved in the db yet,
81 * thus need <code>INSERT</code> statemets, and on for object that have
82 * already been saved, thus need <code>UPDATE</code> statements.</p>
83 *
84 * @return the state of 'saved' flag.
85 */
86 public boolean getSaved();
87
88 /***
89 * Sets the 'saved' flag for the object.
90 *
91 * <p>The id generation will take place only for objects that declare a
92 * single column primary key. Othre objects will receive a <code>-1</code>
93 * as the <code>id</code> parameter. After this call is made on an object,
94 * subsequent calls to {@link #getSaved()} on the same object should
95 * return true.</p>
96 *
97 * @param id The generated value of the primary key.
98 */
99 public void setSaved(long id);
100 }