DDMS
[ class tree: DDMS ] [ index: DDMS ] [ all elements ]
Prev Next

User Guide for the DDMS Client Side Application

To help developers get started with working on the client side and using it in Business Applications

Jan van der Breggen
{@link mailto:jan.vanderbreggen@rigpa.org Jan van der Breggen}

Table of Contents

Introduction

Currently, the best environment for working on the DDMS Client is not the RV2 Application but the so-called Data Test Application. The source code for it can be obtained from the SourceForge SVN repository. Connect to https://retreatreg.svn.sourceforge.net/svnroot/retreatreg and download the directory dataTestApp. For tips for how to do this in Eclipse PDT, see User Guide for the Retreat Registration Version Two (RV2)Project. In addition to the dataTestApp you will also need to download the directory ddms_server

In the User Guide to the DDMS we gave both a very general description of what the DDMS does and will do in the future and a more detailed description. In this document we will describe the Client Side of the DDMS in even more detail. Here the discussion will not shy away from any database and PHP programming jargon.

Definition of Terms Used

The rest of this documentation uses terms that will be defined in this section:

  • Database of Record (DoR): the 'home', or 'source database' of a data record. In addition through data linkage provided by the DDMS a record can also be stored in various Retrieval Caches

  • Retrieval Cache: A copy of a data record obtained by the DDMS Client from the DDMS Server that is connected to that record's DoR

  • Staging: submitting new data records that were created in the Retrieval Cache for insertion into its DoR.

  • Horizontal Data Fragment: a subset of records from a data table

  • Vertical Data Fragment: a subset of fields from a data table

Main PHP Classes

The DDMS Client makes use of the following classes

  1. ExternalDataServerConnection: This is the overall container class where everything comes together. It is instantiated by the hosting business application. During its construction it retrieves information from the DDMS Client configuration database tables. Based on this configuration information it establishes a link with the DDMS Server specified by a URL. In addition it creates a series of ExternallyLinkedOrm objects all of which are linked to data managed by the DDMS Server.

  2. ExternallyLinkedOrm: This class represent a table in the database the data of which is linked to an external database. This class contains all the functionality the system needs for running the regular 'refresh data' event.

  3. PhPUrlConnection: This is the class that does the actual sending and receiving of data between Client and Server sides of the DDMS.

  4. UpdateLocalDataRule: This class is crucial for integrating the DDMS Client with its hosting business application. It encodes rules for which data must be refreshed during the 'refresh data' event for each ExternallyLinkedOrm object.

Interface with Hosting Business Application

As said before, the DDMS is completely generic and can function in the context of any PHP database application. However, the fact is that it does operate in the context of specific business applications, so it must provide some points of contact, as it were, between itself and the hosting business application. These points of contact are the following:

  • The hosting business application instantiates the DDMS Client by creating a new ExternalDataServerConnection object.

  • The hosting business application calls the ExternalDataServerConnection Object's refreshLocalData() method

  • The hosting business application decides which data records must be updated for each linked table by implementing the applyRule() method in the UpdateLocalDataRule class

  • The hosting business appliation calls the ExternalDataServer's refreshDataTableFragment() method in order to directly refresh a horizontal data fragment of a linked table, based on parameters passed into the refreshDataTableFragment() method. This functionality will be implemented during the next development phase of the DDMS.


DDMS Client Configuration Settings

In order to link a local data table to a data table on the server side the following configuration information needs to be supplied to the DDMS Client:

  1. The name of the table that must be linked externally

  2. The field in the table that is the remote primary key

  3. The field in the table that is the local primary key (if this is the same as the remote primary key that is a sign to the system that this is a 'select-only' linked table).

  4. Whether or not the data in the table must be updated during the regular 'refresh data' event. In practice not all linked data will need to be refreshed every time the refresh event runs. For example in 'lookup tables' that are used to populate drop down boxes on the User Interface there are often not many updates of data, or inserts of new records.

All this information is stored in the linked_tables DDMS configuration data table.

For every foreign key field in the linked table the DDMS wants to know the following:

  1. The Column Name of the Foreign Key field

  2. The name of the table that the values in that field refer to.

  3. The column name that is being referred to

In addition to this there are three further pieces of configuration to do with Foreign Key relationships. These will be described below.

All this information is stored in the references DDMS configuration data table. In future it might be useful to develop a user interface for the managing the DDMS Client configuration settings.

Refreshing the linked Retrieval Cache data

An important challenge of the DDMS Client is to create a lot of flexibility for refreshing the local data in accordance with the needs of the business application. The crux in this is efficiency. If there were no time and resources involved it would of course be great to completely refresh all data very often. However, in practice this would cause a potentially large amount of data to be transferred across the network, causing delays and high demand on computer's CPUs and network bandwidth. So the challenge for the DDMS Client is to allow for data fragments to be strategically refreshed at appropriate moments.

An additional factor that makes this even more challenging is that the DDMS has been designed to work in the context of any PHP database. In other words: it does not make assumptions about there for example being a 'date_last_updated' field in linked data tables, based on which a decision can be made to update data records.

In response to this challenge, the following functionality was developed to handle the refresh data event.

There are two basic types of refresh events in the DDMS Client: , and a. The 'All Data' refresh event

  • The 'All Data' refresh event, which does exactly what it's name promises: it replaces all data that is held in the local cache with data from the DoR.

  • The 'Refresh Data Fragment' refresh event, which will be described in more detail below

  • The 'Refresh Table Fragment' refresh event, which provides the hosting business application with a powerful way to directly request for a refresh of a specified horizontal fragment of one of the linked tables. This functionality has not yet been implemented, and the functional requirements will be described below.

The Refresh Data Fragment event

The 'Refresh Data Fragment' event works as follows: It is run only for those linked tables that have the field 'local_refresh' set to have the value 1 in the linked_tables table. During this event there are three distinct phases:

  1. Delete: during this phase the records that were deleted from the DoR are cleared from the local Retrieval Cache.

  2. Update: during this phase all fields in a selected set of records in the local retrieval cache are replaced with the values in their DoR countreparts. The way to determine which f records to update will be described a bit later.

  3. Insert: during this phase all records that were newly inserted in the DoR since the last refresh data event ran are inserted into the local retrieval cache.

The Update phase

The rules to determine which records must be updated are encoded in the UpdateLocalDataRule object that was introduced briefly above. This object plays an important role in interfacing the DDMS Client with its hosing business application. Simply explained it works like this: during the update phase the ExternallyLinkedOrm object will instantiate an instance of the UpdateLocalDataRule class, call the newly created object's applyRule() method. This method returns a set of primary key values to the ExternallyLinkedOrm object, the records corresponding to which need to updated. The ExternallyLinkedOrm object then sends this key set to the DDMS Server which in response sends back the set of records that were requested from it. The DDMS Client then proceeds the Update Phase by replacing records held in local retrieval cache with the records it received from the DDMS Server.


Cascading update, delete, insert

To make the Refresh Data Fragment event more sophisticated each of its three phases (Delete, Update, Insert) optionally includes respectively a cascading delete, cascading update, and cascading insert. The meaning of this will be explained in this section. Be careful, reading this could result in a headache is you're not in the right space for it......! ;-)

As you'll see, the relationships between linked table is crucial in these cascading refresh events. In the description below I'll refer to the the following

  1. Current Table: table whose data is currently in the process of being refreshed.

  2. Referenced Table: table that the Current Table has a foreign key relationship with.

  3. Referencing Table: table that has a foreign key relationship with the Current Table.


Cascading Delete

Cascading Delete means that for each record that needs to be deleted in the Current Table, the DDMS Client checks for records in other linked tables that have a foreign key relationship with the record that is about to be deleted, and runs the regular Update Phase for these records.


Cascading Update

As part of the Update Phase, the Cascading Update option means that for the Current Table, in addition to the set of records that is updated as defined in the UpdateLocalDataRule object, an additional set of records is updated, based its Referenced Tables. For each of its Referenced Tables, first the applyRule() method in the UpdateLocalDataRule object is invoked, resulting in a set of primary key values for the Referenced Table. Based on this set of primary key values, which are foreign key values Current Table, a set of primary key values is retrieved from the Current Table, and the records corresponding to it are updated in the way described above.


Cascading Insert

Cascading Insert means that for each record that is newly inserted into the local retrieval cache as part of the Insert Phase of the Refresh event, for each Referencing Table the DDMS Client requests from the DDMS Server the set of Records from the Referencing Table that refer to the newly inserted record of the Current Table. On the Client Side the corresponding records in the Referencing table will then be updated with these records.


Example

Let's lighten up this heavy going stuff with a humorous example to illustrate the usefulness of these cascading refresh events. Imagine the purely hypothetical situation that Germany decided it would be better off if all of its citizens spoke Dutch and if it would join the Netherlands. Imagine that the UpdateLocalDataRule in France's instance of a business application results in only student records for France to be updated during the Refresh Data Fragment event, and we would not have the cascading refresh events described above. The result would be that from the Countries table in the database the record for Germany would be dutifully deleted, but the Student Table would still have many records that refer to a by now non-existent Germany record in the Country table

Now imagine the same scenario but this time with the Cascading Delete event as part of it. Even though initially only all the French student records will be updated in the DDMS Clients retrieval cache, when the time comes to delete the Germany record from the Countries table the system would actually go and refresh every record in the student table that refers to the Germany record. The result this time would be that the DDMS Clients set of data would reflect the new geopolitical situation and all students formerly known as german would now be dutch in the database.............


Cascading Refresh Config Settings

Back to reality: as was said before, the cascading refresh events are optionally. This means that for each reference in the referenced_tables system configuration table the following three values need to be present

  1. cascading_update

  2. cascading_delete

  3. cascading_insert.

For each of these fields, if their value is 1 this indicates a cascading update, delete, or insert, if the value is 0, this means the reference does not cascade its update, delete or insert events.



The Refresh Table Fragment Refresh Event

As said above, there is a need to implement a kind of functionality that allows the hosting business application to request a refresh of a horizontal fragment of a specific linked table's data. For example, if a person logs into the system and the login credentials cannot be matched with any person's record in the person table, the system could request a refresh of the person table of all records that match the username supplied by the user. This is to cater for the situation that the user's login credentials were updated in the DoR and this update not having been made in the local Retrieval Cache yet.


Staging new data records for insertion into the DoR

This refers to newly created data records on the DDMS Client Side that has the DDMS Server side as its DoR. Functionality on both Client and Server Side needs to be developed to implement this functionality. This will be part of the next development phase.


Synchronising local DoR data with the Server

This refers to data that has the DDMS Client's database as its DoR. Currently this functionality has not been implemented. This will be part of the next development phase.

:
Prev   Next
User Guide for Distributed Data Management System (DDMS)

Documentation generated on Mon, 18 May 2009 11:21:27 +0200 by phpDocumentor 1.4.1