use of org.apache.olingo.commons.api.data.Property 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.apache.olingo.commons.api.data.Property 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.apache.olingo.commons.api.data.Property in project teiid by teiid.
the class ODataDocument method createDocument.
private static ODataDocument createDocument(String name, ComplexValue complex, ODataDocument parent) {
ODataDocument document = new ODataDocument(name, parent);
List<Property> properties = complex.getValue();
for (Property property : properties) {
populateDocument(property, document);
}
return document;
}
use of org.apache.olingo.commons.api.data.Property in project teiid by teiid.
the class ODataDocument method createDocument.
public static ODataDocument createDocument(ComplexValue complex) {
ODataDocument document = new ODataDocument();
List<Property> properties = complex.getValue();
for (Property property : properties) {
populateDocument(property, document);
}
return document;
}
use of org.apache.olingo.commons.api.data.Property in project teiid by teiid.
the class ODataProcedureExecution method handleResponse.
private void handleResponse(final Procedure procedure, final String baseUri, final InputStream payload) throws TranslatorException, ODataDeserializerException {
if (procedure.getResultSet() != null) {
ODataType type = ODataType.valueOf(procedure.getResultSet().getProperty(ODataMetadataProcessor.ODATA_TYPE, false));
this.response = new ODataResponse(payload, type, new DocumentNode()) {
@Override
public InputStream nextBatch(java.net.URI uri) throws TranslatorException {
return executeSkipToken(uri, baseUri, new HttpStatusCode[] { HttpStatusCode.OK });
}
};
} else if (getReturnParameter() != null) {
// this is scalar result
JsonDeserializer parser = new JsonDeserializer(false);
Property property = parser.toProperty(payload).getPayload();
if (property.isCollection()) {
this.returnValue = property.asCollection();
} else {
this.returnValue = property.asPrimitive();
}
}
}
Aggregations