1 // Copyright 2011 Google Inc. All Rights Reserved.
2 package com
.google
.appengine
.api
.datastore
;
4 import java
.util
.ArrayList
;
8 * Describes options for transactions, passed at transaction creation time.
10 * <p>{@code XG} is a boolean that enables or disables the use of cross-group
13 * <p>Notes on usage:<br>
14 * The recommended way to instantiate a {@code TransactionsOptions} object is to
15 * statically import {@link Builder}.* and invoke a static
16 * creation method followed by an instance mutator (if needed):
19 * import static com.google.appengine.api.datastore.TransactionOptions.Builder.*;
23 * datastoreService.beginTransaction(withXG(true));
27 public final class TransactionOptions
{
29 private boolean xg
= false;
31 private TransactionOptions() {
34 TransactionOptions(TransactionOptions original
) {
35 this.xg
= original
.xg
;
39 * Enable or disable the use of cross-group transactions.
41 * @param enable true to cross-group transactions, false to
42 * restrict transactions to a single entity group.
43 * @return {@code this} (for chaining)
45 public TransactionOptions
setXG(boolean enable
) {
51 * Return the cross-group transaction setting to default (disabled).
53 public TransactionOptions
clearXG() {
59 * @return {@code true} if cross-group transactions are allowed,
60 * {@code false} if they are not allowed.
62 public boolean isXG() {
70 @Deprecated public TransactionOptions
multipleEntityGroups(boolean enable
) {
78 @Deprecated public TransactionOptions
clearMultipleEntityGroups() {
86 @Deprecated public Boolean
allowsMultipleEntityGroups() {
91 public int hashCode() {
94 result
= result
* 31 + (xg ?
1 : 0);
100 public boolean equals(Object obj
) {
105 if (obj
.getClass() != this.getClass()) {
109 TransactionOptions that
= (TransactionOptions
) obj
;
111 return xg
== that
.xg
;
115 public String
toString() {
116 List
<String
> result
= new ArrayList
<String
>();
118 result
.add("XG=" + xg
);
120 return "TransactionOptions" + result
;
124 * Contains static creation methods for {@link TransactionOptions}.
126 public static final class Builder
{
128 * Create a {@link TransactionOptions} that enables or disables the use of
129 * cross-group transactions. Shorthand for
130 * <code>TransactionOptions.withDefaults().setXG(...);</code>
132 * @param enable true to allow cross-group transactions, false to
133 * restrict transactions to a single entity group.
134 * @return {@code this} (for chaining)
136 public static TransactionOptions
withXG(boolean enable
) {
137 return withDefaults().setXG(enable
);
144 @Deprecated public static TransactionOptions
allowMultipleEntityGroups(boolean enable
) {
145 return withDefaults().setXG(enable
);
149 * Helper method for creating a {@link TransactionOptions} instance with
150 * default values. The defaults is false (disabled) for XG.
152 public static TransactionOptions
withDefaults() {
153 return new TransactionOptions();