--
PedroRio - 17 Dec 2010
XEO Library - Modeling the Entities
In the
last section, you've seen how to use XEO Studio to create the XEO Model for the Author entity (named LIB_Author). Now we'll start by progressively create the XEO Object Models for the other entities. To make things easier to explain and also to show XEO's ability to deal with change over time we'll first create some Object Models that do not contain all of their attributes and, as the explanation progresses, add the remaining attributes later on.
We've already learned how to add a textual attribute, define the label, set its length and make it a required attribute (from the previous section), so we'll now make use of that knowledge to define the next entity: the "Book Category". We'll first define a small convention to use in this section of the documentation regarding XEO Object Models, which is:
Object_Model_Name ( Object Model Label)
- attribute name (type, label, description [,length] [, required ])
- attribute2 name (type, label, description [, length] [, required ])
- etc...
We first start with the Object Model Name and it label within curly brackets. For each attribute of the Object Model we have an unordered list item with the name of the attribute and properties about it inside curly brackets (such as its type (text, number, date), a label, a description, its lenght (1 - 5000+). An example maybe more clear, for the Book Category entity (
recall the book category entity from previous sections):
LIB_BookCategory ( Book Category)
- name (Text, 'Name', 'Name of the Category' ,30, required)
To create the LIB_Category Object Model, go to the "File" menu, select "New" and then "XEO Object Model". In the XEO Package field, browse to the "LIB$1.0" package and in the name fill "LIB_BookCategory", in the description you can write "Represents a book category". Press finish and add a "Text" attribute and fill the name with "name", label with "Name" , description with "Name of the category", length with 30 and in the "Required" section, choose "BOL" from the dropdown menu and type "true" in the field that appears. Your Object Model should look like the one depicted in figure ME.1 and ME.1a.
Figure ME.1 - Book Category Object Model
Figure ME.1a - Book Category Name Attribute
Next, let's create a few more Object Models for entities (Publisher and Book). Create the Publisher entity as the following (use the new Object Model wizard as before and choose the LIB$1.0 Package):
LIB_Publisher ( Publisher )
- name (Text, "Name", "Publisher Name", 40, required)
- address (Text, "Address", "Publisher Address", 100, required)
- website (Text, "Website", "Publisher WebSite", 40)
Then, create the Book entity with the following definition (also in the LIB$1.0 package):
LIB_Book (Book)
- title (Text, 'Title', 'Book title', 100, required)
- isbn (Text, 'ISBN', 'The Book's ISBN', 13, required)
- edition (Text, 'Edition', 'Book Edition', 30, required)
- summary (LongText, 'Summary', 'Summary of the Book') - LongText attributes do not have the length property
- frontCover (BinaryData, 'Front Cover', 'The Book's Front Cover') - Binary Data attributes (files) also don't have length property
- backCover (BinaryData, 'BackCover', 'The Book's Back Cover')
Save both Object Models and by now you'll have four XEO Object Models (LIB_Author, LIB_BookCategory, LIB_Publisher and LIB_Book). If you recall from the
introduction, the Book entity had a 1:N relation with authors and categories and a 1:1 relation with publishers. We'll now add those relations to the LIB_Book Object Model.
Adding a 1:1 Relation attribute
We'll begin with the 1:1 relation with publishers. Open the LIB_Book Object Model and add another attribute of type "Object". For the attribute name use "publisher", for the label type "Publisher" and in the description "Book Publisher". You'll notice that Object attributes have a different set of properties from previous attributes created, one of them being the "Type" (highlighted in red in figure ME.2). The type property defines which type of instances (i.e. instances of which Object Model) can relate to instances of the current Object Model; in this situation we want that LIB_Book instances have a relation with LIB_Publisher instances so we'll have to select the LIB_Publisher object model.
The default value for the Type property of an Object attribute is
object.boObject. boObject is the super class for all Object Model instances (similar to Object in Java) and you can use it as representation of "any Object Model". The object.ObjectModelName is the syntax used internally but by pressing the "Brower" button (see figure ME.2) you only need to choose from the list of Object Models in your project (Typing Object Model names will narrow the list progressively). Choose "LIB_Publisher" as the type for the publisher attribute.
Figure ME.2 - Editing an attribute of type Object (for the LIB_Book Object Model)
Note: Object attributes can have several more properties which will be discussed later in the documentation (for example, it's possible to declare the following: instances "LIB_Book" have a 1:1 relation, through attribute X, with an instance of Model A, Model B or Model C)
To finalize the LIB_Book Object Model we'll need the 1:N relations (to Categories and Authors) which will be done in the following section.
Adding a 1:N Relation (Collection) attribute
Collection attributes in Object Models represent 1:N relations, which are among the most common in XEO Object Modeling. To create a Collection attribute it's required to specify not only the target Object Model(s) and the cardinality of the relation (minimum an maximum), as usual there are several other options which will be explorer later. Check figure ME.3 to see how to create the collection attribute for the "Book Categories" relations.
Figure ME.3 - Editing an attribute of type Collection (for the LIB_Book Object Model)
To finalize the LIB_Book Object Model, add another Collection attribute named "authors" (label = Authors, description = "Book Authors", type = LIB_Author). The LIB_Publisher Object Model has a 1:N relation with Publisher Nucleus, and a 1:N relation with Contacts but we'll leave for later. In the next section entities representing users and their interaction with books shall be created.
Librarians, Users, Messages, Movements and Returns
In this chapter we'll model the entities that deal with users and their interaction with books. (Librarians and Users, Movements and Returns and finally the Messages librarians can send each other). XEO comes with Object Models that help dealing with users, so the best way is always to reuse one of those; one the Object Models is the iXEOUser interface which declares a set of attributes (name, username, password, id, e-mail) necessary for user accounts. Librarians and Users will require these attributes and add another attribute which is the library identifier (for users) and library employee identifier (for librarians). The
Figure ME.4 - User and Librarian implementing interface iXEOUser
Start by creating the Library User and Librarian models with the following structure (respectively):
LIB_User ( Library User )
- userIdentifier (Number, "Library ID", "Library Identifier", 10, required)
- active (Boolean, "Active", "Active Flag")
LIB_Librarian ( Library User )
- employeeId (Number, "Employee Number", "Library Identifier", 10, required)
Now, we must set both the Object Models to implement the iXEOUser interface. Doing so, requires to open each Object Model, find the "General" section and press the "Edit..." button which will open the general properties in the details panel; find the "Implemented Interfaces" section and press the add button. The result is depitected in figure ME.5.
Figure ME.5 - Interface Implementation in XEO Studio
aaa
Contact and Publisher Nucleus
A contact asda
adsdad
s
a