Search in sources :

Example 6 with ASTEqual

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

the class DerbyQualifierTranslator method processColumnWithQuoteSqlIdentifiers.

@Override
protected void processColumnWithQuoteSqlIdentifiers(DbAttribute dbAttr, Expression pathExp) {
    SimpleNode parent = null;
    if (pathExp instanceof SimpleNode) {
        parent = (SimpleNode) ((SimpleNode) pathExp).jjtGetParent();
    }
    // we need do it by casting the Clob to VARCHAR.
    if (parent != null && (parent instanceof ASTEqual || parent instanceof ASTNotEqual) && dbAttr.getType() == Types.CLOB && parent.getOperandCount() == 2 && parent.getOperand(1) instanceof String) {
        Integer size = parent.getOperand(1).toString().length() + 1;
        out.append("CAST(");
        super.processColumnWithQuoteSqlIdentifiers(dbAttr, pathExp);
        out.append(" AS VARCHAR(").append(size).append("))");
    } else {
        super.processColumnWithQuoteSqlIdentifiers(dbAttr, pathExp);
    }
}
Also used : ASTEqual(org.apache.cayenne.exp.parser.ASTEqual) ASTNotEqual(org.apache.cayenne.exp.parser.ASTNotEqual) SimpleNode(org.apache.cayenne.exp.parser.SimpleNode)

Example 7 with ASTEqual

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

the class PathAliasesIT method testAliasForPath.

@Test
public void testAliasForPath() {
    ASTPath astPath = new ASTObjPath("paintingArray.a.galleryName");
    astPath.setPathAliases(Collections.singletonMap("a", "toGallery"));
    ASTEqual astEqual = new ASTEqual(astPath, "tate modern");
    List<Object[]> artists = ObjectSelect.columnQuery(Artist.class, Artist.ARTIST_NAME, PropertyFactory.createBase(astPath, String.class)).where(astEqual).orderBy(Artist.ARTIST_NAME.asc()).select(context);
    assertEquals(5, artists.size());
    assertEquals("artist1", artists.get(0)[0]);
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) ASTObjPath(org.apache.cayenne.exp.parser.ASTObjPath) ASTEqual(org.apache.cayenne.exp.parser.ASTEqual) ASTPath(org.apache.cayenne.exp.parser.ASTPath) Test(org.junit.Test)

Example 8 with ASTEqual

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

the class ExpressionFactory method matchAllExp.

/**
 * @since 3.0
 */
public static Expression matchAllExp(String path, Object... values) {
    if (values == null) {
        throw new NullPointerException("Null values collection");
    }
    if (values.length == 0) {
        return new ASTTrue();
    }
    int split = path.indexOf(SPLIT_SEPARATOR);
    List<Expression> matches = new ArrayList<>(values.length);
    if (split >= 0 && split < path.length() - 1) {
        int splitEnd = path.indexOf(Entity.PATH_SEPARATOR, split + 1);
        String beforeSplit = split > 0 ? path.substring(0, split) : "";
        String afterSplit = splitEnd > 0 ? "." + path.substring(splitEnd + 1) : "";
        String aliasBase = "split" + autoAliasId++ + "_";
        String splitChunk = splitEnd > 0 ? path.substring(split + 1, splitEnd) : path.substring(split + 1);
        // fix the path - replace split with dot if it's in the middle, or
        // strip it if
        // it's in the beginning
        path = split == 0 ? path.substring(1) : path.replace(SPLIT_SEPARATOR, '.');
        int i = 0;
        for (Object value : values) {
            String alias = aliasBase + i;
            String aliasedPath = beforeSplit + alias + afterSplit;
            i++;
            ASTPath pathExp = new ASTObjPath(aliasedPath);
            pathExp.setPathAliases(Collections.singletonMap(alias, splitChunk));
            matches.add(new ASTEqual(pathExp, value));
        }
    } else {
        for (Object value : values) {
            matches.add(new ASTEqual(new ASTObjPath(path), value));
        }
    }
    return joinExp(Expression.AND, matches);
}
Also used : ASTObjPath(org.apache.cayenne.exp.parser.ASTObjPath) ArrayList(java.util.ArrayList) ASTEqual(org.apache.cayenne.exp.parser.ASTEqual) ASTEnclosingObject(org.apache.cayenne.exp.parser.ASTEnclosingObject) ASTFullObject(org.apache.cayenne.exp.parser.ASTFullObject) ASTPath(org.apache.cayenne.exp.parser.ASTPath) ASTTrue(org.apache.cayenne.exp.parser.ASTTrue)

Example 9 with ASTEqual

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

the class Cay2666IT method testExpDbPathWithDollarSign.

@Test
public void testExpDbPathWithDollarSign() throws IOException {
    Expression exp = ExpressionFactory.exp("db:x$ = 'A'");
    Expression expression = new ASTEqual(new ASTDbPath("x$"), "A");
    assertEquals(exp, expression);
    exp = ExpressionFactory.exp("x$ = 'A'");
    expression = new ASTEqual(new ASTDbPath("x$"), "A");
    assertNotEquals(exp, expression);
    exp = ExpressionFactory.exp("db:x$ = $name", "A");
    expression = new ASTEqual(new ASTDbPath("x$"), "A");
    assertEquals(exp, expression);
}
Also used : ASTDbPath(org.apache.cayenne.exp.parser.ASTDbPath) Expression(org.apache.cayenne.exp.Expression) ASTEqual(org.apache.cayenne.exp.parser.ASTEqual) Test(org.junit.Test)

Example 10 with ASTEqual

use of org.apache.cayenne.exp.parser.ASTEqual 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);
    List<ReturnTypesMap1> objects = ObjectSelect.query(ReturnTypesMap1.class, equal).select(context);
    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)

Aggregations

ASTEqual (org.apache.cayenne.exp.parser.ASTEqual)11 Test (org.junit.Test)8 ASTObjPath (org.apache.cayenne.exp.parser.ASTObjPath)7 Expression (org.apache.cayenne.exp.Expression)6 ASTScalar (org.apache.cayenne.exp.parser.ASTScalar)4 ASTPath (org.apache.cayenne.exp.parser.ASTPath)3 ReturnTypesMap1 (org.apache.cayenne.testdo.return_types.ReturnTypesMap1)3 ASTDbPath (org.apache.cayenne.exp.parser.ASTDbPath)2 ASTNotEqual (org.apache.cayenne.exp.parser.ASTNotEqual)2 SimpleNode (org.apache.cayenne.exp.parser.SimpleNode)2 Artist (org.apache.cayenne.testdo.testmap.Artist)2 ArrayList (java.util.ArrayList)1 ObjectId (org.apache.cayenne.ObjectId)1 ASTBitwiseAnd (org.apache.cayenne.exp.parser.ASTBitwiseAnd)1 ASTBitwiseOr (org.apache.cayenne.exp.parser.ASTBitwiseOr)1 ASTBitwiseXor (org.apache.cayenne.exp.parser.ASTBitwiseXor)1 ASTEnclosingObject (org.apache.cayenne.exp.parser.ASTEnclosingObject)1 ASTFullObject (org.apache.cayenne.exp.parser.ASTFullObject)1 ASTTrue (org.apache.cayenne.exp.parser.ASTTrue)1