@PostConstruct private void postConstruct() { // Need to post-process travel data to add _class attribute List<Airline> airlinesWithoutClassAttribute = couchbaseOperations.findByN1QL(N1qlQuery.simple( // "SELECT META(`travel-sample`).id AS _ID, META(`travel-sample`).cas AS _CAS, `travel-sample`.* " + // "FROM `travel-sample` " + // "WHERE type = \"airline\" AND _class IS MISSING;"), Airline.class); airlinesWithoutClassAttribute.forEach(couchbaseOperations::save); } }
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); }
@PostConstruct private void postConstruct() { // Need to post-process travel data to add _class attribute CouchbaseOperations couchbaseOperations = couchbaseOperationsProvider.getIfUnique(); List<Airline> airlinesWithoutClassAttribute = couchbaseOperations.findByN1QL(N1qlQuery.simple( // "SELECT META(`travel-sample`).id AS _ID, META(`travel-sample`).cas AS _CAS, `travel-sample`.* " + // "FROM `travel-sample` " + // "WHERE type = \"airline\" AND _class IS MISSING;"), Airline.class); airlinesWithoutClassAttribute.forEach(couchbaseOperations::save); } }
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 List<?> executeCollection(N1qlQuery query, Class<?> typeToRead) { logIfNecessary(query); List<?> result = couchbaseOperations.findByN1QL(query, typeToRead); return result; }
List<T> pageContent = getCouchbaseOperations().findByN1QL(query, getEntityInformation().getJavaType());
protected List<?> executeCollection(N1qlQuery query, Class<?> typeToRead) { logIfNecessary(query); List<?> result = couchbaseOperations.findByN1QL(query, typeToRead); return result; }
List<T> pageContent = getCouchbaseOperations().findByN1QL(query, getEntityInformation().getJavaType());
protected Object executeSliced(N1qlQuery query, N1qlQuery countQuery, Pageable pageable, Class<?> typeToRead) { Assert.notNull(pageable, "Pageable must not be null!"); logIfNecessary(query); List<?> result = couchbaseOperations.findByN1QL(query, typeToRead); int pageSize = pageable.getPageSize(); boolean hasNext = result.size() > pageSize; return new SliceImpl(hasNext ? result.subList(0, pageSize) : result, pageable, hasNext); }
protected Object executeSliced(N1qlQuery query, N1qlQuery countQuery, Pageable pageable, Class<?> typeToRead) { Assert.notNull(pageable, "Pageable must not be null!"); logIfNecessary(query); List<?> result = couchbaseOperations.findByN1QL(query, typeToRead); int pageSize = pageable.getPageSize(); boolean hasNext = result.size() > pageSize; return new SliceImpl(hasNext ? result.subList(0, pageSize) : result, pageable, hasNext); }
@Override public Iterable<T> findAll(Sort sort) { Assert.notNull(sort, "Sort must not be null!"); //prepare elements of the query WherePath selectFrom = N1qlUtils.createSelectFromForEntity(getCouchbaseOperations().getCouchbaseBucket().name()); Expression whereCriteria = N1qlUtils.createWhereFilterForEntity(null, getCouchbaseOperations().getConverter(), getEntityInformation()); //apply the sort com.couchbase.client.java.query.dsl.Sort[] orderings = N1qlUtils.createSort(sort, getCouchbaseOperations().getConverter()); Statement st = selectFrom.where(whereCriteria).orderBy(orderings); //fire the query ScanConsistency consistency = getCouchbaseOperations().getDefaultConsistency().n1qlConsistency(); N1qlQuery query = N1qlQuery.simple(st, N1qlParams.build().consistency(consistency)); return getCouchbaseOperations().findByN1QL(query, getEntityInformation().getJavaType()); }
@Override public Iterable<T> findAll(Sort sort) { Assert.notNull(sort, "Sort must not be null!"); //prepare elements of the query WherePath selectFrom = N1qlUtils.createSelectFromForEntity(getCouchbaseOperations().getCouchbaseBucket().name()); Expression whereCriteria = N1qlUtils.createWhereFilterForEntity(null, getCouchbaseOperations().getConverter(), getEntityInformation()); //apply the sort com.couchbase.client.java.query.dsl.Sort[] orderings = N1qlUtils.createSort(sort, getCouchbaseOperations().getConverter()); Statement st = selectFrom.where(whereCriteria).orderBy(orderings); //fire the query ScanConsistency consistency = getCouchbaseOperations().getDefaultConsistency().n1qlConsistency(); N1qlQuery query = N1qlQuery.simple(st, N1qlParams.build().consistency(consistency)); return getCouchbaseOperations().findByN1QL(query, getEntityInformation().getJavaType()); }