Package com.orientechnologies.orient.core.id

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


    ORawBuffer buffer;
    objectsRead = 0;

    int clusterId = db.getClusterIdByName(CLUSTER_NAME);

    final ORecordId rid = new ORecordId(clusterId);
    for (int i = 0; i < db.countClusterElements(CLUSTER_NAME); ++i) {
      rid.clusterPosition = i;
     
      buffer = db.read(rid, null);
      if (buffer != null)
View Full Code Here


      iRequest.data.commandInfo = "Studio edit document";

      if (rid == null)
        throw new IllegalArgumentException("Record ID not found in request");

      ODocument doc = new ODocument(db, className, new ORecordId(rid));
      doc = (ODocument) doc.load();

      // BIND ALL CHANGED FIELDS
      Object oldValue;
      Object newValue;
      for (Entry<String, String> f : fields.entrySet()) {
        oldValue = doc.field(f.getKey());
        newValue = f.getValue();

        if (oldValue != null) {
          if (oldValue instanceof ORecord<?>) {
            ORecord<?> rec = (ORecord<?>) oldValue;
            String parsedRid = f.getValue();
            if (parsedRid != null && parsedRid.charAt(0) == '#')
              parsedRid = parsedRid.substring(1);

            if (!rec.getIdentity().toString().equals(parsedRid)) {
              // CHANGED RID
              rec.reset();
              ((ORecordId) rec.getIdentity()).fromString(parsedRid);

              // RELOAD TO ASSURE IT EXISTS
              rec.load();
            }
            newValue = oldValue;
          } else if (oldValue instanceof Collection<?>) {
            newValue = new ArrayList<ODocument>();

            if (f.getValue() != null) {
              String[] items = f.getValue().split(",");
              for (String s : items) {
                ((List<ODocument>) newValue).add(new ODocument(db, new ORecordId(s)));
              }
            }
          }
        }

        doc.field(f.getKey(), newValue);
      }

      doc.save();
      sendTextContent(iRequest, OHttpUtils.STATUS_OK_CODE, "OK", null, OHttpUtils.CONTENT_TEXT_PLAIN, "Record " + rid
          + " updated successfully.");
    } else if ("add".equals(operation)) {
      iRequest.data.commandInfo = "Studio create document";

      final ODocument doc = new ODocument(db, className);

      // BIND ALL CHANGED FIELDS
      for (Entry<String, String> f : fields.entrySet())
        doc.field(f.getKey(), f.getValue());

      doc.save();
      sendTextContent(iRequest, 201, "OK", null, OHttpUtils.CONTENT_TEXT_PLAIN, "Record " + doc.getIdentity()
          + " updated successfully.");

    } else if ("del".equals(operation)) {
      iRequest.data.commandInfo = "Studio delete document";

      if (rid == null)
        throw new IllegalArgumentException("Record ID not found in request");

      final ODocument doc = new ODocument(db, new ORecordId(rid));
      doc.load();
      doc.delete();
      sendTextContent(iRequest, OHttpUtils.STATUS_OK_CODE, "OK", null, OHttpUtils.CONTENT_TEXT_PLAIN, "Record " + rid
          + " deleted successfully.");
View Full Code Here

    for (ODocument d : result) {
      Assert.assertTrue(d.containsField("key"));
      Assert.assertTrue(d.containsField("rid"));

      if (d.field("key").equals(10))
        Assert.assertEquals(d.rawField("rid"), new ORecordId("#3:0"));
      else if (d.field("key").equals(20))
        Assert.assertEquals(d.rawField("rid"), new ORecordId("#3:1"));
      else
        Assert.assertTrue(false);
    }

    result = database.command(new OCommandSQL("select key, rid from index:IDX")).execute();
    Assert.assertNotNull(result);
    Assert.assertEquals(result.size(), 2);
    for (ODocument d : result) {
      Assert.assertTrue(d.containsField("key"));
      Assert.assertTrue(d.containsField("rid"));

      if (d.field("key").equals(10))
        Assert.assertEquals(d.rawField("rid"), new ORecordId("#3:0"));
      else if (d.field("key").equals(20))
        Assert.assertEquals(d.rawField("rid"), new ORecordId("#3:1"));
      else
        Assert.assertTrue(false);
    }

    result = database.command(new OCommandSQL("select key from index:IDX")).execute();
View Full Code Here

    final Collection<Integer> valuesMajorResults = new ArrayList<Integer>(Arrays.asList(4, 5));
    Collection<ODocument> indexCollection = index.getEntriesMajor(3, false);
    Assert.assertEquals(indexCollection.size(), 2);
    for (ODocument doc : indexCollection) {
      valuesMajorResults.remove(doc.<Integer> field("key"));
      Assert.assertEquals(doc.<ORecordId> rawField("rid"), new ORecordId(10, doc.<Integer> field("key").longValue()));
    }
    Assert.assertEquals(valuesMajorResults.size(), 0);

    final Collection<Integer> valuesMajorInclusiveResults = new ArrayList<Integer>(Arrays.asList(3, 4, 5));
    indexCollection = index.getEntriesMajor(3, true);
    Assert.assertEquals(indexCollection.size(), 3);
    for (ODocument doc : indexCollection) {
      valuesMajorInclusiveResults.remove(doc.<Integer> field("key"));
      Assert.assertEquals(doc.<ORecordId> rawField("rid"), new ORecordId(10, doc.<Integer> field("key").longValue()));
    }
    Assert.assertEquals(valuesMajorInclusiveResults.size(), 0);

    indexCollection = index.getEntriesMajor(5, true);
    Assert.assertEquals(indexCollection.size(), 1);
    Assert.assertEquals(indexCollection.iterator().next().<Integer> field("key"), Integer.valueOf(5));
    Assert.assertEquals(indexCollection.iterator().next().<ORecordId> rawField("rid"), new ORecordId(10, 5));

    indexCollection = index.getEntriesMajor(5, false);
    Assert.assertEquals(indexCollection.size(), 0);

    database.command(new OCommandSQL("drop index equalityIdx")).execute();
View Full Code Here

    final Collection<Integer> valuesMinorResults = new ArrayList<Integer>(Arrays.asList(0, 1, 2));
    Collection<ODocument> indexCollection = index.getEntriesMinor(3, false);
    Assert.assertEquals(indexCollection.size(), 3);
    for (ODocument doc : indexCollection) {
      valuesMinorResults.remove(doc.<Integer> field("key"));
      Assert.assertEquals(doc.<ORecordId> rawField("rid"), new ORecordId(10, doc.<Integer> field("key").longValue()));
    }
    Assert.assertEquals(valuesMinorResults.size(), 0);

    final Collection<Integer> valuesMinorInclusiveResults = new ArrayList<Integer>(Arrays.asList(0, 1, 2, 3));
    indexCollection = index.getEntriesMinor(3, true);
    Assert.assertEquals(indexCollection.size(), 4);
    for (ODocument doc : indexCollection) {
      valuesMinorInclusiveResults.remove(doc.<Integer> field("key"));
      Assert.assertEquals(doc.<ORecordId> rawField("rid"), new ORecordId(10, doc.<Integer> field("key").longValue()));
    }
    Assert.assertEquals(valuesMinorInclusiveResults.size(), 0);

    indexCollection = index.getEntriesMinor(0, true);
    Assert.assertEquals(indexCollection.size(), 1);
    Assert.assertEquals(indexCollection.iterator().next().<Integer> field("key"), Integer.valueOf(0));
    Assert.assertEquals(indexCollection.iterator().next().<ORecordId> rawField("rid"), new ORecordId(10, 0));

    indexCollection = index.getEntriesMinor(0, false);
    Assert.assertEquals(indexCollection.size(), 0);

    database.command(new OCommandSQL("drop index equalityIdx")).execute();
View Full Code Here

    final Collection<Integer> betweenResults = new ArrayList<Integer>(Arrays.asList(1, 2, 3));
    Collection<ODocument> indexCollection = index.getEntriesBetween(1, 3);
    Assert.assertEquals(indexCollection.size(), 3);
    for (ODocument doc : indexCollection) {
      betweenResults.remove(doc.<Integer> field("key"));
      Assert.assertEquals(doc.<ORecordId> rawField("rid"), new ORecordId(10, doc.<Integer> field("key").longValue()));
    }
    Assert.assertEquals(betweenResults.size(), 0);

    database.command(new OCommandSQL("drop index equalityIdx")).execute();
  }
View Full Code Here

        }

        try {
          beginResponse(network);
          final int createdRecords = network.readInt();
          ORecordId currentRid;
          ORecordId createdRid;
          for (int i = 0; i < createdRecords; i++) {
            currentRid = network.readRID();
            createdRid = network.readRID();
            for (OTransactionRecordEntry txEntry : iTx.getAllRecordEntries()) {
              if (txEntry.getRecord().getIdentity().equals(currentRid)) {
                txEntry.getRecord().setIdentity(createdRid);
                break;
              }
            }
          }
          final int updatedRecords = network.readInt();
          ORecordId rid;
          for (int i = 0; i < updatedRecords; ++i) {
            rid = network.readRID();

            // SEARCH THE RECORD WITH THAT ID TO UPDATE THE VERSION
            for (OTransactionRecordEntry txEntry : iTx.getAllRecordEntries()) {
View Full Code Here

  @ConsoleCommand(description = "Display a record as raw bytes")
  public void displayRawRecord(@ConsoleParameter(name = "rid", description = "The record id to display") final String iRecordId) {
    checkCurrentDatabase();

    ORecordId rid = new ORecordId(iRecordId);
    final ORawBuffer buffer = currentDatabase.getStorage().readRecord(currentDatabase, rid, null);

    if (buffer == null)
      throw new OException("The record has been deleted");
View Full Code Here

  public void dictionaryPut(
      @ConsoleParameter(name = "key", description = "The key to bind") final String iKey,
      @ConsoleParameter(name = "record-id", description = "The record-id of the record to bind to the key passes") final String iRecordId) {
    checkCurrentDatabase();

    currentRecord = currentDatabase.load(new ORecordId(iRecordId));
    if (currentRecord == null)
      out.println("Error: record with id '" + iRecordId + "' was not found in database");
    else {
      currentDatabase.getDictionary().put(iKey, (ODocument) currentRecord);
      displayRecord(null);
View Full Code Here

  }

  protected void loadRecordInternal(String iRecordId, String iFetchPlan) {
    checkCurrentDatabase();

    currentRecord = currentDatabase.load(new ORecordId(iRecordId), iFetchPlan);
    displayRecord(null);

    out.println("OK");
  }
View Full Code Here

TOP

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

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.