use of org.teiid.query.sql.symbol.ElementSymbol 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.ElementSymbol 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.ElementSymbol in project teiid by teiid.
the class ODataExpressionToSQLVisitor method visit.
@Override
public void visit(UriResourceIt info) {
if (info.getType() instanceof SingletonPrimitiveType) {
org.teiid.query.sql.symbol.Expression ex = null;
if (this.ctxQuery.getIterator() == null) {
String group = this.nameGenerator.getNextGroup();
GroupSymbol groupSymbol = new GroupSymbol(group);
StoredProcedure procedure = new StoredProcedure();
procedure.setProcedureName("arrayiterate");
// the projected should only be the collection property at this point
// we may need more checks here to ensure that is valid
Collection<ProjectedColumn> values = this.ctxQuery.getProjectedColumns().values();
Assertion.assertTrue(values.size() == 1);
ProjectedColumn projectedColumn = values.iterator().next();
ElementSymbol projectedEs = (ElementSymbol) projectedColumn.getExpression();
List<SPParameter> params = new ArrayList<SPParameter>();
SPParameter param = new SPParameter(1, SPParameter.IN, "val");
param.setExpression(projectedEs);
params.add(param);
procedure.setParameter(param);
SubqueryFromClause fromClause = new SubqueryFromClause(group, procedure);
fromClause.setLateral(true);
ElementSymbol es = new ElementSymbol("col", groupSymbol);
String type = ODataTypeManager.teiidType((SingletonPrimitiveType) info.getType(), false);
Function castFunction = new Function(CAST, new org.teiid.query.sql.symbol.Expression[] { es, new Constant(type) });
DocumentNode itResource = new DocumentNode();
org.teiid.query.sql.symbol.Expression clone = (org.teiid.query.sql.symbol.Expression) castFunction.clone();
AggregateSymbol symbol = new AggregateSymbol(AggregateSymbol.Type.ARRAY_AGG.name(), false, clone);
AliasSymbol expression = new AliasSymbol(projectedEs.getShortName(), symbol);
itResource.setFromClause(fromClause);
itResource.setGroupSymbol(groupSymbol);
itResource.addProjectedColumn(expression, info.getType(), projectedColumn.getProperty(), true);
this.ctxQuery.getProjectedColumns().remove(projectedColumn.getExpression());
this.ctxQuery.setIterator(itResource);
ex = castFunction;
} else {
GroupSymbol groupSymbol = this.ctxQuery.getIterator().getGroupSymbol();
ElementSymbol es = new ElementSymbol("col", groupSymbol);
String type = ODataTypeManager.teiidType((SingletonPrimitiveType) info.getType(), false);
ex = new Function(CAST, new org.teiid.query.sql.symbol.Expression[] { es, new Constant(type) });
}
this.stack.push(ex);
} else {
boolean ex = true;
if (this.ctxQuery instanceof ExpandDocumentNode) {
ExpandDocumentNode node = (ExpandDocumentNode) this.ctxQuery;
DocumentNode parent = node.getCollectionContext();
if (parent != null) {
this.ctxExpression = parent;
ex = false;
}
}
if (ex) {
throw new TeiidRuntimeException(new TeiidNotImplementedException(ODataPlugin.Event.TEIID16010, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16010)));
}
}
}
use of org.teiid.query.sql.symbol.ElementSymbol in project teiid by teiid.
the class ODataExpressionToSQLVisitor method visit.
// ///////////////////////////////////////////////////////////////////////
// RequestURLHierarchyVisitor specific methods
// ///////////////////////////////////////////////////////////////////////
@Override
public void visit(UriResourcePrimitiveProperty info) {
if (this.root) {
this.stack.add(new ScalarSubquery(buildRootSubQuery(info.getProperty().getName(), this.ctxExpression)));
root = false;
} else {
this.stack.add(new ElementSymbol(info.getProperty().getName(), this.ctxExpression.getGroupSymbol()));
}
// hack to resolve the property type.
Column c = this.ctxExpression.getColumnByName(info.getProperty().getName());
this.lastPropertyType = c.getRuntimeType();
// revert back to the query context
this.ctxExpression = this.ctxQuery;
}
use of org.teiid.query.sql.symbol.ElementSymbol in project teiid by teiid.
the class ComplexDocumentNode method addAllColumns.
@Override
protected void addAllColumns(boolean onlyPK) {
for (final Column column : procedure.getResultSet().getColumns()) {
if (column.isSelectable()) {
EdmReturnType returnType = procedureReturn.getReturnType();
EdmComplexType complexType = (EdmComplexType) returnType.getType();
EdmPropertyImpl edmProperty = (EdmPropertyImpl) complexType.getProperty(column.getName());
addProjectedColumn(new ElementSymbol(column.getName(), getGroupSymbol()), edmProperty.getType(), edmProperty, edmProperty.isCollection());
}
}
}
Aggregations