/* Generated By:JJTree: Do not edit this line. OHaStatusStatement.java Version 4.3 */
/* JavaCCOptions:MULTI=true,NODE_USES_PARSER=false,VISITOR=true,TRACK_TOKENS=true,NODE_PREFIX=O,NODE_EXTENDS=,NODE_FACTORY=,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
package com.orientechnologies.orient.core.sql.parser;

import com.orientechnologies.common.exception.OException;
import com.orientechnologies.common.log.OLogManager;
import com.orientechnologies.orient.core.command.OCommandContext;
import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal;
import com.orientechnologies.orient.core.exception.OCommandExecutionException;
import com.orientechnologies.orient.core.sql.executor.OInternalResultSet;
import com.orientechnologies.orient.core.sql.executor.OResultInternal;
import com.orientechnologies.orient.core.sql.executor.OResultSet;
import java.util.Map;

public class OHaStatusStatement extends OSimpleExecStatement {

  public boolean servers = false;
  public boolean db = false;
  public boolean latency = false;
  public boolean messages = false;
  public boolean outputText = false;
  public boolean locks = false;

  public OHaStatusStatement(int id) {
    super(id);
  }

  public OHaStatusStatement(OrientSql p, int id) {
    super(p, id);
  }

  @Override
  public void toString(Map<Object, Object> params, StringBuilder builder) {
    builder.append("HA STATUS");
    if (servers) {
      builder.append(" -servers");
    }
    if (db) {
      builder.append(" -db");
    }
    if (latency) {
      builder.append(" -latency");
    }
    if (messages) {
      builder.append(" -messages");
    }
    if (locks) {
      builder.append(" -locks");
    }
    if (outputText) {
      builder.append(" -output=text");
    }
    if (servers) {
      builder.append(" -servers");
    }
  }

  @Override
  public OResultSet executeSimple(OCommandContext ctx) {
    if (outputText) {
      OLogManager.instance().info(this, "HA STATUS with text output is deprecated");
    }
    final ODatabaseDocumentInternal database = (ODatabaseDocumentInternal) ctx.getDatabase();

    OInternalResultSet rs = new OInternalResultSet();
    try {
      Map<String, Object> res = database.getHaStatus(servers, this.db, latency, messages);
      if (res != null) {
        OResultInternal row = new OResultInternal();
        res.entrySet().forEach(x -> row.setProperty(x.getKey(), x.getValue()));
        rs.add(row);
      }
      return rs;
    } catch (Exception x) {
      throw OException.wrapException(new OCommandExecutionException("Cannot execute HA STATUS"), x);
    }
  }
}
/* JavaCC - OriginalChecksum=c8ab1b0172e8cdbea2078efe2c629e6a (do not edit this line) */

/* Generated By:JJTree: Do not edit this line. OHaStatusStatement.java Version 4.3 */
/* JavaCCOptions:MULTI=true,NODE_USES_PARSER=false,VISITOR=true,TRACK_TOKENS=true,NODE_PREFIX=O,NODE_EXTENDS=,NODE_FACTORY=,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
package com.orientechnologies.orient.core.sql.parser;

import com.orientechnologies.common.exception.OException;
import com.orientechnologies.common.log.OLogManager;
import com.orientechnologies.orient.core.command.OCommandContext;
import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal;
import com.orientechnologies.orient.core.exception.OCommandExecutionException;
import com.orientechnologies.orient.core.sql.executor.OInternalResultSet;
import com.orientechnologies.orient.core.sql.executor.OResultInternal;
import com.orientechnologies.orient.core.sql.executor.OResultSet;
import java.util.Map;

public class OHaStatusStatement extends OSimpleExecStatement {

  public boolean servers = false;
  public boolean db = false;
  public boolean latency = false;
  public boolean messages = false;
  public boolean outputText = false;
  public boolean locks = false;

  public OHaStatusStatement(int id) {
    super(id);
  }

  public OHaStatusStatement(OrientSql p, int id) {
    super(p, id);
  }

  @Override
  public boolean isIdempotent() {
    return true;
  }

  @Override
  public void toString(Map<Object, Object> params, StringBuilder builder) {
    builder.append("HA STATUS");
    if (servers) {
      builder.append(" -servers");
    }
    if (db) {
      builder.append(" -db");
    }
    if (latency) {
      builder.append(" -latency");
    }
    if (messages) {
      builder.append(" -messages");
    }
    if (locks) {
      builder.append(" -locks");
    }
    if (outputText) {
      builder.append(" -output=text");
    }
    if (servers) {
      builder.append(" -servers");
    }
  }

  @Override
  public OResultSet executeSimple(OCommandContext ctx) {
    if (outputText) {
      OLogManager.instance().info(this, "HA STATUS with text output is deprecated");
    }
    final ODatabaseDocumentInternal database = (ODatabaseDocumentInternal) ctx.getDatabase();

    OInternalResultSet rs = new OInternalResultSet();
    try {
      Map<String, Object> res = database.getHaStatus(servers, this.db, latency, messages);
      if (res != null) {
        OResultInternal row = new OResultInternal();
        res.entrySet().forEach(x -> row.setProperty(x.getKey(), x.getValue()));
        rs.add(row);
      }
      return rs;
    } catch (Exception x) {
      throw OException.wrapException(new OCommandExecutionException("Cannot execute HA STATUS"), x);
    }
  }
}
/* JavaCC - OriginalChecksum=c8ab1b0172e8cdbea2078efe2c629e6a (do not edit this line) */

Mark HA STATUS idempotent so it can be used from SQL API.