SHARE
TWEET

Untitled

a guest Jan 24th, 2020 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package main.resources.domain.templates;
  2.  
  3.  
  4. import main.resources.model.BusinessRule;
  5. import main.resources.model.Operator;
  6. import main.resources.model.Values;
  7.  
  8. public class TemplateTriggerICMPOracle extends TriggerTemplate {
  9.    
  10.     public String generateCode(BusinessRule br) {
  11.     String code = super.generateCode(br);
  12.     String tableTwoSubstr = br.getTableNameTwo().substring(0, 3);
  13.     String cursorName =  "cursor_" + tableTwoSubstr;
  14.     String attributeVar = "l_" + br.getTableNameTwo() + br.getAttributeNameOne();
  15.     String attributeCompareOne = br.getValueList().get(0);
  16.     String attributeCompareTwo = br.getValueList().get(1);
  17.    
  18.     code += "\ncursor " + cursorName + " IS "
  19.                 + "\nSELECT " + tableTwoSubstr + "." + br.getAttributeNameTwo()
  20.                 + "\nFROM " + br.getTableNameTwo() + " " + tableTwoSubstr
  21.                 + "\nWHERE " + tableTwoSubstr + "." + attributeCompareTwo + " = :new." + attributeCompareOne + ";"
  22.                 + "\n" + attributeVar + " " + br.getTableNameTwo() + "." + br.getAttributeNameTwo() + "%type;"
  23.                 + "\nBEGIN"
  24.                 + "\nOPEN " + cursorName + ";"
  25.                 + "\nFETCH " + cursorName + " INTO " + attributeVar + ";"
  26.                 + "\nCLOSE " + cursorName + ";"
  27.                 +"\nIF l_oper in ('INS', 'UPD')"
  28.                 + "\nTHEN"
  29.                 + "\nl_passed := :new." + br.getAttributeNameOne() + " " + br.getOperator().getValue() + " " + attributeVar + ";"
  30.    
  31.                 + "\nIF NOT l_passed"
  32.                 + "\nTHEN"
  33.                 + "\nl_error_stack := l_error_stack || '" + "ERROR MESSAGE" + "';"
  34.                 + "\nEND IF;"
  35.                 + "\nEND IF;"
  36.                 + "\nEND;"
  37.                 + "\nIF l_error_stack is not null"
  38.                 + "\nTHEN"
  39.                 + "\nraise_application_error(-20800, l_error_stack);"
  40.                 + "\nEND IF;"
  41.                 + "\nEND " + br.getConstraintName() + ";";
  42.    
  43.     return code;
  44.     }
  45.    
  46.     public static void main(String args[]) {
  47.         TriggerTemplate test = new TemplateTriggerICMPOracle();
  48.         Values val = new Values();
  49.         val.addValue("order_id");
  50.         val.addValue("id");
  51.        
  52.         BusinessRule testbr = new BusinessRule.Builder("BRG_TEST_TRIGGER_ICMP")
  53.                 .firstComparableTable("levering")
  54.                 .secondComparableTable("orders")
  55.                 .firstComparableAttribute("datum")
  56.                 .secondComparableAttribute("datum")
  57.                 .comparableValues(val)
  58.                 .usingOperator(new Operator("GREATER THAN OR EQUALS", ">="))
  59.                 .usingTemplate(test)
  60.                 .build();
  61.        
  62.         System.out.println(test.generateCode(testbr));
  63.     }
  64. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top