

package org.apache.ignite.internal.processors.odbc.jdbc;

import org.apache.ignite.internal.binary.BinaryReaderExImpl;
import org.apache.ignite.internal.binary.BinaryWriterExImpl;
import org.apache.ignite.internal.util.typedef.internal.S;

/**
 * JDBC statement result information. Keeps statement type (SELECT or UPDATE) and
 * queryId or update count (depends on statement type).
 */
public class JdbcResultInfo implements JdbcRawBinarylizable {
    /** Query flag. */
    private boolean isQuery;

    /** Update count. */
    private long updCnt;

    /** Cursor ID. */
    private long cursorId;

    /**
     * Default constructor is used for serialization.
     */
    JdbcResultInfo() {
        // No-op.
    }

    /**
     * @param isQuery Query flag.
     * @param updCnt Update count.
     * @param cursorId  Cursor ID.
     */
    public JdbcResultInfo(boolean isQuery, long updCnt, long cursorId) {
        this.isQuery = isQuery;
        this.updCnt = updCnt;
        this.cursorId = cursorId;
    }

    /**
     * @return Query flag.
     */
    public boolean isQuery() {
        return isQuery;
    }

    /**
     * @return Cursor ID.
     */
    public long cursorId() {
        return cursorId;
    }

    /**
     * @return Update count.
     */
    public long updateCount() {
        return updCnt;
    }

    /** {@inheritDoc} */
    @Override public void writeBinary(
        BinaryWriterExImpl writer,
        JdbcProtocolContext protoCtx
    ) {
        writer.writeBoolean(isQuery);
        writer.writeLong(updCnt);
        writer.writeLong(cursorId);
    }

    /** {@inheritDoc} */
    @Override public void readBinary(
        BinaryReaderExImpl reader,
        JdbcProtocolContext protoCtx
    ) {
        isQuery = reader.readBoolean();
        updCnt = reader.readLong();
        cursorId = reader.readLong();
    }

    /** {@inheritDoc} */
    @Override public String toString() {
        return S.toString(JdbcResultInfo.class, this);
    }
}
