@Override public void serialize(RestEntity entity, OutputStream outputStream) throws RestException { if(entity instanceof StreamableEntityCollection) { StreamableEntityCollection entityCollection = (StreamableEntityCollection) entity; generateEntityOutput(entityCollection.getSize(), entityCollection.getTimeMilliseconds(), entityCollection.getResult(), outputStream); } else { throw new RestException("Unable to serialize the entity, not of type: " + StreamableEntityCollection.class.getName()); } }
private StreamableEntityCollection handleCollection(HttpServletRequest request, String instanceId, String bagName, int max) throws JasDBStorageException { StorageService storageService = storageServiceFactory.getOrCreateStorageService(instanceId, bagName); long start = System.currentTimeMillis(); QueryResult queryResult; if(max != -1) { queryResult = storageService.getEntities(getRequestContext(request), max); } else { queryResult = storageService.getEntities(getRequestContext(request)); } StreamableEntityCollection collection = new StreamableEntityCollection(queryResult); long end = System.currentTimeMillis(); collection.setTimeMilliseconds((end - start)); return collection; } }
log.debug("Parsing a stream of entities of size: {} queried in: {} ms.", size, timeMilliseconds); QueryResult result = new StreamableQueryResult(parser, size, inputStream); return dataType.cast(new StreamableEntityCollection(result));
private QueryResult parseAsEntityCollection(ClientResponse response) throws RemoteException { try { StreamableEntityCollection entityCollection = new JsonRestResponseHandler().deserialize(StreamableEntityCollection.class, new WrappedInputStream(response)); return entityCollection.getResult(); } catch(RestException e) { throw new RemoteException("Unable to parse remote entity data", e); } }
private RestEntity handleQuery(StorageService storageService, InputCondition condition, int begin, int top, List<OrderParam> orderParams, RequestContext context) throws JasDBStorageException { LOG.debug("Query: {} begin: {} top: {}", condition, begin, top); if(condition.getTokenType() == TokenType.LITERAL && ((FieldCondition)condition).getField().equals(FieldCondition.ID_PARAM)) { FieldCondition idCondition = (FieldCondition) condition; return requestById(storageService, idCondition.getValue(), context); } else { QueryBuilder parentBuilder = generateQueryBuilder(condition, QueryBuilder.createBuilder()); setOrderingParams(parentBuilder, orderParams); long start = System.currentTimeMillis(); QueryResult result = storageService.search(context, BuilderTransformer.transformBuilder(parentBuilder), new SearchLimit(begin, top), parentBuilder.getSortParams()); long end = System.currentTimeMillis(); StreamableEntityCollection collection = new StreamableEntityCollection(result); collection.setTimeMilliseconds((end - start)); return collection; } }