package org.postgresql.core;
import org.postgresql.util.GT;
import org.postgresql.util.PSQLException;
import org.postgresql.util.PSQLState;
public final class CommandCompleteParser {
private long oid;
private long rows;
public CommandCompleteParser() {
}
public long getOid() {
return oid;
}
public long getRows() {
return rows;
}
void set(long oid, long rows) {
this.oid = oid;
this.rows = rows;
}
public void parse(String status) throws PSQLException {
if (!Parser.isDigitAt(status, status.length() - 1)) {
set(0, 0);
return;
}
long oid = 0;
long rows = 0;
try {
int lastSpace = status.lastIndexOf(' ');
if (Parser.isDigitAt(status, lastSpace + 1)) {
rows = Parser.parseLong(status, lastSpace + 1, status.length());
if (Parser.isDigitAt(status, lastSpace - 1)) {
int penultimateSpace = status.lastIndexOf(' ', lastSpace - 1);
if (Parser.isDigitAt(status, penultimateSpace + 1)) {
oid = Parser.parseLong(status, penultimateSpace + 1, lastSpace);
}
}
}
} catch (NumberFormatException e) {
throw new PSQLException(
GT.tr("Unable to parse the count in command completion tag: {0}.", status),
PSQLState.CONNECTION_FAILURE, e);
}
set(oid, rows);
}
@Override
public String toString() {
return "CommandStatus{"
+ "oid=" + oid
+ ", rows=" + rows
+ '}';
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
CommandCompleteParser that = (CommandCompleteParser) o;
if (oid != that.oid) {
return false;
}
return rows == that.rows;
}
@Override
public int hashCode() {
int result = (int) (oid ^ (oid >>> 32));
result = 31 * result + (int) (rows ^ (rows >>> 32));
return result;
}
}