Revision created by MOE tool push_codebase.
[gae.git] / java / src / main / com / google / appengine / api / datastore / ReadPolicy.java
blob0ff9c26ef73f238378c037aa86374dee81de2673
1 // Copyright 2010 Google Inc. All Rights Reserved.
3 package com.google.appengine.api.datastore;
5 /**
6 * Policy for reads.
8 */
9 public final class ReadPolicy {
11 /**
12 * Setting the {@code Consistency} for reads allows you to decide whether
13 * freshness or availability is more important.
15 public enum Consistency {
17 /**
18 * Selects freshness over availability. Strongly consistent reads are
19 * guaranteed to return the most up-to-date data but will timeout more
20 * often than eventually consistent reads.
22 STRONG,
24 /**
25 * Selects availability over freshness. Eventually consistent reads will
26 * timeout less often than Strong reads but will occasionally return
27 * stale results.
29 EVENTUAL
32 private final Consistency consistency;
34 public ReadPolicy(Consistency consistency) {
35 if (consistency == null) {
36 throw new NullPointerException("consistency must not be null");
38 this.consistency = consistency;
41 public Consistency getConsistency() {
42 return consistency;
45 @Override
46 public boolean equals(Object o) {
47 if (this == o) {
48 return true;
50 if (o == null || getClass() != o.getClass()) {
51 return false;
54 ReadPolicy that = (ReadPolicy) o;
56 if (consistency != that.consistency) {
57 return false;
60 return true;
63 @Override
64 public int hashCode() {
65 return consistency.hashCode();