Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.69 KB | None | 0 0
  1. BEGIN
  2. SYS.DBMS_AQADM.CREATE_QUEUE_TABLE
  3. (
  4. QUEUE_TABLE => 'QT_NEW_CASE'
  5. ,QUEUE_PAYLOAD_TYPE => 'FILE_ACTION'
  6. ,COMPATIBLE => '8.1'
  7. ,STORAGE_CLAUSE => '
  8. TABLESPACE USERS
  9. PCTUSED 0
  10. PCTFREE 10
  11. INITRANS 1
  12. MAXTRANS 255
  13. STORAGE (
  14. INITIAL 64K
  15. NEXT 1M
  16. MINEXTENTS 1
  17. MAXEXTENTS UNLIMITED
  18. PCTINCREASE 0
  19. BUFFER_POOL DEFAULT
  20. )'
  21. ,SORT_LIST => 'ENQ_TIME'
  22. ,MULTIPLE_CONSUMERS => FALSE
  23. ,MESSAGE_GROUPING => 0
  24. ,SECURE => FALSE
  25. );
  26. End;
  27.  
  28. CREATE OR REPLACE TYPE FILE_ACTION AS OBJECT
  29. ( ACTION VARCHAR2(20),
  30. CASE_ID NUMBER(10),
  31. OTHER VARCHAR2(20)
  32. );
  33.  
  34. queue_util.add_file ('CLOSE', v_case_id,:NEW.ID);
  35.  
  36. PROCEDURE add_file_to_queue (action_in IN VARCHAR2,
  37. d_case_id_in IN NUMBER,
  38. d_other_in IN VARCHAR2:= NULL)
  39. IS
  40. /******************************************************************************
  41. PURPOSE: when there is a change to a file (create, closed or reopen) add the change to the queue of changes
  42. ******************************************************************************/
  43. queue_options SYS.DBMS_AQ.enqueue_options_t;
  44. message_properties SYS.DBMS_AQ.message_properties_t;
  45. message_id RAW (16);
  46. my_message file_action;
  47. err_text VARCHAR2 (2000);
  48. PRAGMA AUTONOMOUS_TRANSACTION;
  49. BEGIN
  50. my_message := file_action (action_in, d_case_id_in, d_other_in);
  51. DBMS_AQ.enqueue (queue_name => 'NEW_CASE_QUEUE',
  52. enqueue_options => queue_options,
  53. message_properties => message_properties,
  54. payload => my_message,
  55. msgid => message_id);
  56.  
  57. IF g_debugging
  58. THEN
  59. ;
  60. --insert debugging info if g_debugging is true
  61. END IF;
  62.  
  63. COMMIT;
  64. EXCEPTION
  65. WHEN NO_DATA_FOUND
  66. THEN
  67. err_text := SQLERRM;
  68. --logging error to another table
  69.  
  70. WHEN OTHERS
  71. THEN
  72. err_text := SQLERRM;
  73. --more logging
  74. END add_file_to_queue;
  75.  
  76. PROCEDURE send_from queue (case_id_in IN NUMBER := NULL)
  77. IS
  78. /******************************************************************************
  79. PURPOSE:get the list of file changes and send them out
  80. *****************************************************************************/
  81. queue_options DBMS_AQ.dequeue_options_t;
  82. message_properties DBMS_AQ.message_properties_t;
  83. message_id file_action;
  84. v_file VARCHAR2 (20);
  85. v_case_id NUMBER (10);
  86. v_filename VARCHAR2 (500);
  87. v_action VARCHAR2 (20);
  88. v_other VARCHAR2 (20);
  89. v_err_id INTEGER;
  90. bad_data_ex EXCEPTION;
  91. v_err_text VARCHAR2 (50);
  92.  
  93. TYPE cases_cur IS REF CURSOR;
  94.  
  95. new_cases cases_cur;
  96. BEGIN
  97. IF case_id_in IS NULL
  98. THEN
  99. OPEN new_cases FOR
  100. SELECT qt.msgid
  101. FROM cqt_new_case qt
  102. ORDER BY qt.enq_time;
  103. ELSE
  104. OPEN new_cases FOR
  105. SELECT qt.msgid
  106. FROM qt_new_case qt
  107. WHERE qt.user_data.case_id = case_id_in
  108. ORDER BY qt.enq_time;
  109. END IF;
  110.  
  111. --should have added a check here to make sure
  112. --the other database is up and running
  113. LOOP
  114. BEGIN
  115. FETCH new_cases INTO message_id;
  116.  
  117. --reinitialize values to null
  118. v_case_id := NULL;
  119. v_filename := NULL;
  120. v_file := NULL;
  121. v_action := NULL;
  122. v_other := NULL;
  123. --to try and clear all locks
  124. COMMIT;
  125. EXIT WHEN new_cases%NOTFOUND;
  126.  
  127. IF case_id_in IS NOT NULL
  128. THEN
  129. queue_options.deq_condition :=
  130. 'tab.user_data.case_id = ' || case_id_in;
  131. END IF;
  132.  
  133. DBMS_AQ.dequeue (queue_name => 'NEW_CASE_QUEUE',
  134. dequeue_options => queue_options,
  135. message_properties => message_properties,
  136. payload => my_message,
  137. msgid => message_id);
  138. v_case_id := my_message.case_id;
  139. v_action := my_message.action;
  140. v_other := my_message.other;
  141.  
  142. IF v_case_id IS NOT NULL AND v_case_id > 0
  143. THEN
  144. IF g_debugging
  145. THEN
  146. ;
  147. --insert your debugging information
  148. END IF;
  149. --continues on with lengthy data transforms
  150. --for actions like NEW, CLOSE, REOPEN
  151. END SEND_FROM_QUEUE;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement