com.couchbase.spark.japi.CouchbaseDocumentRDD Maven / Gradle / Ivy
/*
* Copyright (c) 2015 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.spark.japi;
import com.couchbase.client.java.document.Document;
import com.couchbase.spark.DocumentRDDFunctions;
import com.couchbase.spark.StoreMode;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.rdd.RDD;
import scala.concurrent.duration.Duration;
import scala.reflect.ClassTag;
import java.util.concurrent.TimeUnit;
public class CouchbaseDocumentRDD> extends JavaRDD {
private final JavaRDD source;
protected CouchbaseDocumentRDD(JavaRDD source) {
super(source.rdd(), source.classTag());
this.source = source;
}
public static > CouchbaseDocumentRDD couchbaseDocumentRDD(RDD source) {
return couchbaseDocumentRDD(source.toJavaRDD());
}
public static > CouchbaseDocumentRDD couchbaseDocumentRDD(JavaRDD source) {
return new CouchbaseDocumentRDD(source);
}
public void saveToCouchbase() {
saveToCouchbase(StoreMode.UPSERT, null);
}
public void saveToCouchbase(StoreMode storeMode) {
saveToCouchbase(storeMode, null);
}
public void saveToCouchbase(String bucket) {
saveToCouchbase(StoreMode.UPSERT, bucket);
}
public void saveToCouchbase(StoreMode storeMode, String bucket) {
new DocumentRDDFunctions(source.rdd()).saveToCouchbase(bucket, storeMode,
scala.Option.apply(null),
DocumentRDDFunctions.MaxConcurrentDefault());
}
public void saveToCouchbase(long timeout) {
saveToCouchbase(StoreMode.UPSERT, null, timeout);
}
public void saveToCouchbase(StoreMode storeMode, long timeout) {
saveToCouchbase(storeMode, null, timeout);
}
public void saveToCouchbase(String bucket, long timeout) {
saveToCouchbase(StoreMode.UPSERT, bucket, timeout);
}
public void saveToCouchbase(StoreMode storeMode, String bucket, long timeout) {
new DocumentRDDFunctions(source.rdd()).saveToCouchbase(bucket, storeMode,
scala.Option.apply(Duration.create(timeout, TimeUnit.MILLISECONDS)),
DocumentRDDFunctions.MaxConcurrentDefault());
}
public void saveToCouchbase(StoreMode storeMode, String bucket, long timeout, int maxConcurrent) {
new DocumentRDDFunctions(source.rdd()).saveToCouchbase(bucket, storeMode,
scala.Option.apply(Duration.create(timeout, TimeUnit.MILLISECONDS)),
maxConcurrent);
}
@Override
public RDD rdd() {
return source.rdd();
}
@Override
public ClassTag classTag() {
return source.classTag();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy