Search in sources :

Example 6 with ORecord

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

the class OrientDBClient method update.

@Override
public Status update(String table, String key, HashMap<String, ByteIterator> values) {
    while (true) {
        try (ODatabaseDocumentTx db = databasePool.acquire()) {
            final ODictionary<ORecord> dictionary = db.getMetadata().getIndexManager().getDictionary();
            final ODocument document = dictionary.get(key);
            if (document != null) {
                for (Map.Entry<String, String> entry : StringByteIterator.getStringMap(values).entrySet()) {
                    document.field(entry.getKey(), entry.getValue());
                }
                document.save();
                return Status.OK;
            }
        } catch (OConcurrentModificationException cme) {
            continue;
        } 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) OConcurrentModificationException(com.orientechnologies.orient.core.exception.OConcurrentModificationException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 7 with ORecord

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

the class OrientDBClientTest method updateTest.

@Test
public void updateTest() {
    String preupdateString = "preupdate";
    String user0 = "user0";
    String user1 = "user1";
    String user2 = "user2";
    OPartitionedDatabasePool pool = orientDBClient.getDatabasePool();
    try (ODatabaseDocumentTx db = pool.acquire()) {
        // Manually insert three documents
        for (String key : Arrays.asList(user0, user1, user2)) {
            ODocument doc = new ODocument(CLASS);
            for (int i = 0; i < NUM_FIELDS; i++) {
                doc.field(FIELD_PREFIX + i, preupdateString);
            }
            doc.save();
            ODictionary<ORecord> dictionary = db.getDictionary();
            dictionary.put(key, doc);
        }
    }
    HashMap<String, ByteIterator> updateMap = new HashMap<>();
    for (int i = 0; i < NUM_FIELDS; i++) {
        updateMap.put(FIELD_PREFIX + i, new StringByteIterator(buildDeterministicValue(user1, FIELD_PREFIX + i)));
    }
    orientDBClient.update(CLASS, user1, updateMap);
    try (ODatabaseDocumentTx db = pool.acquire()) {
        ODictionary<ORecord> dictionary = db.getDictionary();
        // Ensure that user0 record was not changed
        ODocument result = dictionary.get(user0);
        for (int i = 0; i < NUM_FIELDS; i++) {
            assertEquals("Assert first row fields contain preupdateString", result.field(FIELD_PREFIX + i), preupdateString);
        }
        // Check that all the columns have expected values for user1 record
        result = dictionary.get(user1);
        for (int i = 0; i < NUM_FIELDS; i++) {
            assertEquals("Assert updated row fields are correct", result.field(FIELD_PREFIX + i), updateMap.get(FIELD_PREFIX + i).toString());
        }
        // Ensure that user2 record was not changed
        result = dictionary.get(user2);
        for (int i = 0; i < NUM_FIELDS; i++) {
            assertEquals("Assert third row fields contain preupdateString", result.field(FIELD_PREFIX + i), preupdateString);
        }
    }
}
Also used : StringByteIterator(com.yahoo.ycsb.StringByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) OPartitionedDatabasePool(com.orientechnologies.orient.core.db.OPartitionedDatabasePool) ORecord(com.orientechnologies.orient.core.record.ORecord) StringByteIterator(com.yahoo.ycsb.StringByteIterator) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 8 with ORecord

use of com.orientechnologies.orient.core.record.ORecord in project guice-persist-orient by xvik.

the class LiveResultMapper method onLiveResult.

@Override
@SuppressWarnings("unchecked")
public void onLiveResult(final int iLiveToken, final ORecordOperation iOp) throws OException {
    final RecordOperation op = RecordOperation.forType(iOp.type);
    final ORecord rec = iOp.getRecord();
    try {
        listener.onLiveResult(iLiveToken, op, converter.convert(rec, targetType));
    } catch (Exception th) {
        final StringBuilder id = new StringBuilder(rec instanceof ODocument ? ((ODocument) rec).getClassName() : rec.getClass().getSimpleName()).append("(").append(rec.getIdentity()).append(")");
        throw new LiveResultMappingException("Error calling live result listener " + iLiveToken + " for " + op + " record " + id, th);
    }
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord) ORecordOperation(com.orientechnologies.orient.core.db.record.ORecordOperation) OException(com.orientechnologies.common.exception.OException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 9 with ORecord

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

the class OPropertyValueValidator method validateLink.

protected void validateLink(final IValidatable<T> validatable, final OProperty p, final Object linkValue) {
    if (linkValue == null)
        validatable.error(newValidationError("nulllink"));
    else {
        ORecord linkedRecord = null;
        if (linkValue instanceof OIdentifiable)
            linkedRecord = ((OIdentifiable) linkValue).getRecord();
        else if (linkValue instanceof String)
            linkedRecord = new ORecordId((String) linkValue).getRecord();
        else
            validatable.error(newValidationError("linkwrong"));
        if (linkedRecord != null && p.getLinkedClass() != null) {
            if (!(linkedRecord instanceof ODocument))
                validatable.error(newValidationError("linktypewrong", "linkedClass", p.getLinkedClass(), "identity", linkedRecord.getIdentity()));
            final ODocument doc = (ODocument) linkedRecord;
            // OF GRAPHS THE RECORD COULD BE PARTIAL
            if (doc.getSchemaClass() != null && !p.getLinkedClass().isSuperClassOf(doc.getSchemaClass()))
                validatable.error(newValidationError("linktypewrong", "linkedClass", p.getLinkedClass(), "identity", linkedRecord.getIdentity()));
        }
    }
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 10 with ORecord

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

the class OStorageRemote method readSynchResult.

protected Object readSynchResult(final OChannelBinaryAsynchClient network, final ODatabaseDocument database, List<ORecord> temporaryResults) throws IOException {
    final Object result;
    final byte type = network.readByte();
    switch(type) {
        case 'n':
            result = null;
            break;
        case 'r':
            result = OChannelBinaryProtocol.readIdentifiable(network);
            if (result instanceof ORecord)
                database.getLocalCache().updateRecord((ORecord) result);
            break;
        case 'l':
        case 's':
            final int tot = network.readInt();
            final Collection<OIdentifiable> coll;
            coll = type == 's' ? new HashSet<OIdentifiable>(tot) : new OBasicResultSet<OIdentifiable>(tot);
            for (int i = 0; i < tot; ++i) {
                final OIdentifiable resultItem = OChannelBinaryProtocol.readIdentifiable(network);
                if (resultItem instanceof ORecord)
                    database.getLocalCache().updateRecord((ORecord) resultItem);
                coll.add(resultItem);
            }
            result = coll;
            break;
        case 'i':
            coll = new OBasicResultSet<OIdentifiable>();
            byte status;
            while ((status = network.readByte()) > 0) {
                final OIdentifiable record = OChannelBinaryProtocol.readIdentifiable(network);
                if (record == null)
                    continue;
                if (status == 1) {
                    if (record instanceof ORecord)
                        database.getLocalCache().updateRecord((ORecord) record);
                    coll.add(record);
                }
            }
            result = coll;
            break;
        case 'w':
            final OIdentifiable record = OChannelBinaryProtocol.readIdentifiable(network);
            // ((ODocument) record).setLazyLoad(false);
            result = ((ODocument) record).field("result");
            break;
        default:
            OLogManager.instance().warn(this, "Received unexpected result from query: %d", type);
            result = null;
    }
    if (network.getSrvProtocolVersion() >= 17) {
        // LOAD THE FETCHED RECORDS IN CACHE
        byte status;
        while ((status = network.readByte()) > 0) {
            final ORecord record = (ORecord) OChannelBinaryProtocol.readIdentifiable(network);
            if (record != null && status == 2) {
                // PUT IN THE CLIENT LOCAL CACHE
                database.getLocalCache().updateRecord(record);
                if (record.getIdentity().getClusterId() == -2)
                    temporaryResults.add(record);
            }
        }
    }
    return result;
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OBasicResultSet(com.orientechnologies.orient.core.sql.query.OBasicResultSet)

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