use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.
the class ServerRun method deleteStorages.
public void deleteStorages() {
for (OStorage s : Orient.instance().getStorages()) {
if (s instanceof OLocalPaginatedStorage && new File(((OLocalPaginatedStorage) s).getStoragePath()).getAbsolutePath().startsWith(getDatabasePath(""))) {
s.close(true, true);
Orient.instance().unregisterStorage(s);
}
}
}
use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.
the class ORidBagTest method testAddSBTreeAddInMemoryIterateAndRemove.
public void testAddSBTreeAddInMemoryIterateAndRemove() {
List<OIdentifiable> rids = new ArrayList<OIdentifiable>();
ORidBag bag = new ORidBag();
bag.setAutoConvertToRecord(false);
assertEmbedded(bag.isEmbedded());
bag.add(new ORecordId("#77:2"));
rids.add(new ORecordId("#77:2"));
bag.add(new ORecordId("#77:2"));
rids.add(new ORecordId("#77:2"));
bag.add(new ORecordId("#77:3"));
rids.add(new ORecordId("#77:3"));
bag.add(new ORecordId("#77:4"));
rids.add(new ORecordId("#77:4"));
bag.add(new ORecordId("#77:4"));
rids.add(new ORecordId("#77:4"));
bag.add(new ORecordId("#77:7"));
rids.add(new ORecordId("#77:7"));
bag.add(new ORecordId("#77:8"));
rids.add(new ORecordId("#77:8"));
assertEmbedded(bag.isEmbedded());
ODocument doc = new ODocument();
doc.field("ridbag", bag);
doc.save();
ORID rid = doc.getIdentity();
OStorage storage = database.getStorage();
database.close();
storage.close(true, false);
database = new ODatabaseDocumentTx(database.getURL());
database.open("admin", "admin");
doc = database.load(rid);
doc.setLazyLoad(false);
bag = doc.field("ridbag");
assertEmbedded(bag.isEmbedded());
bag.add(new ORecordId("#77:0"));
rids.add(new ORecordId("#77:0"));
bag.add(new ORecordId("#77:1"));
rids.add(new ORecordId("#77:1"));
bag.add(new ORecordId("#77:2"));
rids.add(new ORecordId("#77:2"));
bag.add(new ORecordId("#77:3"));
rids.add(new ORecordId("#77:3"));
bag.add(new ORecordId("#77:3"));
rids.add(new ORecordId("#77:3"));
bag.add(new ORecordId("#77:5"));
rids.add(new ORecordId("#77:5"));
bag.add(new ORecordId("#77:6"));
rids.add(new ORecordId("#77:6"));
assertEmbedded(bag.isEmbedded());
Iterator<OIdentifiable> iterator = bag.iterator();
int r2c = 0;
int r3c = 0;
int r6c = 0;
int r4c = 0;
int r7c = 0;
while (iterator.hasNext()) {
OIdentifiable identifiable = iterator.next();
if (identifiable.equals(new ORecordId("#77:2"))) {
if (r2c < 2) {
r2c++;
iterator.remove();
rids.remove(identifiable);
}
}
if (identifiable.equals(new ORecordId("#77:3"))) {
if (r3c < 1) {
r3c++;
iterator.remove();
rids.remove(identifiable);
}
}
if (identifiable.equals(new ORecordId("#77:6"))) {
if (r6c < 1) {
r6c++;
iterator.remove();
rids.remove(identifiable);
}
}
if (identifiable.equals(new ORecordId("#77:4"))) {
if (r4c < 1) {
r4c++;
iterator.remove();
rids.remove(identifiable);
}
}
if (identifiable.equals(new ORecordId("#77:7"))) {
if (r7c < 1) {
r7c++;
iterator.remove();
rids.remove(identifiable);
}
}
}
assertEquals(r2c, 2);
assertEquals(r3c, 1);
assertEquals(r6c, 1);
assertEquals(r4c, 1);
assertEquals(r7c, 1);
for (OIdentifiable identifiable : bag) assertTrue(rids.remove(identifiable));
assertTrue(rids.isEmpty());
for (OIdentifiable identifiable : bag) rids.add(identifiable);
doc = new ODocument();
final ORidBag otherBag = new ORidBag();
for (OIdentifiable id : bag) otherBag.add(id);
assertEmbedded(otherBag.isEmbedded());
doc.field("ridbag", otherBag);
doc.save();
rid = doc.getIdentity();
doc = database.load(rid);
doc.setLazyLoad(false);
bag = doc.field("ridbag");
assertEmbedded(bag.isEmbedded());
for (OIdentifiable identifiable : bag) assertTrue(rids.remove(identifiable));
assertTrue(rids.isEmpty());
}
use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.
the class ORidBagTest method testAddRemoveDuringIterationSBTreeContainsValues.
public void testAddRemoveDuringIterationSBTreeContainsValues() {
ORidBag bag = new ORidBag();
bag.setAutoConvertToRecord(false);
assertEmbedded(bag.isEmbedded());
bag.add(new ORecordId("#77:2"));
bag.add(new ORecordId("#77:2"));
bag.add(new ORecordId("#77:3"));
bag.add(new ORecordId("#77:4"));
bag.add(new ORecordId("#77:4"));
bag.add(new ORecordId("#77:4"));
bag.add(new ORecordId("#77:5"));
bag.add(new ORecordId("#77:6"));
assertEmbedded(bag.isEmbedded());
ODocument doc = new ODocument();
doc.field("ridbag", bag);
doc.save();
ORID rid = doc.getIdentity();
OStorage storage = database.getStorage();
database.close();
storage.close(true, false);
database.activateOnCurrentThread();
database.resetInitialization();
database.open("admin", "admin");
doc = database.load(rid);
doc.setLazyLoad(false);
bag = doc.field("ridbag");
assertEmbedded(bag.isEmbedded());
bag.remove(new ORecordId("#77:1"));
bag.remove(new ORecordId("#77:2"));
bag.remove(new ORecordId("#77:2"));
bag.remove(new ORecordId("#77:4"));
bag.remove(new ORecordId("#77:6"));
assertEmbedded(bag.isEmbedded());
final List<OIdentifiable> rids = new ArrayList<OIdentifiable>();
rids.add(new ORecordId("#77:3"));
rids.add(new ORecordId("#77:4"));
rids.add(new ORecordId("#77:4"));
rids.add(new ORecordId("#77:5"));
for (OIdentifiable identifiable : bag) assertTrue(rids.remove(identifiable));
assertTrue(rids.isEmpty());
for (OIdentifiable identifiable : bag) rids.add(identifiable);
Iterator<OIdentifiable> iterator = bag.iterator();
while (iterator.hasNext()) {
final OIdentifiable identifiable = iterator.next();
if (identifiable.equals(new ORecordId("#77:4"))) {
iterator.remove();
assertTrue(rids.remove(identifiable));
}
}
for (OIdentifiable identifiable : bag) assertTrue(rids.remove(identifiable));
for (OIdentifiable identifiable : bag) rids.add(identifiable);
assertEmbedded(bag.isEmbedded());
doc = new ODocument();
final ORidBag otherBag = new ORidBag();
for (OIdentifiable id : bag) otherBag.add(id);
assertEmbedded(otherBag.isEmbedded());
doc.field("ridbag", otherBag);
doc.save();
rid = doc.getIdentity();
doc = database.load(rid);
doc.setLazyLoad(false);
bag = doc.field("ridbag");
assertEmbedded(bag.isEmbedded());
for (OIdentifiable identifiable : bag) assertTrue(rids.remove(identifiable));
assertTrue(rids.isEmpty());
}
use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.
the class ORidBagTest method testAddRemoveSBTreeContainsValues.
public void testAddRemoveSBTreeContainsValues() {
ORidBag bag = new ORidBag();
bag.setAutoConvertToRecord(false);
bag.add(new ORecordId("#77:2"));
bag.add(new ORecordId("#77:2"));
bag.add(new ORecordId("#77:3"));
bag.add(new ORecordId("#77:4"));
bag.add(new ORecordId("#77:4"));
bag.add(new ORecordId("#77:4"));
bag.add(new ORecordId("#77:5"));
bag.add(new ORecordId("#77:6"));
assertEmbedded(bag.isEmbedded());
ODocument doc = new ODocument();
doc.field("ridbag", bag);
doc.save();
ORID rid = doc.getIdentity();
OStorage storage = database.getStorage();
database.close();
storage.close(true, false);
database = new ODatabaseDocumentTx(database.getURL());
database.open("admin", "admin");
doc = database.load(rid);
doc.setLazyLoad(false);
bag = doc.field("ridbag");
assertEmbedded(bag.isEmbedded());
bag.remove(new ORecordId("#77:1"));
bag.remove(new ORecordId("#77:2"));
bag.remove(new ORecordId("#77:2"));
bag.remove(new ORecordId("#77:4"));
bag.remove(new ORecordId("#77:6"));
final List<OIdentifiable> rids = new ArrayList<OIdentifiable>();
rids.add(new ORecordId("#77:3"));
rids.add(new ORecordId("#77:4"));
rids.add(new ORecordId("#77:4"));
rids.add(new ORecordId("#77:5"));
for (OIdentifiable identifiable : bag) assertTrue(rids.remove(identifiable));
assertTrue(rids.isEmpty());
for (OIdentifiable identifiable : bag) rids.add(identifiable);
doc = new ODocument();
ORidBag otherBag = new ORidBag();
for (OIdentifiable id : bag) otherBag.add(id);
assertEmbedded(otherBag.isEmbedded());
doc.field("ridbag", otherBag);
doc.save();
rid = doc.getIdentity();
doc = database.load(rid);
doc.setLazyLoad(false);
bag = doc.field("ridbag");
assertEmbedded(bag.isEmbedded());
for (OIdentifiable identifiable : bag) assertTrue(rids.remove(identifiable));
assertTrue(rids.isEmpty());
}
use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.
the class ORidBagTest method testAddSBTreeAddInMemoryIterate.
public void testAddSBTreeAddInMemoryIterate() {
List<OIdentifiable> rids = new ArrayList<OIdentifiable>();
ORidBag bag = new ORidBag();
assertEmbedded(bag.isEmbedded());
bag.setAutoConvertToRecord(false);
bag.add(new ORecordId("#77:2"));
rids.add(new ORecordId("#77:2"));
bag.add(new ORecordId("#77:2"));
rids.add(new ORecordId("#77:2"));
bag.add(new ORecordId("#77:3"));
rids.add(new ORecordId("#77:3"));
bag.add(new ORecordId("#77:4"));
rids.add(new ORecordId("#77:4"));
bag.add(new ORecordId("#77:4"));
rids.add(new ORecordId("#77:4"));
assertEmbedded(bag.isEmbedded());
ODocument doc = new ODocument();
doc.field("ridbag", bag);
doc.save();
ORID rid = doc.getIdentity();
OStorage storage = database.getStorage();
database.close();
storage.close(true, false);
database = new ODatabaseDocumentTx(database.getURL());
database.open("admin", "admin");
doc = database.load(rid);
doc.setLazyLoad(false);
bag = doc.field("ridbag");
assertEmbedded(bag.isEmbedded());
bag.add(new ORecordId("#77:0"));
rids.add(new ORecordId("#77:0"));
bag.add(new ORecordId("#77:1"));
rids.add(new ORecordId("#77:1"));
bag.add(new ORecordId("#77:2"));
rids.add(new ORecordId("#77:2"));
bag.add(new ORecordId("#77:3"));
rids.add(new ORecordId("#77:3"));
bag.add(new ORecordId("#77:5"));
rids.add(new ORecordId("#77:5"));
bag.add(new ORecordId("#77:6"));
rids.add(new ORecordId("#77:6"));
assertEmbedded(bag.isEmbedded());
for (OIdentifiable identifiable : bag) assertTrue(rids.remove(identifiable));
assertTrue(rids.isEmpty());
for (OIdentifiable identifiable : bag) rids.add(identifiable);
doc = new ODocument();
final ORidBag otherBag = new ORidBag();
for (OIdentifiable id : bag) otherBag.add(id);
doc.field("ridbag", otherBag);
doc.save();
rid = doc.getIdentity();
doc = database.load(rid);
doc.setLazyLoad(false);
bag = doc.field("ridbag");
assertEmbedded(bag.isEmbedded());
for (OIdentifiable identifiable : bag) assertTrue(rids.remove(identifiable));
assertTrue(rids.isEmpty());
}
Aggregations