Search in sources :

Example 26 with OBlob

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

the class Account method toStream.

@OBeforeSerialization
public void toStream(final ODocument iDocument) {
    if (thumbnail != null) {
        // WRITE THE PHOTO IN AN EXTERNAL RECORD AS PURE BINARY
        OBlob externalPhoto = new ORecordBytes(thumbnail);
        iDocument.field("externalPhoto", externalPhoto);
    }
}
Also used : OBlob(com.orientechnologies.orient.core.record.impl.OBlob) ORecordBytes(com.orientechnologies.orient.core.record.impl.ORecordBytes) OBeforeSerialization(com.orientechnologies.orient.core.annotation.OBeforeSerialization)

Example 27 with OBlob

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

the class LocalDocumentAndBinarySpeedTest method loadRandomMixed.

@Test(dependsOnMethods = "saveLotOfMixedData")
public void loadRandomMixed() {
    database.open(DEFAULT_DB_USER, DEFAULT_DB_PASSWORD);
    index = database.getMetadata().getSchema().getClass("Chunk").getProperty("hash").getIndexes().iterator().next();
    Assert.assertNotNull(index);
    Set<Integer> alreadyLoaded = new HashSet<Integer>();
    try {
        for (int i = 0; i < load; i++) {
            int rand = (int) (Math.random() * count);
            if (!alreadyLoaded.contains(rand))
                alreadyLoaded.add(rand);
            else
                System.out.println("already loaded");
            OIdentifiable result = (OIdentifiable) index.get("key" + Integer.toString(rand));
            Assert.assertNotNull(result);
            ODocument doc = (ODocument) result.getRecord();
            System.out.println("loaded " + i + "(" + rand + "), binary record: " + doc.field("binary", ORID.class));
            OBlob record = doc.field("binary");
            Assert.assertNotNull(record);
            if (record != null) {
                byte[] data = record.toStream();
                Assert.assertTrue(data.length == size);
            }
            if (i % 100 == 0)
                System.out.println("loaded " + i);
        }
    } finally {
        database.close();
    }
}
Also used : OBlob(com.orientechnologies.orient.core.record.impl.OBlob) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) HashSet(java.util.HashSet) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 28 with OBlob

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

the class OConsoleDatabaseApp method dumpRecordDetails.

private void dumpRecordDetails() {
    if (currentRecord == null)
        return;
    else if (currentRecord instanceof ODocument) {
        ODocument rec = (ODocument) currentRecord;
        if (rec.getClassName() != null || rec.getIdentity().isValid()) {
            message("\nDOCUMENT @class:%s @rid:%s @version:%d", rec.getClassName(), rec.getIdentity().toString(), rec.getVersion());
        }
        final List<ODocument> resultSet = new ArrayList<ODocument>();
        Object value;
        for (String fieldName : rec.fieldNames()) {
            value = rec.field(fieldName);
            if (value instanceof byte[])
                value = "byte[" + ((byte[]) value).length + "]";
            else if (value instanceof Iterator<?>) {
                final List<Object> coll = new ArrayList<Object>();
                while (((Iterator<?>) value).hasNext()) coll.add(((Iterator<?>) value).next());
                value = coll;
            } else if (OMultiValue.isMultiValue(value)) {
                value = OTableFormatter.getPrettyFieldMultiValue(OMultiValue.getMultiValueIterator(value), getMaxMultiValueEntries());
            }
            final ODocument row = new ODocument();
            resultSet.add(row);
            row.field("NAME", fieldName);
            row.field("VALUE", value);
        }
        final OTableFormatter formatter = new OTableFormatter(this);
        formatter.writeRecords(resultSet, -1);
    } else if (currentRecord instanceof OBlob) {
        OBlob rec = (OBlob) currentRecord;
        message("\n+-------------------------------------------------------------------------------------------------+");
        message("\n| Bytes    - @rid: %s @version: %d", rec.getIdentity().toString(), rec.getVersion());
        message("\n+-------------------------------------------------------------------------------------------------+");
        final byte[] value = rec.toStream();
        final int max = Math.min(Integer.parseInt(properties.get("maxBinaryDisplay")), Array.getLength(value));
        for (int i = 0; i < max; ++i) {
            message("%03d", Array.getByte(value, i));
        }
        message("\n+-------------------------------------------------------------------------------------------------+");
    } else {
        message("\n+-------------------------------------------------------------------------------------------------+");
        message("\n| %s - record id: %s   v.%d", currentRecord.getClass().getSimpleName(), currentRecord.getIdentity().toString(), currentRecord.getVersion());
        message("\n+-------------------------------------------------------------------------------------------------+");
    }
    out.println();
}
Also used : OBlob(com.orientechnologies.orient.core.record.impl.OBlob) OIdentifiableIterator(com.orientechnologies.orient.core.iterator.OIdentifiableIterator) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 29 with OBlob

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

the class BinaryTest method testBasicReadExternal.

@Test(dependsOnMethods = "testBasicCreateExternal")
public void testBasicReadExternal() {
    OBlob record = database.load(rid);
    Assert.assertEquals("This is a test", new String(record.toStream()));
}
Also used : OBlob(com.orientechnologies.orient.core.record.impl.OBlob) Test(org.testng.annotations.Test)

Example 30 with OBlob

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

the class BinaryTest method testMixedReadExternal.

@Test(dependsOnMethods = "testMixedCreateExternal")
public void testMixedReadExternal() {
    ODocument doc = new ODocument(rid);
    doc.reload();
    Assert.assertEquals("Binary data", new String(((OBlob) doc.field("binary")).toStream()));
}
Also used : OBlob(com.orientechnologies.orient.core.record.impl.OBlob) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

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