Search in sources :

Example 11 with ORecordBytes

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

the class LocalCreateBinarySpeedTest method init.

@Override
public void init() {
    Orient.instance().getProfiler().startRecording();
    database = new ODatabaseDocumentTx(System.getProperty("url")).open("admin", "admin");
    record = new ORecordBytes();
    database.declareIntent(new OIntentMassiveInsert());
    database.begin(TXTYPE.NOTX);
    Random rnd = new Random();
    recordContent = new byte[RECORD_SIZE];
    for (int i = 0; i < RECORD_SIZE; ++i) recordContent[i] = (byte) rnd.nextInt(256);
}
Also used : Random(java.util.Random) ORecordBytes(com.orientechnologies.orient.core.record.impl.ORecordBytes) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OIntentMassiveInsert(com.orientechnologies.orient.core.intent.OIntentMassiveInsert)

Example 12 with ORecordBytes

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

the class OHttpMultipartFileToRecordContentParser method parse.

@Override
public ORID parse(final OHttpRequest iRequest, final Map<String, String> headers, final OHttpMultipartContentInputStream in, ODatabaseDocument database) throws IOException {
    final OBlob record = new ORecordBytes();
    record.fromInputStream(in);
    record.save();
    return record.getIdentity();
}
Also used : OBlob(com.orientechnologies.orient.core.record.impl.OBlob) ORecordBytes(com.orientechnologies.orient.core.record.impl.ORecordBytes)

Example 13 with ORecordBytes

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

the class CRUDObjectPhysicalTestSchemaFull method testOrphanDelete.

@Test(dependsOnMethods = "testObjectDelete")
public void testOrphanDelete() {
    Media media = new Media();
    OBlob testRecord = new ORecordBytes("This is a test".getBytes());
    media.setContent(testRecord);
    media = database.save(media);
    Assert.assertEquals(new String(media.getContent().toStream()), "This is a test");
    // try to delete
    database.delete(media);
}
Also used : OBlob(com.orientechnologies.orient.core.record.impl.OBlob) ORecordBytes(com.orientechnologies.orient.core.record.impl.ORecordBytes) Test(org.testng.annotations.Test)

Example 14 with ORecordBytes

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

the class CRUDObjectPhysicalTestSchemaFull method oidentifableFieldsTest.

@Test(dependsOnMethods = "testNoGenericCollectionsWrongAdding")
public void oidentifableFieldsTest() {
    JavaComplexTestClass p = database.newInstance(JavaComplexTestClass.class);
    p.setName("Dean Winchester");
    ODocument testEmbeddedDocument = new ODocument();
    testEmbeddedDocument.field("testEmbeddedField", "testEmbeddedValue");
    p.setEmbeddedDocument(testEmbeddedDocument);
    ODocument testDocument = new ODocument();
    testDocument.field("testField", "testValue");
    p.setDocument(testDocument);
    OBlob testRecordBytes = new ORecordBytes("this is a bytearray test. if you read this Object database has stored it correctly".getBytes());
    p.setByteArray(testRecordBytes);
    database.save(p);
    ORID rid = database.getRecordByUserObject(p, false).getIdentity();
    database.close();
    database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
    JavaComplexTestClass loaded = database.load(rid);
    Assert.assertTrue(loaded.getByteArray() instanceof OBlob);
    try {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try {
            loaded.getByteArray().toOutputStream(out);
            Assert.assertEquals("this is a bytearray test. if you read this Object database has stored it correctly".getBytes(), out.toByteArray());
            Assert.assertEquals("this is a bytearray test. if you read this Object database has stored it correctly", new String(out.toByteArray()));
        } finally {
            out.close();
        }
    } catch (IOException ioe) {
        Assert.assertTrue(false);
        OLogManager.instance().error(this, "Error reading byte[]", ioe);
    }
    Assert.assertTrue(loaded.getDocument() instanceof ODocument);
    Assert.assertEquals("testValue", loaded.getDocument().field("testField"));
    Assert.assertTrue(loaded.getDocument().getIdentity().isPersistent());
    Assert.assertTrue(loaded.getEmbeddedDocument() instanceof ODocument);
    Assert.assertEquals("testEmbeddedValue", loaded.getEmbeddedDocument().field("testEmbeddedField"));
    Assert.assertFalse(loaded.getEmbeddedDocument().getIdentity().isValid());
    database.close();
    database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
    p = database.newInstance(JavaComplexTestClass.class);
    byte[] thumbnailImageBytes = "this is a bytearray test. if you read this Object database has stored it correctlyVERSION2".getBytes();
    OBlob oRecordBytes = new ORecordBytes(database.getUnderlying(), thumbnailImageBytes);
    oRecordBytes.save();
    p.setByteArray(oRecordBytes);
    p = database.save(p);
    Assert.assertTrue(p.getByteArray() instanceof OBlob);
    try {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try {
            p.getByteArray().toOutputStream(out);
            Assert.assertEquals("this is a bytearray test. if you read this Object database has stored it correctlyVERSION2".getBytes(), out.toByteArray());
            Assert.assertEquals("this is a bytearray test. if you read this Object database has stored it correctlyVERSION2", new String(out.toByteArray()));
        } finally {
            out.close();
        }
    } catch (IOException ioe) {
        Assert.assertTrue(false);
        OLogManager.instance().error(this, "Error reading byte[]", ioe);
    }
    rid = database.getIdentity(p);
    database.close();
    database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
    loaded = database.load(rid);
    Assert.assertTrue(loaded.getByteArray() instanceof OBlob);
    try {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try {
            loaded.getByteArray().toOutputStream(out);
            Assert.assertEquals("this is a bytearray test. if you read this Object database has stored it correctlyVERSION2".getBytes(), out.toByteArray());
            Assert.assertEquals("this is a bytearray test. if you read this Object database has stored it correctlyVERSION2", new String(out.toByteArray()));
        } finally {
            out.close();
        }
    } catch (IOException ioe) {
        Assert.assertTrue(false);
        OLogManager.instance().error(this, "Error reading byte[]", ioe);
    }
    database.close();
    database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
    p = new JavaComplexTestClass();
    thumbnailImageBytes = "this is a bytearray test. if you read this Object database has stored it correctlyVERSION2".getBytes();
    oRecordBytes = new ORecordBytes(database.getUnderlying(), thumbnailImageBytes);
    oRecordBytes.save();
    p.setByteArray(oRecordBytes);
    p = database.save(p);
    Assert.assertTrue(p.getByteArray() instanceof OBlob);
    try {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try {
            p.getByteArray().toOutputStream(out);
            Assert.assertEquals("this is a bytearray test. if you read this Object database has stored it correctlyVERSION2".getBytes(), out.toByteArray());
            Assert.assertEquals("this is a bytearray test. if you read this Object database has stored it correctlyVERSION2", new String(out.toByteArray()));
        } finally {
            out.close();
        }
    } catch (IOException ioe) {
        Assert.assertTrue(false);
        OLogManager.instance().error(this, "Error reading byte[]", ioe);
    }
    rid = database.getIdentity(p);
    database.close();
    database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
    loaded = database.load(rid);
    Assert.assertTrue(loaded.getByteArray() instanceof OBlob);
    try {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try {
            loaded.getByteArray().toOutputStream(out);
            Assert.assertEquals("this is a bytearray test. if you read this Object database has stored it correctlyVERSION2".getBytes(), out.toByteArray());
            Assert.assertEquals("this is a bytearray test. if you read this Object database has stored it correctlyVERSION2", new String(out.toByteArray()));
        } finally {
            out.close();
        }
    } catch (IOException ioe) {
        Assert.assertTrue(false);
        OLogManager.instance().error(this, "Error reading byte[]", ioe);
    }
}
Also used : OBlob(com.orientechnologies.orient.core.record.impl.OBlob) ORecordBytes(com.orientechnologies.orient.core.record.impl.ORecordBytes) ORID(com.orientechnologies.orient.core.id.ORID) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 15 with ORecordBytes

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

the class SQLSelectTest method testBinaryClusterSelect3.

@Test
public void testBinaryClusterSelect3() {
    database.command(new OCommandSQL("create class testBinaryClusterSelect3")).execute();
    database.command(new OCommandSQL("create blob cluster testBinaryClusterSelect3_blob")).execute();
    database.reload();
    OBlob bytes = new ORecordBytes(new byte[] { 1, 2, 3 });
    database.save(bytes, "testBinaryClusterSelect3_blob");
    ODocument doc = new ODocument("testBinaryClusterSelect3");
    doc.field("Blob", bytes);
    doc.save();
    ODocument doc2 = new ODocument("testBinaryClusterSelect3");
    doc2.save();
    List<OIdentifiable> result = database.query(new OSQLSynchQuery<OIdentifiable>("select from cluster:testBinaryClusterSelect3_blob"));
    Assert.assertEquals(result.size(), 1);
    database.command(new OCommandSQL("delete from (select expand(Blob) from testBinaryClusterSelect3)")).execute();
    result = database.query(new OSQLSynchQuery<OIdentifiable>("select from cluster:testBinaryClusterSelect3_blob"));
    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) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) 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