Search in sources :

Example 6 with ASTScalar

use of org.apache.cayenne.exp.parser.ASTScalar 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 7 with ASTScalar

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

the class FunctionExpressionFactoryTest method substringExp.

@Test
public void substringExp() throws Exception {
    Expression exp1 = FunctionExpressionFactory.substringExp(Artist.ARTIST_NAME.path(), 10, 15);
    Expression exp2 = FunctionExpressionFactory.substringExp(Artist.ARTIST_NAME.getName(), 10, 15);
    Expression exp3 = FunctionExpressionFactory.substringExp(Artist.ARTIST_NAME.path(), new ASTScalar(10), new ASTScalar(15));
    assertTrue(exp1 instanceof ASTSubstring);
    assertEquals(3, exp1.getOperandCount());
    assertEquals(Artist.ARTIST_NAME.path(), exp1.getOperand(0));
    assertEquals(10, exp1.getOperand(1));
    assertEquals(15, exp1.getOperand(2));
    assertEquals(exp1, exp2);
    assertEquals(exp2, exp3);
}
Also used : ASTSubstring(org.apache.cayenne.exp.parser.ASTSubstring) ASTScalar(org.apache.cayenne.exp.parser.ASTScalar) Test(org.junit.Test)

Example 8 with ASTScalar

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

the class FunctionExpressionFactoryTest method concatExp.

@Test
public void concatExp() throws Exception {
    Expression exp1 = FunctionExpressionFactory.concatExp(Artist.ARTIST_NAME.path(), new ASTScalar("abc"), Artist.DATE_OF_BIRTH.path());
    assertTrue(exp1 instanceof ASTConcat);
    assertEquals(3, exp1.getOperandCount());
    assertEquals(Artist.ARTIST_NAME.path(), exp1.getOperand(0));
    assertEquals("abc", exp1.getOperand(1));
    assertEquals(Artist.DATE_OF_BIRTH.path(), exp1.getOperand(2));
    Expression exp2 = FunctionExpressionFactory.concatExp(Artist.ARTIST_NAME.getName(), Artist.DATE_OF_BIRTH.getName(), Artist.PAINTING_ARRAY.getName());
    assertTrue(exp2 instanceof ASTConcat);
    assertEquals(3, exp2.getOperandCount());
    assertEquals(Artist.ARTIST_NAME.path(), exp2.getOperand(0));
    assertEquals(Artist.DATE_OF_BIRTH.path(), exp2.getOperand(1));
    assertEquals(Artist.PAINTING_ARRAY.path(), exp2.getOperand(2));
}
Also used : ASTConcat(org.apache.cayenne.exp.parser.ASTConcat) ASTScalar(org.apache.cayenne.exp.parser.ASTScalar) Test(org.junit.Test)

Aggregations

ASTScalar (org.apache.cayenne.exp.parser.ASTScalar)8 Test (org.junit.Test)8 Expression (org.apache.cayenne.exp.Expression)4 ASTObjPath (org.apache.cayenne.exp.parser.ASTObjPath)4 ReturnTypesMap1 (org.apache.cayenne.testdo.return_types.ReturnTypesMap1)4 ASTEqual (org.apache.cayenne.exp.parser.ASTEqual)3 ASTBitwiseAnd (org.apache.cayenne.exp.parser.ASTBitwiseAnd)1 ASTBitwiseNot (org.apache.cayenne.exp.parser.ASTBitwiseNot)1 ASTBitwiseOr (org.apache.cayenne.exp.parser.ASTBitwiseOr)1 ASTBitwiseXor (org.apache.cayenne.exp.parser.ASTBitwiseXor)1 ASTConcat (org.apache.cayenne.exp.parser.ASTConcat)1 ASTGreater (org.apache.cayenne.exp.parser.ASTGreater)1 ASTLocate (org.apache.cayenne.exp.parser.ASTLocate)1 ASTMod (org.apache.cayenne.exp.parser.ASTMod)1 ASTSubstring (org.apache.cayenne.exp.parser.ASTSubstring)1