Search in sources :

Example 86 with ORecord

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;
}
Also used : OProfiler(com.orientechnologies.common.profiler.OProfiler) ORecord(com.orientechnologies.orient.core.record.ORecord)

Example 87 with ORecord

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;
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord)

Example 88 with ORecord

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;
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord)

Example 89 with ORecord

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;
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 90 with ORecord

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;
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OConcurrentModificationException(com.orientechnologies.orient.core.exception.OConcurrentModificationException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

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