Package com.orientechnologies.orient.core.id

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


      setUsingLog(channel.readByte() == 1);

      while (channel.readByte() == 1) {
        final byte recordStatus = channel.readByte();

        final ORecordId rid = channel.readRID();

        final OTransactionEntryProxy entry = new OTransactionEntryProxy(channel.readByte());
        entry.status = recordStatus;

        switch (entry.status) {
        case OTransactionRecordEntry.CREATED:
          entry.clusterName = channel.readString();
          entry.getRecord().fill(database, rid, 0, channel.readBytes(), true);

          // SAVE THE RECORD TO RETRIEVE THEM FOR THE NEW RID TO SEND BACK TO THE REQUESTER
          createdRecords.put(rid.copy(), entry.getRecord());
          break;

        case OTransactionRecordEntry.UPDATED:
          entry.getRecord().fill(database, rid, channel.readInt(), channel.readBytes(), true);
View Full Code Here


    }

    case OChannelBinaryProtocol.REQUEST_RECORD_LOAD: {
      data.commandInfo = "Load record";

      final ORecordId rid = channel.readRID();
      final String fetchPlanString = channel.readString();
      if (rid.clusterId == 0 && rid.clusterPosition == 0) {
        // @COMPATIBILITY 0.9.25
        // SEND THE DB CONFIGURATION INSTEAD SINCE IT WAS ON RECORD 0:0
        OFetchHelper.checkFetchPlanValid(fetchPlanString);
        channel.acquireExclusiveLock();
        try {
          sendOk(lastClientTxId);
          channel.writeByte((byte) 1);
          channel.writeBytes(connection.database.getStorage().getConfiguration().toStream());
          channel.writeInt(0);
          channel.writeByte(ORecordBytes.RECORD_TYPE);
        } finally {
          channel.releaseExclusiveLock();
        }
      } else {
        final ORecordInternal<?> record = connection.database.load(rid, fetchPlanString);

        // if (rid.equals(((OSchemaImpl) connection.database.getMetadata().getSchema()).getDocument().getIdentity()))
        // connection.database.getMetadata().getSchema().reload();

        channel.acquireExclusiveLock();
        try {
          sendOk(lastClientTxId);

          if (record != null) {
            channel.writeByte((byte) 1);
            channel.writeBytes(record.toStream());
            channel.writeInt(record.getVersion());
            channel.writeByte(record.getRecordType());

            if (fetchPlanString.length() > 0) {
              // BUILD THE SERVER SIDE RECORD TO ACCES TO THE FETCH
              // PLAN
              if (record instanceof ODocument) {
                final Map<String, Integer> fetchPlan = OFetchHelper.buildFetchPlan(fetchPlanString);

                final Set<ODocument> recordsToSend = new HashSet<ODocument>();
                OFetchHelper.fetch((ODocument) record, record, fetchPlan, null, 0, -1, new OFetchListener() {
                  @Override
                  public int size() {
                    return recordsToSend.size();
                  }

                  // ADD TO THE SET OF OBJECTS TO SEND
                  @Override
                  public Object fetchLinked(final ODocument iRoot, final Object iUserObject, final String iFieldName,
                      final Object iLinked) {
                    if (iLinked instanceof ODocument) {
                      if (((ODocument) iLinked).getIdentity().isValid())
                        return recordsToSend.add((ODocument) iLinked) ? iLinked : null;
                      return null;
                    } else if (iLinked instanceof Collection<?>)
                      return recordsToSend.addAll((Collection<? extends ODocument>) iLinked) ? iLinked : null;
                    else if (iLinked instanceof Map<?, ?>)
                      return recordsToSend.addAll(((Map<String, ? extends ODocument>) iLinked).values()) ? iLinked : null;
                    else
                      throw new IllegalArgumentException("Unrecognized type while fetching records: " + iLinked);
                  }
                });

                // SEND RECORDS TO LOAD IN CLIENT CACHE
                for (ODocument doc : recordsToSend) {
                  if (doc.getIdentity().isValid()) {
                    channel.writeByte((byte) 2); // CLIENT CACHE
                    // RECORD. IT ISN'T PART OF THE RESULT SET
                    writeIdentifiable(doc);
                  }
                }
              }

            }
          }
        } finally {
          channel.releaseExclusiveLock();
        }
      }
      channel.writeByte((byte) 0); // NO MORE RECORDS
      break;
    }

    case OChannelBinaryProtocol.REQUEST_RECORD_CREATE: {
      data.commandInfo = "Create record";

      final ORecordId rid = new ORecordId(channel.readShort(), ORID.CLUSTER_POS_INVALID);

      final byte[] buffer = channel.readBytes();
      final byte recordType = channel.readByte();

      final ORecordInternal<?> record = Orient.instance().getRecordFactoryManager().newInstance(connection.database, recordType);
      record.fill(connection.database, rid, 0, buffer, true);
      connection.database.save(record);

      channel.acquireExclusiveLock();
      try {
        sendOk(lastClientTxId);
        channel.writeLong(record.getIdentity().getClusterPosition());
      } finally {
        channel.releaseExclusiveLock();
      }
      break;
    }

    case OChannelBinaryProtocol.REQUEST_RECORD_UPDATE: {
      data.commandInfo = "Update record";

      final ORecordId rid = channel.readRID();

      final byte[] buffer = channel.readBytes();
      final int version = channel.readInt();
      final byte recordType = channel.readByte();
      final ORecordInternal<?> newRecord = Orient.instance().getRecordFactoryManager().newInstance(connection.database, recordType);
      newRecord.fill(connection.database, rid, version, buffer, true);

      if (((OSchemaProxy) connection.database.getMetadata().getSchema()).getIdentity().equals(rid))
        // || ((OIndexManagerImpl) connection.database.getMetadata().getIndexManager()).getDocument().getIdentity().equals(rid)) {
        throw new OSecurityAccessException("Can't update internal record " + rid);

      final ORecordInternal<?> currentRecord;
      if (newRecord instanceof ODocument) {
        currentRecord = connection.database.load(rid);

        if (currentRecord == null)
          throw new ORecordNotFoundException(rid.toString());

        final ODocument doc = (ODocument) currentRecord;
        doc.merge((ODocument) newRecord, false, false);

      } else
View Full Code Here

    case LINK:
      if (iValue instanceof ORID)
        return iValue.toString();
      else if (iValue instanceof String)
        return new ORecordId((String) iValue);
      else
        return ((ORecord<?>) iValue).getIdentity().toString();

    case EMBEDDED:
      // RECORD
View Full Code Here

      try {

        final int dataSegment = getDataSegmentForRecord(iClusterSegment, iContent);
        final ODataLocal data = getDataSegment(dataSegment);

        final ORecordId rid = new ORecordId(iClusterSegment.getId());
        rid.clusterPosition = iClusterSegment.addPhysicalPosition(-1, -1, iRecordType);

        final long dataOffset = data.addRecord(rid, iContent);

        // UPDATE THE POSITION IN CLUSTER WITH THE POSITION OF RECORD IN
View Full Code Here

      // 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

          // TREATS AS CLUSTER POSITION
          final OClass cls = iDb.getMetadata().getSchema().getClass(iPojo.getClass());
          if (cls == null)
            throw new OConfigurationException("Class " + iPojo.getClass() + " is not managed by current database");

          return new ORecordId(cls.getDefaultClusterId(), ((Number) id).longValue());
        } else if (id instanceof String)
          return new ORecordId((String) id);
      }
    }
    return null;
  }
View Full Code Here

    return true;
  }

  private void commitEntry(final int iTxId, final OTransactionRecordEntry txEntry) throws IOException {

    final ORecordId rid = (ORecordId) txEntry.getRecord().getIdentity();

    final OCluster cluster = txEntry.clusterName != null ? getClusterByName(txEntry.clusterName) : getClusterById(rid.clusterId);
    rid.clusterId = cluster.getId();

    switch (txEntry.status) {
    case OTransactionRecordEntry.LOADED:
      break;

    case OTransactionRecordEntry.CREATED:
      if (rid.isNew()) {
        // CHECK 2 TIMES TO ASSURE THAT IT'S A CREATE OR AN UPDATE BASED ON RECURSIVE TO-STREAM METHOD
        final byte[] stream = txEntry.getRecord().toStream();

        if (rid.isNew()) {
          createRecord(rid, stream, txEntry.getRecord().getRecordType());
        } else {
          txEntry.getRecord().setVersion(
              updateRecord(rid, stream, txEntry.getRecord().getVersion(), txEntry.getRecord().getRecordType()));
        }
View Full Code Here

    database.getMetadata().getSchema().reload();

    Profile profile = (Profile) database.browseClass("Profile").next();

    final OSQLSynchQuery<Profile> query = new OSQLSynchQuery<Profile>("select from Profile where @rid = ?");
    List<Profile> result = database.query(query, new ORecordId(profile.getId()));

    Assert.assertEquals(result.size(), 1);

    database.close();
  }
View Full Code Here

          final List<String> entry = OStringSerializerHelper.smartSplit(item, OStringSerializerHelper.ENTRY_SEPARATOR);
          if (entry.size() > 0) {
            String mapValue = entry.get(1);
            if (mapValue != null && mapValue.length() > 0)
              mapValue = mapValue.substring(1);
            map.put(fieldTypeFromStream((ODocument) iSourceRecord, OType.STRING, entry.get(0)), new ORecordId(mapValue));
          }

        }
      }
      return map;
    }

    case EMBEDDEDMAP:
      return embeddedMapFromStream((ODocument) iSourceRecord, iLinkedType, iValue);

    case LINK:
      if (iValue.length() > 1) {
        int pos = iValue.indexOf(OStringSerializerHelper.CLASS_SEPARATOR);
        if (pos > -1)
          iLinkedClass = database.getMetadata().getSchema().getClass(iValue.substring(1, pos));
        else
          pos = 0;

        return new ORecordId(iValue.substring(pos + 1));
      } else
        return null;

    case EMBEDDED:
      if (iValue.length() > 2) {
View Full Code Here

    pTree = (OMVRBTreePersistent<K, V>) tree;
    record = new ORecordBytesLazy(this);

    setParent(iParent);

    parentRid = new ORecordId();
    leftRid = new ORecordId();
    rightRid = new ORecordId();

    pageSize = pTree.getPageSize();

    // COPY ALSO THE SERIALIZED KEYS/VALUES
    serializedKeys = new int[pageSize];
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.