Oracle7 Server Distributed Systems Volume II: Replicated Data

Contents Index Home Previous Next

Sample Application

Suppose that you have the following tables in your INVENTORY database: CUSTOMER, ORDERS, ORDER_LINE, ITEM, and STOCK.

Now suppose that you decide to replicate these tables to multiple sites. Because you have chosen to asynchronously propagate your changes between sites, you decide to avoid possible update conflicts by partitioning the ownership of the data based on workflow.

To partition ownership, you add a STATUS column to the ORDERS table. The status of an order can be: S (shippable), B (billable), O (outstanding bill), or C (complete).

This example has two order entry sites, so you must take steps to ensure either that conflicts do not occur, or that they can be resolved. In this example, all orders have a unique order ID.

The sequence used to generate this ID is partitioned between the master definition site and this snapshot site. Even if the same customer places one order at the master definition site and another at the snapshot site, each order will have a unique ID and will be treated separately. In this example, only one of the sites is allowed to update the CUSTOMER table, therefore no conflict resolution is required for this table.

This example assumes that the appropriate database links have been created at each site, and that the appropriate privileges have been granted to the replication administrator at each site.

To create your replicated environment, perform the following steps:

 	DBMS_REPCAT.CREATE_MASTER_REPGROUP('inventory')

 -- replicate customer table
DBMS_REPCAT.CREATE_MASTER_REPOBJECT('acct','customer',
                                    'table','inventory',); 
-- insert appropriate calls to conflict resolution methods
DBMS_REPCAT.GENERATE_REPLICATION_SUPPORT('acct',
                                         'customer','table');
 -- replicate orders table
DBMS_REPCAT.CREATE_MASTER_REPOBJECT('acct','orders',
                                    'table','inventory');
DBMS_REPCAT.GENERATE_REPLICATION_SUPPORT('acct',
                                         'orders','table');
 -- replicate order_line table
DBMS_REPCAT.CREATE_MASTER_REPOBJECT('acct','order_line',
                                    'table','inventory');
DBMS_REPCAT.GENERATE_REPLICATION_SUPPORT('acct',
                                         'order_line','table');
 -- replicate item table
DBMS_REPCAT.CREATE_MASTER_REPOBJECT('acct',
                                    'item','table','inventory');
DBMS_REPCAT.GENERATE_REPLICATION_SUPPORT('acct','item',
                                         'table');
 -- replicate stock table
DBMS_REPCAT.CREATE_MASTER_REPOBJECT('acct','stock','table',
                                    'inventory');
DBMS_REPCAT.GENERATE_REPLICATION_SUPPORT('acct','stock',
                                         'table');

 DBMS_REPCAT.ADD_MASTER_DATABASE('inventory', 'dbs2');

 DBMS_REPCAT.RESUME_MASTER_ACTIVITY('inventory');

 DBMS_REPCAT.CREATE_SNAPSHOT_REPGROUP('inventory', 'dbs2',
                                      'asynchronous')

 -- create read-only snapshot of customer table
DBMS_REPCAT.CREATE_SNAPSHOT_REPOBJECT(
      'acct', 'customer', 'snapshot', 
      'CREATE SNAPSHOT customer' || 
      'AS SELECT * FROM customer@dbs2','','inventory');
 -- create updatable snapshot of orders table
DBMS_REPCAT.CREATE_SNAPSHOT_REPOBJECT(
      'acct','orders','snapshot', 
      'CREATE SNAPSHOT orders FOR UPDATE AS' || 
      'SELECT * FROM orders@dbs2 WHERE status = ''B''',
      '','inventory');
 -- create updatable snapshot of order_line table
DBMS_REPCAT.CREATE_SNAPSHOT_REPOBJECT(
      'acct', 'order_line', 'snapshot', 
      'CREATE SNAPSHOT order_line FOR UPDATE AS' || 
      'SELECT * FROM order_line@dbs2','','inventory');
 -- create updatable snapshot of item table
DBMS_REPCAT.CREATE_SNAPSHOT_REPOBJECT(
      'acct', 'item', 'snapshot', 
      'CREATE SNAPSHOT item FOR UPDATE AS' || 
      'SELECT * FROM item@dbs2','','inventory')


Contents Index Home Previous Next