com.couchbase.client.java.kv.ArrayAddUnique Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-client Show documentation
Show all versions of java-client Show documentation
The official Couchbase Java SDK
/*
* Copyright (c) 2019 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.kv;
import com.couchbase.client.core.api.kv.CoreSubdocMutateCommand;
import com.couchbase.client.core.msg.kv.SubdocCommandType;
import com.couchbase.client.java.codec.JsonSerializer;
/**
* An intention to perform a SubDocument array add-unique operation.
*
* @author Graham Pople
* @since 1.0.0
*/
public class ArrayAddUnique extends MutateInSpec {
private final String path;
private final Object doc;
private boolean xattr = false;
private boolean expandMacro = false;
private boolean createPath = false;
ArrayAddUnique(String path, Object doc) {
this.path = path;
if (doc instanceof MutateInMacro) {
this.doc = ((MutateInMacro) doc).value();
expandMacro = true;
xattr = true;
}
else {
this.doc = doc;
}
}
/**
* Sets that this is an extended attribute (xattr) field.
* @return this, for chaining
*/
public ArrayAddUnique xattr() {
xattr = true;
return this;
}
/**
* Sets that this parent fields should be created automatically.
* @return this, for chaining
*/
public ArrayAddUnique createPath() {
createPath = true;
return this;
}
@Override
public CoreSubdocMutateCommand toCore(JsonSerializer serializer) {
return new CoreSubdocMutateCommand(
SubdocCommandType.ARRAY_ADD_UNIQUE,
path,
serializer.serialize(doc),
createPath,
xattr,
expandMacro
);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy