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);
}
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();
}
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);
}
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);
}
}
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);
}
Aggregations