Package com.orientechnologies.orient.core.record.impl

Examples of com.orientechnologies.orient.core.record.impl.ODocument


    }

    final List<ODocument> edges2Remove = new ArrayList<ODocument>();

    // REMOVE THE EDGE DOCUMENT
    ODocument edge = null;
    Set<ODocument> docs = iSourceVertex.field(OGraphDatabase.VERTEX_FIELD_OUT);
    if (docs != null) {
      // USE A TEMP ARRAY TO AVOID CONCURRENT MODIFICATION TO THE ITERATOR
      for (ODocument d : docs)
        if (d.<ODocument> field(OGraphDatabase.EDGE_FIELD_IN).equals(iTargetVertex)) {
          edges2Remove.add(d);
          edge = d;
        }

      for (ODocument d : edges2Remove)
        docs.remove(d);
    }

    if (edge == null)
      throw new OGraphException("Edge not found between the ougoing edges");

    iSourceVertex.setDirty();
    iSourceVertex.save();

    docs = iTargetVertex.field(OGraphDatabase.VERTEX_FIELD_IN);

    // REMOVE THE EDGE DOCUMENT FROM THE TARGET VERTEX
    if (docs != null) {
      edges2Remove.clear();

      for (ODocument d : docs)
        if (d.<ODocument> field(OGraphDatabase.EDGE_FIELD_IN).equals(iTargetVertex))
          edges2Remove.add(d);

      for (ODocument d : edges2Remove)
        docs.remove(d);
    }

    iTargetVertex.setDirty();
    iTargetVertex.save();

    edge.delete();
  }
View Full Code Here


    checkOpeness();
    if (iPojo == null)
      return;

    // GET THE ASSOCIATED DOCUMENT
    final ODocument record = getRecordByUserObject(iPojo, true);
    underlying.reload(record, iFetchPlan, iIgnoreCache);

    stream2pojo(record, iPojo, iFetchPlan);
  }
View Full Code Here

    checkOpeness();
    if (iPojo == null)
      return this;

    // GET THE ASSOCIATED DOCUMENT
    ODocument record = getRecordByUserObject(iPojo, true);
    try {
      record.setInternalStatus(com.orientechnologies.orient.core.db.record.ORecordElement.STATUS.UNMARSHALLING);

      record = underlying.load(record, iFetchPlan, iIgnoreCache);

      stream2pojo(record, iPojo, iFetchPlan);
    } finally {
      record.setInternalStatus(com.orientechnologies.orient.core.db.record.ORecordElement.STATUS.LOADED);
    }

    return this;
  }
View Full Code Here

  public Object load(final ORID iRecordId, final String iFetchPlan, final boolean iIgnoreCache) {
    checkOpeness();
    if (iRecordId == null)
      return null;

    ODocument record = rid2Records.get(iRecordId);
    if (record == null) {
      // GET THE ASSOCIATED DOCUMENT
      record = (ODocument) underlying.load(iRecordId, iFetchPlan, iIgnoreCache);
      if (record == null)
        return null;
    }

    Object result = records2Objects.get(record);
    if (result != null)
      // FOUND: JUST RETURN IT
      return result;

    result = stream2pojo(record, newInstance(record.getClassName()), iFetchPlan);
    registerUserObject(result, record);
    return result;
  }
View Full Code Here

      return this;

    OSerializationThreadLocal.INSTANCE.get().clear();

    // GET THE ASSOCIATED DOCUMENT
    final ODocument record = getRecordByUserObject(iPojo, true);
    try {
      record.setInternalStatus(com.orientechnologies.orient.core.db.record.ORecordElement.STATUS.MARSHALLING);

      if (!saveOnlyDirty || record.isDirty()) {
        // REGISTER BEFORE TO SERIALIZE TO AVOID PROBLEMS WITH CIRCULAR DEPENDENCY
        // registerUserObject(iPojo, record);

        pojo2Stream(iPojo, record);

        underlying.save(record, iClusterName);

        // RE-REGISTER FOR NEW RECORDS SINCE THE ID HAS CHANGED
        registerUserObject(iPojo, record);
      }
    } finally {
      record.setInternalStatus(com.orientechnologies.orient.core.db.record.ORecordElement.STATUS.LOADED);
    }

    return this;
  }
View Full Code Here

    checkOpeness();

    if (iPojo == null)
      return this;

    ODocument record = getRecordByUserObject(iPojo, false);
    if (record == null) {
      final ORecordId rid = OObjectSerializerHelper.getObjectID(this, iPojo);
      if (rid == null)
        throw new OObjectNotDetachedException("Can't retrieve the object's ID for '" + iPojo + "' because hasn't been detached");
View Full Code Here

   *          User object
   */
  @Override
  public int getVersion(final Object iPojo) {
    checkOpeness();
    final ODocument record = getRecordByUserObject(iPojo, false);
    if (record != null)
      return record.getVersion();

    return OObjectSerializerHelper.getObjectVersion(iPojo);
  }
View Full Code Here

   *          User object
   */
  @Override
  public ORID getIdentity(final Object iPojo) {
    checkOpeness();
    final ODocument record = getRecordByUserObject(iPojo, false);
    if (record != null)
      return record.getIdentity();
    return OObjectSerializerHelper.getObjectID(this, iPojo);
  }
View Full Code Here

    this.saveOnlyDirty = saveOnlyDirty;
  }

  public Object newInstance() {
    checkOpeness();
    return new ODocument(underlying);
  }
View Full Code Here

      throw new OCommandExecutionException("Destination class '" + destClassName + "' not found");

    Object value;
    String cmd = "select from " + destClassName + " where " + destField + " = ";
    List<ODocument> result;
    ODocument target;
    Object oldValue;
    long total = 0;

    if (linkName == null)
      // NO LINK NAME EXPRESSED: OVERWRITE THE SOURCE FIELD
      linkName = sourceField;

    boolean inverse = linkType != null && linkType.equalsIgnoreCase("inverse");
    boolean multipleRelationship = false;

    long totRecords = db.countClass(sourceClass.getName());
    long currRecord = 0;

    if (progressListener != null)
      progressListener.onBegin(this, totRecords);

    try {
      // BROWSE ALL THE RECORDS OF THE SOURCE CLASS
      for (ODocument doc : db.browseClass(sourceClass.getName())) {
        value = doc.field(sourceField);

        if (value != null) {
          if (value instanceof ODocument || value instanceof ORID) {
            // ALREADY CONVERTED
          } else if (value instanceof Collection<?>) {
            // TODO
          } else {
            // SEARCH THE DESTINATION RECORD
            target = null;

            if (value instanceof String)
              if (((String) value).length() == 0)
                value = null;
              else
                value = "'" + value + "'";

            result = database.<OCommandRequest> command(new OSQLSynchQuery<ODocument>(cmd + value)).execute();

            if (result == null || result.size() == 0)
              // throw new
              // OCommandExecutionException("Can't create link because the destination record was not found in class '"
              // + destClass.getName() + "' and with the field '" + destField + "' equals to " + value);
              value = null;
            else if (result.size() > 1)
              throw new OCommandExecutionException("Can't create link because multiple records was found in class '"
                  + destClass.getName() + "' with value " + value + " in field '" + destField + "'");
            else {
              target = result.get(0);
              value = target;
            }

            if (target != null && inverse) {
              // INVERSE RELATIONSHIP
              oldValue = target.field(linkName);

              if (oldValue != null) {
                if (!multipleRelationship)
                  multipleRelationship = true;

                Collection<ODocument> coll;
                if (oldValue instanceof Collection) {
                  // ADD IT IN THE EXISTENT COLLECTION
                  coll = (Collection<ODocument>) oldValue;
                  target.setDirty();
                } else {
                  // CREATE A NEW COLLECTION FOR BOTH
                  coll = new ArrayList<ODocument>(2);
                  target.field(linkName, coll);
                  coll.add((ODocument) oldValue);
                }
                coll.add(doc);
              } else {
                target.field(linkName, doc);
              }
              target.save();

            } else {
              // SET THE REFERENCE
              doc.field(linkName, value);
              doc.save();
View Full Code Here

TOP

Related Classes of com.orientechnologies.orient.core.record.impl.ODocument

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.