com.julienviet.pgclient.impl.CommandResponse Maven / Gradle / Ivy
package com.julienviet.pgclient.impl;
import com.julienviet.pgclient.impl.codec.TxStatus;
import io.vertx.core.AsyncResult;
import io.vertx.core.impl.NoStackTraceThrowable;
public abstract class CommandResponse implements AsyncResult {
static CommandResponse failure(String msg) {
return failure(new NoStackTraceThrowable(msg), null);
}
static CommandResponse failure(String msg, TxStatus txStatus) {
return failure(new NoStackTraceThrowable(msg), txStatus);
}
static CommandResponse failure(Throwable cause) {
return failure(cause, null);
}
static CommandResponse failure(Throwable cause, TxStatus txStatus) {
return new CommandResponse(txStatus) {
@Override
public R result() {
return null;
}
@Override
public Throwable cause() {
return cause;
}
@Override
public boolean succeeded() {
return false;
}
@Override
public boolean failed() {
return true;
}
};
}
static CommandResponse success(R result) {
return success(result, null);
}
static CommandResponse success(R result, TxStatus txStatus) {
return new CommandResponse(txStatus) {
@Override
public R result() {
return result;
}
@Override
public Throwable cause() {
return null;
}
@Override
public boolean succeeded() {
return true;
}
@Override
public boolean failed() {
return false;
}
};
}
private final TxStatus txStatus;
public CommandResponse(TxStatus txStatus) {
this.txStatus = txStatus;
}
TxStatus txStatus() {
return txStatus;
}
}