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