Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 2017 Couchbase, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.couchbase.client.java.analytics;
import com.couchbase.client.core.ClusterFacade;
import com.couchbase.client.core.logging.CouchbaseLogger;
import com.couchbase.client.core.logging.CouchbaseLoggerFactory;
import com.couchbase.client.core.message.analytics.GenericAnalyticsRequest;
import com.couchbase.client.core.message.analytics.GenericAnalyticsResponse;
import com.couchbase.client.core.time.Delay;
import com.couchbase.client.deps.io.netty.buffer.ByteBuf;
import com.couchbase.client.java.bucket.api.Utils;
import com.couchbase.client.java.document.json.JsonObject;
import com.couchbase.client.java.env.CouchbaseEnvironment;
import com.couchbase.client.java.error.CannotRetryException;
import com.couchbase.client.java.error.QueryExecutionException;
import com.couchbase.client.java.error.TemporaryFailureException;
import com.couchbase.client.java.error.TranscodingException;
import com.couchbase.client.java.transcoder.TranscoderUtils;
import com.couchbase.client.java.util.retry.RetryBuilder;
import io.opentracing.tag.Tags;
import rx.Observable;
import rx.Subscriber;
import rx.functions.Action4;
import rx.functions.Func1;
import rx.functions.Func5;
import rx.functions.Func6;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
import static com.couchbase.client.java.CouchbaseAsyncBucket.JSON_OBJECT_TRANSCODER;
import static com.couchbase.client.java.bucket.api.Utils.applyTimeout;
import static com.couchbase.client.java.util.OnSubscribeDeferAndWatch.deferAndWatch;
public class AnalyticsQueryExecutor {
/**
* The logger used.
*/
private static CouchbaseLogger LOGGER = CouchbaseLoggerFactory.getInstance(AnalyticsQueryExecutor.class);
private static final String ERROR_FIELD_CODE = "code";
private final ClusterFacade core;
private final String bucket;
private final String username;
private final String password;
public AnalyticsQueryExecutor(ClusterFacade core, String bucket, String username, String password) {
this.core = core;
this.bucket = bucket;
this.username = username;
this.password = password;
}
public Observable execute(final AnalyticsQuery query, final CouchbaseEnvironment env,
final long timeout, final TimeUnit timeUnit) {
return deferAndWatch(new Func1>() {
@Override
public Observable call(final Subscriber subscriber) {
GenericAnalyticsRequest request = GenericAnalyticsRequest
.jsonQuery(query.query().toString(), bucket, username, password, query.params().priority());
Utils.addRequestSpan(env, request, "analytics");
if (env.operationTracingEnabled()) {
request.span().setTag(Tags.DB_STATEMENT.getKey(), query.statement());
}
request.subscriber(subscriber);
return applyTimeout(core.send(request), request, env, timeout, timeUnit);
}
}).flatMap(new Func1>() {
@Override
public Observable call(final GenericAnalyticsResponse response) {
final Observable