use of org.teiid.query.sql.symbol.Constant in project teiid by teiid.
the class TestSearchedCaseExpressionImpl method getWhenCriteria.
public static List getWhenCriteria(int criteria) {
ArrayList list = new ArrayList();
// $NON-NLS-1$ //$NON-NLS-2$
ElementSymbol x = TestElementImpl.helpExample("vm1.g1", "e1");
for (int i = 0; i < criteria; i++) {
list.add(new CompareCriteria(x, CompareCriteria.EQ, new Constant(new Integer(i))));
}
return list;
}
use of org.teiid.query.sql.symbol.Constant in project teiid by teiid.
the class TestSearchedCaseExpressionImpl method helpExample.
public static SearchedCaseExpression helpExample() {
SearchedCaseExpression caseExpr = new SearchedCaseExpression(getWhenCriteria(3), TestCaseExpression.getThenExpressions(3));
caseExpr.setElseExpression(new Constant(new Integer(9999)));
return caseExpr;
}
use of org.teiid.query.sql.symbol.Constant in project teiid by teiid.
the class ODataSQLBuilder method update.
public Update update(EdmEntityType entityType, Entity entity, boolean prepared) throws TeiidException {
Update update = new Update();
update.setGroup(this.context.getGroupSymbol());
int i = 0;
for (Property property : entity.getProperties()) {
EdmProperty edmProperty = (EdmProperty) entityType.getProperty(property.getName());
Column column = this.context.getColumnByName(edmProperty.getName());
ElementSymbol symbol = new ElementSymbol(column.getName(), this.context.getGroupSymbol());
boolean add = true;
for (String c : this.context.getKeyColumnNames()) {
if (c.equals(column.getName())) {
add = false;
break;
}
}
if (add) {
if (prepared) {
update.addChange(symbol, new Reference(i++));
this.params.add(asParam(edmProperty, property.getValue()));
} else {
update.addChange(symbol, new Constant(asParam(edmProperty, property.getValue()).getValue()));
}
}
}
update.setCriteria(this.context.getCriteria());
return update;
}
use of org.teiid.query.sql.symbol.Constant in project teiid by teiid.
the class ODataSQLBuilder method selectWithEntityKey.
// TODO: allow the generated key building.
public Query selectWithEntityKey(EdmEntityType entityType, Entity entity, Map<String, Object> generatedKeys, List<ExpandNode> expand) throws TeiidException {
Table table = findTable(entityType.getName(), this.metadata);
DocumentNode resource = new DocumentNode(table, new GroupSymbol(table.getFullName()), entityType);
resource.setFromClause(new UnaryFromClause(new GroupSymbol(table.getFullName())));
resource.addAllColumns(false);
this.context = resource;
Query query = this.context.buildQuery();
processExpand(expand, resource, query, 1);
Criteria criteria = null;
KeyRecord pk = ODataSchemaBuilder.getIdentifier(table);
for (Column c : pk.getColumns()) {
Property prop = entity.getProperty(c.getName());
Constant right = null;
if (prop != null) {
right = new Constant(ODataTypeManager.convertToTeiidRuntimeType(c.getJavaType(), prop.getValue(), null));
} else {
Object value = generatedKeys.get(c.getName());
if (value == null) {
throw new TeiidProcessingException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16016, entityType.getName()));
}
right = new Constant(value);
}
ElementSymbol left = new ElementSymbol(c.getName(), this.context.getGroupSymbol());
if (criteria == null) {
criteria = new CompareCriteria(left, AbstractCompareCriteria.EQ, right);
} else {
CompareCriteria rightCC = new CompareCriteria(left, AbstractCompareCriteria.EQ, right);
criteria = new CompoundCriteria(CompoundCriteria.AND, criteria, rightCC);
}
}
query.setCriteria(criteria);
return query;
}
use of org.teiid.query.sql.symbol.Constant in project teiid by teiid.
the class ODataExpressionToSQLVisitor method visit.
@Override
public void visit(Literal expr) {
try {
Object value = null;
if (expr.getText() != null && !expr.getText().equalsIgnoreCase("null")) {
String type = expr.getType().getFullQualifiedName().getFullQualifiedNameAsString();
value = ODataTypeManager.parseLiteral(type, expr.getText());
}
if (this.prepared) {
if (value == null) {
this.stack.add(new Constant(value));
} else {
Function ref = new Function(CONVERT, new org.teiid.query.sql.symbol.Expression[] { new Reference(this.params.size()), new Constant(DataTypeManager.getDataTypeName(value.getClass())) });
stack.add(ref);
this.params.add(new SQLParameter(value, JDBCSQLTypeInfo.getSQLTypeFromClass(value.getClass().getName())));
}
} else {
this.stack.add(new Constant(value));
}
} catch (TeiidException e) {
throw new TeiidRuntimeException(e);
}
}
Aggregations