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();
}
}
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();
}
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);
}
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;
}
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;
}
Aggregations