Search in sources :

Example 16 with ORecordBytes

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

the class OrientDbCreationHelper method loadFile.

private static OBlob loadFile(ODatabaseDocumentInternal database, String filePath) throws IOException {
    final File f = new File(filePath);
    if (f.exists()) {
        BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(f));
        OBlob record = new ORecordBytes(database);
        record.fromInputStream(inputStream);
        return record;
    }
    return null;
}
Also used : OBlob(com.orientechnologies.orient.core.record.impl.OBlob) BufferedInputStream(java.io.BufferedInputStream) ORecordBytes(com.orientechnologies.orient.core.record.impl.ORecordBytes) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 17 with ORecordBytes

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

the class OrientDbCreationHelper method loadFile.

private static List<ORID> loadFile(ODatabaseDocumentInternal database, String filePath, int bufferSize) throws IOException {
    File binaryFile = new File(filePath);
    long binaryFileLength = binaryFile.length();
    int numberOfRecords = (int) (binaryFileLength / bufferSize);
    int remainder = (int) (binaryFileLength % bufferSize);
    if (remainder > 0)
        numberOfRecords++;
    List<ORID> binaryChuncks = new ArrayList<ORID>(numberOfRecords);
    BufferedInputStream binaryStream = new BufferedInputStream(new FileInputStream(binaryFile));
    byte[] chunk;
    database.declareIntent(new OIntentMassiveInsert());
    OBlob recordChunk;
    for (int i = 0; i < numberOfRecords; i++) {
        if (i == numberOfRecords - 1)
            chunk = new byte[remainder];
        else
            chunk = new byte[bufferSize];
        binaryStream.read(chunk);
        recordChunk = new ORecordBytes(database, chunk);
        database.save(recordChunk);
        binaryChuncks.add(recordChunk.getIdentity());
    }
    database.declareIntent(null);
    return binaryChuncks;
}
Also used : OBlob(com.orientechnologies.orient.core.record.impl.OBlob) BufferedInputStream(java.io.BufferedInputStream) ORecordBytes(com.orientechnologies.orient.core.record.impl.ORecordBytes) ArrayList(java.util.ArrayList) ORID(com.orientechnologies.orient.core.id.ORID) File(java.io.File) FileInputStream(java.io.FileInputStream) OIntentMassiveInsert(com.orientechnologies.orient.core.intent.OIntentMassiveInsert)

Example 18 with ORecordBytes

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

the class SQLDeleteTest method testBinaryClusterDelete.

@Test
public void testBinaryClusterDelete() {
    database.command(new OCommandSQL("create blob cluster testbinaryclusterdelete")).execute();
    database.reload();
    OBlob bytes = new ORecordBytes(new byte[] { 1, 2, 3 });
    database.save(bytes, "testbinaryclusterdelete");
    List<OIdentifiable> result = database.query(new OSQLSynchQuery<OIdentifiable>("select from cluster:testbinaryclusterdelete"));
    Assert.assertEquals(result.size(), 1);
    ORID rid = result.get(0).getIdentity();
    database.command(new OCommandSQL("delete from " + rid)).execute();
    result = database.query(new OSQLSynchQuery<OIdentifiable>("select from cluster:testbinaryclusterdelete"));
    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) ORID(com.orientechnologies.orient.core.id.ORID) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) Test(org.testng.annotations.Test)

Example 19 with ORecordBytes

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

the class TransactionOptimisticTest method testTransactionOptimisticRollback.

@Test
public void testTransactionOptimisticRollback() throws IOException {
    if (database.getClusterIdByName("binary") == -1)
        database.addBlobCluster("binary");
    long rec = database.countClusterElements("binary");
    database.begin();
    OBlob recordBytes = new ORecordBytes("This is the first version".getBytes());
    recordBytes.save("binary");
    database.rollback();
    Assert.assertEquals(database.countClusterElements("binary"), rec);
}
Also used : OBlob(com.orientechnologies.orient.core.record.impl.OBlob) ORecordBytes(com.orientechnologies.orient.core.record.impl.ORecordBytes) Test(org.testng.annotations.Test)

Example 20 with ORecordBytes

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

the class TransactionOptimisticTest method testTransactionOptimisticConcurrentException.

@Test(dependsOnMethods = "testTransactionOptimisticCommit")
public void testTransactionOptimisticConcurrentException() throws IOException {
    if (database.getClusterIdByName("binary") == -1)
        database.addBlobCluster("binary");
    ODatabaseDocumentTx db2 = new ODatabaseDocumentTx(database.getURL());
    db2.open("admin", "admin");
    database.activateOnCurrentThread();
    OBlob record1 = new ORecordBytes("This is the first version".getBytes());
    record1.save("binary");
    try {
        database.begin();
        // RE-READ THE RECORD
        record1.load();
        ODatabaseRecordThreadLocal.INSTANCE.set(db2);
        OBlob record2 = db2.load(record1.getIdentity());
        record2.setDirty();
        record2.fromStream("This is the second version".getBytes());
        record2.save();
        ODatabaseRecordThreadLocal.INSTANCE.set(database);
        record1.setDirty();
        record1.fromStream("This is the third version".getBytes());
        record1.save();
        database.commit();
        Assert.assertTrue(false);
    } catch (OConcurrentModificationException e) {
        Assert.assertTrue(true);
        database.rollback();
    } finally {
        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) OConcurrentModificationException(com.orientechnologies.orient.core.exception.OConcurrentModificationException) Test(org.testng.annotations.Test)

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