use of org.apache.cayenne.exp.parser.SimpleNode in project cayenne by apache.
the class DB2QualifierTranslator 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(" + size + "))");
} else {
super.processColumnWithQuoteSqlIdentifiers(dbAttr, pathExp);
}
}
use of org.apache.cayenne.exp.parser.SimpleNode 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.SimpleNode in project cayenne by apache.
the class QueryAssemblerHelper method paramsDbType.
/**
* Returns database type of expression parameters or null if it can not be
* determined.
*/
protected DbAttribute paramsDbType(Expression e) {
int len = e.getOperandCount();
// ASTList
if (len < 2) {
if (e instanceof SimpleNode) {
Expression parent = (Expression) ((SimpleNode) e).jjtGetParent();
if (parent != null) {
return paramsDbType(parent);
}
}
return null;
}
// naive algorithm:
// if at least one of the sibling operands is a
// OBJ_PATH or DB_PATH expression, use its attribute type as
// a final answer.
// find attribute or relationship matching the value
DbAttribute attribute = null;
DbRelationship relationship = null;
for (int i = 0; i < len; i++) {
Object op = e.getOperand(i);
if (op instanceof Expression) {
Expression expression = (Expression) op;
if (expression.getType() == Expression.OBJ_PATH) {
PathComponent<ObjAttribute, ObjRelationship> last = getObjEntity().lastPathComponent(expression, queryAssembler.getPathAliases());
if (last.getAttribute() != null) {
attribute = last.getAttribute().getDbAttribute();
break;
} else if (last.getRelationship() != null) {
List<DbRelationship> dbPath = last.getRelationship().getDbRelationships();
if (dbPath.size() > 0) {
relationship = dbPath.get(dbPath.size() - 1);
break;
}
}
} else if (expression.getType() == Expression.DB_PATH) {
PathComponent<DbAttribute, DbRelationship> last = getDbEntity().lastPathComponent(expression, queryAssembler.getPathAliases());
if (last.getAttribute() != null) {
attribute = last.getAttribute();
break;
} else if (last.getRelationship() != null) {
relationship = last.getRelationship();
break;
}
}
}
}
if (attribute != null) {
return attribute;
}
if (relationship != null) {
// Can't properly handle multiple joins....
if (relationship.getJoins().size() == 1) {
DbJoin join = relationship.getJoins().get(0);
return join.getSource();
}
}
return null;
}
Aggregations