Search in sources :

Example 21 with ORecordBytes

use of com.orientechnologies.orient.core.record.impl.ORecordBytes 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 ORecordBytes

use of com.orientechnologies.orient.core.record.impl.ORecordBytes 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 ORecordBytes

use of com.orientechnologies.orient.core.record.impl.ORecordBytes 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 ORecordBytes

use of com.orientechnologies.orient.core.record.impl.ORecordBytes 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 ORecordBytes

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

the class GiantFileTest method main.

public static void main(final String[] args) throws Exception {
    OGlobalConfiguration.USE_WAL.setValue(false);
    OGlobalConfiguration.DISK_CACHE_SIZE.setValue(1024);
    try {
        db = new ODatabaseDocumentTx("plocal:" + DATABASE_NAME);
        if (db.exists() && RECREATE_DATABASE) {
            db.open("admin", "admin");
            db.drop();
            System.out.println("Dropped database.");
        }
        if (!db.exists()) {
            db.create();
            System.out.println("Created database.");
            final OSchema schema = db.getMetadata().getSchema();
            // Create class for storing files.
            final OClass fileClass = schema.createClass("File");
            fileClass.createProperty("FileName", OType.STRING).setMandatory(true).setNotNull(true).setMin("1");
            fileClass.createProperty("FileSize", OType.LONG).setMandatory(true).setNotNull(true).setMin("0");
            // ORecordBytes is a special low-level class defined by OrientDB for efficient storage of raw data.
            fileClass.createProperty("DataChunks", OType.LINKLIST, OType.getTypeByClass(ORecordBytes.class)).setMandatory(true).setNotNull(false);
            System.out.println("Created schema.");
        } else {
            db.open("admin", "admin");
        }
        final File giantFile = new File("giantFile.bin");
        // Create the giant file if it doesn't already exist.
        if (!giantFile.exists()) {
            // 2 GiB
            final long fileSize = (long) 2 * 1024 * 1024 * 1024;
            final long createFileStartTime = System.currentTimeMillis();
            createGiantFile(giantFile, fileSize);
            final long createFileMs = System.currentTimeMillis() - createFileStartTime;
            System.out.printf("Finished creating giant file in %f seconds.\n", (float) createFileMs / 1000);
        }
        // Save the metadata about the file.
        final ODocument fileDoc = db.newInstance("File");
        fileDoc.field("FileName", giantFile.getName());
        fileDoc.field("FileSize", giantFile.length());
        fileDoc.field("DataChunks", (byte[]) null);
        fileDoc.save();
        // Store the actual file data.
        final long storeFileStartTime = System.currentTimeMillis();
        storeFileData(fileDoc, giantFile);
        final long storeFileMs = System.currentTimeMillis() - storeFileStartTime;
        System.out.printf("Finished storing giant file in %f seconds.\n", (float) storeFileMs / 1000);
    } finally {
        db.close();
        OGlobalConfiguration.USE_WAL.setValue(true);
    }
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) ORecordBytes(com.orientechnologies.orient.core.record.impl.ORecordBytes) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

ORecordBytes (com.orientechnologies.orient.core.record.impl.ORecordBytes)33 OBlob (com.orientechnologies.orient.core.record.impl.OBlob)20 Test (org.testng.annotations.Test)19 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)9 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)7 ORID (com.orientechnologies.orient.core.id.ORID)6 ORecord (com.orientechnologies.orient.core.record.ORecord)6 Test (org.junit.Test)6 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)4 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)4 IOException (java.io.IOException)4 OIntentMassiveInsert (com.orientechnologies.orient.core.intent.OIntentMassiveInsert)3 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)3 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)2 BufferedInputStream (java.io.BufferedInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ArrayList (java.util.ArrayList)2 OConsoleDatabaseApp (com.orientechnologies.orient.console.OConsoleDatabaseApp)1