ActiveFacts Example Models
ActiveFacts converts fact-oriented models into matching object-oriented and relational models. It accepts models in the Constellation Query Language (CQL) or NORMA, and emits CQL, Ruby, or SQL. This page contains many examples.
The CQL files look like hand-written code, but they aren't. They're generated from the ORM2 files, and have not been edited. You can of course write them by hand.
The ActiveFacts generator afgen does semantic analysis to convert these input files to SQL or Ruby, using the relational and object-oriented mapping algorithms. The Ruby code uses the Constellation API provided by the activefacts gem.
To make a start learning Object Role Modeling, read the Introduction to ORM2 or check the Resources page for other sites.
If you're looking at a git clone of this project, and have Visual Studio (pro) on Windows with NORMA installed, you can open the Visual Studio solution here. Otherwise, you won't be able to edit the ORM2 files, but never fear, you can do all the same things by editing the CQL text.
Table of examples
|Shows how a complex entity (Address) can be absorbed in more than one place in the relational mapping. xml|
|The Blog model supports a hierarchy of topics, Posts by Authors, and Comments on individual Paragraphs. Each Paragraph and Comment is styled Text. xml|
|This model shows the relationships of a person to a company of which they may be a director or employee. xml|
|An event-based model for Genealogy which allows for different versions of the same fact to be claimed by different sources, for use in reconciling contradictory information. xml|
|A partial model for an insurance company's claims management, extended into automotive insurance claims|
This is the metamodel of ActiveFacts itself.
The generated Ruby code provides the intermediate representation for the compiler!
The Metamodel encodes the meaning of an ORM2 or CQL model. All features of the ORM2 and CQL languages have a representation here, as well as a few CQL features that haven't yet been implemented yet. xml and the upcoming version.
|An example of multiple inheritance. The solid subtype connectors show the identification path (for example, an AustralianEmployee is identified by his/her EmployeeID). xml|
|A model of the supply and demand for refined oil. A populated database can be used to optimise profitability by minimising transport costs, maximise supply by allowing substitution of compatible products (with compatibility depending on season) and also to predict shortages. xml|
|A model for the sport of Orienteering, broken into three diagrams. xml|
|Perhaps the simplest possible model, which maps to a single table. xml|
|This model illustrates an outstanding problem in some fact-oriented modelling tools, including ActiveFacts. The problem is that the Address table contains two copies of the same value, StateOrProvinceId. xml|
|This model represents students representing their school in school-sanctioned activities. It includes the ternary StudentParticipation Fact Type, which represents a student's participation in a school-sanctioned activity. The model has constraints that allow a given Student to participate only in a given Activity for a single School, only representing the School in which they're enrolled, and only if the School sanctions that activity. xml|
|An example of an equality constraint that spans conceptul joins. The constraint requires that tickets issued for an event are for a seat at the venue where that event will be held. xml|
|Based on a classic model of warehousing, it records stock levels for every product in each bin in every warehouse, and allows incoming and outgoing products to be allocated to be allocated to orders, including requests for transfers between warehouses. An order does not have to be shipped in a single shipment, but each item must be checked off for each shipment. xml|
|CQL Unit conversions|
|This CQL file contains an extensive library of fundamental units and unit conversions. These definitions can be used with your value types, so that queries can convert values from any compatible units.|
|This model shows how object types can get absorbed into others for efficient storage. In this case, every window is in a wall, every wall in a room, and every room in a building - yet only one table is needed to store a record of all windows. Try adding further properties to a room, and see what happens to the relational form! xml|