All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.scalar.database.api.Mutation Maven / Gradle / Ivy

Go to download

A universal transaction manager that achieves database-agnostic transactions and distributed transactions that span multiple databases

There is a newer version: 3.14.0-alpha.1
Show newest version
package com.scalar.database.api;

import com.google.common.base.MoreObjects;
import com.scalar.database.io.Key;
import java.util.Optional;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.NotThreadSafe;

/**
 * An abstraction for mutation operations such as {@link Put} and {@link Delete}.
 *
 * @author Hiroyuki Yamada
 */
@NotThreadSafe
public abstract class Mutation extends Operation {
  private Optional condition;

  public Mutation(Key partitionKey, Key clusteringKey) {
    super(partitionKey, clusteringKey);
    condition = Optional.empty();
  }

  /**
   * Returns the {@link MutationCondition}
   *
   * @return {@code MutationCondition}
   */
  @Nonnull
  public Optional getCondition() {
    return condition;
  }

  /**
   * Sets the specified {@link MutationCondition}
   *
   * @param condition a {@code MutationCondition}
   * @return this object
   */
  public Mutation withCondition(MutationCondition condition) {
    this.condition = Optional.ofNullable(condition);
    return this;
  }

  /**
   * Indicates whether some other object is "equal to" this object. The other object is considered
   * equal if:
   *
   * 
    *
  • both super class instances are equal and *
  • it is also an {@code Mutation} and *
  • both instances have the same condition *
* * @param o an object to be tested for equality * @return {@code true} if the other object is "equal to" this object otherwise {@code false} */ @Override public boolean equals(Object o) { if (!super.equals(o)) { return false; } if (o == this) { return true; } if (!(o instanceof Mutation)) { return false; } Mutation other = (Mutation) o; return condition.equals(other.condition); } @Override public String toString() { return MoreObjects.toStringHelper(this) .add("namespace", forNamespace()) .add("table", forTable()) .add("partitionKey", getPartitionKey()) .add("clusteringKey", getClusteringKey()) .add("consistency", getConsistency()) .add("condition", condition) .toString(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy