Search in sources :

Example 11 with ASTObjPath

use of org.apache.cayenne.exp.parser.ASTObjPath in project cayenne by apache.

the class SelectQueryReturnTypesIT method testSelectBitwiseAnd.

@Test
public void testSelectBitwiseAnd() throws Exception {
    if (!accessStackAdapter.supportsBitwiseOps()) {
        return;
    }
    createNumericsDataSet();
    // to simplify result checking, do double NOT
    Expression left = new ASTBitwiseAnd(new Object[] { new ASTObjPath(ReturnTypesMap1.INTEGER_COLUMN.getName()), new ASTScalar(1) });
    Expression right = new ASTScalar(0);
    Expression equal = new ASTEqual();
    equal.setOperand(0, left);
    equal.setOperand(1, right);
    SelectQuery query = new SelectQuery(ReturnTypesMap1.class);
    query.setQualifier(equal);
    List<ReturnTypesMap1> objects = context.performQuery(query);
    assertEquals(3, objects.size());
}
Also used : ASTObjPath(org.apache.cayenne.exp.parser.ASTObjPath) ReturnTypesMap1(org.apache.cayenne.testdo.return_types.ReturnTypesMap1) Expression(org.apache.cayenne.exp.Expression) ASTEqual(org.apache.cayenne.exp.parser.ASTEqual) ASTBitwiseAnd(org.apache.cayenne.exp.parser.ASTBitwiseAnd) ASTScalar(org.apache.cayenne.exp.parser.ASTScalar) Test(org.junit.Test)

Example 12 with ASTObjPath

use of org.apache.cayenne.exp.parser.ASTObjPath in project cayenne by apache.

the class SelectQueryReturnTypesIT method testSelectBitwiseOr.

@Test
public void testSelectBitwiseOr() throws Exception {
    if (!accessStackAdapter.supportsBitwiseOps()) {
        return;
    }
    createNumericsDataSet();
    // to simplify result checking, do double NOT
    Expression left = new ASTBitwiseOr(new Object[] { new ASTObjPath(ReturnTypesMap1.INTEGER_COLUMN.getName()), new ASTScalar(1) });
    Expression right = new ASTScalar(1);
    Expression equal = new ASTEqual();
    equal.setOperand(0, left);
    equal.setOperand(1, right);
    SelectQuery query = new SelectQuery(ReturnTypesMap1.class);
    query.setQualifier(equal);
    List<ReturnTypesMap1> objects = context.performQuery(query);
    assertEquals(2, objects.size());
}
Also used : ASTObjPath(org.apache.cayenne.exp.parser.ASTObjPath) ReturnTypesMap1(org.apache.cayenne.testdo.return_types.ReturnTypesMap1) Expression(org.apache.cayenne.exp.Expression) ASTEqual(org.apache.cayenne.exp.parser.ASTEqual) ASTBitwiseOr(org.apache.cayenne.exp.parser.ASTBitwiseOr) ASTScalar(org.apache.cayenne.exp.parser.ASTScalar) Test(org.junit.Test)

Example 13 with ASTObjPath

use of org.apache.cayenne.exp.parser.ASTObjPath in project cayenne by apache.

the class LikeExpressionHelperTest method testEscape_OneChar.

@Test
public void testEscape_OneChar() {
    PatternMatchNode node = new ASTLike(new ASTObjPath("x"), "ab_c");
    LikeExpressionHelper.escape(node);
    assertEquals("ab!_c", node.getOperand(1));
    assertEquals('!', node.getEscapeChar());
}
Also used : ASTObjPath(org.apache.cayenne.exp.parser.ASTObjPath) ASTLike(org.apache.cayenne.exp.parser.ASTLike) PatternMatchNode(org.apache.cayenne.exp.parser.PatternMatchNode) Test(org.junit.Test)

Example 14 with ASTObjPath

use of org.apache.cayenne.exp.parser.ASTObjPath in project cayenne by apache.

the class LikeExpressionHelperTest method testEscape_NoEscapeChars.

@Test
public void testEscape_NoEscapeChars() {
    PatternMatchNode node = new ASTLike(new ASTObjPath("x"), "abc");
    LikeExpressionHelper.escape(node);
    assertEquals("abc", node.getOperand(1));
    assertEquals(0, node.getEscapeChar());
}
Also used : ASTObjPath(org.apache.cayenne.exp.parser.ASTObjPath) ASTLike(org.apache.cayenne.exp.parser.ASTLike) PatternMatchNode(org.apache.cayenne.exp.parser.PatternMatchNode) Test(org.junit.Test)

Example 15 with ASTObjPath

use of org.apache.cayenne.exp.parser.ASTObjPath in project cayenne by apache.

the class LikeExpressionHelperTest method testEscape_TwoChars.

@Test
public void testEscape_TwoChars() {
    PatternMatchNode node = new ASTLike(new ASTObjPath("x"), "ab_c_");
    LikeExpressionHelper.escape(node);
    assertEquals("ab!_c!_", node.getOperand(1));
    assertEquals('!', node.getEscapeChar());
}
Also used : ASTObjPath(org.apache.cayenne.exp.parser.ASTObjPath) ASTLike(org.apache.cayenne.exp.parser.ASTLike) PatternMatchNode(org.apache.cayenne.exp.parser.PatternMatchNode) Test(org.junit.Test)

Aggregations

ASTObjPath (org.apache.cayenne.exp.parser.ASTObjPath)18 Test (org.junit.Test)13 ASTLike (org.apache.cayenne.exp.parser.ASTLike)6 PatternMatchNode (org.apache.cayenne.exp.parser.PatternMatchNode)6 Expression (org.apache.cayenne.exp.Expression)5 ArrayList (java.util.ArrayList)4 ASTEqual (org.apache.cayenne.exp.parser.ASTEqual)4 ASTScalar (org.apache.cayenne.exp.parser.ASTScalar)4 ReturnTypesMap1 (org.apache.cayenne.testdo.return_types.ReturnTypesMap1)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ObjAttribute (org.apache.cayenne.map.ObjAttribute)2 ObjEntity (org.apache.cayenne.map.ObjEntity)2 ObjRelationship (org.apache.cayenne.map.ObjRelationship)2 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ExpressionException (org.apache.cayenne.exp.ExpressionException)1 ExpressionParameter (org.apache.cayenne.exp.ExpressionParameter)1 ASTBitwiseAnd (org.apache.cayenne.exp.parser.ASTBitwiseAnd)1