DATACOUCH-164 - Use stable Couchbase SDK

Make modifications due to name changing in 2.2.0, the latest stable release of the Couchbase SDK.
This commit is contained in:
Simon Baslé
2015-09-21 16:46:51 +02:00
parent f661bad73b
commit 7654af7608
12 changed files with 126 additions and 134 deletions

View File

@@ -27,7 +27,7 @@ import com.couchbase.client.java.CouchbaseCluster;
import com.couchbase.client.java.cluster.ClusterInfo;
import com.couchbase.client.java.env.CouchbaseEnvironment;
import com.couchbase.client.java.env.DefaultCouchbaseEnvironment;
import com.couchbase.client.java.query.Query;
import com.couchbase.client.java.query.N1qlQuery;
import com.couchbase.client.java.view.ViewQuery;
import org.springframework.beans.factory.config.BeanDefinition;
@@ -268,7 +268,7 @@ public abstract class AbstractCouchbaseConfiguration {
/**
* Configures the default consistency for generated {@link ViewQuery view queries}
* and {@link Query N1QL queries} in repositories.
* and {@link N1qlQuery N1QL queries} in repositories.
*
* @return the {@link Consistency consistency} to apply by default on generated queries.
*/

View File

@@ -250,8 +250,8 @@ public class CouchbaseEnvironmentNoShutdownProxy implements CouchbaseEnvironment
}
@Override
public MetricsCollector systemMetricsCollector() {
return delegate.systemMetricsCollector();
public MetricsCollector runtimeMetricsCollector() {
return delegate.runtimeMetricsCollector();
}
@Override

View File

@@ -24,9 +24,9 @@ import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.PersistTo;
import com.couchbase.client.java.ReplicateTo;
import com.couchbase.client.java.cluster.ClusterInfo;
import com.couchbase.client.java.query.Query;
import com.couchbase.client.java.query.QueryParams;
import com.couchbase.client.java.query.QueryResult;
import com.couchbase.client.java.query.N1qlQuery;
import com.couchbase.client.java.query.N1qlQueryResult;
import com.couchbase.client.java.query.N1qlParams;
import com.couchbase.client.java.query.Statement;
import com.couchbase.client.java.view.ViewQuery;
import com.couchbase.client.java.view.ViewResult;
@@ -219,11 +219,11 @@ public interface CouchbaseOperations {
* {@value #SELECT_CAS} (document id and cas, obtained through N1QL's
* "{@code META(bucket).id AS} {@value #SELECT_ID}" and
* "{@code META(bucket).cas AS} {@value #SELECT_CAS}").
* <p>This is done via a {@link Query} that contains a {@link Statement} and possibly
* additional query parameters ({@link QueryParams}) and placeholder values if the
* <p>This is done via a {@link N1qlQuery} that contains a {@link Statement} and possibly
* additional query parameters ({@link N1qlParams}) and placeholder values if the
* statement contains placeholders.
* <br/>
* Use {@link Query}'s factory methods to construct such a Query.</p>
* Use {@link N1qlQuery}'s factory methods to construct such a Query.</p>
*
* @param n1ql the N1QL query.
* @param entityClass the target class for the returned entities.
@@ -231,38 +231,38 @@ public interface CouchbaseOperations {
* @return the list of entities matching this query.
* @throws CouchbaseQueryExecutionException if the id and cas are not selected.
*/
<T> List<T> findByN1QL(Query n1ql, Class<T> entityClass);
<T> List<T> findByN1QL(N1qlQuery n1ql, Class<T> entityClass);
/**
* Query the N1QL Service for partial JSON data of type T. The selected field will be
* used in a {@link TranslationService#decodeFragment(String, Class) straightforward decoding}
* (no document, metadata like id nor cas) to map to a "fragment class".
* <p>This is done via a {@link Query} that contains a {@link Statement} and possibly
* additional query parameters ({@link QueryParams}) and placeholder values if the
* <p>This is done via a {@link N1qlQuery} that contains a {@link Statement} and possibly
* additional query parameters ({@link N1qlParams}) and placeholder values if the
* statement contains placeholders.
* <br/>
* Use {@link Query}'s factory methods to construct such a Query.</p>
* Use {@link N1qlQuery}'s factory methods to construct such a Query.</p>
*
* @param n1ql the N1QL query.
* @param fragmentClass the target class for the returned fragments.
* @param <T> the fragment class
* @return the list of entities matching this query.
*/
<T> List<T> findByN1QLProjection(Query n1ql, Class<T> fragmentClass);
<T> List<T> findByN1QLProjection(N1qlQuery n1ql, Class<T> fragmentClass);
/**
* Query the N1QL Service with direct access to the {@link QueryResult}.
* Query the N1QL Service with direct access to the {@link N1qlQueryResult}.
* <p>
* This is done via a {@link Query} that can
* contain a {@link Statement}, additional query parameters ({@link QueryParams})
* This is done via a {@link N1qlQuery} that can
* contain a {@link Statement}, additional query parameters ({@link N1qlParams})
* and placeholder values if the statement contains placeholders.</p>
* <p>
* Use {@link Query}'s factory methods to construct this.</p>
* Use {@link N1qlQuery}'s factory methods to construct this.</p>
*
* @param n1ql the N1QL query.
* @return {@link QueryResult} containing the results of the n1ql query.
* @return {@link N1qlQueryResult} containing the results of the n1ql query.
*/
QueryResult queryN1QL(Query n1ql);
N1qlQueryResult queryN1QL(N1qlQuery n1ql);
/**
* Checks if the given document exists.

View File

@@ -35,10 +35,10 @@ import com.couchbase.client.java.document.RawJsonDocument;
import com.couchbase.client.java.document.json.JsonObject;
import com.couchbase.client.java.error.CASMismatchException;
import com.couchbase.client.java.error.TranscodingException;
import com.couchbase.client.java.query.Query;
import com.couchbase.client.java.query.QueryParams;
import com.couchbase.client.java.query.QueryResult;
import com.couchbase.client.java.query.QueryRow;
import com.couchbase.client.java.query.N1qlQuery;
import com.couchbase.client.java.query.N1qlQueryResult;
import com.couchbase.client.java.query.N1qlQueryRow;
import com.couchbase.client.java.query.N1qlParams;
import com.couchbase.client.java.query.consistency.ScanConsistency;
import com.couchbase.client.java.util.features.CouchbaseFeature;
import com.couchbase.client.java.view.ViewQuery;
@@ -327,15 +327,15 @@ public class CouchbaseTemplate implements CouchbaseOperations, ApplicationEventP
}
@Override
public <T> List<T> findByN1QL(Query n1ql, Class<T> entityClass) {
public <T> List<T> findByN1QL(N1qlQuery n1ql, Class<T> entityClass) {
checkN1ql();
try {
QueryResult queryResult = queryN1QL(n1ql);
N1qlQueryResult queryResult = queryN1QL(n1ql);
if (queryResult.finalSuccess()) {
List<QueryRow> allRows = queryResult.allRows();
List<N1qlQueryRow> allRows = queryResult.allRows();
List<T> result = new ArrayList<T>(allRows.size());
for (QueryRow row : allRows) {
for (N1qlQueryRow row : allRows) {
JsonObject json = row.value();
String id = json.getString(SELECT_ID);
Long cas = json.getLong(SELECT_CAS);
@@ -364,15 +364,15 @@ public class CouchbaseTemplate implements CouchbaseOperations, ApplicationEventP
}
@Override
public <T> List<T> findByN1QLProjection(Query n1ql, Class<T> entityClass) {
public <T> List<T> findByN1QLProjection(N1qlQuery n1ql, Class<T> entityClass) {
checkN1ql();
try {
QueryResult queryResult = queryN1QL(n1ql);
N1qlQueryResult queryResult = queryN1QL(n1ql);
if (queryResult.finalSuccess()) {
List<QueryRow> allRows = queryResult.allRows();
List<N1qlQueryRow> allRows = queryResult.allRows();
List<T> result = new ArrayList<T>(allRows.size());
for (QueryRow row : allRows) {
for (N1qlQueryRow row : allRows) {
JsonObject json = row.value();
T decoded = translationService.decodeFragment(json.toString(), entityClass);
result.add(decoded);
@@ -393,11 +393,11 @@ public class CouchbaseTemplate implements CouchbaseOperations, ApplicationEventP
}
@Override
public QueryResult queryN1QL(final Query query) {
public N1qlQueryResult queryN1QL(final N1qlQuery query) {
checkN1ql();
return execute(new BucketCallback<QueryResult>() {
return execute(new BucketCallback<N1qlQueryResult>() {
@Override
public QueryResult doInBucket() throws TimeoutException, ExecutionException, InterruptedException {
public N1qlQueryResult doInBucket() throws TimeoutException, ExecutionException, InterruptedException {
return client.query(query);
}
});

View File

@@ -16,7 +16,7 @@
package org.springframework.data.couchbase.core.convert.translation;
import com.couchbase.client.java.query.QueryRow;
import com.couchbase.client.java.query.N1qlQueryRow;
import org.springframework.data.couchbase.core.mapping.CouchbaseDocument;
import org.springframework.data.couchbase.core.mapping.CouchbaseStorable;
@@ -48,7 +48,7 @@ public interface TranslationService {
/**
* Decodes an ad-hoc JSON object into a corresponding "case" class.
*
* @param source the JSON for the ad-hoc JSON object (from a N1QL {@link QueryRow} for instance).
* @param source the JSON for the ad-hoc JSON object (from a N1QL {@link N1qlQueryRow} for instance).
* @param target the target class information.
* @param <T> the target class.
* @return an ad-hoc instance of the decoded JSON into the corresponding "case" class.

View File

@@ -19,9 +19,9 @@ package org.springframework.data.couchbase.repository.query;
import java.util.List;
import com.couchbase.client.java.document.json.JsonArray;
import com.couchbase.client.java.query.Query;
import com.couchbase.client.java.query.QueryParams;
import com.couchbase.client.java.query.QueryResult;
import com.couchbase.client.java.query.N1qlQuery;
import com.couchbase.client.java.query.N1qlQueryResult;
import com.couchbase.client.java.query.N1qlParams;
import com.couchbase.client.java.query.Statement;
import com.couchbase.client.java.query.consistency.ScanConsistency;
import org.slf4j.Logger;
@@ -41,7 +41,7 @@ import org.springframework.util.Assert;
/**
* Abstract base for all Couchbase {@link RepositoryQuery}. It is in charge of inspecting the parameters
* and choosing the correct {@link Query} implementation to use.
* and choosing the correct {@link N1qlQuery} implementation to use.
*/
public abstract class AbstractN1qlBasedQuery implements RepositoryQuery {
@@ -68,32 +68,32 @@ public abstract class AbstractN1qlBasedQuery implements RepositoryQuery {
JsonArray queryPlaceholderValues = getPlaceholderValues(accessor);
//prepare the final query
Query query = buildQuery(statement, queryPlaceholderValues,
N1qlQuery query = buildQuery(statement, queryPlaceholderValues,
getCouchbaseOperations().getDefaultConsistency().n1qlConsistency());
//prepare a count query
//TODO only do that when necessary (isPageQuery or isSliceQuery)
Statement countStatement = getCount(accessor);
Query countQuery = buildQuery(countStatement, queryPlaceholderValues,
N1qlQuery countQuery = buildQuery(countStatement, queryPlaceholderValues,
getCouchbaseOperations().getDefaultConsistency().n1qlConsistency());
return executeDependingOnType(query, countQuery, queryMethod, accessor.getPageable(),
queryMethod.isPageQuery(), queryMethod.isSliceQuery(), queryMethod.isModifyingQuery());
}
protected static Query buildQuery(Statement statement, JsonArray queryPlaceholderValues, ScanConsistency scanConsistency) {
QueryParams queryParams = QueryParams.build().consistency(scanConsistency);
Query query;
protected static N1qlQuery buildQuery(Statement statement, JsonArray queryPlaceholderValues, ScanConsistency scanConsistency) {
N1qlParams n1qlParams = N1qlParams.build().consistency(scanConsistency);
N1qlQuery query;
if (!queryPlaceholderValues.isEmpty()) {
query = Query.parameterized(statement, queryPlaceholderValues, queryParams);
query = N1qlQuery.parameterized(statement, queryPlaceholderValues, n1qlParams);
}
else {
query = Query.simple(statement, queryParams);
query = N1qlQuery.simple(statement, n1qlParams);
}
return query;
}
protected Object executeDependingOnType(Query query, Query countQuery, QueryMethod queryMethod, Pageable pageable,
protected Object executeDependingOnType(N1qlQuery query, N1qlQuery countQuery, QueryMethod queryMethod, Pageable pageable,
boolean isPage, boolean isSlice, boolean isModifying) {
if (isModifying) {
throw new UnsupportedOperationException("Modifying queries not yet supported");
@@ -112,30 +112,30 @@ public abstract class AbstractN1qlBasedQuery implements RepositoryQuery {
}
}
private void logIfNecessary(Query query) {
private void logIfNecessary(N1qlQuery query) {
if (LOG.isDebugEnabled()) {
LOG.debug("Executing N1QL query: " + query.n1ql());
}
}
protected List<?> executeCollection(Query query) {
protected List<?> executeCollection(N1qlQuery query) {
logIfNecessary(query);
List<?> result = couchbaseOperations.findByN1QL(query, queryMethod.getEntityInformation().getJavaType());
return result;
}
protected Object executeEntity(Query query) {
protected Object executeEntity(N1qlQuery query) {
logIfNecessary(query);
List<?> result = executeCollection(query);
return result.isEmpty() ? null : result.get(0);
}
protected Object executeStream(Query query) {
protected Object executeStream(N1qlQuery query) {
logIfNecessary(query);
return StreamUtils.createStreamFromIterator(executeCollection(query).iterator());
}
protected Object executePaged(Query query, Query countQuery, Pageable pageable) {
protected Object executePaged(N1qlQuery query, N1qlQuery countQuery, Pageable pageable) {
Assert.notNull(pageable);
long total = 0L;
logIfNecessary(countQuery);
@@ -149,7 +149,7 @@ public abstract class AbstractN1qlBasedQuery implements RepositoryQuery {
return new PageImpl(result, pageable, total);
}
protected Object executeSliced(Query query, Query countQuery, Pageable pageable) {
protected Object executeSliced(N1qlQuery query, N1qlQuery countQuery, Pageable pageable) {
Assert.notNull(pageable);
logIfNecessary(query);
List<?> result = couchbaseOperations.findByN1QL(query, queryMethod.getEntityInformation().getJavaType());

View File

@@ -17,7 +17,7 @@
package org.springframework.data.couchbase.repository.query;
import com.couchbase.client.java.document.json.JsonArray;
import com.couchbase.client.java.query.Query;
import com.couchbase.client.java.query.N1qlQuery;
import com.couchbase.client.java.query.Statement;
import org.springframework.data.couchbase.core.CouchbaseOperations;
@@ -99,7 +99,7 @@ public class StringN1qlBasedQuery extends AbstractN1qlBasedQuery {
result = result.replaceFirst("\\$FILTER_TYPE\\$", typeSelection);
}
return Query.simple(result).statement();
return N1qlQuery.simple(result).statement();
}
@Override

View File

@@ -19,7 +19,7 @@ package org.springframework.data.couchbase.repository.support;
import java.io.Serializable;
import java.util.List;
import com.couchbase.client.java.query.Query;
import com.couchbase.client.java.query.N1qlQuery;
import com.couchbase.client.java.query.Statement;
import com.couchbase.client.java.query.dsl.Expression;
import com.couchbase.client.java.query.dsl.path.WherePath;
@@ -68,7 +68,7 @@ public class N1qlCouchbaseRepository<T, ID extends Serializable>
Statement st = selectFrom.where(whereCriteria).orderBy(orderings);
//fire the query
Query query = Query.simple(st);
N1qlQuery query = N1qlQuery.simple(st);
return getCouchbaseOperations().findByN1QL(query, getEntityInformation().getJavaType());
}
@@ -82,7 +82,7 @@ public class N1qlCouchbaseRepository<T, ID extends Serializable>
//TODO how to avoid to do that more than once?
//fire the count query and get total count
List<CountFragment> countResult = getCouchbaseOperations().findByN1QLProjection(Query.simple(countStatement), CountFragment.class);
List<CountFragment> countResult = getCouchbaseOperations().findByN1QLProjection(N1qlQuery.simple(countStatement), CountFragment.class);
long totalCount = countResult == null || countResult.isEmpty() ? 0 : countResult.get(0).count;
//prepare elements of the data query
@@ -94,7 +94,7 @@ public class N1qlCouchbaseRepository<T, ID extends Serializable>
Statement pageStatement = selectFrom.where(whereCriteria).limit(pageable.getPageSize()).offset(pageable.getOffset());
//fire the query
Query query = Query.simple(pageStatement);
N1qlQuery query = N1qlQuery.simple(pageStatement);
List<T> pageContent = getCouchbaseOperations().findByN1QL(query, getEntityInformation().getJavaType());
//return the list as a Page