|
Configuration ExamplesCurrently, a DTD is not available for the Tornado configuration files. Until one is created, the following examples are intentded to illustrate how to configure mappings for common usages. Defining a database
<database name="xplanner" engine="mysql"> Defining a simple object mapping This mapping defines a Note object consisting of several simple fields. The object is mapped to the "note" table and the object identity is defined by the "id" column in that table. When the object is deleted, the "is_deleted" column will be set to "1". If a "deleted-column" element is not specified, objects will be deleted from the database instead of marked for deletion. Upon insert and subsequent updates of a Note instance, the last update column will be immediately updated with the current time. The optional identity generator is specified as an attribute of the class element. <mapping> Defining an object mapping with a one-to-many relationship. This mapping defines a Task object consisting of several simple fields and a relationship. The object is mapped to the "task" table and the object identity is defined by the "id" column in that table. A Task has a one-to-many association with Notes. The foreign key in the Note table is "attachedTo_id". This relationship is also specified with a cascading delete, so that when a Task is deleted all it's related Notes are deleted (or marked for delete is a deleted column is specified). <mapping> Defining an object mapping with a many-to-many relationship. This mapping defines an ElectronicResource object containing a many-to-many relationship. The many-to-many relationship uses an intermediate table to define the association. In this example, the table is called "assoc". The "from_column" and "to_column" attributes define the columns that hold the identifiers for the ElectronicResource and Category objects (note: currently many-to-many relationships are not supported for compound keys). Furthermore, this mapping is sharing it's association table with other associations. To distinguish this association from others that exist in the table, the "where" attribute specifies how to select the entries for this type of association. The intent behind this feature is to allow dynamic associations to be created at runtime. Of course, these associations would probably not be represented in the Java class definition but they can be accessed programatically. Sharing association tables is an optional feature. Each association can have it's own table if that's desired. <mapping> |
tornado-db@sourceforge.net |