Search in sources :

Example 56 with ORecord

use of com.orientechnologies.orient.core.record.ORecord in project orientdb by orientechnologies.

the class IndexTxAwareMultiValueGetEntriesTest method getValidPositions.

private List<Long> getValidPositions(int clusterId) {
    final List<Long> positions = new ArrayList<Long>();
    final ORecordIteratorCluster<?> iteratorCluster = database.browseCluster(database.getClusterNameById(clusterId));
    for (int i = 0; i < 7; i++) {
        iteratorCluster.hasNext();
        ORecord doc = iteratorCluster.next();
        positions.add(doc.getIdentity().getClusterPosition());
    }
    return positions;
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord) ArrayList(java.util.ArrayList)

Example 57 with ORecord

use of com.orientechnologies.orient.core.record.ORecord in project orientdb by orientechnologies.

the class ORecordIteratorCluster method hasNext.

public boolean hasNext() {
    checkDirection(true);
    if (Thread.interrupted())
        // INTERRUPTED
        return false;
    updateRangesOnLiveUpdate();
    if (currentRecord != null) {
        return true;
    }
    if (limit > -1 && browsedRecords >= limit)
        // LIMIT REACHED
        return false;
    if (browsedRecords >= totalAvailableRecords)
        return false;
    if (!(current.getClusterPosition() < ORID.CLUSTER_POS_INVALID) && getCurrentEntry() < lastClusterEntry) {
        ORecord record = getRecord();
        try {
            currentRecord = readCurrentRecord(record, +1);
        } catch (Exception e) {
            OLogManager.instance().error(this, "Error during read of record", e);
            currentRecord = null;
        }
        if (currentRecord != null)
            return true;
    }
    // CHECK IN TX IF ANY
    if (txEntries != null)
        return txEntries.size() - (currentTxEntryPosition + 1) > 0;
    return false;
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord)

Example 58 with ORecord

use of com.orientechnologies.orient.core.record.ORecord in project orientdb by orientechnologies.

the class ORecordIteratorCluster method next.

/**
   * Return the element at the current position and move forward the cursor to the next position available.
   * 
   * @return the next record found, otherwise the NoSuchElementException exception is thrown when no more records are found.
   */
@SuppressWarnings("unchecked")
public REC next() {
    checkDirection(true);
    ORecord record;
    // ITERATE UNTIL THE NEXT GOOD RECORD
    while (hasNext()) {
        // FOUND
        if (currentRecord != null) {
            try {
                return (REC) currentRecord;
            } finally {
                currentRecord = null;
            }
        }
        record = getTransactionEntry();
        if (record != null)
            return (REC) record;
    }
    return null;
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord)

Example 59 with ORecord

use of com.orientechnologies.orient.core.record.ORecord in project orientdb by orientechnologies.

the class ORecordIteratorClusters method begin.

/**
   * Move the iterator to the begin of the range. If no range was specified move to the first record of the cluster.
   *
   * @return The object itself
   */
@Override
public ORecordIteratorClusters<REC> begin() {
    if (clusterIds.length == 0)
        return this;
    browsedRecords = 0;
    currentClusterIdx = 0;
    current.setClusterId(clusterIds[currentClusterIdx]);
    updateClusterRange();
    resetCurrentPosition();
    nextPosition();
    final ORecord record = getRecord();
    currentRecord = readCurrentRecord(record, 0);
    if (currentRecord != null && !include(currentRecord)) {
        currentRecord = null;
        hasNext();
    }
    return this;
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord)

Example 60 with ORecord

use of com.orientechnologies.orient.core.record.ORecord in project orientdb by orientechnologies.

the class ORecordIteratorClusters method next.

/**
   * Return the element at the current position and move forward the cursor to the next position available.
   *
   * @return the next record found, otherwise the NoSuchElementException exception is thrown when no more records are found.
   */
@SuppressWarnings("unchecked")
public REC next() {
    checkDirection(true);
    if (currentRecord != null)
        try {
            // RETURN LAST LOADED RECORD
            return (REC) currentRecord;
        } finally {
            currentRecord = null;
        }
    ORecord record;
    // MOVE FORWARD IN THE CURRENT CLUSTER
    while (hasNext()) {
        if (currentRecord != null)
            try {
                // RETURN LAST LOADED RECORD
                return (REC) currentRecord;
            } finally {
                currentRecord = null;
            }
        record = getTransactionEntry();
        if (record == null)
            record = readCurrentRecord(null, +1);
        if (record != null)
            // FOUND
            if (include(record))
                return (REC) record;
    }
    record = getTransactionEntry();
    if (record != null)
        return (REC) record;
    throw new NoSuchElementException("Direction: forward, last position was: " + current + ", range: " + beginRange + "-" + endRange);
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

ORecord (com.orientechnologies.orient.core.record.ORecord)177 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)80 ORecordId (com.orientechnologies.orient.core.id.ORecordId)37 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)35 ORID (com.orientechnologies.orient.core.id.ORID)24 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)19 IOException (java.io.IOException)18 Test (org.junit.Test)15 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)14 OException (com.orientechnologies.common.exception.OException)13 ORecordNotFoundException (com.orientechnologies.orient.core.exception.ORecordNotFoundException)13 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)12 ORecordOperation (com.orientechnologies.orient.core.db.record.ORecordOperation)11 ArrayList (java.util.ArrayList)10 Test (org.testng.annotations.Test)8 OIOException (com.orientechnologies.common.io.OIOException)7 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)7 OOfflineClusterException (com.orientechnologies.orient.core.storage.impl.local.paginated.OOfflineClusterException)7 OSerializationException (com.orientechnologies.orient.core.exception.OSerializationException)6 ORecordHook (com.orientechnologies.orient.core.hook.ORecordHook)6