trafodion-codereview mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robertamarton <...@git.apache.org>
Subject [GitHub] trafodion pull request #1721: [TRAFODION-3216]UDR libraries need to be store...
Date Sun, 14 Oct 2018 23:52:47 GMT
Github user robertamarton commented on a diff in the pull request:

    https://github.com/apache/trafodion/pull/1721#discussion_r225015002
  
    --- Diff: core/sql/sqlcomp/CmpSeabaseDDLroutine.cpp ---
    @@ -995,180 +1561,293 @@ void CmpSeabaseDDL::createSeabaseRoutine(
       sigBuf[0] = '\0';
     
       if (style == COM_STYLE_JAVA_CALL) 
    -  {
    -     // validate routine for Java call based on signature
    -     Lng32 numJavaParam = 0;
    -     ComFSDataType *paramType = new ComFSDataType[numParams];
    -     ComUInt32     *subType   = new ComUInt32    [numParams];
    -     ComColumnDirection *direction = new ComColumnDirection[numParams];
    -     NAType *genericType;
    +    {
    +      // validate routine for Java call based on signature
    +      Lng32 numJavaParam = 0;
    +      ComFSDataType *paramType = new ComFSDataType[numParams];
    +      ComUInt32     *subType   = new ComUInt32    [numParams];
    +      ComColumnDirection *direction = new ComColumnDirection[numParams];
    +      NAType *genericType;
     
    -     // Gather the param attributes for LM from the paramDefArray previously
    -     // populated and from the routineparamList generated from paramDefArray.
    +      // Gather the param attributes for LM from the paramDefArray previously
    +      // populated and from the routineparamList generated from paramDefArray.
     
    -     for (CollIndex i = 0; (Int32)i < numParams; i++)
    -     {
    -       paramType[i] = (ComFSDataType)routineParamArray[i]->getParamDataType()->getFSDatatype();
    -       subType[i] = 0;  // default
    -       // Set subType for special cases detected by LM
    -       switch ( paramType[i] )
    -       {
    -         case COM_SIGNED_BIN8_FSDT :
    -         case COM_UNSIGNED_BIN8_FSDT :
    -         case COM_SIGNED_BIN16_FSDT :
    -         case COM_SIGNED_BIN32_FSDT :
    -         case COM_SIGNED_BIN64_FSDT :
    -         case COM_UNSIGNED_BIN16_FSDT :
    -         case COM_UNSIGNED_BIN32_FSDT :
    -         case COM_UNSIGNED_BPINT_FSDT :
    -         {
    -           genericType = routineParamArray[i]->getParamDataType() ;
    -           if (genericType->getTypeName() == LiteralNumeric)
    -             subType[i] = genericType->getPrecision();
    -           else
    -             subType[i] = 0 ;
    -
    -           break;
    -         }
    -
    -         case COM_DATETIME_FSDT :
    -         {
    -           genericType = routineParamArray[i]->getParamDataType() ;
    -           DatetimeType & datetimeType = (DatetimeType &) *genericType;
    -            if (datetimeType.getSimpleTypeName() EQU "DATE")
    -              subType[i] = 1 ;
    -            else if (datetimeType.getSimpleTypeName() EQU "TIME")
    -              subType[i] = 2;
    -            else if (datetimeType.getSimpleTypeName() EQU "TIMESTAMP")
    -              subType[i] = 3;
    -         }
    -       } // end switch paramType[i]
    -
    -       direction[i] = (ComColumnDirection) routineParamArray[i]->getParamDirection();
    -     }
    +      for (CollIndex i = 0; (Int32)i < numParams; i++)
    +        {
    +          paramType[i] = (ComFSDataType)routineParamArray[i]->getParamDataType()->getFSDatatype();
    +          subType[i] = 0;  // default
    +          // Set subType for special cases detected by LM
    +          switch ( paramType[i] )
    +            {
    +            case COM_SIGNED_BIN8_FSDT :
    +            case COM_UNSIGNED_BIN8_FSDT :
    +            case COM_SIGNED_BIN16_FSDT :
    +            case COM_SIGNED_BIN32_FSDT :
    +            case COM_SIGNED_BIN64_FSDT :
    +            case COM_UNSIGNED_BIN16_FSDT :
    +            case COM_UNSIGNED_BIN32_FSDT :
    +            case COM_UNSIGNED_BPINT_FSDT :
    +              {
    +                genericType = routineParamArray[i]->getParamDataType() ;
    +                if (genericType->getTypeName() == LiteralNumeric)
    +                  subType[i] = genericType->getPrecision();
    +                else
    +                  subType[i] = 0 ;
    +
    +                break;
    +              }
    +
    +            case COM_DATETIME_FSDT :
    +              {
    +                genericType = routineParamArray[i]->getParamDataType() ;
    +                DatetimeType & datetimeType = (DatetimeType &) *genericType;
    +                if (datetimeType.getSimpleTypeName() EQU "DATE")
    +                  subType[i] = 1 ;
    +                else if (datetimeType.getSimpleTypeName() EQU "TIME")
    +                  subType[i] = 2;
    +                else if (datetimeType.getSimpleTypeName() EQU "TIMESTAMP")
    +                  subType[i] = 3;
    +              }
    +            } // end switch paramType[i]
    +
    +          direction[i] = (ComColumnDirection) routineParamArray[i]->getParamDirection();
    +        }
         
    -     // If the syntax specified a signature, pass that to LanguageManager.
    -     NAString specifiedSig( createRoutineNode->getJavaSignature() );
    -     char* optionalSig;
    -     if ( specifiedSig.length() == 0 )
    -       optionalSig = NULL;
    -     else
    -       optionalSig = (char *)specifiedSig.data();
    +      // If the syntax specified a signature, pass that to LanguageManager.
    +      NAString specifiedSig( createRoutineNode->getJavaSignature() );
    +      char* optionalSig;
    +      if ( specifiedSig.length() == 0 )
    +        optionalSig = NULL;
    +      else
    +        optionalSig = (char *)specifiedSig.data();
          
    -     ComBoolean isJavaMain =
    -       ((str_cmp_ne(createRoutineNode->getJavaMethodName(), "main") == 0) ? TRUE :
FALSE);
    -
    -     LmResult createSigResult;
    -     LmJavaSignature *lmSignature =  new (STMTHEAP) LmJavaSignature(NULL,
    -                                                                    STMTHEAP);
    -     createSigResult = lmSignature->createSig(paramType, subType, direction,
    -                                              numParams, COM_UNKNOWN_FSDT, 0,
    -                                              createRoutineNode->getMaxResults(),
optionalSig, isJavaMain, sigBuf,
    -                                              MAX_SIGNATURE_LENGTH,
    -                                              CmpCommon::diags());
    -     NADELETE(lmSignature, LmJavaSignature, STMTHEAP);
    -     delete [] paramType;
    -     delete [] subType;
    -     delete [] direction;
    -
    -     // Lm returned error. Lm fills diags area, so no need to worry about diags.
    -     if (createSigResult == LM_ERR)
    -     {
    -       *CmpCommon::diags() << DgSqlCode(-1231)
    -			  << DgString0(extRoutineName);
    -       deallocEHI(ehi); 
    -       processReturn();
    -       return;
    -     }
    +      ComBoolean isJavaMain =
    +        ((str_cmp_ne(createRoutineNode->getJavaMethodName(), "main") == 0) ? TRUE
: FALSE);
    +
    +      LmResult createSigResult;
    +      LmJavaSignature *lmSignature =  new (STMTHEAP) LmJavaSignature(NULL,
    +                                                                     STMTHEAP);
    +      createSigResult = lmSignature->createSig(paramType, subType, direction,
    +                                               numParams, COM_UNKNOWN_FSDT, 0,
    +                                               createRoutineNode->getMaxResults(),
optionalSig, isJavaMain, sigBuf,
    +                                               MAX_SIGNATURE_LENGTH,
    +                                               CmpCommon::diags());
    +      NADELETE(lmSignature, LmJavaSignature, STMTHEAP);
    +      delete [] paramType;
    +      delete [] subType;
    +      delete [] direction;
    +
    +      // Lm returned error. Lm fills diags area, so no need to worry about diags.
    +      if (createSigResult == LM_ERR)
    +        {
    +          *CmpCommon::diags() << DgSqlCode(-1231)
    +                              << DgString0(extRoutineName);
    +          deallocEHI(ehi); 
    +          processReturn();
    +          return;
    +        }
     
    -     numJavaParam = (isJavaMain ? 1 : numParams);
    +      numJavaParam = (isJavaMain ? 1 : numParams);
    +
    +      if( libBlobHandle[0] != '\0' )
    +        {
    +          NAString dummyUser;
    +          NAString cachedLibName, cachedLibPath;
    +          
    +          if(ComGenerateUdrCachedLibName(extPath,redefTime,libSchNamePart,dummyUser,
cachedLibName, cachedLibPath))
    +            {
    +              *CmpCommon::diags() << DgSqlCode(-1231)
    +                                  << DgString0(extRoutineName);
    +              deallocEHI(ehi); 
    +              processReturn();
    +              return;
    +            }
    +         
    +          NAString cachedFullName = cachedLibPath+"/"+cachedLibName;
    +          
    +          if (extractLibrary(&cliInterface,libBlobHandle, (char *)cachedFullName.data()))
    +            {
    +              *CmpCommon::diags() << DgSqlCode(-1231)
    +                                  << DgString0(extRoutineName);
    +              deallocEHI(ehi); 
    +              processReturn();
    +              return;
    +            }
    +                       
    +          if (validateRoutine(&cliInterface, 
    +                              createRoutineNode->getJavaClassName(),
    +                              createRoutineNode->getJavaMethodName(),
    +                              cachedFullName,
    +                              sigBuf,
    +                              numJavaParam,
    +                              createRoutineNode->getMaxResults(),
    +                              optionalSig))
    +            {
    +              *CmpCommon::diags() << DgSqlCode(-1231)
    +                                  << DgString0(extRoutineName);
    +              deallocEHI(ehi); 
    +              processReturn();
    +              return;
    +            }
    +        }
    +    
    +      else
    +        {                      
    +          if (validateRoutine(&cliInterface, 
    +                          createRoutineNode->getJavaClassName(),
    +                          createRoutineNode->getJavaMethodName(),
    +                          externalPath,
    +                          sigBuf,
    +                          numJavaParam,
    +                          createRoutineNode->getMaxResults(),
    +                          optionalSig))
    +           
    +            {
    +              *CmpCommon::diags() << DgSqlCode(-1231)
    +                              << DgString0(extRoutineName);
    +              deallocEHI(ehi); 
    +              processReturn();
    +              return;
    +            }
    +        }
    +    }
    +          
     
    -     if (validateRoutine(&cliInterface, 
    -                         createRoutineNode->getJavaClassName(),
    -                         createRoutineNode->getJavaMethodName(),
    -                         externalPath,
    -                         sigBuf,
    -                         numJavaParam,
    -                         createRoutineNode->getMaxResults(),
    -                         optionalSig))
    -     {
    -       *CmpCommon::diags() << DgSqlCode(-1231)
    -                           << DgString0(extRoutineName);
    -       deallocEHI(ehi); 
    -       processReturn();
    -       return;
    -     }
    -  }
       else if (style == COM_STYLE_JAVA_OBJ ||
                style == COM_STYLE_CPP_OBJ)
    -  {
    -    // validate existence of the C++ or Java class in the library
    -    Int32 routineHandle = NullCliRoutineHandle;
    -    NAString externalPrefix(externalPath);
    -    NAString externalNameForValidation(externalName);
    -    NAString containerName;
    +    {
    +      // validate existence of the C++ or Java class in the library
    +      Int32 routineHandle = NullCliRoutineHandle;
    +      NAString externalPrefix(externalPath);
    +      NAString externalNameForValidation(externalName);
    +      NAString containerName;
     
    -    if (language == COM_LANGUAGE_C || language == COM_LANGUAGE_CPP)
    -      {
    -        // separate the actual DLL name from the prefix
    -        char separator = '/';
    -        size_t separatorPos = externalPrefix.last(separator);
    +      if (language == COM_LANGUAGE_C || language == COM_LANGUAGE_CPP)
    +        {
    +          if( libBlobHandle[0] != '\0' )
    +            {
    +              NAString dummyUser;
    +              NAString cachedLibName, cachedLibPath;
    +              
    +              if (ComGenerateUdrCachedLibName(externalPrefix,redefTime,libSchNamePart,dummyUser,
cachedLibName, cachedLibPath))
    +                {
    +                  *CmpCommon::diags() << DgSqlCode(-1231)
    +                                      << DgString0(extRoutineName);
    +                  deallocEHI(ehi); 
    +                  processReturn();
    +                  return;
    +                }
    +         
    +              NAString cachedFullName = cachedLibPath+"/"+cachedLibName;
    +          
    +              if (extractLibrary(&cliInterface,libBlobHandle, (char *)cachedFullName.data()))
    +                {
    +                  *CmpCommon::diags() << DgSqlCode(-1231)
    +                                      << DgString0(extRoutineName);
    +                  deallocEHI(ehi); 
    +                  processReturn();
    +                  return;
    +                }
    +              externalPrefix = cachedLibPath;
    +              containerName = cachedLibName;
    +              
    +            }
    +          else
    +            {
    +              // separate the actual DLL name from the prefix
    +              char separator = '/';
    +              size_t separatorPos = externalPrefix.last(separator);
    +
    +              if (separatorPos != NA_NPOS)
    +                {
    +                  containerName = externalPrefix(separatorPos+1,
    +                                                 externalPrefix.length()-separatorPos-1);
    +                  externalPrefix.remove(separatorPos,
    +                                        externalPrefix.length()-separatorPos);
    +                }
    +              else
    +                {
    +                  // assume the entire string is a local name
    +                  containerName = externalPrefix;
    +                  externalPrefix = ".";
    +                }
    +            }
    +        }
    +      else
    +        {
    +          // For Java, the way the language manager works is that the
    +          // external path is the fully qualified name of the jar and
    +          // the container is the class name (external name).  We load
    +          // the container (the class) by searching in the path (the
    +          // jar). The external name is the method name, which in this
    +          // case is the constructor of the class, <init>.
     
    -        if (separatorPos != NA_NPOS)
    -          {
    -            containerName = externalPrefix(separatorPos+1,
    -                                           externalPrefix.length()-separatorPos-1);
    -            externalPrefix.remove(separatorPos,
    -                                  externalPrefix.length()-separatorPos);
    -          }
    -        else
    -          {
    -            // assume the entire string is a local name
    -            containerName = externalPrefix;
    -            externalPrefix = ".";
    -          }
    -      }
    -    else
    -      {
    -        // For Java, the way the language manager works is that the
    -        // external path is the fully qualified name of the jar and
    -        // the container is the class name (external name).  We load
    -        // the container (the class) by searching in the path (the
    -        // jar). The external name is the method name, which in this
    -        // case is the constructor of the class, <init>.
    -
    -        // leave externalPrevix unchanged, fully qualified jar file
    -        containerName = externalName;
    -        externalNameForValidation = "<init>";
    -      }
    +          // leave externalPrevix unchanged, fully qualified jar file
     
    -    // use a CLI call to validate that the library contains the routine
    -    if (cliInterface.getRoutine(
    -             NULL, // No InvocationInfo specified in this step
    -             0,
    -             NULL,
    -             0,
    -             (Int32) language,
    -             (Int32) style,
    -             externalNameForValidation.data(),
    -             containerName.data(),
    -             externalPrefix.data(),
    -             extLibraryName.data(),
    -             &routineHandle,
    -             CmpCommon::diags()) != LME_ROUTINE_VALIDATED)
    -      {
    -        if (routineHandle != NullCliRoutineHandle)
    -          cliInterface.putRoutine(routineHandle,
    -                                  CmpCommon::diags());
     
    -        CMPASSERT(CmpCommon::diags()->mainSQLCODE() < 0);
    -        processReturn();
    -        return;
    -      }
     
    -    cliInterface.putRoutine(routineHandle,
    -                            CmpCommon::diags());
    -  }
    +          if( libBlobHandle[0] != '\0' )
    +            {
    +              NAString dummyUser;
    +              NAString cachedLibName, cachedLibPath;
    +              NAString libSchema(libSchNamePart);
    +              if(ComGenerateUdrCachedLibName(extPath,redefTime,libSchNamePart,dummyUser,
cachedLibName, cachedLibPath))
    +                {
    +                  *CmpCommon::diags() << DgSqlCode(-1231)
    +                                      << DgString0(extRoutineName);
    +                  deallocEHI(ehi); 
    +                  processReturn();
    +                  return;
    +                }
    +         
    +              NAString cachedFullName = cachedLibPath+"/"+cachedLibName;
    +          
    +              if (extractLibrary(&cliInterface,libBlobHandle, (char *)cachedFullName.data()))
    +                {
    +                  *CmpCommon::diags() << DgSqlCode(-1231)
    +                                      << DgString0(extRoutineName);
    +                  deallocEHI(ehi); 
    +                  processReturn();
    +                  return;
    +                }
    +              externalPrefix = cachedFullName;
    +              containerName = externalName;
    +              externalNameForValidation="<init>";
    +            }
    +          else
    +            {
    +              containerName = externalName;
    +              externalNameForValidation = "<init>";
    +            }
    +        }
    +
    +      // use a CLI call to validate that the library contains the routine
    +      if (cliInterface.getRoutine(
    +               NULL, // No InvocationInfo specified in this step
    +               0,
    +               NULL,
    +               0,
    +               (Int32) language,
    +               (Int32) style,
    +               externalNameForValidation.data(),
    +               containerName.data(),
    +               externalPrefix.data(),
    +               extLibraryName.data(),
    +               &routineHandle,
    +               CmpCommon::diags()) != LME_ROUTINE_VALIDATED)
    +        {
    +          if (routineHandle != NullCliRoutineHandle)
    +            cliInterface.putRoutine(routineHandle,
    +                                    CmpCommon::diags());
    +
    +          CMPASSERT(CmpCommon::diags()->mainSQLCODE() < 0);
    +          processReturn();
    --- End diff --
    
    deallocEHI?


---

Mime
View raw message