protected Object executeSingleProjection(N1qlQuery query) { logIfNecessary(query); //the structure of the response from N1QL gives us a JSON object even when selecting a single aggregation List<Map> resultAsMap = couchbaseOperations.findByN1QLProjection(query, Map.class); if (resultAsMap.size() != 1) { throw new CouchbaseQueryExecutionException("Query returning a primitive type are expected to return " + "exactly 1 result, got " + resultAsMap.size()); } Map<String, Object> singleRow = (Map<String, Object>) resultAsMap.get(0); if (singleRow.size() != 1) { throw new CouchbaseQueryExecutionException("Query returning a simple type are expected to return " + "a unique value, got " + singleRow.size()); } Collection<Object> rowValues = singleRow.values(); if (rowValues.size() != 1) { throw new CouchbaseQueryExecutionException("Query returning a simple type are expected to use a " + "single aggregation/projection, got " + rowValues.size()); } return rowValues.iterator().next(); }
protected Object executeSingleProjection(N1qlQuery query) { logIfNecessary(query); //the structure of the response from N1QL gives us a JSON object even when selecting a single aggregation List<Map> resultAsMap = couchbaseOperations.findByN1QLProjection(query, Map.class); if (resultAsMap.size() != 1) { throw new CouchbaseQueryExecutionException("Query returning a primitive type are expected to return " + "exactly 1 result, got " + resultAsMap.size()); } Map<String, Object> singleRow = (Map<String, Object>) resultAsMap.get(0); if (singleRow.size() != 1) { throw new CouchbaseQueryExecutionException("Query returning a simple type are expected to return " + "a unique value, got " + singleRow.size()); } Collection<Object> rowValues = singleRow.values(); if (rowValues.size() != 1) { throw new CouchbaseQueryExecutionException("Query returning a simple type are expected to use a " + "single aggregation/projection, got " + rowValues.size()); } return rowValues.iterator().next(); }
protected Object executePaged(N1qlQuery query, N1qlQuery countQuery, Pageable pageable, Class<?> typeToRead) { Assert.notNull(pageable, "Pageable must not be null!"); long total = 0L; logIfNecessary(countQuery); List<CountFragment> countResult = couchbaseOperations.findByN1QLProjection(countQuery, CountFragment.class); if (countResult != null && !countResult.isEmpty()) { total = countResult.get(0).count; } logIfNecessary(query); List<?> result = couchbaseOperations.findByN1QL(query, typeToRead); return new PageImpl(result, pageable, total); }
protected Object executePaged(N1qlQuery query, N1qlQuery countQuery, Pageable pageable, Class<?> typeToRead) { Assert.notNull(pageable, "Pageable must not be null!"); long total = 0L; logIfNecessary(countQuery); List<CountFragment> countResult = couchbaseOperations.findByN1QLProjection(countQuery, CountFragment.class); if (countResult != null && !countResult.isEmpty()) { total = countResult.get(0).count; } logIfNecessary(query); List<?> result = couchbaseOperations.findByN1QL(query, typeToRead); return new PageImpl(result, pageable, total); }
List < CountFragment > countResult = getCouchbaseOperations().findByN1QLProjection(countQuery, CountFragment.class); long totalCount = countResult == null || countResult.isEmpty() ? 0 : countResult.get(0).count;
List < CountFragment > countResult = getCouchbaseOperations().findByN1QLProjection(countQuery, CountFragment.class); long totalCount = countResult == null || countResult.isEmpty() ? 0 : countResult.get(0).count;