Package com.orientechnologies.orient.core.id

Examples of com.orientechnologies.orient.core.id.ORID


      // NULL VALUE
      return null;

    final ORecordInternal<?> obj = Orient.instance().getRecordFactoryManager().newInstance(iDatabase);

    final ORID rid = new ORecordId().fromStream(iStream);

    obj.setIdentity(rid.getClusterId(), rid.getClusterPosition());
    return obj;
  }
View Full Code Here


  public OIndexInternal loadFromConfiguration(final ODocument iConfig) {
    acquireExclusiveLock();
    try {

      final ORID rid = (ORID) iConfig.field(CONFIG_MAP_RID, ORID.class);
      if (rid == null)
        return null;

      configuration = iConfig;
      name = configuration.field(OIndexInternal.CONFIG_NAME);
View Full Code Here

    if (iLinked == null)
      // NULL REFERENCE
      return null;

    OIdentifiable resultRid = null;
    ORID rid;

    if (iLinked instanceof ORID) {
      // JUST THE REFERENCE
      rid = (ORID) iLinked;

      if (rid.isNew()) {
        // SAVE AT THE FLY AND STORE THE NEW RID
        final ORecord<?> record = rid.getRecord();

        if (record.getDatabase().getTransaction().isActive()) {
          final OTransactionRecordEntry recordEntry = record.getDatabase().getTransaction().getRecordEntry(rid);
          if (recordEntry != null)
            // GET THE CLUSTER SPECIFIED
            record.getDatabase().save((ORecordInternal<?>) record, recordEntry.clusterName);
          else
            // USE THE DEFAULT CLUSTER
            record.getDatabase().save((ORecordInternal<?>) record);

        } else
          record.getDatabase().save((ORecordInternal<?>) record);

        rid = record.getIdentity();
      }
    } else {
      if (!(iLinked instanceof ORecordInternal<?>)) {
        // NOT RECORD: TRY TO EXTRACT THE DOCUMENT IF ANY
        final String boundDocumentField = OObjectSerializerHelper.getDocumentBoundField(iLinked.getClass());
        if (boundDocumentField != null)
          iLinked = OObjectSerializerHelper.getFieldValue(iLinked, boundDocumentField);
      }

      if (!(iLinked instanceof ORecordInternal<?>))
        throw new IllegalArgumentException("Invalid object received. Expected a record but received type="
            + iLinked.getClass().getName() + " and value=" + iLinked);

      // RECORD
      ORecordInternal<?> iLinkedRecord = (ORecordInternal<?>) iLinked;
      rid = iLinkedRecord.getIdentity();

      if (rid.isNew() || iLinkedRecord.isDirty()) {
        if (iLinkedRecord.getDatabase() == null && iParentRecord != null)
          // OVERWRITE THE DATABASE TO THE SAME OF THE PARENT ONE
          iLinkedRecord.setDatabase(iParentRecord.getDatabase());

        if (iLinkedRecord instanceof ODocument) {
          final OClass schemaClass = ((ODocument) iLinkedRecord).getSchemaClass();
          iLinkedRecord.getDatabase().save(iLinkedRecord,
              schemaClass != null ? iLinkedRecord.getDatabase().getClusterNameById(schemaClass.getDefaultClusterId()) : null);
        } else
          // STORE THE TRAVERSED OBJECT TO KNOW THE RECORD ID. CALL THIS VERSION TO AVOID CLEAR OF STACK IN THREAD-LOCAL
          iLinkedRecord.getDatabase().save(iLinkedRecord);

        iLinkedRecord.getDatabase().registerUserObject(iLinkedRecord.getDatabase().getUserObjectByRecord(iLinkedRecord, null),
            iLinkedRecord);

        resultRid = iLinkedRecord;
      }

      if (iParentRecord != null && iParentRecord.getDatabase() instanceof ODatabaseRecord) {
        final ODatabaseRecord db = iParentRecord.getDatabase();
        if (!db.isRetainRecords())
          // REPLACE CURRENT RECORD WITH ITS ID: THIS SAVES A LOT OF MEMORY
          resultRid = iLinkedRecord.getIdentity();
      }
    }

    if (rid.isValid())
      rid.toString(buffer);

    return resultRid;
  }
View Full Code Here

  public void testInvalidFetchplanLoad() {
    database = ODatabaseDocumentPool.global().acquire(url, "admin", "admin");
    ODocument doc = database.newInstance();
    doc.field("test", "test");
    doc.save();
    ORID docRid = doc.getIdentity().copy();
    // RELOAD THE DOCUMENT, THIS WILL PUT IT IN L1 CACHE
    doc = database.load(docRid, "*:-1");
    doc = testInvalidFetchPlanInvalidateL1Cache(doc, docRid);
    doc = testInvalidFetchPlanInvalidateL1Cache(doc, new ORecordId(1, 0));
    doc = testInvalidFetchPlanInvalidateL1Cache(doc, new ORecordId(1, 1));
View Full Code Here

  }

  public OSerializableStream fromStream(final byte[] iStream) throws OSerializationException {
    final long timer = OProfiler.getInstance().startChrono();

    final ORID rootRid = new ORecordId();

    try {
      final OMemoryInputStream stream = new OMemoryInputStream(iStream);

      byte protocolVersion = stream.peek();
      if (protocolVersion != -1) {
        // @COMPATIBILITY BEFORE 0.9.25
        stream.getAsByte();
        if (protocolVersion != CURRENT_PROTOCOL_VERSION)
          throw new OSerializationException(
              "The index has been created with a previous version of OrientDB. Soft transitions between version is a featured supported since 0.9.25. In order to use it with this version of OrientDB you need to export and import your database. "
                  + protocolVersion + "<->" + CURRENT_PROTOCOL_VERSION);
      }

      rootRid.fromStream(stream.getAsByteArrayFixed(ORecordId.PERSISTENT_SIZE));

      size = stream.getAsInteger();
      if (protocolVersion == -1)
        // @COMPATIBILITY BEFORE 0.9.25
        lastPageSize = stream.getAsShort();
      else
        lastPageSize = stream.getAsInteger();

      serializerFromStream(stream);

      // LOAD THE ROOT OBJECT AFTER ALL
      if (rootRid.isValid())
        root = loadEntry(null, rootRid);

      return this;

    } catch (Exception e) {
View Full Code Here

    recordsToCommit.add((OMVRBTreeEntryPersistent<K, V>) iNode);
  }

  @Override
  public int hashCode() {
    final ORID rid = record.getIdentity();
    return rid == null ? 0 : rid.hashCode();
  }
View Full Code Here

    Assert.assertTrue(result.iterator().next().toString().equals(johnDoeID.toString()));

    result = database.command(new OCommandSQL("find references " + chuckNorrisID.toString())).execute();

    Assert.assertTrue(result.size() == 2);
    ORID rid = result.iterator().next();
    Assert.assertTrue(rid.toString().equals(ctuID.toString()) || rid.toString().equals(fbiID.toString()));
    rid = result.iterator().next();
    Assert.assertTrue(rid.toString().equals(ctuID.toString()) || rid.toString().equals(fbiID.toString()));

    result = database.command(new OCommandSQL("find references " + johnDoeID.toString())).execute();
    Assert.assertTrue(result.size() == 0);

    result.clear();
View Full Code Here

    result = database.command(
        new OCommandSQL("find references " + jackBauerID.toString() + " [" + WORKPLACE + ",cluster:" + CAR + "]")).execute();

    Assert.assertTrue(result.size() == 3);
    ORID rid = result.iterator().next();
    Assert.assertTrue(rid.toString().equals(ctuID.toString()) || rid.toString().equals(fbiID.toString())
        || rid.toString().equals(carID.toString()));
    rid = result.iterator().next();
    Assert.assertTrue(rid.toString().equals(ctuID.toString()) || rid.toString().equals(fbiID.toString())
        || rid.toString().equals(carID.toString()));
    rid = result.iterator().next();
    Assert.assertTrue(rid.toString().equals(ctuID.toString()) || rid.toString().equals(fbiID.toString())
        || rid.toString().equals(carID.toString()));

    result = database.command(
        new OCommandSQL("find references " + johnDoeID.toString() + " [" + WORKPLACE + "," + CAR + ",cluster:" + WORKER + "]"))
        .execute();
View Full Code Here

    List<ODocument> resultset = database.query(new OSQLSynchQuery<ODocument>(query));
    Assert.assertFalse(resultset.isEmpty());
    Assert.assertTrue(resultset.size() <= 3);

    while (!resultset.isEmpty()) {
      ORID last = resultset.get(resultset.size() - 1).getIdentity();

      resultset = database.query(new OSQLSynchQuery<ODocument>(query + " range " + last.next()));
      Assert.assertTrue(resultset.size() <= 3);

      for (ODocument d : resultset)
        Assert.assertTrue(d.getIdentity().getClusterId() >= last.getClusterId()
            && d.getIdentity().getClusterPosition() > last.getClusterPosition());
    }

    database.close();
  }
View Full Code Here

  public void queryWithPagination() {
    database.open("admin", "admin");

    final OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<ODocument>("select from Profile LIMIT 3");

    ORID last = new ORecordId();

    for (List<ODocument> resultset = database.query(query); !resultset.isEmpty(); resultset = query.execute()) {
      Assert.assertTrue(resultset.size() <= 3);

      for (ODocument d : resultset)
        Assert.assertTrue(d.getIdentity().getClusterId() >= last.getClusterId()
            && d.getIdentity().getClusterPosition() > last.getClusterPosition());

      last = resultset.get(resultset.size() - 1).getIdentity();
    }

    database.close();
View Full Code Here

TOP

Related Classes of com.orientechnologies.orient.core.id.ORID

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.