View Javadoc
1   /*
2    * $Source$
3    * $Revision$
4    *
5    * Copyright (C) 2000 William Chesters
6    *
7    * Part of Melati (http://melati.org), a framework for the rapid
8    * development of clean, maintainable web applications.
9    *
10   * Melati is free software; Permission is granted to copy, distribute
11   * and/or modify this software under the terms either:
12   *
13   * a) the GNU General Public License as published by the Free Software
14   *    Foundation; either version 2 of the License, or (at your option)
15   *    any later version,
16   *
17   *    or
18   *
19   * b) any version of the Melati Software License, as published
20   *    at http://melati.org
21   *
22   * You should have received a copy of the GNU General Public License and
23   * the Melati Software License along with this program;
24   * if not, write to the Free Software Foundation, Inc.,
25   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA to obtain the
26   * GNU General Public License and visit http://melati.org to obtain the
27   * Melati Software License.
28   *
29   * Feel free to contact the Developers of Melati (http://melati.org),
30   * if you would like to work out a different arrangement than the options
31   * outlined here.  It is our intention to allow Melati to be used by as
32   * wide an audience as possible.
33   *
34   * This program is distributed in the hope that it will be useful,
35   * but WITHOUT ANY WARRANTY; without even the implied warranty of
36   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
37   * GNU General Public License for more details.
38   *
39   * Contact details for copyright holder:
40   *
41   *     William Chesters <williamc@paneris.org>
42   *     http://paneris.org/~williamc
43   *     Obrechtstraat 114, 2517VX Den Haag, The Netherlands
44   */
45  
46  package org.melati.poem;
47  
48  import org.melati.poem.generated.TableInfoBase;
49  
50  /**
51   * All the data defining a {@link Table}; actually a {@link Persistent} 
52   * from the {@link TableInfoTable}.
53   * 
54   * Melati POEM generated, programmer modifiable stub 
55   * for a <code>Persistent</code> <code>TableInfo</code> object.
56   * 
57   * <p> 
58   * Description: 
59   *   Configuration information about a table in the database. 
60   * </p>
61   * 
62   * <table> 
63   * <caption>
64   * Field summary for SQL table <code>TableInfo</code>
65   * </caption>
66   * <tr><th>Name</th><th>Type</th><th>Description</th></tr>
67   * <tr><td> id </td><td> Integer </td><td> The Table Row Object ID </td></tr> 
68   * <tr><td> name </td><td> String </td><td> A code-name for the table 
69   * </td></tr> 
70   * <tr><td> displayname </td><td> String </td><td> A user-friendly name for 
71   * the table </td></tr> 
72   * <tr><td> description </td><td> String </td><td> A brief description of the 
73   * table's function </td></tr> 
74   * <tr><td> displayorder </td><td> Integer </td><td> A rank determining where 
75   * the table appears in the list of all tables </td></tr> 
76   * <tr><td> defaultcanread </td><td> Capability </td><td> The capability 
77   * required, by default, for reading the table's records </td></tr> 
78   * <tr><td> defaultcanwrite </td><td> Capability </td><td> The capability 
79   * required, by default, for updating the table's records </td></tr> 
80   * <tr><td> defaultcandelete </td><td> Capability </td><td> The capability 
81   * required, by default, for deleting the table's records </td></tr> 
82   * <tr><td> cancreate </td><td> Capability </td><td> The capability required, 
83   * by default, for creating records in the table </td></tr> 
84   * <tr><td> cachelimit </td><td> Integer </td><td> The maximum number of 
85   * records from the table to keep in the cache </td></tr> 
86   * <tr><td> seqcached </td><td> Boolean </td><td> Whether the display 
87   * sequence for the table's records is cached </td></tr> 
88   * <tr><td> category </td><td> TableCategory </td><td> Which category the 
89   * table falls into </td></tr> 
90   * </table> 
91   * 
92   * See org.melati.poem.prepro.TableDef#generateMainJava 
93   */
94  
95  public class TableInfo extends TableInfoBase {
96  
97   /**
98    * Constructor 
99    * for a <code>Persistent</code> <code>TableInfo</code> object.
100   * <p>
101   * Description: 
102   *   Configuration information about a table in the database. 
103   * </p>
104   * 
105   * See org.melati.poem.prepro.TableDef#generateMainJava 
106   */
107   public TableInfo() { }
108 
109   // programmer's domain-specific code here
110 
111   private Table<?> _actualTable = null;
112 
113   /**
114    * Constructor creates a {@link TableInfo} from a {@link Table}.
115    * Note This must be overridden if you extend TableInfo in your DSD.
116    * 
117    * @param table from which to get metadata
118    */
119   public TableInfo(Table<?> table) {
120     setName_unsafe(table.getName());
121     setDisplayname_unsafe(table.defaultDisplayName());
122     setDisplayorder_unsafe(new Integer(table.defaultDisplayOrder()));
123     setDescription_unsafe(table.defaultDescription());
124     setCachelimit_unsafe(table.defaultCacheLimit());
125     setSeqcached_unsafe(table.defaultRememberAllTroids() ? 
126                             Boolean.TRUE : Boolean.FALSE);
127     setCategory_unsafe(table.getDatabase().getTableCategoryTable().
128                            ensure(table.defaultCategory()).troid());
129   }
130   
131   /**
132    * Get the {@link Table} this is about.
133    * 
134    * @return The table this object represents.
135    */
136   public Table<?> actualTable() {
137     if (_actualTable == null && troid() != null)
138       _actualTable = getDatabase().tableWithTableInfoID(troid().intValue());
139     return _actualTable;
140   }
141 
142  /**
143   * Allow this object to be read by anyone.
144   * 
145   * @param token any {@link AccessToken}
146   */
147   public void assertCanRead(AccessToken token) {}
148 
149   /**
150    * Overridden to disallow table renaming.
151    * 
152    * @see org.melati.poem.generated.TableInfoBase#setName(java.lang.String)
153    */
154   public void setName(String name) {
155     String current = getName();
156     if (current != null && !current.equals(name))
157       throw new TableRenamePoemException(name);
158     super.setName(name);
159   }
160 
161   /**
162    * Set here and in table we represent. 
163    * 
164    * @see org.melati.poem.generated.TableInfoBase#setSeqcached(java.lang.Boolean)
165    */
166   public void setSeqcached(Boolean b) throws AccessPoemException {
167     super.setSeqcached(b);
168     if (actualTable() != null) 
169       actualTable().rememberAllTroids(b.booleanValue());
170   }
171 
172   /**
173    * Set here and in table we represent. 
174    * 
175    * @see org.melati.poem.generated.TableInfoBase#setCachelimit(java.lang.Integer)
176    */
177   public void setCachelimit(Integer limit) throws AccessPoemException {
178     super.setCachelimit(limit);
179     if (actualTable() != null) 
180       actualTable().setCacheLimit(limit);
181   }
182 
183 }