use of org.teiid.query.sql.lang.Criteria in project teiid by teiid.
the class TestWhileStatement method sample2.
public static final WhileStatement sample2() {
Block block = TestBlock.sample2();
Criteria criteria = TestSetCriteria.sample2();
return new WhileStatement(criteria, block);
}
use of org.teiid.query.sql.lang.Criteria in project teiid by teiid.
the class ReferenceUpdateSQLBuilder method updateReference.
public Update updateReference(URI referenceId, boolean prepared, boolean delete) throws SQLException {
try {
if (referenceId != null) {
UriInfo uriInfo = ODataSQLBuilder.buildUriInfo(referenceId, this.baseURI, this.serviceMetadata, this.odata);
UriResourceEntitySet uriEnitytSet = (UriResourceEntitySet) uriInfo.asUriInfoResource().getUriResourceParts().get(0);
if (this.collection) {
this.updateTable.setKeyPredicates(uriEnitytSet.getKeyPredicates());
} else {
this.referenceTable.setKeyPredicates(uriEnitytSet.getKeyPredicates());
}
}
} catch (UriParserException e) {
throw new SQLException(e);
} catch (URISyntaxException e) {
throw new SQLException(e);
} catch (UriValidationException e) {
throw new SQLException(e);
}
try {
Update update = new Update();
update.setGroup(this.updateTable.getGroupSymbol());
List<String> columnNames = DocumentNode.getColumnNames(this.updateTable.getFk().getColumns());
for (int i = 0; i < columnNames.size(); i++) {
Column column = this.updateTable.getFk().getColumns().get(i);
String columnName = columnNames.get(i);
ElementSymbol symbol = new ElementSymbol(columnName, this.updateTable.getGroupSymbol());
EdmEntityType entityType = this.updateTable.getEdmEntityType();
EdmProperty edmProperty = (EdmProperty) entityType.getProperty(columnName);
// reference table keys will be null for delete scenario
Object value = null;
if (!delete) {
UriParameter parameter = getParameter(this.updateTable.getFk().getReferenceColumns().get(i), this.referenceTable.getKeyPredicates());
value = ODataTypeManager.parseLiteral(edmProperty, column.getJavaType(), parameter.getText());
}
if (prepared) {
update.addChange(symbol, new Reference(i++));
this.params.add(ODataSQLBuilder.asParam(edmProperty, value));
} else {
update.addChange(symbol, new Constant(ODataSQLBuilder.asParam(edmProperty, value).getValue()));
}
}
Criteria criteria = DocumentNode.buildEntityKeyCriteria(this.updateTable, null, this.metadata, this.odata, null, null);
update.setCriteria(criteria);
return update;
} catch (TeiidException e) {
throw new SQLException(e);
}
}
Aggregations