Search in sources :

Example 91 with ORecord

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

the class OrientDBClient method read.

@Override
public Status read(String table, String key, Set<String> fields, HashMap<String, ByteIterator> result) {
    try (ODatabaseDocumentTx db = databasePool.acquire()) {
        final ODictionary<ORecord> dictionary = db.getMetadata().getIndexManager().getDictionary();
        final ODocument document = dictionary.get(key);
        if (document != null) {
            if (fields != null) {
                for (String field : fields) {
                    result.put(field, new StringByteIterator((String) document.field(field)));
                }
            } else {
                for (String field : document.fieldNames()) {
                    result.put(field, new StringByteIterator((String) document.field(field)));
                }
            }
            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)

Example 92 with ORecord

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

the class OrientDBClient method scan.

@Override
public Status scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
    if (isRemote) {
        // Iterator methods needed for scanning are Unsupported for remote database connections.
        LOG.warn("OrientDB scan operation is not implemented for remote database connections.");
        return Status.NOT_IMPLEMENTED;
    }
    try (ODatabaseDocumentTx db = databasePool.acquire()) {
        final ODictionary<ORecord> dictionary = db.getMetadata().getIndexManager().getDictionary();
        final OIndexCursor entries = dictionary.getIndex().iterateEntriesMajor(startkey, true, true);
        int currentCount = 0;
        while (entries.hasNext()) {
            final ODocument document = entries.next().getRecord();
            final HashMap<String, ByteIterator> map = new HashMap<>();
            result.add(map);
            if (fields != null) {
                for (String field : fields) {
                    map.put(field, new StringByteIterator((String) document.field(field)));
                }
            } else {
                for (String field : document.fieldNames()) {
                    map.put(field, new StringByteIterator((String) document.field(field)));
                }
            }
            currentCount++;
            if (currentCount >= recordcount) {
                break;
            }
        }
        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) OIndexCursor(com.orientechnologies.orient.core.index.OIndexCursor) OConcurrentModificationException(com.orientechnologies.orient.core.exception.OConcurrentModificationException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 93 with ORecord

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

the class OrientDBClientTest method deleteTest.

@Test
public void deleteTest() {
    String user0 = "user0";
    String user1 = "user1";
    String user2 = "user2";
    insertRow(user0);
    insertRow(user1);
    insertRow(user2);
    orientDBClient.delete(CLASS, user1);
    OPartitionedDatabasePool pool = orientDBClient.getDatabasePool();
    try (ODatabaseDocumentTx db = pool.acquire()) {
        ODictionary<ORecord> dictionary = db.getDictionary();
        assertNotNull("Assert user0 still exists", dictionary.get(user0));
        assertNull("Assert user1 does not exist", dictionary.get(user1));
        assertNotNull("Assert user2 still exists", dictionary.get(user2));
    }
}
Also used : OPartitionedDatabasePool(com.orientechnologies.orient.core.db.OPartitionedDatabasePool) ORecord(com.orientechnologies.orient.core.record.ORecord) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)

Example 94 with ORecord

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

the class OrientDBClientTest method insertTest.

@Test
public void insertTest() {
    String insertKey = "user0";
    Map<String, ByteIterator> insertMap = insertRow(insertKey);
    OPartitionedDatabasePool pool = orientDBClient.getDatabasePool();
    try (ODatabaseDocumentTx db = pool.acquire()) {
        ODictionary<ORecord> dictionary = db.getDictionary();
        ODocument result = dictionary.get(insertKey);
        assertTrue("Assert a row was inserted.", result != null);
        for (int i = 0; i < NUM_FIELDS; i++) {
            assertEquals("Assert all inserted columns have correct values.", result.field(FIELD_PREFIX + i), insertMap.get(FIELD_PREFIX + i).toString());
        }
    }
}
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) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 95 with ORecord

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

the class OFieldTransformer method executeTransform.

@Override
public Object executeTransform(final Object input) {
    if (input instanceof OIdentifiable) {
        final ORecord rec = ((OIdentifiable) input).getRecord();
        if (rec instanceof ODocument) {
            final ODocument doc = (ODocument) rec;
            if (setOperation) {
                final Object newValue;
                if (expression != null) {
                    if (sqlFilter == null)
                        // ONLY THE FIRST TIME
                        sqlFilter = new OSQLFilter(expression, context, null);
                    newValue = sqlFilter.evaluate(doc, null, context);
                } else
                    newValue = value;
                // SET THE TRANSFORMED FIELD BACK
                doc.field(fieldName, newValue);
                log(OETLProcessor.LOG_LEVELS.DEBUG, "set %s=%s in document=%s", fieldName, newValue, doc);
            } else {
                if (fieldName != null) {
                    final Object prev = doc.removeField(fieldName);
                    log(OETLProcessor.LOG_LEVELS.DEBUG, "removed %s (value=%s) from document=%s", fieldName, prev, doc);
                } else {
                    for (String f : fieldNames) {
                        final Object prev = doc.removeField(f);
                        log(OETLProcessor.LOG_LEVELS.DEBUG, "removed %s (value=%s) from document=%s", f, prev, doc);
                    }
                }
            }
            if (save) {
                log(OETLProcessor.LOG_LEVELS.DEBUG, "saving record %s", doc);
                final ODatabaseDocument db = super.pipeline.getDocumentDatabase();
                db.save(doc);
            }
        }
    }
    return input;
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ORecord(com.orientechnologies.orient.core.record.ORecord) OSQLFilter(com.orientechnologies.orient.core.sql.filter.OSQLFilter) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) 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