Search in sources :

Example 21 with OBlob

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();
    }
}
Also used : OBlob(com.orientechnologies.orient.core.record.impl.OBlob) ORecordBytes(com.orientechnologies.orient.core.record.impl.ORecordBytes) Test(org.testng.annotations.Test)

Example 22 with OBlob

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();
    }
}
Also used : OBlob(com.orientechnologies.orient.core.record.impl.OBlob) ORecordBytes(com.orientechnologies.orient.core.record.impl.ORecordBytes) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) Test(org.testng.annotations.Test)

Example 23 with OBlob

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"));
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OBlob(com.orientechnologies.orient.core.record.impl.OBlob) ORecordBytes(com.orientechnologies.orient.core.record.impl.ORecordBytes) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 24 with OBlob

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);
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OBlob(com.orientechnologies.orient.core.record.impl.OBlob) ORecordBytes(com.orientechnologies.orient.core.record.impl.ORecordBytes) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) Test(org.testng.annotations.Test)

Example 25 with OBlob

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

Aggregations

OBlob (com.orientechnologies.orient.core.record.impl.OBlob)32 ORecordBytes (com.orientechnologies.orient.core.record.impl.ORecordBytes)20 Test (org.testng.annotations.Test)19 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)12 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)8 ORID (com.orientechnologies.orient.core.id.ORID)4 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)4 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)3 IOException (java.io.IOException)3 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)2 ORecordId (com.orientechnologies.orient.core.id.ORecordId)2 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)2 BufferedInputStream (java.io.BufferedInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 OAfterDeserialization (com.orientechnologies.orient.core.annotation.OAfterDeserialization)1 OBeforeSerialization (com.orientechnologies.orient.core.annotation.OBeforeSerialization)1 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)1 ORecordLazyList (com.orientechnologies.orient.core.db.record.ORecordLazyList)1