Skip to content

Commit d8cbf43

Browse files
committed
[refactor] Add a Materializable interface to explicitly mark which expressions use the Materialization query execution model
1 parent bfa7afa commit d8cbf43

File tree

4 files changed

+87
-44
lines changed

4 files changed

+87
-44
lines changed

exist-core/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,7 @@
705705
<exclude>src/main/java/org/exist/xmlrpc/ACEAiderSerializer.java</exclude>
706706
<exclude>src/main/java/org/exist/xquery/Cardinality.java</exclude>
707707
<exclude>src/test/java/org/exist/xquery/ImportModuleTest.java</exclude>
708+
<exclude>src/main/java/org/exist/xquery/Materializable.java</exclude>
708709
<exclude>src/test/java/org/exist/xquery/XQueryContextAttributesTest.java</exclude>
709710
<exclude>src/main/java/org/exist/xquery/functions/map/MapType.java</exclude>
710711
<exclude>src/test/java/org/exist/xquery/functions/session/AbstractSessionTest.java</exclude>
@@ -856,6 +857,7 @@ The original license statement is also included below.]]></preamble>
856857
<include>src/main/java/org/exist/xmlrpc/ACEAiderSerializer.java</include>
857858
<include>src/main/java/org/exist/xquery/Cardinality.java</include>
858859
<include>src/test/java/org/exist/xquery/ImportModuleTest.java</include>
860+
<include>src/main/java/org/exist/xquery/Materializable.java</include>
859861
<include>src/test/java/org/exist/xquery/XQueryContextAttributesTest.java</include>
860862
<include>src/main/java/org/exist/xquery/functions/map/MapType.java</include>
861863
<include>src/test/java/org/exist/xquery/functions/session/AbstractSessionTest.java</include>

exist-core/src/main/java/org/exist/xquery/Expression.java

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,12 @@
2525
import org.exist.source.Source;
2626
import org.exist.xquery.parser.XQueryAST;
2727
import org.exist.xquery.util.ExpressionDumper;
28-
import org.exist.xquery.value.Item;
29-
import org.exist.xquery.value.Sequence;
30-
31-
import javax.annotation.Nullable;
3228

3329
/**
3430
* Base interface implemented by all classes which are part
35-
* of an XQuery/XPath expression. The main method is
36-
* {@link #eval(Sequence, Item)}. Please
37-
* read the description there.
31+
* of an XQuery/XPath expression.
3832
*/
39-
public interface Expression {
33+
public interface Expression extends Materializable {
4034

4135
// Flags to be passed to analyze:
4236
/**
@@ -113,39 +107,6 @@ public interface Expression {
113107
*/
114108
public void analyze(AnalyzeContextInfo contextInfo) throws XPathException;
115109

116-
/**
117-
* Evaluate the expression represented by this object.
118-
*
119-
* Depending on the context in which this expression is executed,
120-
* either the context sequence, the context item or both of them may
121-
* be set. An implementing class should know how to handle this.
122-
*
123-
* The general contract is as follows: if the {@link Dependency#CONTEXT_ITEM}
124-
* bit is set in the bit field returned by {@link #getDependencies()}, the eval method will
125-
* be called once for every item in the context sequence. The <b>contextItem</b>
126-
* parameter will be set to the current item. Otherwise, the eval method will only be called
127-
* once for the whole context sequence and <b>contextItem</b> will be null.
128-
*
129-
* eXist tries to process the entire context set in one, single step whenever
130-
* possible. Thus, most classes only expect context to contain a list of
131-
* nodes which represents the current context of the expression.
132-
*
133-
* The position() function in XPath is an example for an expression,
134-
* which requires both, context sequence and context item to be set.
135-
*
136-
* The context sequence might be a node set, a sequence of atomic values or a single
137-
* node or atomic value.
138-
*
139-
* @param contextSequence the current context sequence, or null if there is no context sequence.
140-
* @param contextItem a single item, taken from context, or null if there is no context item.
141-
* This defines the item, the expression should work on.
142-
*
143-
* @return the result sequence.
144-
*
145-
* @throws XPathException if an error occurs during evaluation.
146-
*/
147-
public Sequence eval(@Nullable Sequence contextSequence, @Nullable Item contextItem) throws XPathException;
148-
149110
public void setPrimaryAxis(int axis);
150111

151112
public int getPrimaryAxis();
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright (C) 2014, Evolved Binary Ltd
3+
*
4+
* This file was originally ported from FusionDB to eXist-db by
5+
* Evolved Binary, for the benefit of the eXist-db Open Source community.
6+
* Only the ported code as it appears in this file, at the time that
7+
* it was contributed to eXist-db, was re-licensed under The GNU
8+
* Lesser General Public License v2.1 only for use in eXist-db.
9+
*
10+
* This license grant applies only to a snapshot of the code as it
11+
* appeared when ported, it does not offer or infer any rights to either
12+
* updates of this source code or access to the original source code.
13+
*
14+
* The GNU Lesser General Public License v2.1 only license follows.
15+
*
16+
* ---------------------------------------------------------------------
17+
*
18+
* Copyright (C) 2014, Evolved Binary Ltd
19+
*
20+
* This library is free software; you can redistribute it and/or
21+
* modify it under the terms of the GNU Lesser General Public
22+
* License as published by the Free Software Foundation; version 2.1.
23+
*
24+
* This library is distributed in the hope that it will be useful,
25+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
26+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27+
* Lesser General Public License for more details.
28+
*
29+
* You should have received a copy of the GNU Lesser General Public
30+
* License along with this library; if not, write to the Free Software
31+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
32+
*/
33+
package org.exist.xquery;
34+
35+
import org.exist.xquery.value.Item;
36+
import org.exist.xquery.value.Sequence;
37+
38+
import javax.annotation.Nullable;
39+
40+
/**
41+
* Marks an expression as being Materializable as per the
42+
* Materialization query execution model.
43+
*
44+
* @author <a href="mailto:[email protected]">Adam Retter</a>
45+
*/
46+
public interface Materializable {
47+
48+
/**
49+
* Materialize the result.
50+
*
51+
* Depending on the context in which this expression is executed,
52+
* either the context sequence, the context item or both of them may
53+
* be set. An implementing class should know how to handle this.
54+
*
55+
* The general contract is as follows: if the {@link Dependency#CONTEXT_ITEM}
56+
* bit is set in the bit field returned by {@link Expression#getDependencies()}, the eval method will
57+
* be called once for every item in the context sequence. The <b>contextItem</b>
58+
* parameter will be set to the current item. Otherwise, the eval method will only be called
59+
* once for the whole context sequence and <b>contextItem</b> will be null.
60+
*
61+
* eXist-db tries to process the entire context set in one, single step whenever
62+
* possible. Thus, most classes only expect context to contain a list of
63+
* nodes which represents the current context of the expression.
64+
*
65+
* The position() function in XPath is an example for an expression,
66+
* which requires both, context sequence and context item to be set.
67+
*
68+
* The context sequence might be a node set, a sequence of atomic values or a single
69+
* node or atomic value.
70+
*
71+
* @param contextSequence the current context sequence, or null if there is no context sequence.
72+
* @param contextItem a single item, taken from context, or null if there is no context item.
73+
* This defines the item, the expression should work on.
74+
*
75+
* @return the result sequence.
76+
*
77+
* @throws XPathException if an error occurs during evaluation.
78+
*/
79+
Sequence eval(@Nullable Sequence contextSequence, @Nullable Item contextItem) throws XPathException;
80+
}

exist-core/src/main/java/org/exist/xquery/value/FunctionReference.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public void analyze(AnalyzeContextInfo contextInfo) throws XPathException {
103103
}
104104

105105
/**
106-
* Calls {@link FunctionCall#eval(Sequence)}.
106+
* Evaluates the referenced function.
107107
*
108108
* @param contextSequence the input sequence
109109
* @return evaluation result of the function call
@@ -114,7 +114,7 @@ public Sequence eval(Sequence contextSequence) throws XPathException {
114114
}
115115

116116
/**
117-
* Calls {@link FunctionCall#eval(Sequence, Item)}.
117+
* Evaluates the referenced function.
118118
*
119119
* @param contextSequence the input sequence
120120
* @param contextItem optional: the current context item
@@ -126,7 +126,7 @@ public Sequence eval(final Sequence contextSequence, final Item contextItem) thr
126126
}
127127

128128
/**
129-
* Calls {@link FunctionCall#evalFunction(Sequence, Item, Sequence[])}.
129+
* Evaluates the referenced function.
130130
*
131131
* @param contextSequence the input sequence
132132
* @param contextItem optional: the current context item

0 commit comments

Comments
 (0)