SQL: Cleanup of Cursor wrappers
The follow up for elastic/x-pack-elasticsearch#3197, addresses nik9000's review comments. Original commit: elastic/x-pack-elasticsearch@2307029bd8
This commit is contained in:
parent
4e84a1d658
commit
3b2667048a
|
@ -22,9 +22,13 @@ import java.util.Objects;
|
|||
public class CliFormatterCursor implements Cursor {
|
||||
public static final String NAME = "f";
|
||||
|
||||
private Cursor delegate;
|
||||
private CliFormatter formatter;
|
||||
private final Cursor delegate;
|
||||
private final CliFormatter formatter;
|
||||
|
||||
/**
|
||||
* If the newCursor is empty, returns an empty cursor. Otherwise, creates a new
|
||||
* CliFormatterCursor that wraps the newCursor.
|
||||
*/
|
||||
public static Cursor wrap(Cursor newCursor, CliFormatter formatter) {
|
||||
if (newCursor == EMPTY) {
|
||||
return EMPTY;
|
||||
|
@ -32,7 +36,7 @@ public class CliFormatterCursor implements Cursor {
|
|||
return new CliFormatterCursor(newCursor, formatter);
|
||||
}
|
||||
|
||||
public CliFormatterCursor(Cursor delegate, CliFormatter formatter) {
|
||||
private CliFormatterCursor(Cursor delegate, CliFormatter formatter) {
|
||||
this.delegate = delegate;
|
||||
this.formatter = formatter;
|
||||
}
|
||||
|
|
|
@ -24,10 +24,13 @@ import java.util.Objects;
|
|||
*/
|
||||
public class JdbcCursor implements Cursor {
|
||||
public static final String NAME = "j";
|
||||
private Cursor delegate;
|
||||
private List<JDBCType> types;
|
||||
|
||||
private final Cursor delegate;
|
||||
private final List<JDBCType> types;
|
||||
|
||||
/**
|
||||
* If the newCursor is empty, returns an empty cursor. Otherwise, creates a new
|
||||
* CliFormatterCursor that wraps the newCursor.
|
||||
*/
|
||||
public static Cursor wrap(Cursor newCursor, List<JDBCType> types) {
|
||||
if (newCursor == EMPTY) {
|
||||
return EMPTY;
|
||||
|
@ -35,7 +38,7 @@ public class JdbcCursor implements Cursor {
|
|||
return new JdbcCursor(newCursor, types);
|
||||
}
|
||||
|
||||
public JdbcCursor(Cursor delegate, List<JDBCType> types) {
|
||||
private JdbcCursor(Cursor delegate, List<JDBCType> types) {
|
||||
this.delegate = delegate;
|
||||
this.types = types;
|
||||
}
|
||||
|
|
|
@ -44,11 +44,11 @@ public class SqlResponseTests extends AbstractStreamableTestCase<SqlResponse> {
|
|||
for (int i = 0; i < typeNum; i++) {
|
||||
types.add(randomFrom(JDBCType.values()));
|
||||
}
|
||||
return new JdbcCursor(ScrollCursorTests.randomScrollCursor(), types);
|
||||
return JdbcCursor.wrap(ScrollCursorTests.randomScrollCursor(), types);
|
||||
case 2:
|
||||
SqlResponse response = createRandomInstance(Cursor.EMPTY);
|
||||
if (response.columns() != null && response.rows() != null) {
|
||||
return new CliFormatterCursor(ScrollCursorTests.randomScrollCursor(), new CliFormatter(response));
|
||||
return CliFormatterCursor.wrap(ScrollCursorTests.randomScrollCursor(), new CliFormatter(response));
|
||||
} else {
|
||||
return ScrollCursorTests.randomScrollCursor();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue