Download ERW

Transcript
Chapter 1. Overall System Design
);
Again, the additional primary key id let us distinguish every relationship (even in
multirelations), whereas id0_person and id1_book are the images of a relationship
through the two legs. The remaining columns are attributes.
If, however, the cardinality constraints imposed force the multirelation instantiating
a relationship type (or its transpose) to be monodrome (or even a function), there is
a more efficient method: a column named id_relationship-type_other-entity-type
is added to the table reifying an entity type. In this case, we say that the SQL table
reifying the entity type absorbed the SQL table reifying the relationship type, or, informally, that the entity type absorbed the relationship type. Thus, for instance, if we
modified our example and set upper="1" in the definition of the book leg (i.e., each
book is on loan to at most one person), and moreover we eliminated all attributes
from the relationship, instead of a support table we would have produced a new column id_loan_person in the table reifying the entity book. That is, book would have
absorbed loan.
When ERtool reifies an entity-relationship schema, it first tries to absorb all relationship types without attributes into their sources (if it is possible); then it checks
whether it would be possible to absorb the remaining relationship types without attributes into their targets, and complains if this is true, as by design absorption is possible only in the source entity types; finally, it creates a support table for all remaining
types. There is some control on the first part of the process, as you can explicitly ask
for a relationship type not to be absorbed even if it is possible.
Subtypes are realised by keeping in sync the id fields of the tables reifying the types
involved. Thus, for instance, if A is a B then for each value of the id field in the table
reifying A there is a corresponding row of B whose id field has the same value. This
behaviour mimics exactly set-theoretical inclusion.
Note: The reification process is more complicated, as, for instance, part of the reification
of a dynamic enumerative attribute consist in creating an ad hoc table for storing the
enumeration. The details of the reification process are given for each ERL element in
detail in Chapter 2. In any case, ERtool generates detailed documentation about the
reification process.
Concurrency
ERW is able to coordinate any number of users accessing concurrently a database.
The design principle guiding the handling of concurrency is very simple, but effective: since editing is local, ERW keeps track of all changes made by the user in the
browser. When the user submits its changes, ERW locks all tables involved with the
editing of an entity before starting the update. Then, it checks whether referential or
logical integrity might be violated by the modifications submitted by the user; then,
it checks that read-only attribute values match the ones in the form; then, it perform
custom checks using the pre-update hook (if any of the previous check fails, the transaction is aborted). Finally, it applies the required modifications, it performs custom
updates using the post-update hook and unlocks the tables.
Locking is important because it guarantees atomicity. ERW does not assume finegrained locking in the underlying database: rather, it locks all tables that could be
possibly involved with an entity update or deletion. Unfortunately, an unpleasant
side-effect is that in databases with a rich ownership/subtyping structure updating
an entity may require locking a large number of tables. Note, however, that editing
can be always carried out in parallel, because of ERW’s stateless editing design. When
changes are written to the database, however, the access will be suitably serialised.
7