Browse Source

Merge pull request #3691 from ghalliday/issue8286

HPCC-8286 Make sure the IXmlToRowTransformer is cached as a member

Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 12 years ago
parent
commit
484939881d
1 changed files with 18 additions and 3 deletions
  1. 18 3
      ecl/hqlcpp/hqlcppds.cpp

+ 18 - 3
ecl/hqlcpp/hqlcppds.cpp

@@ -328,10 +328,25 @@ IReferenceSelector * HqlCppTranslator::doBuildRowFromXML(BuildCtx & ctx, IHqlExp
     bool usesContents = false;
     bool usesContents = false;
     getUniqueId(xmlInstanceName.append("xml"));
     getUniqueId(xmlInstanceName.append("xml"));
     buildXmlReadTransform(ds, xmlFactoryName, usesContents);
     buildXmlReadTransform(ds, xmlFactoryName, usesContents);
+
     OwnedHqlExpr curActivityId = getCurrentActivityId(ctx);
     OwnedHqlExpr curActivityId = getCurrentActivityId(ctx);
-    s.append("Owned<IXmlToRowTransformer> ").append(xmlInstanceName).append(" = ").append(xmlFactoryName).append("(ctx,");
-    generateExprCpp(s, curActivityId).append(");");
-    ctx.addQuoted(s);
+
+    //MORE: This should be generalised so that any invariant class creation can be handled by the same code.
+    BuildCtx * declareCtx = &ctx;
+    BuildCtx * initCtx = &ctx;
+    if (!insideOnCreate(ctx) && getInvariantMemberContext(ctx, &declareCtx, &initCtx, false, false))
+    {
+        declareCtx->addQuoted(s.clear().append("Owned<IXmlToRowTransformer> ").append(xmlInstanceName).append(";"));
+        s.clear().append(xmlInstanceName).append(".setown(").append(xmlFactoryName).append("(ctx,");
+        generateExprCpp(s, curActivityId).append("));");
+        initCtx->addQuoted(s);
+    }
+    else
+    {
+        s.append("Owned<IXmlToRowTransformer> ").append(xmlInstanceName).append(" = ").append(xmlFactoryName).append("(ctx,");
+        generateExprCpp(s, curActivityId).append(");");
+        ctx.addQuoted(s);
+    }
 
 
     HqlExprArray args;
     HqlExprArray args;
     args.append(*createRowAllocator(ctx, record));
     args.append(*createRowAllocator(ctx, record));