Wednesday, June 3, 2009

The Trac Ticket Database Model

In Trac trunk, we can get a glimpse into the schematics behind the Trac ticket. The internals of the Trac ticket database model are interesting to see because the ticket is such a central concept in the Trac system. Below is an illustration of the Ticket database model class.



Here are some brief highlights of what each method does.
  • __init__() - Performs initialization actions. If the ticket id was passed, the values of the ticket in the database will be populated in this instance. Otherwise, the default values will be used.
  • id_is_valid() - Return true if the specified ticket id is valid.
  • _get_db() - Return the database connection.
  • _get_db_for_write() - Return the database connection for writing.
  • _init_defaults() - Initialize the default field values. In addition to initializing the default field values, the default options that are available for a given ticket field are also initialized.
  • _fetch_ticket() - Initialize this ticket instance using specific ticket field values. This is done by first executing a query to load the stored ticket data from the database.
  • __getitem__() - Support the getitem operator to retrieve ticket field values.
  • __setitem__() - Support the setitem operator store ticket field values.
  • get_value_or_default() - Return the value of the field or the default value. The default value is only returned if there is a problem retrieving the actual value because it does not yet exist.
  • populate() - Populate the ticket fields using the specified dictionary. Only valid keys in the supplied dictionary, that exist as ticket fields, will be populated.
  • insert() - Insert this ticket into the database. This method will not insert the ticket if the ticket id already exists in the database.
  • save_changes() - Update the database with any changes made to this ticket. This includes updating the ticket changelog.
  • get_changelog() - Retrieve the changelog data for this ticket.
  • delete() - Delete this ticket from the database.

No comments :

Post a Comment