Skip to content

Commit

Permalink
refactor: removed legacy command classes with relative implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
tglman committed Dec 23, 2024
1 parent b60d7b6 commit f974824
Show file tree
Hide file tree
Showing 55 changed files with 117 additions and 3,717 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import com.orientechnologies.enterprise.server.listener.OEnterpriseConnectionListener;
import com.orientechnologies.enterprise.server.listener.OEnterpriseStorageListener;
import com.orientechnologies.orient.core.Orient;
import com.orientechnologies.orient.core.command.OCommandExecutor;
import com.orientechnologies.orient.core.command.OCommandRequestText;
import com.orientechnologies.orient.core.db.*;
import com.orientechnologies.orient.core.db.OSystemDatabase;
import com.orientechnologies.orient.core.db.document.OQueryDatabaseState;
Expand Down Expand Up @@ -406,13 +404,6 @@ public void onAfterTxCommit(ODatabase iDatabase) {}
@Override
public void onClose(ODatabase iDatabase) {}

@Override
public void onBeforeCommand(OCommandRequestText iCommand, OCommandExecutor executor) {}

@Override
public void onAfterCommand(
OCommandRequestText iCommand, OCommandExecutor executor, Object result) {}

@Override
public void onCommandStart(ODatabase database, OResultSet result) {
this.dbListeners.forEach((c -> c.onCommandStart(database, result)));
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.orientechnologies.orient.client.remote.OStorageRemoteSession;
import com.orientechnologies.orient.core.command.OCommandDistributedReplicateRequest;
import com.orientechnologies.orient.core.command.OCommandDistributedReplicateRequest.DISTRIBUTED_EXECUTION_MODE;
import com.orientechnologies.orient.core.command.OCommandRequestText;
import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.exception.OSerializationException;
Expand Down Expand Up @@ -205,7 +204,6 @@ public Map<Object, Object> getParameters() {

private ODatabaseDocumentInternal database;
private boolean asynch;
private OCommandRequestText query;
private boolean live;
private OQuery queryD;
private OCommand commandD;
Expand Down Expand Up @@ -613,7 +611,7 @@ public boolean isLive() {

@Override
public OCommandResponse createResponse() {
return new OCommandResponse(this.query.getResultListener(), database, live);
return new OCommandResponse(database, live);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
import com.orientechnologies.common.log.OLogManager;
import com.orientechnologies.common.log.OLogger;
import com.orientechnologies.orient.client.remote.OBinaryResponse;
import com.orientechnologies.orient.client.remote.OFetchPlanResults;
import com.orientechnologies.orient.client.remote.OStorageRemoteSession;
import com.orientechnologies.orient.client.remote.SimpleValueFetchPlanCommandListener;
import com.orientechnologies.orient.core.command.OCommandResultListener;
import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
Expand All @@ -51,57 +48,32 @@

public final class OCommandResponse implements OBinaryResponse {
private static final OLogger logger = OLogManager.instance().logger(OCommandResponse.class);
private final OCommandResultListener listener;
private final ODatabaseDocumentInternal database;
private boolean live;
private Object result;
private boolean isRecordResultSet;

public OCommandResponse(
Object result,
SimpleValueFetchPlanCommandListener listener,
boolean isRecordResultSet,
ODatabaseDocumentInternal database) {
Object result, boolean isRecordResultSet, ODatabaseDocumentInternal database) {
this.result = result;
this.listener = listener;
this.isRecordResultSet = isRecordResultSet;
this.database = database;
}

public OCommandResponse(
OCommandResultListener listener, ODatabaseDocumentInternal database, boolean live) {
this.listener = listener;
public OCommandResponse(ODatabaseDocumentInternal database, boolean live) {
this.database = database;
this.live = live;
}

public void write(OChannelDataOutput channel, int protocolVersion, ORecordSerializer serializer)
throws IOException {

serializeValue(
channel,
(SimpleValueFetchPlanCommandListener) listener,
result,
false,
isRecordResultSet,
protocolVersion,
serializer);
if (listener instanceof OFetchPlanResults) {
// SEND FETCHED RECORDS TO LOAD IN CLIENT CACHE
for (ORecord rec : ((OFetchPlanResults) listener).getFetchedRecordsToSend()) {
channel.writeByte((byte) 2); // CLIENT CACHE RECORD. IT
// ISN'T PART OF THE
// RESULT SET
OMessageHelper.writeIdentifiable(channel, rec, serializer);
}

channel.writeByte((byte) 0); // NO MORE RECORDS
}
serializeValue(channel, result, false, isRecordResultSet, protocolVersion, serializer);
channel.writeByte((byte) 0); // NO MORE RECORDS
}

public void serializeValue(
OChannelDataOutput channel,
final SimpleValueFetchPlanCommandListener listener,
Object result,
boolean load,
boolean isRecordResultSet,
Expand All @@ -116,18 +88,16 @@ public void serializeValue(
channel.writeByte((byte) 'r');
if (load && result instanceof ORecordId) result = ((ORecordId) result).getRecord();

if (listener != null) listener.result(result);
OMessageHelper.writeIdentifiable(channel, (OIdentifiable) result, recordSerializer);
} else if (!isRecordResultSet) {
writeSimpleValue(channel, listener, result, protocolVersion, recordSerializer);
writeSimpleValue(channel, result, protocolVersion, recordSerializer);
} else if (OMultiValue.isMultiValue(result)) {
final byte collectionType = result instanceof Set ? (byte) 's' : (byte) 'l';
channel.writeByte(collectionType);
channel.writeInt(OMultiValue.getSize(result));
for (Object o : OMultiValue.getMultiValueIterable(result, false)) {
try {
if (load && o instanceof ORecordId) o = ((ORecordId) o).getRecord();
if (listener != null) listener.result(o);

OMessageHelper.writeIdentifiable(channel, (OIdentifiable) o, recordSerializer);
} catch (Exception e) {
Expand All @@ -142,7 +112,6 @@ public void serializeValue(
for (Object o : OMultiValue.getMultiValueIterable(result)) {
try {
if (load && o instanceof ORecordId) o = ((ORecordId) o).getRecord();
if (listener != null) listener.result(o);

channel.writeByte((byte) 1); // ONE MORE RECORD
OMessageHelper.writeIdentifiable(channel, (OIdentifiable) o, recordSerializer);
Expand All @@ -159,7 +128,6 @@ public void serializeValue(
for (Object o : OMultiValue.getMultiValueIterable(result)) {
try {
if (load && o instanceof ORecordId) o = ((ORecordId) o).getRecord();
if (listener != null) listener.result(o);

OMessageHelper.writeIdentifiable(channel, (OIdentifiable) o, recordSerializer);
} catch (Exception e) {
Expand All @@ -170,13 +138,12 @@ public void serializeValue(

} else {
// ANY OTHER (INCLUDING LITERALS)
writeSimpleValue(channel, listener, result, protocolVersion, recordSerializer);
writeSimpleValue(channel, result, protocolVersion, recordSerializer);
}
}

private void writeSimpleValue(
OChannelDataOutput channel,
SimpleValueFetchPlanCommandListener listener,
Object result,
int protocolVersion,
ORecordSerializer recordSerializer)
Expand All @@ -187,15 +154,9 @@ private void writeSimpleValue(
ODocument document = new ODocument();
document.field("result", result);
OMessageHelper.writeIdentifiable(channel, document, recordSerializer);
if (listener != null) listener.linkdedBySimpleValue(document);
} else {
channel.writeByte((byte) 'a');
final StringBuilder value = new StringBuilder(64);
if (listener != null) {
ODocument document = new ODocument();
document.field("result", result);
listener.linkdedBySimpleValue(document);
}
ORecordSerializerStringAbstract.fieldTypeToString(
value, OType.getTypeByClass(result.getClass()), result);
channel.writeString(value.toString());
Expand All @@ -222,7 +183,6 @@ public void read(OChannelDataInput network, OStorageRemoteSession session) throw
} finally {
// TODO: this is here because we allow query in end listener.
session.commandExecuting = false;
if (listener != null && !live) listener.end();
}
}

Expand Down
Loading

0 comments on commit f974824

Please sign in to comment.