Chapter 17. Introduction

TheonCoupler is used within Theon to: import and subsequently update a model from a physical PostgreSQL database; update a model with any elements maintained via the SchemaFactory; process TheonCoupler configuration data itself.

Optionally TheonCoupler can be used to bring data from an external source into any database managed by Theon. It can also be used to generically automate many types of mapping function within any database managed by Theon.

Generally TheonCoupler loads external data into a table in a database and then applies its automatically built functions to synchronize data between that table and other tables. While this is a common pattern, as the generic synchronisation process is from one table within the database to another, the source table is not constrained to containing a loaded external data set. It could be a view based entirely on internal tables or a table function generating data. This makes TheonCoupler more of a general purpose data movement and processing tool.

A stream represents one source of external data that is processed as an atomic unit. There may be multiple couple synchronisation processes initiated from the stream. These synchronise the changes to actual database tables, however if any one fails the whole stream processing will fail and any changes made rolled back. The definition of a stream includes a description of the processing mechanism for the actual external data, a reference to the table to hold that data and then an ordered list of couples that process the data. The stream source data can be defined as virtual (defined by other tables internally, so in some cases no explicit table) or a foreign data wrapper.

Figure 17.1. Fan

TC_Fan.svg

A single data set for a stream is always mapped to a single Stream Source Table within the PostgreSQL physical database. This mapping can actually be achieved in a number of different ways however, see configurations below. Each Stream Source Table can be used to define any number of distinct Couple Source Tables. A Couple Source Table can just be the Stream Source Table in simpler scenarios or each Couple Source Table can be constructed in a number of different ways, again see configurations below. Finally each Couple Source Table can be used in any number of distinct couple configurations that then synchronise the content of that source table with a final target table. A Target Table can be the target in more than one couple configuration (within the stream or across any number of streams). The same Couple Source Table can be used for any number of couple configurations with different Target Tables. This is illustrated in Figure 17.1, “Fan”.

A stream does not need to have any couple configurations, in which case it is just concerned with loading external data into the Stream Source Table. In this context it is effectively just a simplified instance of the COPY command.

Note that the definition of the Stream Source Table and each Couple Source Table is nothing to do with TheonCoupler. These are defined along with the rest of the schema model (physical database elements). The TheonCoupler is purely concerned with the population method for the Stream Source Table and the synchronisation function from a Couple Source Table to the final Target Table. The underlying construction/implementation of the Stream Source Table and each Couple Source Table for each stream is entirely independent and TheonCoupler is a generic mechanism that sits on top of that, which as a result lends it great flexibility as the configurations below will show.