Esempio n. 1
0
File: DB.java Progetto: o-nix/Kafra
  public Object jsFunction_objectToDocument(Object object) {
    if (object instanceof NativeJavaObject) object = ((NativeJavaObject) object).unwrap();

    ORID id = null;
    ODocument doc = null;

    if (object instanceof DbObject) id = (ORID) ((DbObject) object).getId();

    // we have to convert java object to ODocument in a proper way
    if (id != null && !id.isNew()) {
      String className = ((DbObject) object).getClassName();
      List<ODocument> result =
          getDb()
              .command(
                  new OSQLSynchQuery<ODocument>(
                      String.format("select from %1$s where @rid = ?", className)))
              .execute(id);

      if (result != null && result.size() > 0) doc = result.get(0);
    } else doc = (ODocument) Application.getDb().getRecordByUserObject(object, false);

    // reset thread local db
    getDb();

    return wrap(doc);
  }
Esempio n. 2
0
  public ORecordInternal<?> loadRecord(
      final ORID iRid,
      final ORecordInternal<?> iRecord,
      final String iFetchPlan,
      boolean ignonreCache,
      boolean loadTombstone) {
    if (iRid.isNew()) return null;

    return database.executeReadRecord(
        (ORecordId) iRid, iRecord, iFetchPlan, ignonreCache, loadTombstone);
  }
Esempio n. 3
0
File: DB.java Progetto: o-nix/Kafra
  protected Object wrap(ODocument document) {
    Context context = Context.getCurrentContext();
    Scriptable scope = getParentScope();
    ScriptableObject current = (ScriptableObject) context.newObject(scope);

    for (String key : document.fieldNames()) {
      if (!key.startsWith("_")) {
        Object value = document.field(key);

        if (value instanceof ODocument) value = wrap((ODocument) value);
        else if (value instanceof List) value = wrap((List<?>) value);
        else value = Context.javaToJS(value, scope);

        current.put(key, current, value);
      }
    }

    ORID id = document.getIdentity();

    if (!id.isNew()) current.put("id", current, id.toString());

    // if (proxy == null) {
    String function;

    try {
      function = Files.toString(new File("scripts/me/o_nix/db/DB.template"), Charsets.UTF_8);
    } catch (IOException e) {
      throw new RuntimeException("DB script file not found.", e);
    }

    proxy = context.compileFunction(current, function, getClass().getSimpleName(), 0, null);
    // }

    // proxy.setParentScope(current);

    current.putConst("__noSuchMethod__", current, proxy);
    current.putConst("__original__", current, Context.javaToJS(document, scope));

    return current;
  }
Esempio n. 4
0
  public ORecordInternal<?> loadRecord(
      final ORID iRid, final ORecordInternal<?> iRecord, final String iFetchPlan) {
    if (iRid.isNew()) return null;

    return database.executeReadRecord((ORecordId) iRid, iRecord, iFetchPlan, false);
  }