Skip to content

Commit

Permalink
refactor: clean up some specific types in remote protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
tglman committed Jul 25, 2023
1 parent 66fa78b commit 31b400c
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,7 @@ public OResultSet executeServerStatement(
response.getExecutionPlan(),
response.getQueryStats(),
response.isHasNextPage());
return new ORemoteQueryResult(rs, response.isTxChanges(), response.isReloadMetadata())
.getResult();
return rs;
}

@Override
Expand Down Expand Up @@ -628,8 +627,7 @@ public OResultSet executeServerStatement(
response.getQueryStats(),
response.isHasNextPage());

return new ORemoteQueryResult(rs, response.isTxChanges(), response.isReloadMetadata())
.getResult();
return rs;
}

public OContextConfiguration getContextConfiguration() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.orientechnologies.orient.core.sql.executor.OInfoExecutionPlan;
import com.orientechnologies.orient.core.sql.executor.OInfoExecutionStep;
import com.orientechnologies.orient.core.sql.executor.OResult;
import com.orientechnologies.orient.core.sql.executor.OResultInternal;
import com.orientechnologies.orient.enterprise.channel.binary.OChannelDataInput;
import com.orientechnologies.orient.enterprise.channel.binary.OChannelDataOutput;
import java.io.IOException;
Expand All @@ -30,7 +29,7 @@ public class OQueryResponse implements OBinaryResponse {

private String queryId;
private boolean txChanges;
private List<OResultInternal> result;
private List<OResult> result;
private Optional<OExecutionPlan> executionPlan;
private boolean hasNextPage;
private Map<String, Long> queryStats;
Expand All @@ -39,7 +38,7 @@ public class OQueryResponse implements OBinaryResponse {
public OQueryResponse(
String queryId,
boolean txChanges,
List<OResultInternal> result,
List<OResult> result,
Optional<OExecutionPlan> executionPlan,
boolean hasNextPage,
Map<String, Long> queryStats,
Expand Down Expand Up @@ -150,7 +149,7 @@ public String getQueryId() {
return queryId;
}

public List<OResultInternal> getResult() {
public List<OResult> getResult() {
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ public class ORemoteResultSet implements OResultSet {

private final ODatabaseDocumentRemote db;
private final String queryId;
private List<OResultInternal> currentPage;
private List<OResult> currentPage;
private Optional<OExecutionPlan> executionPlan;
private Map<String, Long> queryStats;
private boolean hasNextPage;

public ORemoteResultSet(
ODatabaseDocumentRemote db,
String queryId,
List<OResultInternal> currentPage,
List<OResult> currentPage,
Optional<OExecutionPlan> executionPlan,
Map<String, Long> queryStats,
boolean hasNextPage) {
Expand All @@ -36,8 +36,10 @@ public ORemoteResultSet(
this.hasNextPage = hasNextPage;
if (db != null) {
db.queryStarted(queryId, new OQueryDatabaseState(this));
for (OResultInternal result : currentPage) {
result.bindToCache(db);
for (OResult result : currentPage) {
if (result instanceof OResultInternal) {
((OResultInternal) result).bindToCache(db);
}
}
}
}
Expand Down Expand Up @@ -71,7 +73,7 @@ public OResult next() {
if (currentPage.isEmpty()) {
throw new IllegalStateException();
}
OResultInternal internal = currentPage.remove(0);
OResult internal = currentPage.remove(0);

if (internal.isRecord() && db != null && db.getTransaction().isActive()) {
ORecord record = db.getTransaction().getRecord(internal.getRecord().get().getIdentity());
Expand Down Expand Up @@ -114,7 +116,7 @@ public String getQueryId() {
}

public void fetched(
List<OResultInternal> result,
List<OResult> result,
boolean hasNextPage,
Optional<OExecutionPlan> executionPlan,
Map<String, Long> queryStats) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class OServerQueryResponse implements OBinaryResponse {

private String queryId;
private boolean txChanges;
private List<OResultInternal> result;
private List<OResult> result;
private Optional<OExecutionPlan> executionPlan;
private boolean hasNextPage;
private Map<String, Long> queryStats;
Expand All @@ -30,7 +30,7 @@ public class OServerQueryResponse implements OBinaryResponse {
public OServerQueryResponse(
String queryId,
boolean txChanges,
List<OResultInternal> result,
List<OResult> result,
Optional<OExecutionPlan> executionPlan,
boolean hasNextPage,
Map<String, Long> queryStats,
Expand Down Expand Up @@ -141,7 +141,7 @@ public String getQueryId() {
return queryId;
}

public List<OResultInternal> getResult() {
public List<OResult> getResult() {
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class OQueryResponseTest {
@Test
public void test() throws IOException {

List<OResultInternal> resuls = new ArrayList<>();
List<OResult> resuls = new ArrayList<>();
for (int i = 0; i < 10; i++) {
OResultInternal item = new OResultInternal();
item.setProperty("name", "foo");
Expand All @@ -40,7 +40,7 @@ public void test() throws IOException {
OQueryResponse newResponse = new OQueryResponse();

newResponse.read(channel, null);
Iterator<OResultInternal> responseRs = newResponse.getResult().iterator();
Iterator<OResult> responseRs = newResponse.getResult().iterator();

for (int i = 0; i < 10; i++) {
Assert.assertTrue(responseRs.hasNext());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class OServerQueryResponseTest {
@Test
public void test() throws IOException {

List<OResultInternal> resuls = new ArrayList<>();
List<OResult> resuls = new ArrayList<>();
for (int i = 0; i < 10; i++) {
OResultInternal item = new OResultInternal();
item.setProperty("name", "foo");
Expand All @@ -37,7 +37,7 @@ public void test() throws IOException {
OServerQueryResponse newResponse = new OServerQueryResponse();

newResponse.read(channel, null);
Iterator<OResultInternal> responseRs = newResponse.getResult().iterator();
Iterator<OResult> responseRs = newResponse.getResult().iterator();

for (int i = 0; i < 10; i++) {
Assert.assertTrue(responseRs.hasNext());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import com.orientechnologies.orient.core.serialization.serializer.record.ORecordSerializerFactory;
import com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializerNetworkV37;
import com.orientechnologies.orient.core.sql.executor.OResult;
import com.orientechnologies.orient.core.sql.executor.OResultInternal;
import com.orientechnologies.orient.core.sql.executor.OResultSet;
import com.orientechnologies.orient.core.sql.parser.OLocalResultSetLifecycleDecorator;
import com.orientechnologies.orient.core.sql.query.OSQLAsynchQuery;
Expand Down Expand Up @@ -1300,16 +1299,11 @@ public OBinaryResponse executeServerQuery(OServerQueryRequest request) {
}

// copy the result-set to make sure that the execution is successful
Stream<OResult> stream = rs.stream();
List<OResultInternal> rsCopy =
stream.map((r) -> (OResultInternal) r).collect(Collectors.toList());

boolean hasNext = rs.hasNext();
boolean txChanges = false;
List<OResult> rsCopy = rs.stream().collect(Collectors.toList());

return new OServerQueryResponse(
((OLocalResultSetLifecycleDecorator) rs).getQueryId(),
txChanges,
false,
rsCopy,
rs.getExecutionPlan(),
false,
Expand Down Expand Up @@ -1358,8 +1352,7 @@ public OBinaryResponse executeQuery(OQueryRequest request) {
.containsKey(((OLocalResultSetLifecycleDecorator) rs).getQueryId())) {
stream = stream.limit(request.getRecordsPerPage());
}
List<OResultInternal> rsCopy =
stream.map((r) -> (OResultInternal) r).collect(Collectors.toList());
List<OResult> rsCopy = stream.collect(Collectors.toList());

boolean hasNext = rs.hasNext();
boolean txChanges = false;
Expand Down Expand Up @@ -1405,13 +1398,13 @@ public OBinaryResponse executeQueryNextPage(OQueryNextPageRequest request) {
try {
orientDB.startCommand(Optional.empty());
// copy the result-set to make sure that the execution is successful
List<OResultInternal> rsCopy = new ArrayList<>(request.getRecordsPerPage());
List<OResult> rsCopy = new ArrayList<>(request.getRecordsPerPage());
int i = 0;
// if it's OInternalResultSet it means that it's a Command, not a Query, so the result has to
// be
// sent as it is, not streamed
while (rs.hasNext() && (rs.isDetached() || i < request.getRecordsPerPage())) {
rsCopy.add((OResultInternal) rs.next());
rsCopy.add((OResult) rs.next());
i++;
}
boolean hasNext = rs.hasNext();
Expand Down

0 comments on commit 31b400c

Please sign in to comment.