use of org.apache.olingo.commons.api.edm.EdmProperty 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.edm.EdmProperty in project teiid by teiid.
the class TeiidServiceHandler method upsertStreamProperty.
@Override
public void upsertStreamProperty(DataRequest request, String entityETag, InputStream streamContent, NoContentResponse response) throws ODataLibraryException, ODataApplicationException {
UpdateResponse updateResponse = null;
EdmProperty edmProperty = request.getUriResourceProperty().getProperty();
try {
ODataSQLBuilder visitor = new ODataSQLBuilder(this.odata, getClient().getMetadataStore(), this.prepared, false, request.getODataRequest().getRawBaseUri(), this.serviceMetadata);
visitor.visit(request.getUriInfo());
Update update = visitor.updateStreamProperty(edmProperty, streamContent);
updateResponse = getClient().executeUpdate(update, visitor.getParameters());
} catch (SQLException | TeiidException e) {
throw new ODataApplicationException(e.getMessage(), HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.getDefault(), e);
}
if (updateResponse != null && updateResponse.getUpdateCount() > 0) {
response.writeNoContent();
} else {
response.writeNotModified();
}
}
use of org.apache.olingo.commons.api.edm.EdmProperty in project teiid by teiid.
the class TeiidServiceHandler method updateProperty.
/**
* since Teiid only deals with primitive types, merge does not apply
*/
@Override
public void updateProperty(DataRequest request, Property property, boolean rawValue, boolean merge, String entityETag, PropertyResponse response) throws ODataLibraryException, ODataApplicationException {
// TODO: need to match entityETag.
checkETag(entityETag);
UpdateResponse updateResponse = null;
EdmProperty edmProperty = request.getUriResourceProperty().getProperty();
try {
ODataSQLBuilder visitor = new ODataSQLBuilder(this.odata, getClient().getMetadataStore(), this.prepared, false, request.getODataRequest().getRawBaseUri(), this.serviceMetadata);
visitor.visit(request.getUriInfo());
Update update = visitor.updateProperty(edmProperty, property, this.prepared, rawValue);
updateResponse = getClient().executeUpdate(update, visitor.getParameters());
} catch (SQLException e) {
throw new ODataApplicationException(e.getMessage(), HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.getDefault(), e);
} catch (TeiidException e) {
throw new ODataApplicationException(e.getMessage(), HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.getDefault(), e);
}
if (updateResponse != null && updateResponse.getUpdateCount() > 0) {
response.writePropertyUpdated();
} else {
response.writeNotModified();
}
}
use of org.apache.olingo.commons.api.edm.EdmProperty in project teiid by teiid.
the class ODataSQLBuilder method insert.
public Insert insert(EdmEntityType entityType, Entity entity, List<UriParameter> keys, boolean prepared) throws TeiidException {
Table entityTable = findTable(entityType.getName(), this.metadata);
DocumentNode resource = new DocumentNode(entityTable, new GroupSymbol(entityTable.getFullName()), entityType);
List<Reference> referenceValues = new ArrayList<Reference>();
List<Constant> constantValues = new ArrayList<Constant>();
Insert insert = new Insert();
insert.setGroup(resource.getGroupSymbol());
if (keys != null) {
for (UriParameter key : keys) {
EdmProperty edmProperty = (EdmProperty) entityType.getProperty(key.getName());
Column column = entityTable.getColumnByName(edmProperty.getName());
Object propertyValue = ODataTypeManager.parseLiteral(edmProperty, column.getJavaType(), key.getText());
Property existing = entity.getProperty(edmProperty.getName());
if (existing == null || (existing.getValue() == null && propertyValue != null) || (existing.getValue() != null && propertyValue == null) || (existing.getValue() != null && !existing.getValue().equals(propertyValue))) {
throw new TeiidProcessingException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16048, edmProperty.getName()));
}
}
}
int i = 0;
for (Property prop : entity.getProperties()) {
EdmProperty edmProp = (EdmProperty) entityType.getProperty(prop.getName());
Column column = entityTable.getColumnByName(edmProp.getName());
insert.addVariable(new ElementSymbol(column.getName(), resource.getGroupSymbol()));
if (prepared) {
referenceValues.add(new Reference(i++));
this.params.add(asParam(edmProp, prop.getValue()));
} else {
constantValues.add(new Constant(asParam(edmProp, prop.getValue()).getValue()));
}
}
if (prepared) {
insert.setValues(referenceValues);
} else {
insert.setValues(constantValues);
}
return insert;
}
use of org.apache.olingo.commons.api.edm.EdmProperty in project teiid by teiid.
the class OperationResponseImpl method getComplexProperty.
private ComplexValue getComplexProperty(ResultSet rs) throws SQLException {
HashMap<Integer, Property> properties = new HashMap<Integer, Property>();
for (int i = 0; i < rs.getMetaData().getColumnCount(); i++) {
Object value = rs.getObject(i + 1);
String propName = rs.getMetaData().getColumnLabel(i + 1);
EdmElement element = ((EdmComplexType) this.procedureReturn.getReturnType().getType()).getProperty(propName);
if (!(element instanceof EdmProperty) && !((EdmProperty) element).isPrimitive()) {
throw new SQLException(new TeiidNotImplementedException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16024)));
}
EdmPropertyImpl edmProperty = (EdmPropertyImpl) element;
Property property;
try {
property = EntityCollectionResponse.buildPropery(propName, (SingletonPrimitiveType) edmProperty.getType(), edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isCollection(), value);
properties.put(i, property);
} catch (IOException e) {
throw new SQLException(e);
} catch (TeiidProcessingException e) {
throw new SQLException(e);
}
}
// filter those columns out.
return createComplex("result", properties.values());
}
Aggregations