Skip to content

Commit

Permalink
refactor: removed usage of command scripts from tools
Browse files Browse the repository at this point in the history
  • Loading branch information
tglman committed Dec 7, 2024
1 parent c4bc32f commit 2e3bcaa
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
package com.orientechnologies.orient.etl.block;

import com.orientechnologies.orient.core.command.OCommandContext;
import com.orientechnologies.orient.core.command.script.OCommandExecutorScript;
import com.orientechnologies.orient.core.command.script.OCommandScript;
import com.orientechnologies.orient.core.record.impl.ODocument;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -29,7 +27,6 @@
public class OETLCodeBlock extends OETLAbstractBlock {
protected String language = "javascript";
protected String code;
protected OCommandExecutorScript cmd;
protected Map<Object, Object> params = new HashMap<Object, Object>();

@Override
Expand All @@ -48,8 +45,6 @@ public void configure(final ODocument iConfiguration, OCommandContext iContext)

if (iConfiguration.containsField("code")) code = iConfiguration.field("code");
else throw new IllegalArgumentException("'code' parameter is mandatory in Code Transformer");

cmd = new OCommandExecutorScript().parse(new OCommandScript(language, code));
}

@Override
Expand All @@ -59,6 +54,6 @@ public String getName() {

@Override
public Object executeBlock() {
return cmd.executeInContext(context, params);
return context.getDatabase().execute(language, code, (Map) params);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package com.orientechnologies.orient.etl.listener;

import com.orientechnologies.orient.core.command.OCommandContext;
import com.orientechnologies.orient.core.command.script.OCommandScript;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.index.OIndex;
import com.orientechnologies.orient.core.record.impl.ODocument;
Expand All @@ -28,7 +27,6 @@

public class OETLScriptImporterListener implements OETLImporterListener {
private final Map<String, String> events;
private Map<String, OCommandScript> scripts = new HashMap<String, OCommandScript>();

public OETLScriptImporterListener() {
events = new HashMap<String, String>();
Expand Down Expand Up @@ -78,23 +76,14 @@ private Object executeEvent(
final ODatabaseDocument db, final String iEventName, final OCommandContext iContext) {
if (events == null) return null;

OCommandScript script = scripts.get(iEventName);
final String code = events.get(iEventName);

if (script == null) {
final String code = events.get(iEventName);
if (code != null) {
// CACHE IT
script = new OCommandScript(code).setLanguage("Javascript");
scripts.put(iEventName, script);
}
}

if (script != null) {
if (code != null) {
final Map<String, Object> pars = new HashMap<String, Object>();
pars.put("task", iContext);
pars.put("importer", this);

return db.command(script).execute(pars);
return db.execute("javascript", code, pars);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
package com.orientechnologies.orient.etl.transformer;

import com.orientechnologies.orient.core.command.OCommandContext;
import com.orientechnologies.orient.core.command.script.OCommandExecutorScript;
import com.orientechnologies.orient.core.command.script.OCommandScript;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.record.impl.ODocument;
Expand All @@ -31,7 +29,7 @@
public class OETLCodeTransformer extends OETLAbstractTransformer {
private final Map<Object, Object> params = new HashMap<Object, Object>();
private String language = "javascript";
private OCommandExecutorScript cmd;
private String code = null;

@Override
public ODocument getConfiguration() {
Expand All @@ -53,8 +51,7 @@ public void configure(final ODocument iConfiguration, OCommandContext iContext)
String code;
if (iConfiguration.containsField("code")) code = iConfiguration.field("code");
else throw new IllegalArgumentException("'code' parameter is mandatory in Code Transformer");

cmd = new OCommandExecutorScript().parse(new OCommandScript(language, code));
this.code = code;
}

@Override
Expand All @@ -70,14 +67,14 @@ public Object executeTransform(ODatabaseDocument db, final Object input) {
if (input instanceof OIdentifiable) params.put("record", ((OIdentifiable) input).getRecord());

try {
Object result = cmd.executeInContext(context, params);
Object result = context.getDatabase().execute(language, code, params);

debug("executed code=%s, result=%s", cmd, result);
debug("executed code=%s, result=%s", code, result);
return result;

} catch (Exception e) {

error("exception=%s - input=%s - command=%s ", e.getMessage(), input, cmd);
error("exception=%s - input=%s - command=%s ", e.getMessage(), input, code);

throw e;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
import com.orientechnologies.orient.core.OSignalHandler;
import com.orientechnologies.orient.core.Orient;
import com.orientechnologies.orient.core.command.OCommandOutputListener;
import com.orientechnologies.orient.core.command.script.OCommandExecutorScript;
import com.orientechnologies.orient.core.command.script.OCommandScript;
import com.orientechnologies.orient.core.config.OGlobalConfiguration;
import com.orientechnologies.orient.core.config.OStorageConfiguration;
import com.orientechnologies.orient.core.config.OStorageEntryConfiguration;
Expand Down Expand Up @@ -1340,10 +1338,7 @@ public void js(
long start = System.currentTimeMillis();
while (true) {
try {
final OCommandExecutorScript cmd = new OCommandExecutorScript();
cmd.parse(new OCommandScript("Javascript", iText));

currentResult = cmd.execute(null);
currentResult = getCurrentDatabase().execute("javascript", iText);
break;
} catch (ORetryQueryException e) {
continue;
Expand Down

0 comments on commit 2e3bcaa

Please sign in to comment.