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