use of org.neo4j.server.rest.web.CypherService in project neo4j by neo4j.
the class TransactionalRequestDispatcher method dispatch.
@Override
public void dispatch(Object o, final HttpContext httpContext) {
RepresentationWriteHandler representationWriteHandler = DO_NOTHING;
SecurityContext securityContext = AuthorizedRequestWrapper.getSecurityContextFromHttpContext(httpContext);
final GraphDatabaseFacade graph = database.getGraph();
if (o instanceof RestfulGraphDatabase) {
RestfulGraphDatabase restfulGraphDatabase = (RestfulGraphDatabase) o;
final Transaction transaction = graph.beginTransaction(KernelTransaction.Type.implicit, securityContext);
restfulGraphDatabase.getOutputFormat().setRepresentationWriteHandler(representationWriteHandler = new CommitOnSuccessfulStatusCodeRepresentationWriteHandler(httpContext, transaction));
} else if (o instanceof BatchOperationService) {
BatchOperationService batchOperationService = (BatchOperationService) o;
final Transaction transaction = graph.beginTransaction(KernelTransaction.Type.explicit, securityContext);
batchOperationService.setRepresentationWriteHandler(representationWriteHandler = new CommitOnSuccessfulStatusCodeRepresentationWriteHandler(httpContext, transaction));
} else if (o instanceof CypherService) {
CypherService cypherService = (CypherService) o;
final Transaction transaction = graph.beginTransaction(KernelTransaction.Type.explicit, securityContext);
cypherService.getOutputFormat().setRepresentationWriteHandler(representationWriteHandler = new CommitOnSuccessfulStatusCodeRepresentationWriteHandler(httpContext, transaction));
} else if (o instanceof DatabaseMetadataService) {
DatabaseMetadataService databaseMetadataService = (DatabaseMetadataService) o;
final Transaction transaction = graph.beginTransaction(KernelTransaction.Type.implicit, securityContext);
databaseMetadataService.setRepresentationWriteHandler(representationWriteHandler = new RepresentationWriteHandler() {
@Override
public void onRepresentationStartWriting() {
// do nothing
}
@Override
public void onRepresentationWritten() {
// doesn't need to commit
}
@Override
public void onRepresentationFinal() {
transaction.close();
}
});
} else if (o instanceof ExtensionService) {
ExtensionService extensionService = (ExtensionService) o;
extensionService.getOutputFormat().setRepresentationWriteHandler(representationWriteHandler = new RepresentationWriteHandler() {
Transaction transaction;
@Override
public void onRepresentationStartWriting() {
transaction = graph.beginTransaction(KernelTransaction.Type.implicit, securityContext);
}
@Override
public void onRepresentationWritten() {
// doesn't need to commit
}
@Override
public void onRepresentationFinal() {
if (transaction != null) {
transaction.close();
}
}
});
}
try {
requestDispatcher.dispatch(o, httpContext);
} catch (RuntimeException e) {
representationWriteHandler.onRepresentationFinal();
throw e;
}
}
Aggregations