use of com.orientechnologies.orient.core.record.impl.ORecordBytes in project orientdb by orientechnologies.
the class TransactionOptimisticTest method testTransactionOptimisticCacheMgmt1Db.
@Test(dependsOnMethods = "testTransactionOptimisticConcurrentException")
public void testTransactionOptimisticCacheMgmt1Db() throws IOException {
if (database.getClusterIdByName("binary") == -1)
database.addBlobCluster("binary");
OBlob record = new ORecordBytes("This is the first version".getBytes());
record.save();
try {
database.begin();
// RE-READ THE RECORD
record.load();
int v1 = record.getVersion();
record.setDirty();
record.fromStream("This is the second version".getBytes());
record.save();
database.commit();
record.reload();
Assert.assertEquals(record.getVersion(), v1 + 1);
Assert.assertTrue(new String(record.toStream()).contains("second"));
} finally {
database.close();
}
}
use of com.orientechnologies.orient.core.record.impl.ORecordBytes in project orientdb by orientechnologies.
the class TransactionOptimisticTest method testTransactionOptimisticCacheMgmt2Db.
@Test(dependsOnMethods = "testTransactionOptimisticCacheMgmt1Db")
public void testTransactionOptimisticCacheMgmt2Db() throws IOException {
if (database.getClusterIdByName("binary") == -1)
database.addBlobCluster("binary");
ODatabaseDocumentTx db2 = new ODatabaseDocumentTx(database.getURL());
db2.open("admin", "admin");
OBlob record1 = new ORecordBytes("This is the first version".getBytes());
record1.save();
try {
ODatabaseRecordThreadLocal.INSTANCE.set(database);
database.begin();
// RE-READ THE RECORD
record1.load();
int v1 = record1.getVersion();
record1.setDirty();
record1.fromStream("This is the second version".getBytes());
record1.save();
database.commit();
db2.activateOnCurrentThread();
OBlob record2 = db2.load(record1.getIdentity(), "*:-1", true);
Assert.assertEquals(record2.getVersion(), v1 + 1);
Assert.assertTrue(new String(record2.toStream()).contains("second"));
} finally {
database.activateOnCurrentThread();
database.close();
db2.activateOnCurrentThread();
db2.close();
}
}
use of com.orientechnologies.orient.core.record.impl.ORecordBytes in project orientdb by orientechnologies.
the class SQLSelectTest method testBinaryClusterSelect2.
@Test
public void testBinaryClusterSelect2() {
database.command(new OCommandSQL("create blob cluster testBinaryClusterSelect2")).execute();
database.reload();
OBlob bytes = new ORecordBytes(new byte[] { 1, 2, 3 });
database.save(bytes, "testBinaryClusterSelect2");
List<OIdentifiable> result = database.query(new OSQLSynchQuery<OIdentifiable>("select @rid, @version, @size, 1 as uno, foo from cluster:testBinaryClusterSelect2"));
Assert.assertEquals(result.size(), 1);
ODocument item = (ODocument) result.get(0);
Assert.assertEquals(item.field("size"), 3);
Assert.assertEquals(item.field("version"), 1);
Assert.assertEquals(item.field("uno"), 1);
Assert.assertEquals(item.field("foo"), null);
Assert.assertNotNull(item.field("rid"));
}
use of com.orientechnologies.orient.core.record.impl.ORecordBytes in project orientdb by orientechnologies.
the class SQLSelectTest method testBinaryClusterSelect.
@Test
public void testBinaryClusterSelect() {
database.command(new OCommandSQL("create blob cluster binarycluster")).execute();
database.reload();
OBlob bytes = new ORecordBytes(new byte[] { 1, 2, 3 });
database.save(bytes, "binarycluster");
List<OIdentifiable> result = database.query(new OSQLSynchQuery<OIdentifiable>("select from cluster:binarycluster"));
Assert.assertEquals(result.size(), 1);
database.command(new OCommandSQL("delete from cluster:binarycluster")).execute();
result = database.query(new OSQLSynchQuery<OIdentifiable>("select from cluster:binarycluster"));
Assert.assertEquals(result.size(), 0);
}
use of com.orientechnologies.orient.core.record.impl.ORecordBytes in project orientdb by orientechnologies.
the class GiantFileTest method main.
public static void main(final String[] args) throws Exception {
OGlobalConfiguration.USE_WAL.setValue(false);
OGlobalConfiguration.DISK_CACHE_SIZE.setValue(1024);
try {
db = new ODatabaseDocumentTx("plocal:" + DATABASE_NAME);
if (db.exists() && RECREATE_DATABASE) {
db.open("admin", "admin");
db.drop();
System.out.println("Dropped database.");
}
if (!db.exists()) {
db.create();
System.out.println("Created database.");
final OSchema schema = db.getMetadata().getSchema();
// Create class for storing files.
final OClass fileClass = schema.createClass("File");
fileClass.createProperty("FileName", OType.STRING).setMandatory(true).setNotNull(true).setMin("1");
fileClass.createProperty("FileSize", OType.LONG).setMandatory(true).setNotNull(true).setMin("0");
// ORecordBytes is a special low-level class defined by OrientDB for efficient storage of raw data.
fileClass.createProperty("DataChunks", OType.LINKLIST, OType.getTypeByClass(ORecordBytes.class)).setMandatory(true).setNotNull(false);
System.out.println("Created schema.");
} else {
db.open("admin", "admin");
}
final File giantFile = new File("giantFile.bin");
// Create the giant file if it doesn't already exist.
if (!giantFile.exists()) {
// 2 GiB
final long fileSize = (long) 2 * 1024 * 1024 * 1024;
final long createFileStartTime = System.currentTimeMillis();
createGiantFile(giantFile, fileSize);
final long createFileMs = System.currentTimeMillis() - createFileStartTime;
System.out.printf("Finished creating giant file in %f seconds.\n", (float) createFileMs / 1000);
}
// Save the metadata about the file.
final ODocument fileDoc = db.newInstance("File");
fileDoc.field("FileName", giantFile.getName());
fileDoc.field("FileSize", giantFile.length());
fileDoc.field("DataChunks", (byte[]) null);
fileDoc.save();
// Store the actual file data.
final long storeFileStartTime = System.currentTimeMillis();
storeFileData(fileDoc, giantFile);
final long storeFileMs = System.currentTimeMillis() - storeFileStartTime;
System.out.printf("Finished storing giant file in %f seconds.\n", (float) storeFileMs / 1000);
} finally {
db.close();
OGlobalConfiguration.USE_WAL.setValue(true);
}
}
Aggregations