@Override public long count() { final ResolvedView resolvedView = determineView(); ViewQuery query = ViewQuery.from(resolvedView.getDesignDocument(), resolvedView.getViewName()); query.reduce(true); query.stale(getCouchbaseOperations().getDefaultConsistency().viewConsistency()); ViewResult response = couchbaseOperations.queryView(query); long count = 0; for (ViewRow row : response) { count += Long.parseLong(String.valueOf(row.value())); } return count; }
@Override public <S extends T> Iterable<S> saveAll(Iterable<S> entities) { Assert.notNull(entities, "The given Iterable of entities must not be null!"); List<S> result = new ArrayList<S>(); for (S entity : entities) { save(entity); result.add(entity); } return result; }
/** * Returns a new Repository based on the metadata. Two categories of repositories can be instantiated: * {@link SimpleCouchbaseRepository} and {@link N1qlCouchbaseRepository}. * * This method performs feature checks to decide which of the two categories can be instantiated (eg. is N1QL available?). * Instantiation is done via reflection, see {@link #getRepositoryBaseClass(RepositoryMetadata)}. * * @param metadata the repository metadata. * * @return a new created repository. */ @Override protected final Object getTargetRepository(final RepositoryInformation metadata) { CouchbaseOperations couchbaseOperations = couchbaseOperationsMapping.resolve(metadata.getRepositoryInterface(), metadata.getDomainType()); boolean isN1qlAvailable = couchbaseOperations.getCouchbaseClusterInfo().checkAvailable(CouchbaseFeature.N1QL); ViewIndexed viewIndexed = AnnotationUtils.findAnnotation(metadata.getRepositoryInterface(), ViewIndexed.class); N1qlPrimaryIndexed n1qlPrimaryIndexed = AnnotationUtils.findAnnotation(metadata.getRepositoryInterface(), N1qlPrimaryIndexed.class); N1qlSecondaryIndexed n1qlSecondaryIndexed = AnnotationUtils.findAnnotation(metadata.getRepositoryInterface(), N1qlSecondaryIndexed.class); checkFeatures(metadata, isN1qlAvailable, n1qlPrimaryIndexed, n1qlSecondaryIndexed); indexManager.buildIndexes(metadata, viewIndexed, n1qlPrimaryIndexed, n1qlSecondaryIndexed, couchbaseOperations); CouchbaseEntityInformation<?, Serializable> entityInformation = getEntityInformation(metadata.getDomainType()); SimpleCouchbaseRepository repo = getTargetRepositoryViaReflection(metadata, entityInformation, couchbaseOperations); repo.setViewMetadataProvider(viewPostProcessor.getViewMetadataProvider()); return repo; }
/** * Returns a new Repository based on the metadata. Two categories of repositories can be instantiated: * {@link SimpleCouchbaseRepository} and {@link N1qlCouchbaseRepository}. * * This method performs feature checks to decide which of the two categories can be instantiated (eg. is N1QL available?). * Instantiation is done via reflection, see {@link #getRepositoryBaseClass(RepositoryMetadata)}. * * @param metadata the repository metadata. * * @return a new created repository. */ @Override protected final Object getTargetRepository(final RepositoryInformation metadata) { CouchbaseOperations couchbaseOperations = couchbaseOperationsMapping.resolve(metadata.getRepositoryInterface(), metadata.getDomainType()); boolean isN1qlAvailable = couchbaseOperations.getCouchbaseClusterInfo().checkAvailable(CouchbaseFeature.N1QL); ViewIndexed viewIndexed = AnnotationUtils.findAnnotation(metadata.getRepositoryInterface(), ViewIndexed.class); N1qlPrimaryIndexed n1qlPrimaryIndexed = AnnotationUtils.findAnnotation(metadata.getRepositoryInterface(), N1qlPrimaryIndexed.class); N1qlSecondaryIndexed n1qlSecondaryIndexed = AnnotationUtils.findAnnotation(metadata.getRepositoryInterface(), N1qlSecondaryIndexed.class); checkFeatures(metadata, isN1qlAvailable, n1qlPrimaryIndexed, n1qlSecondaryIndexed); indexManager.buildIndexes(metadata, viewIndexed, n1qlPrimaryIndexed, n1qlSecondaryIndexed, couchbaseOperations); CouchbaseEntityInformation<?, Serializable> entityInformation = getEntityInformation(metadata.getDomainType()); SimpleCouchbaseRepository repo = getTargetRepositoryViaReflection(metadata, entityInformation, couchbaseOperations); repo.setViewMetadataProvider(viewPostProcessor.getViewMetadataProvider()); return repo; }
@Override public long count() { final ResolvedView resolvedView = determineView(); ViewQuery query = ViewQuery.from(resolvedView.getDesignDocument(), resolvedView.getViewName()); query.reduce(true); query.stale(getCouchbaseOperations().getDefaultConsistency().viewConsistency()); ViewResult response = couchbaseOperations.queryView(query); long count = 0; for (ViewRow row : response) { count += Long.parseLong(String.valueOf(row.value())); } return count; }
@Override public <S extends T> Iterable<S> saveAll(Iterable<S> entities) { Assert.notNull(entities, "The given Iterable of entities must not be null!"); List<S> result = new ArrayList<S>(); for (S entity : entities) { save(entity); result.add(entity); } return result; }
@Override public Iterable<T> findAll() { final ResolvedView resolvedView = determineView(); ViewQuery query = ViewQuery.from(resolvedView.getDesignDocument(), resolvedView.getViewName()); query.reduce(false); query.stale(getCouchbaseOperations().getDefaultConsistency().viewConsistency()); return couchbaseOperations.findByView(query, entityInformation.getJavaType()); }
@Override public Iterable<T> findAll() { final ResolvedView resolvedView = determineView(); ViewQuery query = ViewQuery.from(resolvedView.getDesignDocument(), resolvedView.getViewName()); query.reduce(false); query.stale(getCouchbaseOperations().getDefaultConsistency().viewConsistency()); return couchbaseOperations.findByView(query, entityInformation.getJavaType()); }
@Override public void deleteAll() { final ResolvedView resolvedView = determineView(); ViewQuery query = ViewQuery.from(resolvedView.getDesignDocument(), resolvedView.getViewName()); query.reduce(false); query.stale(getCouchbaseOperations().getDefaultConsistency().viewConsistency()); ViewResult response = couchbaseOperations.queryView(query); for (ViewRow row : response) { try { couchbaseOperations.remove(row.id()); } catch (DataRetrievalFailureException e) { //ignore stale deletions if (!(e.getCause() instanceof DocumentDoesNotExistException)) throw e; } } }
@Override public void deleteAll() { final ResolvedView resolvedView = determineView(); ViewQuery query = ViewQuery.from(resolvedView.getDesignDocument(), resolvedView.getViewName()); query.reduce(false); query.stale(getCouchbaseOperations().getDefaultConsistency().viewConsistency()); ViewResult response = couchbaseOperations.queryView(query); for (ViewRow row : response) { try { couchbaseOperations.remove(row.id()); } catch (DataRetrievalFailureException e) { //ignore stale deletions if (!(e.getCause() instanceof DocumentDoesNotExistException)) throw e; } } }
@Override public Iterable<T> findAllById(final Iterable<ID> ids) { final ResolvedView resolvedView = determineView(); ViewQuery query = ViewQuery.from(resolvedView.getDesignDocument(), resolvedView.getViewName()); query.reduce(false); query.stale(getCouchbaseOperations().getDefaultConsistency().viewConsistency()); JsonArray keys = JsonArray.create(); for (ID id : ids) { keys.add(couchbaseOperations.getConverter().convertForWriteIfNeeded(id)); } query.keys(keys); return couchbaseOperations.findByView(query, entityInformation.getJavaType()); }
@Override public Iterable<T> findAllById(final Iterable<ID> ids) { final ResolvedView resolvedView = determineView(); ViewQuery query = ViewQuery.from(resolvedView.getDesignDocument(), resolvedView.getViewName()); query.reduce(false); query.stale(getCouchbaseOperations().getDefaultConsistency().viewConsistency()); JsonArray keys = JsonArray.create(); for (ID id : ids) { keys.add(couchbaseOperations.getConverter().convertForWriteIfNeeded(id)); } query.keys(keys); return couchbaseOperations.findByView(query, entityInformation.getJavaType()); }