Projects >> nuxeo-core >>3e61dd21dfbc92b825417c926d5329616821541c

Chunk
Conflicting content
package org.nuxeo.ecm.core.query.sql.model;

import java.util.Iterator;
<<<<<<< HEAD
import java.util.regex.Matcher;
import java.util.regex.Pattern;
=======
import java.util.LinkedList;
import java.util.List;
>>>>>>> 6ccc8df2095d3a89a586b7b13e1fdbf8ab1683ef

import org.nuxeo.ecm.core.query.sql.SQLQueryParser;
Solution content
package org.nuxeo.ecm.core.query.sql.model;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.nuxeo.ecm.core.query.sql.SQLQueryParser;
File
TestQueryVisitor.java
Developer's decision
Concatenation
Kind of conflict
Import
Chunk
Conflicting content
        PrintVisitor v = new PrintVisitor();
        v.visitQuery(SQLQueryParser.parse(sql));
        String got = v.toString();
<<<<<<< HEAD
        assertEquals(removeTzSuffix(expected), removeTzSuffix(got));
    }
    
    private static final Pattern REMOVE_TZ_PATTERN = Pattern.compile("(.*)(\\+.*|Z)'\\)$");
    private String removeTzSuffix(String value) {
    	Matcher matcher = REMOVE_TZ_PATTERN.matcher(value);
    	if (matcher.matches() == false) throw new RuntimeException(REMOVE_TZ_PATTERN + " pattern does not match " + value);
    	return matcher.group(1);
=======
        got = got.substring(0, got.length() - 8); // truncate timezone
        assertEquals(expected, got);

        sql = "select foo from docs where x = 1 AND x=2 AND x = 3";
        expected = "SELECT foo FROM docs WHERE AND(x = 1, x = 2, x = 3)";
        SQLQuery query = SQLQueryParser.parse(sql);
        // AndExpression is not generated by the parser, build it by hand
        Predicate pred = query.where.predicate;
        List operands = new LinkedList();
        operands.add(((Expression) pred.lvalue).lvalue);
        operands.add(((Expression) pred.lvalue).rvalue);
        operands.add(pred.rvalue);
        query = new SQLQuery(query.select, query.from, new WhereClause(
                new MultiExpression(Operator.AND, operands)), query.groupBy,
                query.having, query.orderBy);
        v = new PrintVisitor();
        v.visitQuery(query);
        assertEquals(expected, v.toString());
>>>>>>> 6ccc8df2095d3a89a586b7b13e1fdbf8ab1683ef
    }

}
Solution content
        PrintVisitor v = new PrintVisitor();
        v.visitQuery(SQLQueryParser.parse(sql));
        String got = v.toString();
        assertEquals(removeTzSuffix(expected), removeTzSuffix(got));

        sql = "select foo from docs where x = 1 AND x=2 AND x = 3";
        expected = "SELECT foo FROM docs WHERE AND(x = 1, x = 2, x = 3)";
        SQLQuery query = SQLQueryParser.parse(sql);
        // AndExpression is not generated by the parser, build it by hand
        Predicate pred = query.where.predicate;
        List operands = new LinkedList();
        operands.add(((Expression) pred.lvalue).lvalue);
        operands.add(((Expression) pred.lvalue).rvalue);
        operands.add(pred.rvalue);
        query = new SQLQuery(query.select, query.from, new WhereClause(
                new MultiExpression(Operator.AND, operands)), query.groupBy,
                query.having, query.orderBy);
        v = new PrintVisitor();
        v.visitQuery(query);
        assertEquals(expected, v.toString());
    }
    
    private static final Pattern REMOVE_TZ_PATTERN = Pattern.compile("(.*)(\\+.*|Z)'\\)$");
    private String removeTzSuffix(String value) {
    	Matcher matcher = REMOVE_TZ_PATTERN.matcher(value);
    	if (matcher.matches() == false) throw new RuntimeException(REMOVE_TZ_PATTERN + " pattern does not match " + value);
    	return matcher.group(1);
    }

}
File
TestQueryVisitor.java
Developer's decision
Combination
Kind of conflict
Attribute
Comment
If statement
Method invocation
Method signature
Return statement
Variable