/*
 * $Source: /usr/cvsroot/melati/poem/src/main/java/org/melati/poem/Poem.dsd,v $
 * $Revision: 1.60 $
 *
 * Copyright (C) 2000 William Chesters
 *
 * Part of Melati (http://melati.org), a framework for the rapid
 * development of clean, maintainable web applications.
 *
 * Melati is free software; Permission is granted to copy, distribute
 * and/or modify this software under the terms either:
 *
 * a) the GNU General Public License as published by the Free Software
 *    Foundation; either version 2 of the License, or (at your option)
 *    any later version,
 *
 *    or
 *
 * b) any version of the Melati Software License, as published
 *    at http://melati.org
 *
 * You should have received a copy of the GNU General Public License and
 * the Melati Software License along with this program;
 * if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA to obtain the
 * GNU General Public License and visit http://melati.org to obtain the
 * Melati Software License.
 *
 * Feel free to contact the Developers of Melati (http://melati.org),
 * if you would like to work out a different arrangement than the options
 * outlined here.  It is our intention to allow Melati to be used by as
 * wide an audience as possible.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * Contact details for copyright holder:
 *
 *     William Chesters <williamc@paneris.org>
 *     http://paneris.org/~williamc
 *     Obrechtstraat 114, 2517VX Den Haag, The Netherlands
 */

package org.melati.poem;

table user
  (displayorder = 2010)
  (description = "A registered User of the database")
  (category = "User")
  (seqcached) {  

  Integer id
    (primary) 
    (description = "The Table Row Object ID")
    (displaylevel = detail) 
    (displayorder = 10);

  String name (size = 60)
    (displayname = "Full name")
    (description = "The user's real name")
    (displayorderpriority = 0) 
    (displaylevel = primary) 
    (searchability = primary) 
    (displayorder = 20)
    (indexed);
                         
  String login 
    (size = 255) (width = 20)
    (unique) 
    (displayorder = 30)
    (description = "The user's login name");

  Password password 
    (size = 20) (width = 10)
    (description = "The user's password")
    (displaylevel = record) 
    (displayorder = 40)
    (searchability = no);
}

table group
  (displayorder = 2020)
  (description = "A Group to which registered Users of the database can belong")
  (category = "User")
  (seqcached) {

  Integer id
    (description = "The Table Row Object ID")
    (displaylevel = detail) 
    (primary);

  String name (size = 60)
    (unique) 
    (description = "A human-readable name for the group")
    (displayorderpriority = 0) 
    (displaylevel = primary) 
    (searchability = primary);
}

table capability
  (displayorder = 2030)
  (description = "A Capability which Users can be required to possess before accessing data")
  (category = "User")
  (seqcached) {

  Integer id
    (description = "The Table Row Object ID")
    (displaylevel = detail) 
    (primary);

  String name 
    (size = 60)
    (unique) 
    (description = "A human-readable name for the Capability")
    (displayorderpriority = 0) 
    (displaylevel = primary) 
    (searchability = primary);
}

table groupMembership
  (displayorder = 2040)
  (displayname = "Group membership")
  (category = "User")
  (description = "A record that a given User is a member of a given Group") {

  Integer id
    (description = "The Table Row Object ID")
    (displaylevel = detail) 
    (primary);

  (indexed)User user 
    (displayorderpriority = 0)
    (displayname = "User")
    (description = "The user who belongs to the group")
    (renderinfo = "SelectionWindow")
    (searchability = yes)
    (integrityfix = delete);

  Group group 
    (displayorderpriority = 1)
    (displayname = "Group")
    (description = "The group to which the user belongs")
    (searchability = primary);
}

table groupCapability
  (displayorder = 2050)
  (displayname = "Group capability")
  (category = "User")
  (description = "A record that Users belonging to a given Group possess a given Capability") {

  Integer id
    (description = "The Table Row Object ID")
    (displaylevel = detail) 
    (primary);

  Group group 
    (displayorderpriority = 0)
    (description = "The Group which has the capability")
    (searchability = primary);

  Capability capability 
    (displayorderpriority = 1)
    (description = "The capability");
}

table tableCategory
  (displayorder = 3030)
  (displayname = "Table type")
  (description = "A category under which a table can be classified")
  (category = "System")
  (cachelimit = unlimited)
  (seqcached) {

  (primary) Integer id
    (description = "The Table Row Object ID");

  (unique) String name 
    (size = 60)
    (description = "A human-readable name for the category")
    (displayorderpriority = 0) 
    (displaylevel = primary) 
    (searchability = primary);
}

table tableInfo
  (displayorder = 3010)
  (displayname = "Table")
  (description = "Configuration information about a table in the database")
  (category = "System")
  (cachelimit = unlimited)
  (seqcached) {

  Integer id
    (description = "The Table Row Object ID")
    (displaylevel = detail) 
    (primary);

  String name 
    (size = 50)
    (unique) 
    (description = "A code-name for the table")
    (uneditable) 
    (displaylevel = record)
    (searchability = no);

  String displayname 
    (size = 60)
    (displayname = "Display name")
    (description = "A user-friendly name for the table")
    (displayorderpriority = 1) 
    (displaylevel = primary);

  String description 
    (size = unlimited) 
    (nullable)
    (description = "A brief description of the table's function")
    (displaylevel = record) 
    (searchability = no);

  Integer displayorder
    (displayname = "Display order")
    (description = "A rank determining where the table appears in the list of all tables")
    (displayorderpriority = 0)
    (displaylevel = summary);

  Capability defaultcanread 
    (nullable)
    (displayname = "Default `read' capability")
    (description = "The capability required, by default, for reading the table's records")
    (displaylevel = record)
    (searchability = no)
    (integrityfix = clear)
    ;
  Capability defaultcanwrite 
    (nullable)
    (displayname = "Default `write' capability")
    (description = "The capability required, by default, for updating the table's records")
    (displaylevel = record) 
    (searchability = no)
    (integrityfix = clear)
    ;
  Capability defaultcandelete 
    (nullable)
    (displayname = "Default `delete' capability")
    (description = "The capability required, by default, for deleting the table's records")
    (displaylevel = record) 
    (searchability = no)
    (integrityfix = clear)
    ;
  Capability cancreate 
    (nullable)
    (displayname = "Default `create' capability")
    (description = "The capability required, by default, for creating records in the table")
    (displaylevel = record) 
    (searchability = no)
    (integrityfix = clear)
    ;
  Integer cachelimit 
    (nullable)
    (displayname = "Cache size limit")
    (description = "The maximum number of records from the table to keep in the cache")
    (displaylevel = record)
    (searchability = no);

  Boolean seqcached
    (displayname = "Record sequence cached")
    (description = "Whether the display sequence for the table's records is cached")
    (displaylevel = record)
    (searchability = no);

  TableCategory category
    (description = "Which category the table falls into")
    (displaylevel = record) 
    (searchability = primary);
}

abstract table ValueInfo {
  String displayname
    (size = 60)
    (displayname = "Display name")
    (displayorder = 100)
    (description = "A user-friendly name for the field")
    (displayorderpriority = 2)
    (displaylevel = primary);

  String description
    (size = unlimited)
    (nullable)
    (description = "A brief description of the field's function")
    (displaylevel = record)
    (searchability = no);

  Boolean usereditable
    (displayname = "User-editable")
    (displayorder = 200)
    (description = "Whether it makes sense for the user to update the field's value")
    (displaylevel = detail) 
    (searchability = no);

  ColumnType typefactory
    (displayname = "Type")
    (description = "The field's POEM type")
    (displaylevel = detail)
    (searchability = no)
    (uneditable);
      // In fact this is a reference into TableInfo.id, or, 
      // if negative, the code for an atomic type.
      // see PoemTypeFactory.forCode

  Boolean nullable
    (description = "Whether the field can be empty")
    (displaylevel = detail)
    (searchability = no)
    (uneditable);

  Integer size
    (description = "For character fields, the maximum number of characters that can be stored, (-1 for unlimited)")
    (displaylevel = record)
    (searchability = no)
    (uneditable);

  Integer width
    (displayname = "Input-box width")
    (description = "A sensible width for text boxes used for entering the field, where appropriate")
    (displaylevel = record)
    (searchability = no);

  Integer height
    (displayname = "Input-box height")
    (description = "A sensible height for text boxes used for entering the field, where appropriate")
    (displaylevel = record)
    (searchability = no);

  Integer precision 
    (displayname = "Precision")
    (description = "Precision (total number of digits) for fixed-point numbers")
    (displaylevel = record)
    (searchability = no)
    (uneditable);

  Integer scale 
    (displayname = "Scale")
    (description = "Scale (number of digits after the decimal) for fixed-point numbers")
    (displaylevel = record)
    (searchability = no)
    (uneditable);

  String renderinfo 
    (size = unlimited) 
    (nullable)
    (displayname = "Rendering information")
    (description = "The name of the Melati templet (if not the default) to use for input controls for the field")
    (displaylevel = record)
    (searchability = no);

  String rangelow_string 
    (size = unlimited) 
    (nullable)
    (displayname = "Range: low")
    (description = "The low end of the range of permissible values for the field")
    (displaylevel = detail)
    (searchability = no);

  String rangelimit_string
    (size = unlimited)
    (nullable)
    (displayname = "Range: limit")
    (description = "The (exclusive) limit of the range of permissible values for the field")
    (displaylevel = detail)
    (searchability = no);
}

table columnInfo extends org.melati.poem.ValueInfo
    (displayorder = 3020)
    (displayname = "Column")
    (description = "Configuration information about a column in the database")
    (category = "System")
    (cachelimit = unlimited)
    (seqcached) {

  (primary) Integer id
      (displayorder = 0);

  TableInfo tableinfo
    (displayname = "Owning table")
    (description = "The table to which the field belongs")
    (displayorderpriority = 0)
    (searchability = primary)
    (renderinfo = "SelectionWindow")
    (uneditable);

  (indexed) String name (size = 50)
    (displayorder = 50)
    (description = "A code-name for the field")
    (uneditable) 
    (displaylevel = record)
    (searchability = no);

  Integer displayorder
    (displayname = "Display order")
    (description = "A rank determining where the field appears in lists")
    (displayorderpriority = 1)
    (displaylevel = record)
    (searchability = no);

  Boolean usercreateable
    (displayname = "User-createable")
    (description = "Whether it makes sense for the user to initialise the field's value")
    (displaylevel = detail)
    (searchability = no);

  DisplayLevel displaylevel
    (displayname = "Display level")
    (description = "A category determining what granularity of report the field appears in")
    (displaylevel = record)
    (searchability = no);

  Searchability searchability
    (description = "A category determining what level of searching this field supports")
    (displaylevel = record)
    (searchability = no);
      
  Integer displayorderpriority
    (nullable)
    (displayname = "Display order priority")
    (description = "If present, the level at which lists of records are sorted by the field")
    (searchability = no);

  Boolean sortdescending
    (displayname = "Sort Descending")
    (description = "Whether when sorting by this column, the sort order should be reversed")
    (nullable)
    (displaylevel = record)
    (searchability = no);

  Boolean indexed
    (description = "Whether the field is indexed (ignored if the field is marked `unique')")
    (displaylevel = record)
    (searchability = no)
    (uneditable);

  Boolean unique
    (description = "Whether the field is unique (implies that it's `indexed')")
    (displaylevel = record)
    (searchability = no)
    (uneditable);

  (nullable) IntegrityFix integrityfix
    (displayname = "Integrity fix")
    (description = "How referential integrity is maintained, what to do when the object referred to is deleted")
    (displaylevel = record)
    (searchability = no)
    ;
}

table setting extends org.melati.poem.ValueInfo
  (displayorder = 3040)
  (description = "A configurable Setting for the application, where a Setting can be of any object type")
  (category = "System")
  (cachelimit = unlimited)
  (seqcached) {

  (primary) Integer id
    (description = "The Table Row Object ID")
    (displayorder = 0);

  (unique) String name (size = 200)
    (description = "A code name for this setting")
    (searchability = primary);

  (nullable) String value (size = unlimited)
    (displayorder = 150)
    (description = "The value of this setting");
}
