use of org.sirix.api.Axis in project sirix by sirixdb.
the class PipelineBuilder method addInstanceOfExpr.
/**
* Adds a instance of expression to the pipeline.
*
* @param mTransaction Transaction to operate with.
* @param mSequenceType sequence type the context item should match.
*/
public void addInstanceOfExpr(final XdmNodeReadTrx mTransaction, final SequenceType mSequenceType) {
assert getPipeStack().size() >= 1;
final Axis candidate = getPipeStack().pop().getExpr();
final Axis axis = new InstanceOfExpr(mTransaction, candidate, mSequenceType);
if (getPipeStack().empty() || getExpression().getSize() != 0) {
addExpressionSingle();
}
getExpression().add(axis);
}
use of org.sirix.api.Axis in project sirix by sirixdb.
the class PipelineBuilder method addForExpression.
/**
* Adds a for expression to the pipeline. In case the for expression has more then one for
* condition, the for expression is converted to a nested for expression with only one for
* condition each, see the following example: for $a in /a, $b in /b, $c in /c return /d is
* converted to for $a in /a return for $b in /b return for $c in /c return /d
*
* @param mForConditionNum Number of all for conditions of the expression
*/
public void addForExpression(final int mForConditionNum) {
assert getPipeStack().size() >= (mForConditionNum + 1);
Axis forAxis = (getPipeStack().pop().getExpr());
int num = mForConditionNum;
while (num-- > 0) {
forAxis = new ForAxis(getPipeStack().pop().getExpr(), forAxis);
}
if (getPipeStack().empty() || getExpression().getSize() != 0) {
addExpressionSingle();
}
getExpression().add(forAxis);
}
use of org.sirix.api.Axis in project sirix by sirixdb.
the class PipelineBuilder method addQuantifierExpr.
/**
* Adds a SomeExpression or an EveryExpression to the pipeline, depending on the parameter isSome.
*
* @param mTransaction Transaction to operate with.
* @param mIsSome defines whether a some- or an EveryExpression is used.
* @param mVarNum number of binding variables
*/
public void addQuantifierExpr(final XdmNodeReadTrx mTransaction, final boolean mIsSome, final int mVarNum) {
assert getPipeStack().size() >= (mVarNum + 1);
final Axis satisfy = getPipeStack().pop().getExpr();
final List<Axis> vars = new ArrayList<Axis>();
int num = mVarNum;
while (num-- > 0) {
// invert current order of variables to get original variable order
vars.add(num, getPipeStack().pop().getExpr());
}
final Axis mAxis = mIsSome ? new SomeExpr(mTransaction, vars, satisfy) : new EveryExpr(mTransaction, vars, satisfy);
if (getPipeStack().empty() || getExpression().getSize() != 0) {
addExpressionSingle();
}
getExpression().add(mAxis);
}
use of org.sirix.api.Axis in project sirix by sirixdb.
the class PipelineBuilder method addRangeExpr.
/**
* Adds a range expression to the pipeline.
*
* @param mTransaction Transaction to operate with.
*/
public void addRangeExpr(final XdmNodeReadTrx mTransaction) {
assert getPipeStack().size() >= 2;
final Axis mOperand2 = getPipeStack().pop().getExpr();
final Axis mOperand1 = getPipeStack().pop().getExpr();
final Axis axis = new RangeAxis(mTransaction, mOperand1, mOperand2);
if (getPipeStack().empty() || getExpression().getSize() != 0) {
addExpressionSingle();
}
getExpression().add(axis);
}
use of org.sirix.api.Axis in project sirix by sirixdb.
the class AbstractDiff method checkReplace.
/**
* Check for a replace of a node.
*
* @param newRtx first {@link XdmNodeReadTrx} instance
* @param oldRtx second {@link XdmNodeReadTrx} instance
* @return true if node has been replaced, false otherwise
*/
boolean checkReplace(final XdmNodeReadTrx newRtx, final XdmNodeReadTrx oldRtx) {
boolean replaced = false;
if (newRtx.getNodeKey() != oldRtx.getNodeKey()) {
final long newKey = newRtx.getNodeKey();
boolean movedNewRtx = newRtx.moveToRightSibling().hasMoved();
final long oldKey = oldRtx.getNodeKey();
boolean movedOldRtx = oldRtx.moveToRightSibling().hasMoved();
if (movedNewRtx && movedOldRtx) {
if (newRtx.getNodeKey() == oldRtx.getNodeKey()) {
replaced = true;
} else {
while (newRtx.hasRightSibling() && oldRtx.hasRightSibling()) {
newRtx.moveToRightSibling();
oldRtx.moveToRightSibling();
if (newRtx.getNodeKey() == oldRtx.getNodeKey()) {
replaced = true;
break;
}
}
}
} else if (!movedNewRtx && !movedOldRtx && (mDiff == DiffType.SAME || mDiff == DiffType.SAMEHASH)) {
movedNewRtx = newRtx.moveToParent().hasMoved();
movedOldRtx = oldRtx.moveToParent().hasMoved();
if (movedNewRtx && movedOldRtx && newRtx.getNodeKey() == oldRtx.getNodeKey()) {
replaced = true;
}
}
newRtx.moveTo(newKey);
oldRtx.moveTo(oldKey);
if (replaced) {
final long newNodeKey = newRtx.getNodeKey();
final long oldNodeKey = oldRtx.getNodeKey();
final Axis oldAxis = new DescendantAxis(oldRtx, IncludeSelf.YES);
final Axis newAxis = new DescendantAxis(newRtx, IncludeSelf.YES);
while (oldAxis.hasNext()) {
oldAxis.next();
fireDiff(DiffType.REPLACEDOLD, newRtx.getNodeKey(), oldRtx.getNodeKey(), new DiffDepth(mDepth.getNewDepth(), mDepth.getOldDepth()));
adjustDepth(oldRtx, oldNodeKey, Revision.OLD);
}
while (newAxis.hasNext()) {
newAxis.next();
fireDiff(DiffType.REPLACEDNEW, newRtx.getNodeKey(), oldRtx.getNodeKey(), new DiffDepth(mDepth.getNewDepth(), mDepth.getOldDepth()));
adjustDepth(newRtx, newNodeKey, Revision.NEW);
}
newRtx.moveTo(newNodeKey);
oldRtx.moveTo(oldNodeKey);
mDiff = DiffType.REPLACED;
// final IAxis oldAxis = new DescendantAxis(pOldRtx, EIncludeSelf.YES);
// final IAxis newAxis = new DescendantAxis(pNewRtx, EIncludeSelf.YES);
// if (pNewRtx.getDescendantCount() >= pOldRtx
// .getDescendantCount()) {
// while (newAxis.hasNext()) {
// newAxis.next();
// boolean moved = false;
// if (oldAxis.hasNext()) {
// oldAxis.next();
// moved = true;
// }
// fireDiff(EDiff.REPLACEDNEW, pNewRtx, pOldRtx,
// new DiffDepth(mDepth.getNewDepth(), mDepth.getOldDepth()));
// adjustDepth(newAxis.getTransaction(), newNodeKey, ERevision.NEW);
// if (moved) {
// adjustDepth(oldAxis.getTransaction(), oldNodeKey, ERevision.OLD);
// }
// }
//
// } else {
// while (oldAxis.hasNext()) {
// oldAxis.next();
// boolean moved = false;
// if (newAxis.hasNext()) {
// newAxis.next();
// moved = true;
// }
// fireDiff(EDiff.REPLACEDOLD, pNewRtx, pOldRtx,
// new DiffDepth(mDepth.getNewDepth(), mDepth.getOldDepth()));
// adjustDepth(oldAxis.getTransaction(), oldNodeKey, ERevision.OLD);
// if (moved) {
// adjustDepth(newAxis.getTransaction(), newNodeKey, ERevision.NEW);
// }
// }
// }
newRtx.moveTo(newNodeKey);
oldRtx.moveTo(oldNodeKey);
}
}
return replaced;
}
Aggregations