forked from eXist-db/exist
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request eXist-db#4530 from evolvedbinary/feature/count-exp…
…ression Support for Count Expressions
- Loading branch information
Showing
20 changed files
with
772 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,13 +23,14 @@ | |
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.exist.dom.QName; | ||
import org.exist.dom.persistent.*; | ||
import org.exist.numbering.NodeId; | ||
import org.exist.storage.UpdateListener; | ||
import org.exist.xquery.value.*; | ||
|
||
/** | ||
* Abstract superclass for the variable binding expressions "for" and "let". | ||
* Abstract superclass for the variable binding expressions "for", "let", and "count". | ||
* | ||
* @author <a href="mailto:[email protected]">Wolfgang Meier</a> | ||
*/ | ||
|
@@ -41,22 +42,20 @@ public abstract class BindingExpression extends AbstractFLWORClause implements R | |
protected final static SequenceType POSITIONAL_VAR_TYPE = | ||
new SequenceType(Type.INTEGER, Cardinality.EXACTLY_ONE); | ||
|
||
protected String varName; | ||
protected QName varName; | ||
protected SequenceType sequenceType = null; | ||
protected Expression inputSequence; | ||
|
||
private ExprUpdateListener listener; | ||
|
||
|
||
public BindingExpression(XQueryContext context) { | ||
public BindingExpression(final XQueryContext context) { | ||
super(context); | ||
} | ||
|
||
public void setVariable(String qname) { | ||
varName = qname; | ||
public void setVariable(final QName varName) { | ||
this.varName = varName; | ||
} | ||
|
||
public String getVariable() { | ||
public QName getVariable() { | ||
return this.varName; | ||
} | ||
|
||
|
@@ -77,52 +76,45 @@ public Expression getInputSequence() { | |
return this.inputSequence; | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see org.exist.xquery.Expression#analyze(org.exist.xquery.Expression, int) | ||
*/ | ||
public void analyze(AnalyzeContextInfo contextInfo) throws XPathException { | ||
@Override | ||
public void analyze(final AnalyzeContextInfo contextInfo) throws XPathException { | ||
unordered = (contextInfo.getFlags() & UNORDERED) > 0; | ||
} | ||
|
||
@Override | ||
public Sequence postEval(Sequence seq) throws XPathException { | ||
if (returnExpr instanceof FLWORClause) { | ||
seq = ((FLWORClause)returnExpr).postEval(seq); | ||
if (returnExpr instanceof FLWORClause flworClause) { | ||
seq = flworClause.postEval(seq); | ||
} | ||
return super.postEval(seq); | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see org.exist.xquery.Expression#preselect(org.exist.dom.persistent.DocumentSet, org.exist.xquery.StaticContext) | ||
*/ | ||
public DocumentSet preselect(DocumentSet in_docs) throws XPathException { | ||
return in_docs; | ||
public DocumentSet preselect(final DocumentSet docs) throws XPathException { | ||
return docs; | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see org.exist.xquery.AbstractExpression#resetState() | ||
*/ | ||
public void resetState(boolean postOptimization) { | ||
@Override | ||
public void resetState(final boolean postOptimization) { | ||
super.resetState(postOptimization); | ||
inputSequence.resetState(postOptimization); | ||
returnExpr.resetState(postOptimization); | ||
} | ||
|
||
public final static void setContext(int contextId, Sequence seq) throws XPathException { | ||
public static void setContext(final int contextId, final Sequence seq) throws XPathException { | ||
if (seq instanceof VirtualNodeSet) { | ||
((VirtualNodeSet)seq).setInPredicate(true); | ||
((VirtualNodeSet)seq).setSelfIsContext(); | ||
} else { | ||
Item next; | ||
for (final SequenceIterator i = seq.unorderedIterator(); i.hasNext();) { | ||
next = i.nextItem(); | ||
if (next instanceof NodeProxy) | ||
{((NodeProxy) next).addContextNode(contextId, (NodeProxy) next);} | ||
for (final SequenceIterator i = seq.unorderedIterator(); i.hasNext(); ) { | ||
final Item next = i.nextItem(); | ||
if (next instanceof NodeProxy) { | ||
((NodeProxy) next).addContextNode(contextId, (NodeProxy) next); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public final static void clearContext(int contextId, Sequence seq) throws XPathException { | ||
public final static void clearContext(final int contextId, final Sequence seq) throws XPathException { | ||
if (seq != null && !(seq instanceof VirtualNodeSet)) { | ||
seq.clearContext(contextId); | ||
} | ||
|
@@ -132,27 +124,29 @@ protected void registerUpdateListener(final Sequence sequence) { | |
if (listener == null) { | ||
listener = new ExprUpdateListener(sequence); | ||
context.registerUpdateListener(listener); | ||
} else | ||
{listener.setSequence(sequence);} | ||
} else { | ||
listener.setSequence(sequence); | ||
} | ||
} | ||
|
||
private class ExprUpdateListener implements UpdateListener { | ||
private Sequence sequence; | ||
|
||
public ExprUpdateListener(Sequence sequence) { | ||
public ExprUpdateListener(final Sequence sequence) { | ||
this.sequence = sequence; | ||
} | ||
|
||
public void setSequence(Sequence sequence) { | ||
public void setSequence(final Sequence sequence) { | ||
this.sequence = sequence; | ||
} | ||
|
||
@Override | ||
public void documentUpdated(DocumentImpl document, int event) { | ||
public void documentUpdated(final DocumentImpl document, final int event) { | ||
// no-op | ||
} | ||
|
||
@Override | ||
public void nodeMoved(NodeId oldNodeId, NodeHandle newNode) { | ||
public void nodeMoved(final NodeId oldNodeId, final NodeHandle newNode) { | ||
sequence.nodeMoved(oldNodeId, newNode); | ||
} | ||
|
||
|
@@ -163,6 +157,7 @@ public void unsubscribe() { | |
|
||
@Override | ||
public void debug() { | ||
// no-op | ||
} | ||
} | ||
|
||
|
@@ -178,11 +173,12 @@ public int returnsType() { | |
/* RewritableExpression API */ | ||
|
||
@Override | ||
public void replace(Expression oldExpr, Expression newExpr) { | ||
if (inputSequence == oldExpr) | ||
{inputSequence = newExpr;} | ||
else if (returnExpr == oldExpr) | ||
{returnExpr = newExpr;} | ||
public void replace(final Expression oldExpr, final Expression newExpr) { | ||
if (inputSequence == oldExpr) { | ||
inputSequence = newExpr; | ||
} else if (returnExpr == oldExpr) { | ||
returnExpr = newExpr; | ||
} | ||
} | ||
|
||
@Override | ||
|
@@ -196,7 +192,8 @@ public Expression getFirst() { | |
} | ||
|
||
@Override | ||
public void remove(Expression oldExpr) throws XPathException { | ||
public void remove(final Expression oldExpr) throws XPathException { | ||
// no-op | ||
} | ||
|
||
/* END RewritableExpression API */ | ||
|
Oops, something went wrong.