Search in sources :

Example 26 with ORecord

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

the class TestOrderBy method testGermanOrderBy.

@Test
public void testGermanOrderBy() {
    ODatabaseDocument db = new ODatabaseDocumentTx("memory:testGermanOrderBy");
    db.set(ATTRIBUTES.LOCALECOUNTRY, Locale.GERMANY.getCountry());
    db.set(ATTRIBUTES.LOCALELANGUAGE, Locale.GERMANY.getLanguage());
    db.create();
    try {
        db.getMetadata().getSchema().createClass("test");
        ORecord res1 = db.save(new ODocument("test").field("name", "Ähhhh"));
        ORecord res2 = db.save(new ODocument("test").field("name", "Ahhhh"));
        ORecord res3 = db.save(new ODocument("test").field("name", "Zebra"));
        List<?> queryRes = db.query(new OSQLSynchQuery<Object>("select from test order by name"));
        assertEquals(queryRes.get(0), res2);
        assertEquals(queryRes.get(1), res1);
        assertEquals(queryRes.get(2), res3);
        queryRes = db.query(new OSQLSynchQuery<Object>("select from test order by name desc "));
        assertEquals(queryRes.get(0), res3);
        assertEquals(queryRes.get(1), res1);
        assertEquals(queryRes.get(2), res2);
    } finally {
        db.drop();
    }
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ORecord(com.orientechnologies.orient.core.record.ORecord) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 27 with ORecord

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

the class BrowseSpeedTest method browseStorageClusters.

protected void browseStorageClusters() throws IOException {
    ODatabaseDocumentTx db = openDatabase();
    final long total = db.countClass(CLASS);
    final OClass cls = db.getMetadata().getSchema().getClass(CLASS);
    final int[] clIds = cls.getPolymorphicClusterIds();
    long start = System.currentTimeMillis();
    int loaded = 0;
    ORecord rec;
    for (int clId : clIds) {
        OCluster cluster = db.getStorage().getClusterById(clId);
        final long clusterRecords = cluster.getEntries();
        for (long rid = 0; rid < clusterRecords; ++rid) {
            final ORawBuffer buffer = cluster.readRecord(rid, true);
            loaded++;
        }
    }
    long end = System.currentTimeMillis();
    System.out.println("Browse clusters " + total + " and loaded " + loaded + " took " + (end - start));
    db.close();
}
Also used : ORawBuffer(com.orientechnologies.orient.core.storage.ORawBuffer) ORecord(com.orientechnologies.orient.core.record.ORecord) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OCluster(com.orientechnologies.orient.core.storage.OCluster)

Example 28 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)

Example 29 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 30 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);
            final ORID recordRid = currentRecord.getIdentity();
            if (recordRid != null)
                brokenRIDs.add(recordRid.copy());
            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) ORID(com.orientechnologies.orient.core.id.ORID)

Aggregations

ORecord (com.orientechnologies.orient.core.record.ORecord)194 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)91 ORecordId (com.orientechnologies.orient.core.id.ORecordId)40 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)36 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)27 ORID (com.orientechnologies.orient.core.id.ORID)27 IOException (java.io.IOException)21 OException (com.orientechnologies.common.exception.OException)17 Test (org.junit.Test)16 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)15 ORecordOperation (com.orientechnologies.orient.core.db.record.ORecordOperation)15 ORecordNotFoundException (com.orientechnologies.orient.core.exception.ORecordNotFoundException)15 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)14 OConcurrentModificationException (com.orientechnologies.orient.core.exception.OConcurrentModificationException)10 ArrayList (java.util.ArrayList)9 Map (java.util.Map)9 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)8 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)8 Test (org.testng.annotations.Test)8 OIOException (com.orientechnologies.common.io.OIOException)7