Factory methods for WriteRequest
Change-Id: If6fae76bd09b3068a8fb60ce27b7cde64cd8dc86
Showing
1 changed file
with
45 additions
and
10 deletions
| ... | @@ -17,24 +17,59 @@ public class WriteRequest { | ... | @@ -17,24 +17,59 @@ public class WriteRequest { |
| 17 | private final long previousVersion; | 17 | private final long previousVersion; |
| 18 | private final byte[] oldValue; | 18 | private final byte[] oldValue; |
| 19 | 19 | ||
| 20 | - // put regardless of previous value | 20 | + /** |
| 21 | - public WriteRequest(String tableName, String key, byte[] newValue) { | 21 | + * Creates a write request, which will |
| 22 | - this(tableName, key, newValue, -1, null); | 22 | + * put the specified value to the table regardless of the previous value. |
| 23 | + * | ||
| 24 | + * @param tableName name of the table | ||
| 25 | + * @param key key in the table | ||
| 26 | + * @param newValue value to write | ||
| 27 | + * @return WriteRequest | ||
| 28 | + */ | ||
| 29 | + public static WriteRequest put(String tableName, String key, | ||
| 30 | + byte[] newValue) { | ||
| 31 | + return new WriteRequest(tableName, key, newValue, -1, null); | ||
| 23 | } | 32 | } |
| 24 | 33 | ||
| 25 | - // put if version matches | 34 | + // FIXME: Is there a special version value to realize putIfAbsent? |
| 26 | - public WriteRequest(String tableName, String key, byte[] newValue, long previousVersion) { | 35 | + /** |
| 27 | - this(tableName, key, newValue, previousVersion, null); | 36 | + * Creates a write request, which will |
| 37 | + * put the specified value to the table if the previous version matches. | ||
| 38 | + * | ||
| 39 | + * @param tableName name of the table | ||
| 40 | + * @param key key in the table | ||
| 41 | + * @param newValue value to write | ||
| 42 | + * @param previousVersion previous version expected | ||
| 43 | + * @return WriteRequest | ||
| 44 | + */ | ||
| 45 | + public static WriteRequest putIfVersionMatches(String tableName, String key, | ||
| 46 | + byte[] newValue, | ||
| 47 | + long previousVersion) { | ||
| 28 | checkArgument(previousVersion >= 0); | 48 | checkArgument(previousVersion >= 0); |
| 49 | + return new WriteRequest(tableName, key, newValue, previousVersion, null); | ||
| 29 | } | 50 | } |
| 30 | 51 | ||
| 31 | - // put if value matches | 52 | + // FIXME: What is the behavior of oldValue=null? putIfAbsent? |
| 32 | - public WriteRequest(String tableName, String key, byte[] newValue, byte[] oldValue) { | 53 | + /** |
| 33 | - this(tableName, key, newValue, -1, oldValue); | 54 | + * Creates a write request, which will |
| 55 | + * put the specified value to the table if the previous value matches. | ||
| 56 | + * | ||
| 57 | + * @param tableName name of the table | ||
| 58 | + * @param key key in the table | ||
| 59 | + * @param newValue value to write | ||
| 60 | + * @param oldValue previous value expected | ||
| 61 | + * @return WriteRequest | ||
| 62 | + */ | ||
| 63 | + public static WriteRequest putIfValueMatches(String tableName, String key, | ||
| 64 | + byte[] newValue, | ||
| 65 | + byte[] oldValue) { | ||
| 66 | + return new WriteRequest(tableName, key, newValue, -1, oldValue); | ||
| 34 | } | 67 | } |
| 35 | 68 | ||
| 69 | + // FIXME: How do we remove value? newValue=null? | ||
| 70 | + | ||
| 36 | // hidden constructor | 71 | // hidden constructor |
| 37 | - private WriteRequest(String tableName, String key, byte[] newValue, long previousVersion, byte[] oldValue) { | 72 | + protected WriteRequest(String tableName, String key, byte[] newValue, long previousVersion, byte[] oldValue) { |
| 38 | 73 | ||
| 39 | checkArgument(tableName != null); | 74 | checkArgument(tableName != null); |
| 40 | checkArgument(key != null); | 75 | checkArgument(key != null); | ... | ... |
-
Please register or login to post a comment