Examples of OFunction


Examples of com.orientechnologies.orient.core.metadata.function.OFunction

      throw new OCommandExecutionException("Syntax Error. You must specify a function name: " + getSyntax());
    if (code == null || code.isEmpty())
      throw new OCommandExecutionException("Syntax Error. You must specify the function code: " + getSyntax());

    ODatabaseRecord database = getDatabase();
    final OFunction f = database.getMetadata().getFunctionLibrary().createFunction(name);
    f.setCode(code);
    f.setIdempotent(idempotent);
    if (parameters != null)
      f.setParameters(parameters);
    if (language != null)
      f.setLanguage(language);

    return f.getId();
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.metadata.function.OFunction

    this.status = doc.field(PROP_STATUS);
    // this.runAtStart = doc.field(PROP_RUN_ON_START) == null ? false : ((Boolean)doc.field(PROP_RUN_ON_START));
    this.started = doc.field(PROP_STARTED) == null ? false : ((Boolean) doc.field(PROP_STARTED));
    ODocument funcDoc = doc.field(PROP_FUNC);
    if (funcDoc != null)
      function = new OFunction(funcDoc);
    else
      throw new OCommandScriptException("function cannot be null");
    this.startTime = doc.field(PROP_STARTTIME);
    this.document = doc;
    this.db = ODatabaseRecordThreadLocal.INSTANCE.get();
View Full Code Here

Examples of com.orientechnologies.orient.core.metadata.function.OFunction

    this.iArgs = doc.field(PROP_ARGUMENTS);
    this.status = doc.field(PROP_STATUS);
    this.started = doc.field(PROP_STARTED) == null ? false : ((Boolean) doc.field(PROP_STARTED));
    ODocument funcDoc = doc.field(PROP_FUNC);
    if (funcDoc != null)
      function = new OFunction(funcDoc);
    else
      throw new OCommandScriptException("function cannot be null");
    this.startTime = doc.field(PROP_STARTTIME);
    this.db = ODatabaseRecordThreadLocal.INSTANCE.get();
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.metadata.function.OFunction

     ODatabaseDocumentTx db = null;

     try {
       db = getProfiledDatabaseInstance(iRequest);

       final OFunction f = db.getMetadata().getFunctionLibrary().getFunction(parts[2]);
       if (f == null)
         throw new IllegalArgumentException("Function '" + parts[2] + "' is not configured");

       if (iRequest.httpMethod.equalsIgnoreCase("GET") && !f.isIdempotent()) {
         iResponse.send(OHttpUtils.STATUS_BADREQ_CODE, OHttpUtils.STATUS_BADREQ_DESCRIPTION, OHttpUtils.CONTENT_TEXT_PLAIN,
             "GET method is not allowed to execute function '" + parts[2]
                 + "' because has been declared as non idempotent. Use POST instead.", null, true);
         return false;
       }

       final Object[] args = new String[parts.length - 3];
       for (int i = 3; i < parts.length; ++i)
         args[i - 3] = parts[i];

       // BIND CONTEXT VARIABLES
       final OBasicCommandContext context = new OBasicCommandContext();
       context.setVariable("session", OHttpSessionManager.getInstance().getSession(iRequest.sessionId));
       context.setVariable("request", new OHttpRequestWrapper(iRequest, (String[]) args));
       context.setVariable("response", new OHttpResponseWrapper(iResponse));

       handleResult(iRequest, iResponse, f.executeInContext(context, args));

     } catch (OCommandScriptException e) {
       // EXCEPTION

       final StringBuilder msg = new StringBuilder(256);
View Full Code Here

Examples of com.orientechnologies.orient.core.metadata.function.OFunction

    ODatabaseRecordInternal db = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
    if (db != null && !(db instanceof ODatabaseRecordTx))
      db = db.getUnderlying();

    final OFunction f = db.getMetadata().getFunctionLibrary().getFunction(parserText);

    db.checkSecurity(ODatabaseSecurityResources.FUNCTION, ORole.PERMISSION_READ, f.getName());

    final OScriptManager scriptManager = Orient.instance().getScriptManager();
    final ScriptEngine scriptEngine = scriptManager.getEngine(f.getLanguage());
    final Bindings binding = scriptManager.bind(scriptEngine.getBindings(ScriptContext.ENGINE_SCOPE), (ODatabaseRecordTx) db,
        iContext, iArgs);

    try {
      // COMPILE FUNCTION LIBRARY
      final String lib = scriptManager.getLibrary(db, f.getLanguage());
      if (lib != null)
        try {
          scriptEngine.eval(lib);
        } catch (ScriptException e) {
          scriptManager.getErrorMessage(e, lib);
View Full Code Here

Examples of com.orientechnologies.orient.core.metadata.function.OFunction

        args[argIdx++] = value;
      }
    } else
      args = null;

    final OFunction f = ODatabaseRecordThreadLocal.INSTANCE.get().getMetadata().getFunctionLibrary().getFunction(function);
    if (f != null) {
      debug(iContext, "Calling database function: " + function + "(" + Arrays.toString(args) + ")...");
      return f.executeInContext(iContext, args);
    }

    int lastDot = function.lastIndexOf('.');
    if (lastDot > -1) {
      final String clsName = function.substring(0, lastDot);
View Full Code Here

Examples of com.orientechnologies.orient.core.metadata.function.OFunction

    final StringBuilder code = new StringBuilder();

    final Set<String> functions = db.getMetadata().getFunctionLibrary().getFunctionNames();
    for (String fName : functions) {
      final OFunction f = db.getMetadata().getFunctionLibrary().getFunction(fName);

      if (f.getLanguage() == null)
        throw new OConfigurationException("Database function '" + fName + "' has no language");

      if (f.getLanguage().equalsIgnoreCase(iLanguage)) {
        final String def = getFunctionDefinition(f);
        if (def != null) {
          code.append(def);
          code.append("\n");
        }
View Full Code Here

Examples of com.orientechnologies.orient.core.metadata.function.OFunction

  }

  private Object checkClzAttribute(final ODocument iDocument, String attr) {
    final OClass clz = iDocument.getSchemaClass();
    if (clz != null && clz.isSubClassOf(CLASSNAME)) {
      OFunction func = null;
      String fieldName = ((OClassImpl) clz).getCustom(attr);
      OClass superClz = clz.getSuperClass();
      while (fieldName == null || fieldName.length() == 0) {
        if (superClz == null || superClz.getName().equals(CLASSNAME))
          break;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.