5 Replies Latest reply: Jun 20, 2014 12:35 PM by gaverill RSS

    Simple Object Instantiations Not Working and Wondering Why

    Joe Upshaw

      I have created an ancestor object, PROGENITOR and one descendant, PRS_ADMIN_PROGENITOR. Everything compiles ok so; it would seem that the syntax is correct.

       

      I attempt to use the PRS_ADMIN_PROGENITOR with this anonymous block of PL/SQL:

      DECLARE
      
          lb_ParameterFound       BOOLEAN := FALSE;
          
          lObj_PRSAdminProgenitor PRS_ADMIN_PROGENITOR;
          
          ls_SuccessMsg           VARCHAR2(4000);
          
      BEGIN
      
          lObj_PRSAdminProgenitor := PRS_ADMIN_PROGENITOR(NULL);
          
          lb_ParameterFound := lObj_PRSAdminProgenitor.GET_PARAM_VALUE( 'SUCCESS_MESSAGE', ls_SuccessMsg );
          
          DBMS_OUTPUT.PUT_LINE( ls_SuccessMsg );
          
      END;
      /
      

      Running this gives me the error "PLS-00302: component 'GET_PARAM_VALUE' must be declared"

       

      I have two questions about the code that follows:

       

      1. I've created a parameterless CONSTRUCTOR function on PRS_ADMIN_PROGENITOR. So, why doesn't in allow me to instantiate with PRS_ADMIN_PROGENITOR()? (It forces me to specify PRS_ADMIN_PROGENITOR(NULL)
      2. Why does it say that the function GET_PARAM_VALUE must be declared when, plainly, it has been declared.
      CREATE OR REPLACE TYPE PROGENITOR AS OBJECT
      (   gs_ObjectType       VARCHAR(32), 
          gtb_Parameters      TAB_PARAMETERS,
          FINAL MEMBER PROCEDURE SET_OBJECT_TYPE( as_ObjectType IN VARCHAR2 ),
          FINAL MEMBER FUNCTION GET_OBJECT_TYPE RETURN VARCHAR2,
          NOT FINAL MEMBER PROCEDURE RELOAD_PARAMETERS,
          NOT FINAL MEMBER FUNCTION GET_PARAM_VALUE( as_ParameterName IN VARCHAR2, as_ParameterValue IN OUT VARCHAR2 ) RETURN BOOLEAN,
          FINAL MEMBER PROCEDURE LOG_INFO( aclb_LogInfo IN CLOB ) )
      NOT INSTANTIABLE NOT FINAL
      /
      CREATE OR REPLACE TYPE BODY PROGENITOR 
      AS
          
          FINAL MEMBER PROCEDURE SET_OBJECT_TYPE( as_ObjectType IN VARCHAR2 )
          IS
          BEGIN
              gs_ObjectType := as_ObjectType;
          END SET_OBJECT_TYPE;
          
          FINAL MEMBER FUNCTION GET_OBJECT_TYPE 
          RETURN VARCHAR2
          IS
          BEGIN
              RETURN gs_ObjectType;
          END GET_OBJECT_TYPE;      
          
          NOT FINAL MEMBER PROCEDURE RELOAD_PARAMETERS
          IS
          BEGIN
              NULL;
          END RELOAD_PARAMETERS;
          
          NOT FINAL MEMBER FUNCTION GET_PARAM_VALUE( as_ParameterName IN VARCHAR2, 
                                                     as_ParameterValue IN OUT VARCHAR2 ) 
          RETURN BOOLEAN
          IS
          BEGIN
              RETURN FALSE;
          END;        
          
          FINAL MEMBER PROCEDURE LOG_INFO( aclb_LogInfo IN CLOB )
          IS
          
              PRAGMA AUTONOMOUS_TRANSACTION;
          
          BEGIN
          
              INSERT INTO LOG_INFO
              ( LOG_INFO )
              VALUES
              ( aclb_LogInfo );
              
              COMMIT;
                  
          END LOG_INFO;
      
      END;
      /
      
      CREATE OR REPLACE TYPE           PRS_ADMIN_PROGENITOR UNDER PROGENITOR
      ( gc_PromotionID            CHAR(32),
        gs_SuccessMsg             VARCHAR2(4000),
        gs_UserInputRequiredMsg   VARCHAR2(4000),
        gs_ErrorMsg               VARCHAR2(4000),
        gs_DefaultAJAXSeperator   VARCHAR2(4000),
        gs_DefaultDateFormat      VARCHAR2(4000),
        gs_DefaultDateTimeFormat  VARCHAR2(4000),
        CONSTRUCTOR FUNCTION PRS_ADMIN_PROGENITOR RETURN SELF AS RESULT,
        FINAL MEMBER FUNCTION GET_CURRENT_BUSINESS_DATE RETURN DATE,
        OVERRIDING MEMBER PROCEDURE RELOAD_PARAMETERS,
        OVERRIDING MEMBER FUNCTION GET_PARAM_VALUE( as_ParameterName IN VARCHAR2, as_ParameterValue IN OUT VARCHAR2 ) RETURN BOOLEAN,
        FINAL MEMBER PROCEDURE SET_PROMOTION_ID( ac_PromotionID IN CHAR ),
        FINAL MEMBER FUNCTION GET_PROMOTION_ID RETURN CHAR )
      NOT FINAL
      /
      CREATE OR REPLACE TYPE BODY           PRS_ADMIN_PROGENITOR 
      AS
          CONSTRUCTOR FUNCTION PRS_ADMIN_PROGENITOR 
          RETURN SELF AS RESULT
          IS
          BEGIN    
              RELOAD_PARAMETERS;
              RETURN;
          END;
          
          FINAL MEMBER FUNCTION GET_CURRENT_BUSINESS_DATE 
          RETURN DATE
          IS
          
              CURSOR lcsr_GetCurrentBusinessDate IS
                  SELECT TO_CHAR( CURRENT_BUSINESS_DATE, gs_DefaultDateFormat ) AS CURRENT_BUSINESS_DATE
                  FROM CURRENT_BUSINESS_DATES;
      
              ldt_CurrentBusiness DATE;
          
          BEGIN
          
              OPEN lcsr_GetCurrentBusinessDate;
              FETCH lcsr_GetCurrentBusinessDate INTO ldt_CurrentBusiness;
              CLOSE lcsr_GetCurrentBusinessDate;
              
              RETURN ldt_CurrentBusiness;
              
          END GET_CURRENT_BUSINESS_DATE;
          
          
          OVERRIDING MEMBER PROCEDURE RELOAD_PARAMETERS
          IS
          
              ldt_CurrentBusiness     DATE;
              
              ltb_PRSAdminParameters  TAB_PARAMETERS;
              
              ls_CurrentBusinessDate  VARCHAR2(4000);
              
              CURSOR lcsr_GetPRSAdminParams IS
                  SELECT PARAMETER_NAME, PARAMETER_VALUE
                  FROM PRS_ADMIN_PARAMETER;
      
              lrec_PRSParam   lcsr_GetPRSAdminParams%ROWTYPE;
          
          BEGIN
              
              -- Empty Out Any Previously Loaded Parameters
              
              gtb_Parameters := ltb_PRSAdminParameters;
              
              OPEN lcsr_GetPRSAdminParams;
      
              LOOP
      
                  FETCH lcsr_GetPRSAdminParams INTO lrec_PRSParam;
                  EXIT WHEN lcsr_GetPRSAdminParams%NOTFOUND;
      
                  gtb_Parameters( lrec_PRSParam.PARAMETER_NAME ).PARAMETER_VALUE := lrec_PRSParam.PARAMETER_VALUE;
      
                  CASE lrec_PRSParam.PARAMETER_NAME
                      WHEN 'SUCCESS_MESSAGE' THEN
                          gs_SuccessMsg := lrec_PRSParam.PARAMETER_VALUE;
                      WHEN 'USER_INPUT_REQUIRED_MESSAGE' THEN
                          gs_UserInputRequiredMsg := lrec_PRSParam.PARAMETER_VALUE;
                      WHEN 'ERROR_MESSAGE' THEN
                          gs_ErrorMsg := lrec_PRSParam.PARAMETER_VALUE;
                      WHEN 'DEFAULT_AJAX_SEPERATOR' THEN
                          gs_DefaultAJAXSeperator := lrec_PRSParam.PARAMETER_VALUE;
                      WHEN 'DEFAULT_DATE_FORMAT' THEN
                          gs_DefaultDateFormat := lrec_PRSParam.PARAMETER_VALUE;
                      WHEN 'DEFAULT_DATETIME_FORMAT' THEN
                          gs_DefaultDateTimeFormat := lrec_PRSParam.PARAMETER_VALUE;
                      ELSE
                          NULL;
                  END CASE;
      
              END LOOP;
      
              CLOSE lcsr_GetPRSAdminParams;
              
              ldt_CurrentBusiness := GET_CURRENT_BUSINESS_DATE;
              
              ls_CurrentBusinessDate := TO_CHAR( ldt_CurrentBusiness, gs_DefaultDateFormat );
              
              gtb_Parameters('CURRENT_BUSINESS_DATE').PARAMETER_VALUE := ls_CurrentBusinessDate;
              
          END RELOAD_PARAMETERS;
          
          OVERRIDING MEMBER FUNCTION GET_PARAM_VALUE( as_ParameterName IN VARCHAR2, 
                                                            as_ParameterValue IN OUT VARCHAR2 ) 
          RETURN BOOLEAN
          IS
          
              lb_ParameterFound BOOLEAN := FALSE;
          
          BEGIN
          
              lb_ParameterFound := gtb_Parameters.EXISTS( as_ParameterName );
      
              If ( lb_ParameterFound = TRUE ) Then
      
                  as_ParameterValue := gtb_Parameters( as_ParameterName ).PARAMETER_VALUE;
      
              End If;
      
              RETURN lb_ParameterFound;
              
          END;        
          
          FINAL MEMBER PROCEDURE SET_PROMOTION_ID( ac_PromotionID IN CHAR )
          IS
          BEGIN
              gc_PromotionID := ac_PromotionID;
          END;
          
          FINAL MEMBER FUNCTION GET_PROMOTION_ID
          RETURN CHAR
          IS
          BEGIN
              RETURN gc_PromotionID;
          END;
      END;
      /