Author: shawkins
Date: 2010-10-22 12:24:31 -0400 (Fri, 22 Oct 2010)
New Revision: 2675
Modified:
branches/7.1.x/engine/src/main/java/org/teiid/query/eval/Evaluator.java
branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java
branches/7.1.x/engine/src/main/java/org/teiid/query/xquery/saxon/SaxonXQueryExpression.java
Log:
ensuring that xquery evaluation closes all sources it creates.
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/eval/Evaluator.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/eval/Evaluator.java 2010-10-22
14:45:09 UTC (rev 2674)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/eval/Evaluator.java 2010-10-22
16:24:31 UTC (rev 2675)
@@ -41,7 +41,6 @@
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
-import net.sf.saxon.om.SequenceIterator;
import net.sf.saxon.trans.XPathException;
import org.teiid.api.exception.query.ExpressionEvaluationException;
@@ -110,6 +109,7 @@
import org.teiid.query.sql.util.ValueIteratorSource;
import org.teiid.query.util.CommandContext;
import org.teiid.query.xquery.saxon.SaxonXQueryExpression;
+import org.teiid.query.xquery.saxon.SaxonXQueryExpression.Result;
import org.teiid.translator.WSConnection.Util;
public class Evaluator {
@@ -761,13 +761,18 @@
if (xmlQuery.getEmptyOnEmpty() != null) {
emptyOnEmpty = xmlQuery.getEmptyOnEmpty();
}
+ Result result = null;
try {
- SequenceIterator iter = evaluateXQuery(xmlQuery.getXQueryExpression(),
xmlQuery.getPassing(), tuple);
- return xmlQuery.getXQueryExpression().createXMLType(iter,
this.context.getBufferManager(), emptyOnEmpty);
+ result = evaluateXQuery(xmlQuery.getXQueryExpression(), xmlQuery.getPassing(),
tuple);
+ return xmlQuery.getXQueryExpression().createXMLType(result.iter,
this.context.getBufferManager(), emptyOnEmpty);
} catch (TeiidProcessingException e) {
throw new FunctionExecutionException(e,
QueryPlugin.Util.getString("Evaluator.xmlquery", e.getMessage()));
//$NON-NLS-1$
} catch (XPathException e) {
throw new FunctionExecutionException(e,
QueryPlugin.Util.getString("Evaluator.xmlquery", e.getMessage()));
//$NON-NLS-1$
+ } finally {
+ if (result != null) {
+ result.close();
+ }
}
}
@@ -837,7 +842,7 @@
}
}
- public SequenceIterator evaluateXQuery(SaxonXQueryExpression xquery,
List<DerivedColumn> cols, List<?> tuple)
+ public Result evaluateXQuery(SaxonXQueryExpression xquery, List<DerivedColumn>
cols, List<?> tuple)
throws BlockedException, TeiidComponentException, TeiidProcessingException {
HashMap<String, Object> parameters = new HashMap<String, Object>();
Object contextItem = null;
Modified:
branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java
===================================================================
---
branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java 2010-10-22
14:45:09 UTC (rev 2674)
+++
branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java 2010-10-22
16:24:31 UTC (rev 2675)
@@ -50,6 +50,7 @@
import org.teiid.query.function.FunctionDescriptor;
import org.teiid.query.sql.lang.XMLTable;
import org.teiid.query.sql.lang.XMLTable.XMLColumn;
+import org.teiid.query.xquery.saxon.SaxonXQueryExpression.Result;
/**
* Handles xml table processing.
@@ -69,7 +70,7 @@
private XMLTable table;
private List<XMLColumn> projectedColumns;
- private SequenceIterator result;
+ private Result result;
private int rowCount = 0;
private Item item;
@@ -130,7 +131,7 @@
TeiidComponentException, TeiidProcessingException {
if (item == null) {
try {
- item = result.next();
+ item = result.iter.next();
} catch (XPathException e) {
throw new TeiidProcessingException(e,
QueryPlugin.Util.getString("XMLTableNode.error", e.getMessage()));
//$NON-NLS-1$
}
Modified:
branches/7.1.x/engine/src/main/java/org/teiid/query/xquery/saxon/SaxonXQueryExpression.java
===================================================================
---
branches/7.1.x/engine/src/main/java/org/teiid/query/xquery/saxon/SaxonXQueryExpression.java 2010-10-22
14:45:09 UTC (rev 2674)
+++
branches/7.1.x/engine/src/main/java/org/teiid/query/xquery/saxon/SaxonXQueryExpression.java 2010-10-22
16:24:31 UTC (rev 2675)
@@ -28,6 +28,7 @@
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -88,10 +89,27 @@
import org.teiid.query.sql.symbol.DerivedColumn;
import org.teiid.query.sql.symbol.XMLNamespaces;
import org.teiid.query.sql.symbol.XMLNamespaces.NamespaceItem;
+import org.teiid.translator.WSConnection.Util;
@SuppressWarnings("serial")
public class SaxonXQueryExpression {
+ public static class Result {
+ public SequenceIterator iter;
+ public List<Source> sources = new LinkedList<Source>();
+
+ public void close() {
+ for (Source source : sources) {
+ Util.closeSource(source);
+ }
+ if (iter != null) {
+ iter.close();
+ }
+ sources.clear();
+ iter = null;
+ }
+ }
+
private static final Expression DUMMY_EXPRESSION = new Expression() {
@Override
public ItemType getItemType(TypeHierarchy th) {
@@ -133,7 +151,7 @@
private net.sf.saxon.query.XQueryExpression xQuery;
private Configuration config = new Configuration();
private PathMapRoot contextRoot;
-
+
public SaxonXQueryExpression(String xQueryString, XMLNamespaces namespaces,
List<DerivedColumn> passing, List<XMLTable.XMLColumn> columns)
throws QueryResolverException {
config.setErrorListener(ERROR_LISTENER);
@@ -354,47 +372,55 @@
xmlColumn.setPathExpression(exp);
}
}
-
- public SequenceIterator evaluateXQuery(Object context, Map<String, Object>
parameterValues) throws TeiidProcessingException {
+
+ public Result evaluateXQuery(Object context, Map<String, Object>
parameterValues) throws TeiidProcessingException {
DynamicQueryContext dynamicContext = new DynamicQueryContext(config);
-
+
+ Result result = new Result();
try {
- for (Map.Entry<String, Object> entry : parameterValues.entrySet()) {
- Object value = entry.getValue();
- if(value instanceof SQLXML) {
- value = XMLSystemFunctions.convertToSource(value);
- } else if (value instanceof java.util.Date) {
- java.util.Date d = (java.util.Date)value;
- value = XMLSystemFunctions.convertToAtomicValue(value);
+ try {
+ for (Map.Entry<String, Object> entry : parameterValues.entrySet()) {
+ Object value = entry.getValue();
+ if(value instanceof SQLXML) {
+ value = XMLSystemFunctions.convertToSource(value);
+ result.sources.add((Source)value);
+ } else if (value instanceof java.util.Date) {
+ value = XMLSystemFunctions.convertToAtomicValue(value);
+ }
+ dynamicContext.setParameter(entry.getKey(), value);
+ }
+ } catch (TransformerException e) {
+ throw new TeiidProcessingException(e);
+ }
+ if (context != null) {
+ Source source = XMLSystemFunctions.convertToSource(context);
+ result.sources.add(source);
+ if (contextRoot != null) {
+ //create our own filter as this logic is not provided in the free saxon
+ ProxyReceiver filter = new PathMapFilter(contextRoot);
+ AugmentedSource sourceInput =
AugmentedSource.makeAugmentedSource(source);
+ sourceInput.addFilter(filter);
+ source = sourceInput;
}
- dynamicContext.setParameter(entry.getKey(), value);
+ DocumentInfo doc;
+ try {
+ doc = config.buildDocument(source);
+ } catch (XPathException e) {
+ throw new TeiidProcessingException(e,
QueryPlugin.Util.getString("SaxonXQueryExpression.bad_context")); //$NON-NLS-1$
+ }
+ dynamicContext.setContextItem(doc);
}
- } catch (TransformerException e) {
- throw new TeiidProcessingException(e);
+ try {
+ result.iter = xQuery.iterator(dynamicContext);
+ return result;
+ } catch (TransformerException e) {
+ throw new TeiidProcessingException(e,
QueryPlugin.Util.getString("SaxonXQueryExpression.bad_xquery")); //$NON-NLS-1$
+ }
+ } finally {
+ if (result.iter == null) {
+ result.close();
+ }
}
-
- if (context != null) {
- Source source = XMLSystemFunctions.convertToSource(context);
- if (contextRoot != null) {
- //create our own filter as this logic is not provided in the free saxon
- ProxyReceiver filter = new PathMapFilter(contextRoot);
- AugmentedSource sourceInput =
AugmentedSource.makeAugmentedSource(source);
- sourceInput.addFilter(filter);
- source = sourceInput;
- }
- DocumentInfo doc;
- try {
- doc = config.buildDocument(source);
- } catch (XPathException e) {
- throw new TeiidProcessingException(e,
QueryPlugin.Util.getString("SaxonXQueryExpression.bad_context")); //$NON-NLS-1$
- }
- dynamicContext.setContextItem(doc);
- }
- try {
- return xQuery.iterator(dynamicContext);
- } catch (TransformerException e) {
- throw new TeiidProcessingException(e,
QueryPlugin.Util.getString("SaxonXQueryExpression.bad_xquery")); //$NON-NLS-1$
- }
}
public XMLType createXMLType(final SequenceIterator iter, BufferManager bufferManager,
boolean emptyOnEmpty) throws XPathException, TeiidComponentException,
TeiidProcessingException {