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

com.datastax.driver.core.ConsistencyLevel Maven / Gradle / Ivy

Go to download

A driver for DataStax Enterprise (DSE) and Apache Cassandra 1.2+ clusters that works exclusively with the Cassandra Query Language version 3 (CQL3) and Cassandra's binary protocol, supporting DSE-specific features such as geospatial types, DSE Graph and DSE authentication.

There is a newer version: 2.4.0
Show newest version
/*
 * Copyright DataStax, Inc.
 *
 * This software can be used solely with DataStax Enterprise. Please consult the license at
 * http://www.datastax.com/terms/datastax-dse-driver-license-terms
 */
package com.datastax.driver.core;

import com.datastax.driver.core.exceptions.DriverInternalError;

public enum ConsistencyLevel {
  ANY(0),
  ONE(1),
  TWO(2),
  THREE(3),
  QUORUM(4),
  ALL(5),
  LOCAL_QUORUM(6),
  EACH_QUORUM(7),
  SERIAL(8),
  LOCAL_SERIAL(9),
  LOCAL_ONE(10);

  // Used by the native protocol
  final int code;
  private static final ConsistencyLevel[] codeIdx;

  static {
    int maxCode = -1;
    for (ConsistencyLevel cl : ConsistencyLevel.values()) maxCode = Math.max(maxCode, cl.code);
    codeIdx = new ConsistencyLevel[maxCode + 1];
    for (ConsistencyLevel cl : ConsistencyLevel.values()) {
      if (codeIdx[cl.code] != null) throw new IllegalStateException("Duplicate code");
      codeIdx[cl.code] = cl;
    }
  }

  private ConsistencyLevel(int code) {
    this.code = code;
  }

  static ConsistencyLevel fromCode(int code) {
    if (code < 0 || code >= codeIdx.length)
      throw new DriverInternalError(String.format("Unknown code %d for a consistency level", code));
    return codeIdx[code];
  }

  /**
   * Whether or not this consistency level applies to the local data-center only.
   *
   * @return whether this consistency level is {@code LOCAL_ONE}, {@code LOCAL_QUORUM}, or {@code
   *     LOCAL_SERIAL}.
   */
  public boolean isDCLocal() {
    return this == LOCAL_ONE || this == LOCAL_QUORUM || this == LOCAL_SERIAL;
  }

  /**
   * Whether or not this consistency level is serial, that is, applies only to the "paxos" phase of
   * a Lightweight
   * transaction.
   *
   * 

Serial consistency levels are only meaningful when executing conditional updates ({@code * INSERT}, {@code UPDATE} or {@code DELETE} statements with an {@code IF} condition). * *

Two consistency levels belong to this category: {@link #SERIAL} and {@link #LOCAL_SERIAL}. * * @return whether this consistency level is {@link #SERIAL} or {@link #LOCAL_SERIAL}. * @see Statement#setSerialConsistencyLevel(ConsistencyLevel) * @see Lightweight * transactions */ public boolean isSerial() { return this == SERIAL || this == LOCAL_SERIAL; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy