Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/RuntimeCollective/webapps/bean/EntityBean.java


1   /* $Header: /home/CVS/rjp/src/com/RuntimeCollective/webapps/bean/EntityBean.java,v 1.6 2003/09/30 15:13:09 joe Exp $
2    * $Revision: 1.6 $
3    * $Date: 2003/09/30 15:13:09 $
4    *
5    * ====================================================================
6    *
7    * Josephine : http://www.runtime-collective.com/josephine/index.html
8    *
9    * Copyright (C) 2003 Runtime Collective
10   * 
11   * This product includes software developed by the
12   * Apache Software Foundation (http://www.apache.org/).
13   *
14   * This library is free software; you can redistribute it and/or
15   * modify it under the terms of the GNU Lesser General Public
16   * License as published by the Free Software Foundation; either
17   * version 2.1 of the License, or (at your option) any later version.
18   *
19   * This library is distributed in the hope that it will be useful,
20   * but WITHOUT ANY WARRANTY; without even the implied warranty of
21   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22   * Lesser General Public License for more details.
23   *
24   * You should have received a copy of the GNU Lesser General Public
25   * License along with this library; if not, write to the Free Software
26   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
27   *
28   */
29  
30  package com.RuntimeCollective.webapps.bean;
31  
32  import java.sql.SQLException;
33  import java.io.Serializable;
34  
35  /** A javabean must implement this interface in order to be handled by the <code>EntityBeanStore</code>.
36   *
37   * <p> As well as implementing this interface, all Entity Beans must define the following two constructors:
38   * <ul>
39   * <li><code>EntityBean()</code> - Return a new blank bean with a new unique id. Throw <code>SQLException</code> if not possible to generate new id.
40   * <li><code>EntityBean(int id)</code> - Generate a bean from the database corresponding to the given primary key. If there is no such bean in the database, then throw <code>SQLException</code>.
41   * </ul>
42   * <p> Entity beans usually have other methods for getting various children or parent beans, and which access the database. The golden rule in these cases is that, wherever possible, beans should only know about their own database tables. If they require access to other tables then this should be done via static methods on the appropriate beans. (Obviously this breaks down where a join between two or more entity tables is required, but the intention is still that access to particular tables should be restricted to particular beans.)
43   *
44   * @version $Id: EntityBean.java,v 1.6 2003/09/30 15:13:09 joe Exp $
45   * @see com.RuntimeCollective.webapps.EntityBeanStore
46   */
47  public interface EntityBean extends Serializable {
48  
49      /** The name of a table (in the default database) that indexes this bean type. This table must have a PK column called "id" and a row for each of the beans of this type. */
50      public static String DATABASE_TABLE = "global_object";
51  
52      /** The name of the interface that this bean implements, and which will be used to key this bean on the session. This field should <code>only</code> be defined in those situations where a bean interface will only have ONE concrete implementation in the application. If an interface may have more than implementation then the application will have to use an IndexedEntityBeanStore in order that the type can be disambiguated. */
53      public static final String INTERFACE_BEAN = "com.RuntimeCollective.webapps.bean.EntityBean";
54  
55      /** Get the unique id of this bean instance. */
56      public int getId();
57  
58      /** Set the unique id of this bean instance. */
59      public void setId(int id);
60  
61      /** Save this bean to the database. */
62      public void save() throws SQLException;
63  
64      /** Delete this bean from the database.
65       * It is up to the particular subclass whether the bean is deleted the database entirely, or just marked as 'archived' -- as long as it is no longer returned by the EntityBean(id) constructor.
66       */
67      public void delete() throws SQLException;
68  
69  
70      public static final int NULL_ID = -1;
71  }
72  
73  
74  
75