use of org.apache.cayenne.access.sqlbuilder.sqltree.TextNode in project cayenne by apache.
the class FrontBaseSQLTreeProcessor method onFunctionNode.
@Override
protected void onFunctionNode(Node parent, FunctionNode child, int index) {
switch(child.getFunctionName()) {
case "CONCAT":
replaceChild(parent, index, new OpExpressionNode("||"));
break;
case "LOCATE":
// POSITION (substr IN str)
replaceChild(parent, index, new FunctionNode("POSITION", child.getAlias()) {
@Override
public void appendChildrenSeparator(QuotingAppendable buffer, int childIdx) {
buffer.append(" IN ");
}
});
break;
case "LENGTH":
replaceChild(parent, index, new FunctionNode("CHAR_LENGTH", child.getAlias()));
break;
case "SUBSTRING":
// SUBSTRING (str FROM offset FOR length)
replaceChild(parent, index, new FunctionNode("SUBSTRING", child.getAlias()) {
@Override
public void appendChildrenSeparator(QuotingAppendable buffer, int childIdx) {
if (childIdx == 0) {
buffer.append(" FROM ");
} else if (childIdx == 1) {
buffer.append(" FOR ");
}
}
});
break;
case "YEAR":
case "MONTH":
case "DAY":
case "DAY_OF_MONTH":
case "HOUR":
case "MINUTE":
case "SECOND":
Node functionReplacement = new ExtractFunctionNode(child.getAlias());
String functionName = child.getFunctionName();
if ("DAY_OF_MONTH".equals(functionName)) {
functionName = "DAY";
}
functionReplacement.addChild(new TextNode(functionName));
replaceChild(parent, index, functionReplacement);
break;
case "DAY_OF_WEEK":
case "DAY_OF_YEAR":
case "WEEK":
throw new CayenneRuntimeException("Function %s() is unsupported in FrontBase.", child.getFunctionName());
}
}
use of org.apache.cayenne.access.sqlbuilder.sqltree.TextNode in project cayenne by apache.
the class OracleSQLTreeProcessor method onFunctionNode.
@Override
protected void onFunctionNode(Node parent, FunctionNode child, int index) {
String functionName = child.getFunctionName();
Node functionReplacement = null;
switch(functionName) {
case "LOCATE":
functionReplacement = new FunctionNode("INSTR", child.getAlias(), true);
for (int i = 0; i <= 1; i++) {
functionReplacement.addChild(child.getChild(1 - i));
}
parent.replaceChild(index, functionReplacement);
return;
case "DAY_OF_YEAR":
case "DAY_OF_WEEK":
case "WEEK":
functionReplacement = new FunctionNode("TO_CHAR", child.getAlias(), true);
functionReplacement.addChild(child.getChild(0));
if ("DAY_OF_YEAR".equals(functionName)) {
functionName = "'DDD'";
} else if ("DAY_OF_WEEK".equals(functionName)) {
functionName = "'D'";
} else {
functionName = "'IW'";
}
functionReplacement.addChild(new TextNode(functionName));
parent.replaceChild(index, functionReplacement);
return;
case "SUBSTRING":
functionReplacement = new FunctionNode("SUBSTR", child.getAlias(), true);
break;
case "CONCAT":
functionReplacement = new OpExpressionNode("||");
break;
case "CURRENT_TIMESTAMP":
case "CURRENT_DATE":
functionReplacement = new FunctionNode(functionName, child.getAlias(), false);
break;
case "CURRENT_TIME":
functionReplacement = new FunctionNode("{fn CURTIME()}", child.getAlias(), false);
break;
case "YEAR":
case "MONTH":
case "DAY":
case "DAY_OF_MONTH":
case "HOUR":
case "MINUTE":
case "SECOND":
functionReplacement = new FunctionNode("EXTRACT", child.getAlias(), true) {
@Override
public void appendChildrenSeparator(QuotingAppendable buffer, int childIdx) {
buffer.append(' ');
}
};
if ("DAY_OF_MONTH".equals(functionName)) {
functionName = "DAY";
}
functionReplacement.addChild(new TextNode(functionName + " FROM "));
break;
}
if (functionReplacement != null) {
replaceChild(parent, index, functionReplacement);
}
}
use of org.apache.cayenne.access.sqlbuilder.sqltree.TextNode in project cayenne by apache.
the class OrderingNodeBuilder method build.
@Override
public Node build() {
Node node = new EmptyNode();
node.addChild(column.build());
node.addChild(new TextNode(direction));
return node;
}
use of org.apache.cayenne.access.sqlbuilder.sqltree.TextNode in project cayenne by apache.
the class FirebirdSQLTreeProcessor method onFunctionNode.
@Override
protected void onFunctionNode(Node parent, FunctionNode child, int index) {
switch(child.getFunctionName()) {
case "LENGTH":
replaceChild(parent, index, new FunctionNode("CHAR_LENGTH", child.getAlias()));
break;
case "LOCATE":
replaceChild(parent, index, new FunctionNode("POSITION", child.getAlias()));
break;
case "CONCAT":
replaceChild(parent, index, new OpExpressionNode("||"));
break;
case "SUBSTRING":
replaceChild(parent, index, new FirebirdSubstringFunctionNode(child.getAlias()));
break;
case "YEAR":
case "MONTH":
case "DAY":
case "DAY_OF_MONTH":
case "DAY_OF_WEEK":
case "DAY_OF_YEAR":
case "WEEK":
case "HOUR":
case "MINUTE":
case "SECOND":
Node functionReplacement = new FunctionNode("EXTRACT", child.getAlias(), true) {
@Override
public void appendChildrenSeparator(QuotingAppendable buffer, int childIdx) {
buffer.append(' ');
}
};
String partName = child.getFunctionName();
if ("DAY_OF_MONTH".equals(partName)) {
partName = "DAY";
} else if ("DAY_OF_WEEK".equals(partName)) {
partName = "WEEKDAY";
} else if ("DAY_OF_YEAR".equals(partName)) {
partName = "YEARDAY";
}
functionReplacement.addChild(new TextNode(partName + " FROM "));
replaceChild(parent, index, functionReplacement);
break;
}
}
use of org.apache.cayenne.access.sqlbuilder.sqltree.TextNode 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);
}
}
Aggregations