You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by GitBox <gi...@apache.org> on 2020/03/25 05:27:46 UTC

[GitHub] [hbase] saintstack commented on a change in pull request #1320: HBASE-8458 Support for batch version of checkAndPut() and checkAndDel…

saintstack commented on a change in pull request #1320: HBASE-8458 Support for batch version of checkAndPut() and checkAndDel…
URL: https://github.com/apache/hbase/pull/1320#discussion_r397612277
 
 

 ##########
 File path: hbase-client/src/main/java/org/apache/hadoop/hbase/CheckAndMutate.java
 ##########
 @@ -0,0 +1,312 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.hadoop.hbase;
+
+import org.apache.hadoop.hbase.client.Delete;
+import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.client.Row;
+import org.apache.hadoop.hbase.client.RowMutations;
+import org.apache.hadoop.hbase.filter.Filter;
+import org.apache.hadoop.hbase.io.TimeRange;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hbase.thirdparty.com.google.common.base.Preconditions;
+import org.apache.yetus.audience.InterfaceAudience;
+
+
+/**
+ * Used to perform batch CheckAndMutate operations.
+ *
+ * Use the builder classes to instantiate a CheckAndMutate object.
+ * This builder classes are fluent style APIs, the code are like:
+ *
+ * <pre>
+ * <code>
+ * CheckAndMutate checkAndMutate = CheckAndMutate.builder(row, family).qualifier(qualifier)
+ *   .ifNotExists().build(put);
+ * </code>
+ * <code>
+ * CheckAndMutate checkAndMutate = CheckAndMutate.builder(row, filter).build(put);
+ * </code>
+ * </pre>
+ */
+@InterfaceAudience.Public
+public class CheckAndMutate implements Row {
+
+  /**
+   * A builder class for building a CheckAndMutate object.
+   */
+  public static class Builder {
+    private final byte[] row;
+    private final byte[] family;
+    private byte[] qualifier;
+    private CompareOperator op;
+    private byte[] value;
+    private TimeRange timeRange;
+
+    private Builder(byte[] row, byte[] family) {
+      this.row = Preconditions.checkNotNull(row, "row is null");
+      this.family = Preconditions.checkNotNull(family, "family is null");
+    }
+
+    /**
+     * @param qualifier column qualifier to check
+     * @return the builder object
+     */
+    public Builder qualifier(byte[] qualifier) {
+      this.qualifier = Preconditions.checkNotNull(qualifier, "qualifier is null. Consider using" +
+        " an empty byte array, or just do not call this method if you want a null qualifier");
+      return this;
+    }
+
+    /**
+     * @param timeRange timeRange to check
+     * @return the builder object
+     */
+    public Builder timeRange(TimeRange timeRange) {
+      this.timeRange = timeRange;
+      return this;
+    }
+
+    /**
+     * Check for lack of column
+     * @return the builder object
+     */
+    public Builder ifNotExists() {
+      this.op = CompareOperator.EQUAL;
+      this.value = null;
+      return this;
+    }
+
+    /**
+     * Check for equality
+     * @param value the expected value
+     * @return the builder object
+     */
+    public Builder ifEquals(byte[] value) {
+      return ifMatches(CompareOperator.EQUAL, value);
+    }
+
+    /**
+     * @param compareOp comparison operator to use
+     * @param value the expected value
+     * @return the builder object
+     */
+    public Builder ifMatches(CompareOperator compareOp, byte[] value) {
 
 Review comment:
   s/ifMatches/ifCompares/?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services