
com.couchbase.transactions.error.internal.TransactionOperationFailedBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of couchbase-transactions Show documentation
Show all versions of couchbase-transactions Show documentation
Transaction Support for Couchbase on top of the Java SDK
The newest version!
/*
* Copyright 2021 Couchbase, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.couchbase.transactions.error.internal;
import com.couchbase.client.core.annotation.Stability;
import com.couchbase.transactions.AttemptContextReactive;
import com.couchbase.transactions.error.external.TransactionOperationFailed;
/**
* Allows constructing a TransactionOperationFailed.
*/
@Stability.Internal
public class TransactionOperationFailedBuilder {
private final AttemptContextReactive ctx;
// The ErrorClass of what caused this to be raised. Required for testing.
private final ErrorClasses causingErrorClass;
private boolean rollbackAttempt = true;
private boolean retryTransaction = false;
private Throwable cause = null;
private TransactionOperationFailed.FinalErrorToRaise toRaise = TransactionOperationFailed.FinalErrorToRaise.TRANSACTION_FAILED;
private TransactionOperationFailedBuilder(ErrorClasses causingErrorClass) {
this.ctx = null;
this.causingErrorClass = causingErrorClass;
}
private TransactionOperationFailedBuilder(AttemptContextReactive ctx, ErrorClasses causingErrorClass) {
this.ctx = ctx;
this.causingErrorClass = causingErrorClass;
}
public static TransactionOperationFailedBuilder createError(ErrorClasses causingErrorClass) {
return new TransactionOperationFailedBuilder(null, causingErrorClass);
}
public static TransactionOperationFailedBuilder createError(AttemptContextReactive ctx,
ErrorClasses causingErrorClass) {
return new TransactionOperationFailedBuilder(ctx, causingErrorClass);
}
public TransactionOperationFailedBuilder raiseException(TransactionOperationFailed.FinalErrorToRaise toRaise) {
this.toRaise = toRaise;
return this;
}
public TransactionOperationFailedBuilder doNotRollbackAttempt() {
rollbackAttempt = false;
return this;
}
public TransactionOperationFailedBuilder rollbackAttempt(boolean value) {
rollbackAttempt = value;
return this;
}
public TransactionOperationFailedBuilder retryTransaction() {
retryTransaction = true;
return this;
}
public TransactionOperationFailedBuilder cause(Throwable cause) {
this.cause = cause;
return this;
}
public TransactionOperationFailed build() {
return new TransactionOperationFailed(ctx,
causingErrorClass,
rollbackAttempt,
retryTransaction,
cause,
toRaise);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy