View Javadoc

1   // 
2   // Copyright (c) 2003, Caltha - Gajda, Krzewski, Mach, Potempski Sp.J. 
3   // All rights reserved. 
4   // 
5   // Redistribution and use in source and binary forms, with or without modification,  
6   // are permitted provided that the following conditions are met: 
7   //  
8   // * Redistributions of source code must retain the above copyright notice,  
9   //   this list of conditions and the following disclaimer. 
10  // * Redistributions in binary form must reproduce the above copyright notice,  
11  //   this list of conditions and the following disclaimer in the documentation  
12  //   and/or other materials provided with the distribution. 
13  // * Neither the name of the Caltha - Gajda, Krzewski, Mach, Potempski Sp.J.  
14  //   nor the names of its contributors may be used to endorse or promote products  
15  //   derived from this software without specific prior written permission. 
16  // 
17  // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"  
18  // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED  
19  // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
20  // IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,  
21  // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,  
22  // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
23  // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,  
24  // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)  
25  // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE  
26  // POSSIBILITY OF SUCH DAMAGE. 
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 }