use of com.orientechnologies.orient.core.record.impl.OBlob in project orientdb by orientechnologies.
the class TransactionOptimisticTest method testTransactionOptimisticCacheMgmt1Db.
@Test(dependsOnMethods = "testTransactionOptimisticConcurrentException")
public void testTransactionOptimisticCacheMgmt1Db() throws IOException {
if (database.getClusterIdByName("binary") == -1)
database.addBlobCluster("binary");
OBlob record = new ORecordBytes("This is the first version".getBytes());
record.save();
try {
database.begin();
// RE-READ THE RECORD
record.load();
int v1 = record.getVersion();
record.setDirty();
record.fromStream("This is the second version".getBytes());
record.save();
database.commit();
record.reload();
Assert.assertEquals(record.getVersion(), v1 + 1);
Assert.assertTrue(new String(record.toStream()).contains("second"));
} finally {
database.close();
}
}
use of com.orientechnologies.orient.core.record.impl.OBlob in project orientdb by orientechnologies.
the class TransactionOptimisticTest method testTransactionOptimisticCacheMgmt2Db.
@Test(dependsOnMethods = "testTransactionOptimisticCacheMgmt1Db")
public void testTransactionOptimisticCacheMgmt2Db() throws IOException {
if (database.getClusterIdByName("binary") == -1)
database.addBlobCluster("binary");
ODatabaseDocumentTx db2 = new ODatabaseDocumentTx(database.getURL());
db2.open("admin", "admin");
OBlob record1 = new ORecordBytes("This is the first version".getBytes());
record1.save();
try {
ODatabaseRecordThreadLocal.INSTANCE.set(database);
database.begin();
// RE-READ THE RECORD
record1.load();
int v1 = record1.getVersion();
record1.setDirty();
record1.fromStream("This is the second version".getBytes());
record1.save();
database.commit();
db2.activateOnCurrentThread();
OBlob record2 = db2.load(record1.getIdentity(), "*:-1", true);
Assert.assertEquals(record2.getVersion(), v1 + 1);
Assert.assertTrue(new String(record2.toStream()).contains("second"));
} finally {
database.activateOnCurrentThread();
database.close();
db2.activateOnCurrentThread();
db2.close();
}
}
use of com.orientechnologies.orient.core.record.impl.OBlob in project orientdb by orientechnologies.
the class SQLSelectTest method testBinaryClusterSelect2.
@Test
public void testBinaryClusterSelect2() {
database.command(new OCommandSQL("create blob cluster testBinaryClusterSelect2")).execute();
database.reload();
OBlob bytes = new ORecordBytes(new byte[] { 1, 2, 3 });
database.save(bytes, "testBinaryClusterSelect2");
List<OIdentifiable> result = database.query(new OSQLSynchQuery<OIdentifiable>("select @rid, @version, @size, 1 as uno, foo from cluster:testBinaryClusterSelect2"));
Assert.assertEquals(result.size(), 1);
ODocument item = (ODocument) result.get(0);
Assert.assertEquals(item.field("size"), 3);
Assert.assertEquals(item.field("version"), 1);
Assert.assertEquals(item.field("uno"), 1);
Assert.assertEquals(item.field("foo"), null);
Assert.assertNotNull(item.field("rid"));
}
use of com.orientechnologies.orient.core.record.impl.OBlob in project orientdb by orientechnologies.
the class SQLSelectTest method testBinaryClusterSelect.
@Test
public void testBinaryClusterSelect() {
database.command(new OCommandSQL("create blob cluster binarycluster")).execute();
database.reload();
OBlob bytes = new ORecordBytes(new byte[] { 1, 2, 3 });
database.save(bytes, "binarycluster");
List<OIdentifiable> result = database.query(new OSQLSynchQuery<OIdentifiable>("select from cluster:binarycluster"));
Assert.assertEquals(result.size(), 1);
database.command(new OCommandSQL("delete from cluster:binarycluster")).execute();
result = database.query(new OSQLSynchQuery<OIdentifiable>("select from cluster:binarycluster"));
Assert.assertEquals(result.size(), 0);
}
use of com.orientechnologies.orient.core.record.impl.OBlob in project orientdb by orientechnologies.
the class Media method setContent.
public void setContent(OBlob content) {
OBlob current = this.getContent();
this.content = content;
if (current != null)
current.getRecord().delete();
}
Aggregations