44import dev .openfga .sdk .api .model .WriteRequestWrites ;
55import java .util .Map ;
66
7+ /**
8+ * Options for controlling the behavior of write operations on the OpenFGA client.
9+ *
10+ * <p>Use this class to configure how tuples are written, including whether to use transactions,
11+ * how writes are chunked, and how duplicate or missing tuples are handled.
12+ */
713public class ClientWriteOptions implements AdditionalHeadersSupplier {
814 private Map <String , String > additionalHeaders ;
915 private String authorizationModelId ;
10- private Boolean disableTransactions = false ;
16+ private boolean transactionsEnabled = true ;
1117 private int transactionChunkSize ;
1218 private WriteRequestWrites .OnDuplicateEnum onDuplicate ;
1319 private WriteRequestDeletes .OnMissingEnum onMissing ;
1420
21+ /**
22+ * Sets additional HTTP headers to include in write requests.
23+ *
24+ * @param additionalHeaders a map of header names to values
25+ * @return this {@code ClientWriteOptions} instance for method chaining
26+ */
1527 public ClientWriteOptions additionalHeaders (Map <String , String > additionalHeaders ) {
1628 this .additionalHeaders = additionalHeaders ;
1729 return this ;
@@ -22,11 +34,24 @@ public Map<String, String> getAdditionalHeaders() {
2234 return this .additionalHeaders ;
2335 }
2436
37+ /**
38+ * Sets the authorization model ID to use for write operations.
39+ *
40+ * <p>If not set, the client will use the authorization model ID from its configuration.
41+ *
42+ * @param authorizationModelId the authorization model ID
43+ * @return this {@code ClientWriteOptions} instance for method chaining
44+ */
2545 public ClientWriteOptions authorizationModelId (String authorizationModelId ) {
2646 this .authorizationModelId = authorizationModelId ;
2747 return this ;
2848 }
2949
50+ /**
51+ * Returns the authorization model ID configured for write operations.
52+ *
53+ * @return the authorization model ID, or {@code null} if not set
54+ */
3055 public String getAuthorizationModelId () {
3156 return authorizationModelId ;
3257 }
@@ -43,7 +68,7 @@ public String getAuthorizationModelId() {
4368 * @see #isTransactionsEnabled()
4469 */
4570 public ClientWriteOptions transactions (boolean enabled ) {
46- this .disableTransactions = ! enabled ;
71+ this .transactionsEnabled = enabled ;
4772 return this ;
4873 }
4974
@@ -54,7 +79,7 @@ public ClientWriteOptions transactions(boolean enabled) {
5479 * @see #transactions(boolean)
5580 */
5681 public boolean isTransactionsEnabled () {
57- return disableTransactions == null || ! disableTransactions ;
82+ return transactionsEnabled ;
5883 }
5984
6085 /**
@@ -69,7 +94,7 @@ public boolean isTransactionsEnabled() {
6994 */
7095 @ Deprecated
7196 public ClientWriteOptions disableTransactions (boolean disableTransactions ) {
72- this .disableTransactions = disableTransactions ;
97+ this .transactionsEnabled = ! disableTransactions ;
7398 return this ;
7499 }
75100
@@ -83,32 +108,73 @@ public ClientWriteOptions disableTransactions(boolean disableTransactions) {
83108 */
84109 @ Deprecated
85110 public boolean disableTransactions () {
86- return disableTransactions != null && disableTransactions ;
111+ return ! transactionsEnabled ;
87112 }
88113
114+ /**
115+ * Sets the number of tuples to include in each non-transactional write chunk.
116+ *
117+ * <p>Only applies when transactions are disabled via {@link #transactions(boolean)}. Writes
118+ * and deletes are split into chunks of this size and sent as separate requests.
119+ *
120+ * @param transactionChunkSize the chunk size; must be greater than zero
121+ * @return this {@code ClientWriteOptions} instance for method chaining
122+ * @see #transactions(boolean)
123+ */
89124 public ClientWriteOptions transactionChunkSize (int transactionChunkSize ) {
90125 this .transactionChunkSize = transactionChunkSize ;
91126 return this ;
92127 }
93128
129+ /**
130+ * Returns the chunk size for non-transactional writes.
131+ *
132+ * <p>Defaults to {@code 1} if not explicitly set.
133+ *
134+ * @return the configured chunk size, or {@code 1} if none was set
135+ */
94136 public int getTransactionChunkSize () {
95137 return transactionChunkSize > 0 ? transactionChunkSize : 1 ;
96138 }
97139
140+ /**
141+ * Sets the behavior when a duplicate tuple is encountered during a write.
142+ *
143+ * @param onDuplicate the action to take on duplicate tuples
144+ * @return this {@code ClientWriteOptions} instance for method chaining
145+ * @see WriteRequestWrites.OnDuplicateEnum
146+ */
98147 public ClientWriteOptions onDuplicate (WriteRequestWrites .OnDuplicateEnum onDuplicate ) {
99148 this .onDuplicate = onDuplicate ;
100149 return this ;
101150 }
102151
152+ /**
153+ * Returns the configured behavior for duplicate tuples during writes.
154+ *
155+ * @return the on-duplicate action, or {@code null} if not set
156+ */
103157 public WriteRequestWrites .OnDuplicateEnum getOnDuplicate () {
104158 return onDuplicate ;
105159 }
106160
161+ /**
162+ * Sets the behavior when a tuple to be deleted is not found.
163+ *
164+ * @param onMissing the action to take when a tuple is missing during delete
165+ * @return this {@code ClientWriteOptions} instance for method chaining
166+ * @see WriteRequestDeletes.OnMissingEnum
167+ */
107168 public ClientWriteOptions onMissing (WriteRequestDeletes .OnMissingEnum onMissing ) {
108169 this .onMissing = onMissing ;
109170 return this ;
110171 }
111172
173+ /**
174+ * Returns the configured behavior for missing tuples during deletes.
175+ *
176+ * @return the on-missing action, or {@code null} if not set
177+ */
112178 public WriteRequestDeletes .OnMissingEnum getOnMissing () {
113179 return onMissing ;
114180 }
0 commit comments