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);
}
}
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]);
}
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);
}
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);
}
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());
}
Aggregations