Search in sources :

Example 1 with FirebirdSubstringFunctionNode

use of org.apache.cayenne.dba.firebird.sqltree.FirebirdSubstringFunctionNode 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;
    }
}
Also used : OpExpressionNode(org.apache.cayenne.access.sqlbuilder.sqltree.OpExpressionNode) TextNode(org.apache.cayenne.access.sqlbuilder.sqltree.TextNode) FirebirdSubstringFunctionNode(org.apache.cayenne.dba.firebird.sqltree.FirebirdSubstringFunctionNode) Node(org.apache.cayenne.access.sqlbuilder.sqltree.Node) FunctionNode(org.apache.cayenne.access.sqlbuilder.sqltree.FunctionNode) OpExpressionNode(org.apache.cayenne.access.sqlbuilder.sqltree.OpExpressionNode) LimitOffsetNode(org.apache.cayenne.access.sqlbuilder.sqltree.LimitOffsetNode) FirebirdLimitNode(org.apache.cayenne.dba.firebird.sqltree.FirebirdLimitNode) InNode(org.apache.cayenne.access.sqlbuilder.sqltree.InNode) ValueNode(org.apache.cayenne.access.sqlbuilder.sqltree.ValueNode) FirebirdSubstringFunctionNode(org.apache.cayenne.dba.firebird.sqltree.FirebirdSubstringFunctionNode) FunctionNode(org.apache.cayenne.access.sqlbuilder.sqltree.FunctionNode) QuotingAppendable(org.apache.cayenne.access.sqlbuilder.QuotingAppendable) TextNode(org.apache.cayenne.access.sqlbuilder.sqltree.TextNode) FirebirdSubstringFunctionNode(org.apache.cayenne.dba.firebird.sqltree.FirebirdSubstringFunctionNode)

Aggregations

QuotingAppendable (org.apache.cayenne.access.sqlbuilder.QuotingAppendable)1 FunctionNode (org.apache.cayenne.access.sqlbuilder.sqltree.FunctionNode)1 InNode (org.apache.cayenne.access.sqlbuilder.sqltree.InNode)1 LimitOffsetNode (org.apache.cayenne.access.sqlbuilder.sqltree.LimitOffsetNode)1 Node (org.apache.cayenne.access.sqlbuilder.sqltree.Node)1 OpExpressionNode (org.apache.cayenne.access.sqlbuilder.sqltree.OpExpressionNode)1 TextNode (org.apache.cayenne.access.sqlbuilder.sqltree.TextNode)1 ValueNode (org.apache.cayenne.access.sqlbuilder.sqltree.ValueNode)1 FirebirdLimitNode (org.apache.cayenne.dba.firebird.sqltree.FirebirdLimitNode)1 FirebirdSubstringFunctionNode (org.apache.cayenne.dba.firebird.sqltree.FirebirdSubstringFunctionNode)1