use of com.orientechnologies.orient.core.record.ORecord in project orientdb by orientechnologies.
the class OCommandCacheSoftRefs method get.
@Override
public Object get(final OSecurityUser iUser, final String queryText, final int iLimit) {
if (!enable)
return null;
OCachedResult result;
synchronized (this) {
final String key = getKey(iUser, queryText, iLimit);
result = cache.get(key);
if (result != null) {
// SERIALIZE ALL THE RECORDS IN LOCK TO AVOID CONCURRENT ACCESS. ONCE SERIALIZED CAN ARE THREAD-SAFE
int resultsetSize = 1;
if (result.result instanceof ORecord)
((ORecord) result.result).toStream();
else if (OMultiValue.isMultiValue(result.result)) {
resultsetSize = OMultiValue.getSize(result.result);
for (Object rc : OMultiValue.getMultiValueIterable(result.result)) {
if (rc != null && rc instanceof ORecord) {
((ORecord) rc).toStream();
}
}
}
if (OLogManager.instance().isDebugEnabled())
OLogManager.instance().debug(this, "Reused cached resultset size=%d", resultsetSize);
}
}
final OProfiler profiler = Orient.instance().getProfiler();
if (profiler.isRecording()) {
// UPDATE PROFILER
if (result != null) {
profiler.updateCounter(profiler.getDatabaseMetric(databaseName, "queryCache.hit"), "Results returned by Query Cache", +1);
} else {
profiler.updateCounter(profiler.getDatabaseMetric(databaseName, "queryCache.miss"), "Results not returned by Query Cache", +1);
}
}
return result != null ? result.result : null;
}
use of com.orientechnologies.orient.core.record.ORecord in project orientdb by orientechnologies.
the class OLocalRecordCache method findRecord.
/**
* Looks up for record in cache by it's identifier. Optionally look up in secondary cache and update primary with found record
*
* @param rid
* unique identifier of record
* @return record stored in cache if any, otherwise - {@code null}
*/
public ORecord findRecord(final ORID rid) {
ORecord record;
record = underlying.get(rid);
if (record != null)
Orient.instance().getProfiler().updateCounter(CACHE_HIT, "Record found in Level1 Cache", 1L, "db.*.cache.level1.cache.found");
else
Orient.instance().getProfiler().updateCounter(CACHE_MISS, "Record not found in Level1 Cache", 1L, "db.*.cache.level1.cache.notFound");
return record;
}
use of com.orientechnologies.orient.core.record.ORecord in project orientdb by orientechnologies.
the class ODatabaseDocumentTx method delete.
/**
* Deletes the record without checking the version.
*/
public ODatabaseDocument delete(final ORID iRecord, final OPERATION_MODE iMode) {
ORecord record = iRecord.getRecord();
if (record == null)
return this;
delete(record, iMode);
return this;
}
use of com.orientechnologies.orient.core.record.ORecord in project orientdb by orientechnologies.
the class ODatabaseDocumentTx method countClass.
/**
* Returns the number of the records of the class iClassName considering also sub classes if polymorphic is true.
*/
public long countClass(final String iClassName, final boolean iPolymorphic) {
final OClass cls = getMetadata().getImmutableSchemaSnapshot().getClass(iClassName);
if (cls == null)
throw new IllegalArgumentException("Class '" + iClassName + "' not found in database");
long totalOnDb = cls.count(iPolymorphic);
long deletedInTx = 0;
long addedInTx = 0;
if (getTransaction().isActive())
for (ORecordOperation op : getTransaction().getAllRecordEntries()) {
if (op.type == ORecordOperation.DELETED) {
final ORecord rec = op.getRecord();
if (rec != null && rec instanceof ODocument) {
OClass schemaClass = ((ODocument) rec).getSchemaClass();
if (iPolymorphic) {
if (schemaClass.isSubClassOf(iClassName))
deletedInTx++;
} else {
if (iClassName.equals(schemaClass.getName()) || iClassName.equals(schemaClass.getShortName()))
deletedInTx++;
}
}
}
if (op.type == ORecordOperation.CREATED) {
final ORecord rec = op.getRecord();
if (rec != null && rec instanceof ODocument) {
OClass schemaClass = ((ODocument) rec).getSchemaClass();
if (iPolymorphic) {
if (schemaClass.isSubClassOf(iClassName))
addedInTx++;
} else {
if (iClassName.equals(schemaClass.getName()) || iClassName.equals(schemaClass.getShortName()))
addedInTx++;
}
}
}
}
return (totalOnDb + addedInTx) - deletedInTx;
}
use of com.orientechnologies.orient.core.record.ORecord in project YCSB by brianfrankcooper.
the class OrientDBClient method insert.
@Override
public Status insert(String table, String key, HashMap<String, ByteIterator> values) {
try (ODatabaseDocumentTx db = databasePool.acquire()) {
final ODocument document = new ODocument(CLASS);
for (Map.Entry<String, String> entry : StringByteIterator.getStringMap(values).entrySet()) {
document.field(entry.getKey(), entry.getValue());
}
document.save();
final ODictionary<ORecord> dictionary = db.getMetadata().getIndexManager().getDictionary();
dictionary.put(key, document);
return Status.OK;
} catch (Exception e) {
e.printStackTrace();
}
return Status.ERROR;
}
Aggregations