-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support $batch operations #1
Comments
For supporting batch this is not enough, however I am not sure that can even help. For me batch is working as soon as we have only one
then it will show the following error: <?xml version='1.0' encoding='UTF-8'?>
<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<code/>
<message xml:lang="en">Error on processing request content:Cannot begin Transaction on closed Session/EntityManager</message>
</error> |
The solution is overriding the @Override
public ODataResponse executeBatch(final BatchHandler handler, final String contentType, final InputStream content)
throws ODataException {
try {
ODataResponse batchResponse;
List<BatchResponsePart> batchResponseParts = new ArrayList<BatchResponsePart>();
PathInfo pathInfo = getContext().getPathInfo();
EntityProviderBatchProperties batchProperties = EntityProviderBatchProperties.init().pathInfo(pathInfo)
.build();
List<BatchRequestPart> batchParts = EntityProvider.parseBatchRequest(contentType, content, batchProperties);
for (BatchRequestPart batchPart : batchParts) {
batchResponseParts.add(handler.handleBatchPart(batchPart));
}
batchResponse = EntityProvider.writeBatchResponse(batchResponseParts);
return batchResponse;
} finally {
close(true);
}
}
@Override
public BatchResponsePart executeChangeSet(final BatchHandler handler, final List<ODataRequest> requests)
throws ODataException {
List<ODataResponse> responses = new ArrayList<ODataResponse>();
try {
//oDataJPAContext.getODataJPATransaction().begin();
for (ODataRequest request : requests) {
//oDataJPAContext.setODataContext(getContext());
ODataResponse response = handler.handleRequest(request);
if (response.getStatus().getStatusCode() >= HttpStatusCodes.BAD_REQUEST.getStatusCode()) {
// Roll Back
oDataJPAContext.getODataJPATransaction().rollback();
List<ODataResponse> errorResponses = new ArrayList<ODataResponse>(1);
errorResponses.add(response);
return BatchResponsePart.responses(errorResponses).changeSet(false).build();
}
responses.add(response);
}
//oDataJPAContext.getODataJPATransaction().commit();
return BatchResponsePart.responses(responses).changeSet(true).build();
} catch (Exception e) {
throw new ODataException("Error on processing request content:" + e.getMessage(), e);
} finally {
close(true);
}
} I have commented the two problematic lines! |
Hey you have mentioned that you have commented 2 lines but in the above code 3 lines seem to be committed. |
In the SevletRegister you need to configure multipart to support batch operations.
Just include this line
odataServletRegistrationBean.setMultipartConfig(new MultipartConfigElement(""));
Thanks for your example, it was very helpful.
The text was updated successfully, but these errors were encountered: