All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.reactiverse.pgclient.impl.CommandResponse Maven / Gradle / Ivy

There is a newer version: 0.11.4
Show newest version
package io.reactiverse.pgclient.impl;

import io.reactiverse.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;
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy