use of org.apache.cayenne.access.sqlbuilder.sqltree.OpExpressionNode in project cayenne by apache.
the class SybaseSQLTreeProcessor method onFunctionNode.
@Override
protected void onFunctionNode(Node parent, FunctionNode child, int index) {
String functionName = child.getFunctionName();
Node replacement = null;
switch(functionName) {
case "LENGTH":
replacement = new FunctionNode("LEN", child.getAlias(), true);
break;
case "LOCATE":
replacement = new FunctionNode("CHARINDEX", child.getAlias(), true);
break;
case "MOD":
replacement = new OpExpressionNode("%");
break;
case "TRIM":
Node rtrim = new FunctionNode("RTRIM", null, true);
replacement = new FunctionNode("LTRIM", child.getAlias(), true);
for (int i = 0; i < child.getChildrenCount(); i++) {
rtrim.addChild(child.getChild(i));
}
replacement.addChild(rtrim);
parent.replaceChild(index, replacement);
return;
case "CURRENT_DATE":
replacement = new FunctionNode("{fn CURDATE()}", child.getAlias(), false);
break;
case "CURRENT_TIME":
replacement = new FunctionNode("{fn CURTIME()}", child.getAlias(), false);
break;
case "CURRENT_TIMESTAMP":
replacement = new FunctionNode("CURRENT_TIMESTAMP", child.getAlias(), false);
break;
case "YEAR":
case "MONTH":
case "WEEK":
case "DAY_OF_YEAR":
case "DAY":
case "DAY_OF_MONTH":
case "DAY_OF_WEEK":
case "HOUR":
case "MINUTE":
case "SECOND":
replacement = new FunctionNode("DATEPART", child.getAlias(), true);
switch(functionName) {
case "DAY_OF_MONTH":
functionName = "DAY";
break;
case "DAY_OF_WEEK":
functionName = "WEEKDAY";
break;
case "DAY_OF_YEAR":
functionName = "DAYOFYEAR";
break;
}
replacement.addChild(new TextNode(functionName));
break;
}
if (replacement != null) {
replaceChild(parent, index, replacement);
}
}
use of org.apache.cayenne.access.sqlbuilder.sqltree.OpExpressionNode in project cayenne by apache.
the class SQLiteTreeProcessor method onFunctionNode.
@Override
protected void onFunctionNode(Node parent, FunctionNode child, int index) {
String functionName = child.getFunctionName();
Node replacement = null;
switch(functionName) {
case "LOCATE":
replacement = new FunctionNode("INSTR", child.getAlias(), true);
for (int i = 0; i <= 1; i++) {
replacement.addChild(child.getChild(1 - i));
}
parent.replaceChild(index, replacement);
return;
case "DAY_OF_YEAR":
replaceExtractFunction(parent, child, index, "'%j'");
return;
case "DAY_OF_WEEK":
replaceExtractFunction(parent, child, index, "'%w'");
return;
case "WEEK":
replaceExtractFunction(parent, child, index, "'%W'");
return;
case "YEAR":
replaceExtractFunction(parent, child, index, "'%Y'");
return;
case "MONTH":
replaceExtractFunction(parent, child, index, "'%m'");
return;
case "DAY":
case "DAY_OF_MONTH":
replaceExtractFunction(parent, child, index, "'%d'");
return;
case "HOUR":
replaceExtractFunction(parent, child, index, "'%H'");
return;
case "MINUTE":
replaceExtractFunction(parent, child, index, "'%M'");
return;
case "SECOND":
replaceExtractFunction(parent, child, index, "'%S'");
return;
case "SUBSTRING":
replacement = new FunctionNode("SUBSTR", child.getAlias(), true);
break;
case "CONCAT":
replacement = new OpExpressionNode("||");
break;
case "MOD":
replacement = new OpExpressionNode("%");
break;
case "CURRENT_DATE":
case "CURRENT_TIMESTAMP":
case "CURRENT_TIME":
replacement = new FunctionNode(functionName, child.getAlias(), false);
break;
}
if (replacement != null) {
replaceChild(parent, index, replacement);
}
}
use of org.apache.cayenne.access.sqlbuilder.sqltree.OpExpressionNode in project cayenne by apache.
the class QualifierTranslationStageTest method perform.
@Test
public void perform() {
QualifierTranslationStage stage = new QualifierTranslationStage();
stage.perform(context);
assertNotNull(context.getQualifierNode());
// Content of "Qualifier" node:
//
// OpExpression
// / \
// Column Value
Node op = context.getQualifierNode();
assertThat(op, instanceOf(OpExpressionNode.class));
assertEquals(">=", ((OpExpressionNode) op).getOp());
assertEquals(2, op.getChildrenCount());
assertThat(op.getChild(0), instanceOf(ColumnNode.class));
assertThat(op.getChild(1), instanceOf(ValueNode.class));
ColumnNode columnNode = (ColumnNode) op.getChild(0);
ValueNode valueNode = (ValueNode) op.getChild(1);
assertEquals("path", columnNode.getColumn());
assertEquals(10, valueNode.getValue());
}
Aggregations