Search in sources :

Example 1 with OBlob

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

the class ORecordSerializerRaw method fromStream.

public ORecord fromStream(final byte[] iSource, final ORecord iRecord, String[] iFields) {
    final OBlob record = (OBlob) iRecord;
    record.reset();
    record.fromStream(iSource);
    return record;
}
Also used : OBlob(com.orientechnologies.orient.core.record.impl.OBlob)

Example 2 with OBlob

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

the class ODatabaseDocumentTx method assignAndCheckCluster.

public int assignAndCheckCluster(ORecord record, String iClusterName) {
    ORecordId rid = (ORecordId) record.getIdentity();
    // if provided a cluster name use it.
    if (rid.getClusterId() <= ORID.CLUSTER_POS_INVALID && iClusterName != null) {
        rid.setClusterId(getClusterIdByName(iClusterName));
        if (rid.getClusterId() == -1)
            throw new IllegalArgumentException("Cluster name '" + iClusterName + "' is not configured");
    }
    OClass schemaClass = null;
    // if cluster id is not set yet try to find it out
    if (rid.getClusterId() <= ORID.CLUSTER_ID_INVALID && storage.isAssigningClusterIds()) {
        if (record instanceof ODocument) {
            schemaClass = ODocumentInternal.getImmutableSchemaClass(((ODocument) record));
            if (schemaClass != null) {
                if (schemaClass.isAbstract())
                    throw new OSchemaException("Document belongs to abstract class " + schemaClass.getName() + " and cannot be saved");
                rid.setClusterId(schemaClass.getClusterForNewInstance((ODocument) record));
            } else
                rid.setClusterId(getDefaultClusterId());
        } else {
            rid.setClusterId(getDefaultClusterId());
            if (record instanceof OBlob && rid.getClusterId() != ORID.CLUSTER_ID_INVALID) {
            // Set<Integer> blobClusters = getMetadata().getSchema().getBlobClusters();
            // if (!blobClusters.contains(rid.clusterId) && rid.clusterId != getDefaultClusterId() && rid.clusterId != 0) {
            // if (iClusterName == null)
            // iClusterName = getClusterNameById(rid.clusterId);
            // throw new IllegalArgumentException(
            // "Cluster name '" + iClusterName + "' (id=" + rid.clusterId + ") is not configured to store blobs, valid are "
            // + blobClusters.toString());
            // }
            }
        }
    } else if (record instanceof ODocument)
        schemaClass = ODocumentInternal.getImmutableSchemaClass(((ODocument) record));
    // If the cluster id was set check is validity
    if (rid.getClusterId() > ORID.CLUSTER_ID_INVALID) {
        if (schemaClass != null) {
            String messageClusterName = getClusterNameById(rid.getClusterId());
            checkRecordClass(schemaClass, messageClusterName, rid);
            if (!schemaClass.hasClusterId(rid.getClusterId())) {
                throw new IllegalArgumentException("Cluster name '" + messageClusterName + "' (id=" + rid.getClusterId() + ") is not configured to store the class '" + schemaClass.getName() + "', valid are " + Arrays.toString(schemaClass.getClusterIds()));
            }
        }
    }
    return rid.getClusterId();
}
Also used : OBlob(com.orientechnologies.orient.core.record.impl.OBlob) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 3 with OBlob

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

Example 4 with OBlob

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

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

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