Line up sql serialization methods with core's (elastic/x-pack-elasticsearch#2538)

This renames that `write` and `read` methods in SQL to `writeTo` and
`readFrom` to line up with the names used in core. I don't have a
strong opinion whether or not any name is better than any other but
I figure there isn't a good reason for SQL to be different from the
rest of Elasticsearch.

Original commit: elastic/x-pack-elasticsearch@e5de9a4b81
This commit is contained in:
Nik Everett 2017-09-18 16:06:14 -04:00 committed by GitHub
parent 204e340397
commit bc03aa6c03
29 changed files with 64 additions and 64 deletions

View File

@ -22,12 +22,12 @@ public final class Proto extends AbstractProto {
@Override
protected RequestType readRequestType(DataInput in) throws IOException {
return RequestType.read(in);
return RequestType.readFrom(in);
}
@Override
protected ResponseType readResponseType(DataInput in) throws IOException {
return ResponseType.read(in);
return ResponseType.readFrom(in);
}
public enum RequestType implements AbstractProto.RequestType {
@ -41,7 +41,7 @@ public final class Proto extends AbstractProto {
this.reader = reader;
}
static RequestType read(DataInput in) throws IOException {
static RequestType readFrom(DataInput in) throws IOException {
byte b = in.readByte();
try {
return values()[b];
@ -51,7 +51,7 @@ public final class Proto extends AbstractProto {
}
@Override
public void write(DataOutput out) throws IOException {
public void writeTo(DataOutput out) throws IOException {
out.writeByte(ordinal());
}
@ -74,7 +74,7 @@ public final class Proto extends AbstractProto {
this.reader = reader;
}
static ResponseType read(DataInput in) throws IOException {
static ResponseType readFrom(DataInput in) throws IOException {
byte b = in.readByte();
try {
return values()[b];
@ -84,7 +84,7 @@ public final class Proto extends AbstractProto {
}
@Override
public void write(DataOutput out) throws IOException {
public void writeTo(DataOutput out) throws IOException {
out.writeByte(ordinal());
}

View File

@ -30,8 +30,8 @@ public abstract class QueryResponse extends AbstractQueryResponse {
}
@Override
protected void write(int clientVersion, DataOutput out) throws IOException {
super.write(clientVersion, out);
protected void writeTo(int clientVersion, DataOutput out) throws IOException {
super.writeTo(clientVersion, out);
out.writeUTF(data);
}

View File

@ -51,7 +51,7 @@ public class ColumnInfo {
label = in.readUTF();
}
void write(DataOutput out) throws IOException {
void writeTo(DataOutput out) throws IOException {
out.writeUTF(name);
out.writeInt(type.getVendorTypeNumber());
out.writeUTF(table);

View File

@ -41,7 +41,7 @@ public class MetaColumnInfo {
position = in.readInt();
}
void write(DataOutput out) throws IOException {
void writeTo(DataOutput out) throws IOException {
out.writeUTF(table);
out.writeUTF(name);
out.writeInt(type.getVendorTypeNumber());

View File

@ -27,7 +27,7 @@ public class MetaColumnRequest extends Request {
}
@Override
protected void write(DataOutput out) throws IOException {
protected void writeTo(DataOutput out) throws IOException {
out.writeUTF(tablePattern);
out.writeUTF(columnPattern);
}

View File

@ -40,10 +40,10 @@ public class MetaColumnResponse extends Response {
}
@Override
protected void write(int clientVersion, DataOutput out) throws IOException {
protected void writeTo(int clientVersion, DataOutput out) throws IOException {
out.writeInt(columns.size());
for (MetaColumnInfo info : columns) {
info.write(out);
info.writeTo(out);
}
}

View File

@ -27,7 +27,7 @@ public class MetaTableRequest extends Request {
}
@Override
public void write(DataOutput out) throws IOException {
public void writeTo(DataOutput out) throws IOException {
out.writeUTF(pattern);
}

View File

@ -38,7 +38,7 @@ public class MetaTableResponse extends Response {
}
@Override
public void write(int clientVersion, DataOutput out) throws IOException {
public void writeTo(int clientVersion, DataOutput out) throws IOException {
out.writeInt(tables.size());
for (String t : tables) {
out.writeUTF(t);

View File

@ -36,7 +36,7 @@ public class Page implements Payload {
private int maxRows;
/**
* Build empty, call {@link #read(DataInput)} after to fill it.
* Build empty, call {@link #readFrom(DataInput)} after to fill it.
*/
Page(List<ColumnInfo> columnInfo) {
this.columnInfo = columnInfo;
@ -91,7 +91,7 @@ public class Page implements Payload {
/**
* Read a value from the stream
*/
public void read(DataInput in) throws IOException {
public void readFrom(DataInput in) throws IOException {
int rows = in.readInt();
// this.rows may be less than the number of rows we have space for
if (rows > maxRows) {
@ -106,7 +106,7 @@ public class Page implements Payload {
}
}
public void write(DataOutput out) throws IOException {
public void writeTo(DataOutput out) throws IOException {
int rows = rows();
out.writeInt(rows);
for (int row = 0; row < rows; row++) {

View File

@ -11,7 +11,7 @@ import java.io.IOException;
public interface Payload {
void read(DataInput in) throws IOException;
void readFrom(DataInput in) throws IOException;
void write(DataOutput out) throws IOException;
void writeTo(DataOutput out) throws IOException;
}

View File

@ -22,12 +22,12 @@ public final class Proto extends AbstractProto {
@Override
protected RequestType readRequestType(DataInput in) throws IOException {
return RequestType.read(in);
return RequestType.readFrom(in);
}
@Override
protected ResponseType readResponseType(DataInput in) throws IOException {
return ResponseType.read(in);
return ResponseType.readFrom(in);
}
public enum RequestType implements AbstractProto.RequestType {
@ -45,7 +45,7 @@ public final class Proto extends AbstractProto {
this.reader = reader;
}
static RequestType read(DataInput in) throws IOException {
static RequestType readFrom(DataInput in) throws IOException {
byte b = in.readByte();
try {
return values()[b];
@ -55,7 +55,7 @@ public final class Proto extends AbstractProto {
}
@Override
public void write(DataOutput out) throws IOException {
public void writeTo(DataOutput out) throws IOException {
out.writeByte(ordinal());
}
@ -82,7 +82,7 @@ public final class Proto extends AbstractProto {
this.reader = reader;
}
static ResponseType read(DataInput in) throws IOException {
static ResponseType readFrom(DataInput in) throws IOException {
byte b = in.readByte();
try {
return values()[b];
@ -92,7 +92,7 @@ public final class Proto extends AbstractProto {
}
@Override
public void write(DataOutput out) throws IOException {
public void writeTo(DataOutput out) throws IOException {
out.writeByte(ordinal());
}

View File

@ -39,18 +39,18 @@ public class QueryInitResponse extends AbstractQueryResponse {
this.columns = unmodifiableList(columns);
// NOCOMMIT - Page is a client class, it shouldn't leak here
Page data = new Page(columns);
data.read(in);
data.readFrom(in);
this.data = data;
}
@Override
public void write(int clientVersion, DataOutput out) throws IOException {
super.write(clientVersion, out);
public void writeTo(int clientVersion, DataOutput out) throws IOException {
super.writeTo(clientVersion, out);
out.writeInt(columns.size());
for (ColumnInfo c : columns) {
c.write(out);
c.writeTo(out);
}
data.write(out);
data.writeTo(out);
}
@Override

View File

@ -27,13 +27,13 @@ public class QueryPageResponse extends AbstractQueryResponse {
super(request, in);
QueryPageRequest queryPageRequest = (QueryPageRequest) request;
data = queryPageRequest.data();
queryPageRequest.data().read(in);
queryPageRequest.data().readFrom(in);
}
@Override
public void write(int clientVersion, DataOutput out) throws IOException {
super.write(clientVersion, out);
data.write(out);
public void writeTo(int clientVersion, DataOutput out) throws IOException {
super.writeTo(clientVersion, out);
data.writeTo(out);
}
@Override

View File

@ -41,7 +41,7 @@ public class ColumnInfoTests extends ESTestCase {
}
public void testRoundTrip() throws IOException {
assertRoundTrip(randomColumnInfo(), ColumnInfo::write, ColumnInfo::new);
assertRoundTrip(randomColumnInfo(), ColumnInfo::writeTo, ColumnInfo::new);
}
public void testToString() {

View File

@ -19,7 +19,7 @@ public class MetaColumnInfoTests extends ESTestCase {
}
public void testRoundTrip() throws IOException {
assertRoundTrip(randomMetaColumnInfo(), MetaColumnInfo::write, MetaColumnInfo::new);
assertRoundTrip(randomMetaColumnInfo(), MetaColumnInfo::writeTo, MetaColumnInfo::new);
}
public void testToString() {

View File

@ -50,9 +50,9 @@ public class PageTests extends ESTestCase {
public void testRoundTripNoReuse() throws IOException {
Page example = randomPage();
assertRoundTrip(example, Page::write, in -> {
assertRoundTrip(example, Page::writeTo, in -> {
Page page = new Page(example.columnInfo());
page.read(in);
page.readFrom(in);
return page;
});
}
@ -60,11 +60,11 @@ public class PageTests extends ESTestCase {
public void testRoundTripReuse() throws IOException {
Page example = randomPage();
Page target = new Page(example.columnInfo());
roundTrip(example, Page::write, in -> {target.read(in); return null;});
roundTrip(example, Page::writeTo, in -> {target.readFrom(in); return null;});
assertEquals(example, target);
example = randomPageContents(example.columnInfo());
roundTrip(example, Page::write, in -> {target.read(in); return null;});
roundTrip(example, Page::writeTo, in -> {target.readFrom(in); return null;});
assertEquals(example, target);
}

View File

@ -25,12 +25,12 @@ public class RowSetPayload implements Payload {
}
@Override
public void read(DataInput in) throws IOException {
public void readFrom(DataInput in) throws IOException {
throw new UnsupportedOperationException("This class can only be serialized");
}
@Override
public void write(DataOutput out) throws IOException {
public void writeTo(DataOutput out) throws IOException {
out.writeInt(rowSet.size());
List<DataType> types = rowSet.schema().types();

View File

@ -34,7 +34,7 @@ public abstract class AbstractErrorResponse extends Response {
}
@Override
protected final void write(int clientVersion, DataOutput out) throws IOException {
protected final void writeTo(int clientVersion, DataOutput out) throws IOException {
out.writeUTF(message);
out.writeUTF(cause);
out.writeUTF(stack);

View File

@ -49,10 +49,10 @@ public abstract class AbstractExceptionResponse extends Response {
}
@Override
protected final void write(int clientVersion, DataOutput out) throws IOException {
protected final void writeTo(int clientVersion, DataOutput out) throws IOException {
out.writeUTF(message);
out.writeUTF(cause);
exceptionType.write(out);
exceptionType.writeTo(out);
}
@Override

View File

@ -44,7 +44,7 @@ public abstract class AbstractInfoRequest extends Request {
}
@Override
public final void write(DataOutput out) throws IOException {
public final void writeTo(DataOutput out) throws IOException {
out.writeUTF(jvmVersion);
out.writeUTF(jvmVendor);
out.writeUTF(jvmClassPath);

View File

@ -40,7 +40,7 @@ public abstract class AbstractInfoResponse extends Response {
}
@Override
protected final void write(int clientVersion, DataOutput out) throws IOException {
protected final void writeTo(int clientVersion, DataOutput out) throws IOException {
out.writeUTF(node);
out.writeUTF(cluster);
out.writeByte(majorVersion);

View File

@ -31,8 +31,8 @@ public abstract class AbstractProto {
public void writeRequest(Request request, DataOutput out) throws IOException {
writeHeader(CURRENT_VERSION, out);
request.requestType().write(out);
request.write(out);
request.requestType().writeTo(out);
request.writeTo(out);
}
public Request readRequest(DataInput in) throws IOException {
@ -45,8 +45,8 @@ public abstract class AbstractProto {
public void writeResponse(Response response, int clientVersion, DataOutput out) throws IOException {
writeHeader(clientVersion, out);
response.responseType().write(out);
response.write(clientVersion, out);
response.responseType().writeTo(out);
response.writeTo(clientVersion, out);
}
public Response readResponse(Request request, DataInput in) throws IOException {
@ -91,7 +91,7 @@ public abstract class AbstractProto {
}
}
public void write(DataOutput out) throws IOException {
public void writeTo(DataOutput out) throws IOException {
out.writeByte(ordinal());
}
@ -110,7 +110,7 @@ public abstract class AbstractProto {
Request read(int clientVersion, DataInput in) throws IOException;
}
protected interface RequestType {
void write(DataOutput out) throws IOException;
void writeTo(DataOutput out) throws IOException;
RequestReader reader();
}
@FunctionalInterface
@ -118,7 +118,7 @@ public abstract class AbstractProto {
Response read(Request request, DataInput in) throws IOException;
}
protected interface ResponseType {
void write(DataOutput out) throws IOException;
void writeTo(DataOutput out) throws IOException;
ResponseReader reader();
}

View File

@ -37,11 +37,11 @@ public abstract class AbstractQueryInitRequest extends Request {
}
@Override
public void write(DataOutput out) throws IOException {
public void writeTo(DataOutput out) throws IOException {
out.writeUTF(query);
out.writeInt(fetchSize);
out.writeUTF(timeZone.getID());
timeout.write(out);
timeout.writeTo(out);
}
@Override

View File

@ -34,10 +34,10 @@ public abstract class AbstractQueryPageRequest extends Request {
}
@Override
public void write(DataOutput out) throws IOException {
public void writeTo(DataOutput out) throws IOException {
out.writeInt(cursor.length);
out.write(cursor);
timeout.write(out);
timeout.writeTo(out);
}
@Override

View File

@ -35,7 +35,7 @@ public abstract class AbstractQueryResponse extends Response {
}
@Override
protected void write(int clientVersion, DataOutput out) throws IOException {
protected void writeTo(int clientVersion, DataOutput out) throws IOException {
out.writeLong(tookNanos);
out.writeInt(cursor.length);
out.write(cursor);

View File

@ -20,7 +20,7 @@ public abstract class Request {
* Write this request to the {@link DataOutput}. Implementers should
* be kind and stick this right under the ctor that reads the response.
*/
protected abstract void write(DataOutput out) throws IOException;
protected abstract void writeTo(DataOutput out) throws IOException;
/**
* Body to go into the {@link #toString()} result.

View File

@ -23,7 +23,7 @@ public abstract class Response {
* the message. This should be used to send a response compatible
* with the client.
*/
protected abstract void write(int clientVersion, DataOutput out) throws IOException;
protected abstract void writeTo(int clientVersion, DataOutput out) throws IOException;
/**
* Body to go into the {@link #toString()} result.

View File

@ -25,7 +25,7 @@ public class TimeoutInfo {
requestTimeout = in.readLong();
}
void write(DataOutput out) throws IOException {
void writeTo(DataOutput out) throws IOException {
out.writeLong(clientTime);
out.writeLong(timeout);
out.writeLong(requestTimeout);

View File

@ -17,6 +17,6 @@ public class TimeoutInfoTests extends ESTestCase {
}
public void testRoundTrip() throws IOException {
assertRoundTrip(randomTimeoutInfo(), TimeoutInfo::write, TimeoutInfo::new);
assertRoundTrip(randomTimeoutInfo(), TimeoutInfo::writeTo, TimeoutInfo::new);
}
}