use of org.teiid.odata.api.UpdateResponse in project teiid by teiid.
the class LocalClient method executeUpdate.
@Override
public UpdateResponse executeUpdate(Command query, List<SQLParameter> parameters) throws SQLException {
String sql = query.toString();
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_ODATA, "Teiid-Query:", sql);
final PreparedStatementImpl stmt = getConnection().prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT, Statement.RETURN_GENERATED_KEYS);
if (!parameters.isEmpty()) {
for (int i = 0; i < parameters.size(); i++) {
stmt.setObject(i + 1, parameters.get(i).getValue(), parameters.get(i).getSqlType());
}
}
final int count = stmt.executeUpdate();
final Map<String, Object> keys = getGeneratedKeys(stmt.getGeneratedKeys());
stmt.close();
return new UpdateResponse() {
@Override
public Map<String, Object> getGeneratedKeys() {
return keys;
}
@Override
public int getUpdateCount() {
return count;
}
};
}
use of org.teiid.odata.api.UpdateResponse in project teiid by teiid.
the class TeiidServiceHandler method performDeepInsert.
private UpdateResponse performDeepInsert(String rawURI, UriInfo uriInfo, EdmEntityType entityType, Entity entity, List<ExpandNode> expandNodes) throws SQLException, TeiidException {
UpdateResponse response = performInsert(rawURI, uriInfo, entityType, entity);
for (String navigationName : entityType.getNavigationPropertyNames()) {
EdmNavigationProperty navProperty = entityType.getNavigationProperty(navigationName);
Link navLink = entity.getNavigationLink(navigationName);
if (navLink != null && navLink.getInlineEntity() != null) {
ExpandNode node = new ExpandNode();
node.navigationProperty = navProperty;
expandNodes.add(node);
performDeepInsert(rawURI, uriInfo, navProperty.getType(), navLink.getInlineEntity(), node.children);
} else if (navLink != null && navLink.getInlineEntitySet() != null && !navLink.getInlineEntitySet().getEntities().isEmpty()) {
ExpandNode node = new ExpandNode();
node.navigationProperty = navProperty;
expandNodes.add(node);
for (Entity inlineEntity : navLink.getInlineEntitySet().getEntities()) {
performDeepInsert(rawURI, uriInfo, navProperty.getType(), inlineEntity, node.children);
}
}
}
return response;
}
use of org.teiid.odata.api.UpdateResponse in project teiid by teiid.
the class TeiidServiceHandler method deleteEntity.
@Override
public void deleteEntity(DataRequest request, String entityETag, EntityResponse response) throws ODataLibraryException, ODataApplicationException {
// TODO: need to match entityETag.
checkETag(entityETag);
UpdateResponse updateResponse = null;
try {
ODataSQLBuilder visitor = new ODataSQLBuilder(this.odata, getClient().getMetadataStore(), this.prepared, false, request.getODataRequest().getRawBaseUri(), this.serviceMetadata);
visitor.visit(request.getUriInfo());
Delete delete = visitor.delete();
updateResponse = getClient().executeUpdate(delete, visitor.getParameters());
} catch (SQLException e) {
throw new ODataApplicationException(e.getMessage(), HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.getDefault(), e);
}
if (updateResponse != null && updateResponse.getUpdateCount() > 0) {
response.writeDeletedEntityOrReference();
} else {
// since DELETE is idempotent same response as otherwise success operation.
response.writeDeletedEntityOrReference();
}
}
use of org.teiid.odata.api.UpdateResponse 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.teiid.odata.api.UpdateResponse 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();
}
}
Aggregations