Package com.orientechnologies.orient.enterprise.command.script

Examples of com.orientechnologies.orient.enterprise.command.script.OCommandScriptException


  public Object execute(final Map<Object, Object> iArgs) {
    final String language = request.getLanguage();
    final String script = request.getText();

    if (language == null)
      throw new OCommandScriptException("No language was specified");

    if (!engines.containsKey(language))
      throw new OCommandScriptException("Unsupported language: " + language + ". Supported languages are: " + engines);

    if (script == null)
      throw new OCommandScriptException("Invalid script: " + script);

    final ScriptEngine scriptEngine = engines.get(language);

    if (scriptEngine == null)
      throw new OCommandScriptException("Cannot find script engine: " + language);

    final Bindings binding = scriptEngine.createBindings();

    // BIND FIXED VARIABLES
    binding.put("db", database);

    // BIND PARAMETERS INTO THE SCRIPT
    if (iArgs != null)
      for (int i = 0; i < iArgs.size(); ++i) {
        binding.put("$" + i, iArgs.get(i));
      }

    try {
      Object result = null;
      result = scriptEngine.eval(script, binding);

      return result;
    } catch (ScriptException e) {
      throw new OCommandScriptException("Error on execution of the script", request.getText(), 0, e);
    }
  }
View Full Code Here


  public Object execute(final Map<Object, Object> iArgs) {
    final String language = request.getLanguage();
    final String script = request.getText();

    if (language == null)
      throw new OCommandScriptException("No language was specified");

    if (!engines.containsKey(language))
      throw new OCommandScriptException("Unsupported language: " + language + ". Supported languages are: " + engines);

    if (script == null)
      throw new OCommandScriptException("Invalid script: null");

    final ScriptEngine scriptEngine = engines.get(language);

    if (scriptEngine == null)
      throw new OCommandScriptException("Cannot find script engine: " + language);

    final Bindings binding = scriptEngine.createBindings();

    // BIND FIXED VARIABLES
    binding.put("db", database);

    // BIND PARAMETERS INTO THE SCRIPT
    if (iArgs != null)
      for (int i = 0; i < iArgs.size(); ++i) {
        binding.put("$" + i, iArgs.get(i));
      }

    try {
      Object result = null;
      result = scriptEngine.eval(script, binding);

      return result;
    } catch (ScriptException e) {
      throw new OCommandScriptException("Error on execution of the script", request.getText(), 0, e);
    }
  }
View Full Code Here

TOP

Related Classes of com.orientechnologies.orient.enterprise.command.script.OCommandScriptException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.