1. Trang chủ
  2. » Công Nghệ Thông Tin

Oracle Built−in Packages- P137 pps

5 67 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 5
Dung lượng 79,17 KB

Nội dung

"REGION_ID1_n", "REGION_NAME2_o", "REGION_NAME2_n", site_name, propagation_flag) then dbms_reputil.rep_end; raise; end if; dbms_reputil.rep_end; exception when others then dbms_reputil.rep_end; raise; end; when dup_val_on_index then begin if not "REGION$RR".unique_conflict_update_handler( "REGION_ID1_o", "REGION_ID1_n", "REGION_NAME2_o", "REGION_NAME2_n", site_name, propagation_flag, SQLERRM) then dbms_reputil.rep_end; raise; end if; dbms_reputil.rep_end; exception when others then dbms_reputil.rep_end; raise; end; when others then dbms_reputil.rep_end; raise; end rep_update; end "REGION$RP"; As you can see, Oracle invokes REGION$RR, the conflict resolution package: package body "REGION$RR" as function unique_conflict_insert_handler( "REGION_ID1_n" IN NUMBER, "REGION_NAME2_n" IN VARCHAR2, site_name IN VARCHAR2, propagation_flag IN CHAR, errmsg IN VARCHAR2) return boolean is begin return FALSE; end unique_conflict_insert_handler; function delete_conflict_handler( "REGION_ID1_o" IN NUMBER, "REGION_NAME2_o" IN VARCHAR2, site_name IN VARCHAR2, propagation_flag IN CHAR) return boolean is begin return FALSE; end delete_conflict_handler; function update_conflict_handler( "REGION_ID1_o" IN NUMBER, "REGION_ID1_n" IN NUMBER, "REGION_NAME2_o" IN VARCHAR2, "REGION_NAME2_n" IN VARCHAR2, [Appendix A] What's on the Companion Disk? 15.3.4 Replication Support with DBMS_REPCAT 671 site_name IN VARCHAR2, propagation_flag IN CHAR) return boolean is begin return FALSE; end update_conflict_handler; function unique_conflict_update_handler( "REGION_ID1_o" IN NUMBER, "REGION_ID1_n" IN NUMBER, "REGION_NAME2_o" IN VARCHAR2, "REGION_NAME2_n" IN VARCHAR2, site_name IN VARCHAR2, propagation_flag IN CHAR, errmsg IN VARCHAR2) return boolean is begin return FALSE; end unique_conflict_update_handler; end "REGION$RR"; This is the default conflict handling package that GENERATE_REPLICATION_SUPPORT creates. Since no conflict resolution methods are defined for REGION, the unique_conflict_insert_handler, delete_conflict_handler, update_conflict_handler, and unique_conflict_update_handler programs all return FALSE, indicating that they cannot resolve the conflict. Chapter 17 contains details about how to define conflict resolution handlers. 15.3.4.1.6 Generating replication support for packages and procedures As well as tables, you can also replicate procedures and packages. When you call a replicated procedure, Oracle builds a deferred RPC that it propagates to all master sites. This deferred RPC invokes the same procedure with the same arguments as the originating call. Oracle recommends procedural replication for situations that call for massive updates to tables (i.e., updates affecting tens of thousands of rows). Procedural replication duplicates the procedure call only, which is more efficient and network−friendly than row−level replication. (Row−level replication sends the old and new column values for every field of every row.) Just as we made two calls to CREATE_MASTER_REPOBJECT to create a replicated package, we must also make two calls to GENERATE_REPLICATION_SUPPORT: BEGIN DBMS_REPCAT.GENERATE_REPLICATION_SUPPORT( sname => 'SPROCKET', oname => 'PRODUCTMAINT', type => 'PACKAGE', distributed => TRUE, gen_objs_owner => 'SPROCKET', gen_rep2_trigger=> FALSE); DBMS_REPCAT.GENERATE_REPLICATION_SUPPORT( sname => 'SPROCKET', oname => 'PRODUCTMAINT', type => 'PACKAGE BODY', distributed => TRUE, gen_objs_owner => 'SPROCKET', gen_rep2_trigger=> FALSE); END; These two calls create a "wrapper" package and package body, named DEFER_PRODUCTMAINT. This package uses DBMS_DEFER.CALL (described in Chapter 17) to build RPCs to PRODUCTMAINT. To replicate a call to procedure ADDPRODUCT, we would call DEFER_PRODUCTMAINT.ADDPRODUCT. package "DEFER_PRODUCTMAINT" as I_am_a_snapshot CHAR; procedure "ADDPRODUCT"( [Appendix A] What's on the Companion Disk? 15.3.4 Replication Support with DBMS_REPCAT 672 "PRODUCT_TYPE_IN" IN number, "CATALOG_ID_IN" IN varchar2, "DESCRIPTION_IN" IN varchar2, "REV_LEVEL_IN" IN varchar2, "PRODUCTION_DATE_IN" IN date, "PRODUCT_STATUS_IN" IN varchar2, call_local IN char := 'N', call_remote IN char := 'Y'); end "DEFER_PRODUCTMAINT"; package body "DEFER_PRODUCTMAINT" as procedure "ADDPRODUCT"( "PRODUCT_TYPE_IN" IN NUMBER, "CATALOG_ID_IN" IN VARCHAR2, "DESCRIPTION_IN" IN VARCHAR2, "REV_LEVEL_IN" IN VARCHAR2, "PRODUCTION_DATE_IN" IN DATE, "PRODUCT_STATUS_IN" IN VARCHAR2, call_local IN char := 'N', call_remote IN char := 'Y') is begin select decode(master, 'N', 'Y', 'N') into I_am_a_snapshot from all_repcat where gname = 'SPROCKET'; if call_local = 'Y' then "SPROCKET"."PRODUCTMAINT"."ADDPRODUCT"( "PRODUCT_TYPE_IN", "CATALOG_ID_IN", "DESCRIPTION_IN", "REV_LEVEL_IN", "PRODUCTION_DATE_IN", "PRODUCT_STATUS_IN"); end if; if call_remote = 'Y' then 8, 'SPROCKET'); dbms_defer.number_arg("PRODUCT_TYPE_IN"); dbms_defer.varchar2_arg("CATALOG_ID_IN"); dbms_defer.varchar2_arg("DESCRIPTION_IN"); dbms_defer.varchar2_arg("REV_LEVEL_IN"); dbms_defer.date_arg("PRODUCTION_DATE_IN"); dbms_defer.varchar2_arg("PRODUCT_STATUS_IN"); dbms_defer.char_arg('Y'); dbms_defer.char_arg(I_am_a_snapshot); end if; end "ADDPRODUCT"; begin select decode(master, 'N', 'Y', 'N') into I_am_a_snapshot from all_repcat where gname = 'SPROCKET'; end "DEFER_PRODUCTMAINT"; 15.3.4.2 The DBMS_REPCAT.GENERATE_REPLICATION_PACKAGE procedure In some situations, you may wish to generate only replication support triggers or replication support packages. For example, if you use DBMS_REPCAT's ALTER_MASTER_PROPAGATION procedure to change from synchronous to asynchronous replication, you will have to recreate replication triggers. The GENERATE_REPLICATION_PACKAGE and GENERATE_REPLICATION_TRIGGERS procedures provide this functionality. The GENERATE_REPLICATION_PACKAGE procedure allows you to generate replication support packages. The specification follows: PROCEDURE DBMS_REPCAT.GENERATE_REPLICATION_PACKAGE [Appendix A] What's on the Companion Disk? 15.3.4 Replication Support with DBMS_REPCAT 673 (sname IN VARCHAR2, oname IN VARCHAR2); Parameters are summarized in the following table. Name Description sname Name of the schema to which table oname belongs oname Name of table for which package is being generated 15.3.4.2.1 Exceptions The GENERATE_REPLICATON_PACKAGE procedure may raise the following exceptions: Name Number Description commfailure −23317 Unable to communicate with all masters dbnotcompatible −23375 One or more masters is a pre−7.3 release missingobject −23308 Table oname does not exist in schema sname nonmasterdef −23312 Calling site is not a master definition site notquiesced −23310 Replication group to which object belongs is not quiesced 15.3.4.2.2 Restrictions Note the following restrictions on calling GENERATE_REPLICATION_PACKAGE: • You must call this procedure from the master definition site. • The replication group must be quiesced. • The Oracle version must be 7.3 or later. 15.3.4.2.3 Example The following call generates the replication support packages for table SPROCKET.PRODUCTS in all master sites: BEGIN DBMS_REPCAT.GENERATE_REPLICATION_PACKAGE( sname => 'SPROCKET', oname => 'PRODUCTS'); END; 15.3.4.3 The DBMS_REPCAT.GENERATE_REPLICATION_TRIGGER procedure The GENERATE_REPLICATION_TRIGGER procedure allows you to generate replication support triggers. The specifications differ for Oracle7 and Oracle8 as follows. Here is the Oracle7 specification: PROCEDURE DBMS_REPCAT.GENERATE_REPLICATION_TRIGGER (sname IN VARCHAR2, oname IN VARCHAR2, gen_objs_owner IN VARCHAR2 := NULL, [Appendix A] What's on the Companion Disk? 15.3.4 Replication Support with DBMS_REPCAT 674 gen_rep2_trigger IN BOOLEAN := FALSE); PROCEDURE DBMS_REPCAT.GENERATE_REPLICATION_TRIGGER (gname IN VARCHAR2, {master_list IN VARCHAR2 := NULL | master_table IN dbms_utility.dblink_array}, gen_objs_owner IN VARCHAR2 := NULL); Here is the Oracle8 specification: PROCEDURE DBMS_REPCAT.GENERATE_REPLICATION_TRIGGER (sname IN VARCHAR2, oname IN VARCHAR2, gen_objs_owner IN VARCHAR2 := NULL, min_communication IN BOOLEAN := TRUE); PROCEDURE DBMS_REPCAT.GENERATE_REPLICATION_TRIGGER (gname IN VARCHAR2, gen_objs_owner IN VARCHAR2 := NULL, min_communication IN BOOLEAN := NULL); Parameters are summarized in the following table. Name Description sname Name of the schema to which table oname belongs. oname Name of object for which support objects are being generated. gen_rep2_trigger (Oracle7 only) Provided for backward compatibility; if any master sites are pre−7.3 releases, this parameter must be set to TRUE (default is FALSE). gname The replication group to which oname belongs. master_list Comma−delimited string of global names for masters in which support objects are to be generated. master_table PL/SQL table of global names for masters in which support objects are to be generated. gen_objs_owner Specifies schema in which to generate replication support objects; if NULL (the default), objects are generated under schema in which they currently reside. min_communication (Oracle8 only) If TRUE (the default) the generated trigger sends the new value of a column only if the value has changed. Old field values are sent only if the field is part of the primary key, or part of a column group for which member columns have changed. 15.3.4.3.1 Exceptions The GENERATE_REPLICATION_TRIGGER procedure may raise the following exceptions: Name Number Description commfailure −23317 Unable to communicate with all masters dbnotcompatible −23375 One or more masters is a pre−7.3 release and gen_rep2_trigger is not set to TRUE missingobject −23308 Table oname does not exist in schema sname missingschema −23306 Schema sname does not exist nonmasterdef −23312 Calling site is not a master definition site notquiesced −23310 Replication group to which object belongs is not quiesced [Appendix A] What's on the Companion Disk? 15.3.4 Replication Support with DBMS_REPCAT 675 . you to generate replication support triggers. The specifications differ for Oracle7 and Oracle8 as follows. Here is the Oracle7 specification: PROCEDURE DBMS_REPCAT.GENERATE_REPLICATION_TRIGGER . replicated procedure, Oracle builds a deferred RPC that it propagates to all master sites. This deferred RPC invokes the same procedure with the same arguments as the originating call. Oracle recommends. this procedure from the master definition site. • The replication group must be quiesced. • The Oracle version must be 7.3 or later. 15.3.4.2.3 Example The following call generates the replication

Ngày đăng: 07/07/2014, 00:20