use of com.orientechnologies.orient.core.id.ORecordId in project orientdb by orientechnologies.
the class ObjectDetachingTestSchemaFull method testUpdateRollback.
@Test(dependsOnMethods = "testUpdateCommit")
public void testUpdateRollback() {
String initialCountryName = "updateRollback";
Country country = new Country(initialCountryName);
country = (Country) database.save(country);
Assert.assertNotNull(country.getId());
Assert.assertNotNull(country.getVersion());
int initVersion = (Integer) country.getVersion();
database.begin();
Country loaded = (Country) database.load((ORecordId) country.getId());
Assert.assertEquals(loaded.getId(), country.getId());
Assert.assertEquals(loaded.getVersion(), country.getVersion());
Assert.assertEquals((Object) database.getRecordByUserObject(loaded, false), database.getRecordByUserObject(country, false));
String newName = "ShouldNotBeChanged";
loaded.setName(newName);
loaded = (Country) database.save(loaded);
database.rollback();
loaded = database.load((ORecordId) country.getId());
Assert.assertNotSame(database.getRecordByUserObject(loaded, false), database.getRecordByUserObject(country, false));
Assert.assertEquals((Integer) loaded.getVersion(), (Integer) initVersion);
Assert.assertEquals(loaded.getName(), initialCountryName);
}
use of com.orientechnologies.orient.core.id.ORecordId in project orientdb by orientechnologies.
the class ObjectDetachingTestSchemaFull method testInsertCommit.
@Test(dependsOnMethods = "testOrientObjectIdPlusVersionAnnotationsInTx")
public void testInsertCommit() {
String initialCountryName = "insertCommit";
Country country = new Country(initialCountryName);
long initCount = database.countClass(Country.class);
database.begin();
country = (Country) database.save(country);
database.commit();
Assert.assertEquals(database.countClass(Country.class), initCount + 1);
Assert.assertNotNull(country.getId());
Assert.assertNotNull(country.getVersion());
Country found = (Country) database.load((ORecordId) country.getId());
Assert.assertNotNull(found);
Assert.assertEquals(country.getName(), found.getName());
}
use of com.orientechnologies.orient.core.id.ORecordId in project orientdb by orientechnologies.
the class ORidBagTest method testAddRemoveNotExisting.
public void testAddRemoveNotExisting() {
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"));
bag.add(new ORecordId("#77:4"));
rids.add(new ORecordId("#77:4"));
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());
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:2"));
rids.add(new ORecordId("#77:2"));
bag.remove(new ORecordId("#77:4"));
rids.remove(new ORecordId("#77:4"));
bag.remove(new ORecordId("#77:4"));
rids.remove(new ORecordId("#77:4"));
bag.remove(new ORecordId("#77:2"));
rids.remove(new ORecordId("#77:2"));
bag.remove(new ORecordId("#77:2"));
rids.remove(new ORecordId("#77:2"));
bag.remove(new ORecordId("#77:7"));
rids.remove(new ORecordId("#77:7"));
bag.remove(new ORecordId("#77:8"));
rids.remove(new ORecordId("#77:8"));
bag.remove(new ORecordId("#77:8"));
rids.remove(new ORecordId("#77:8"));
bag.remove(new ORecordId("#77:8"));
rids.remove(new ORecordId("#77:8"));
assertEmbedded(bag.isEmbedded());
for (OIdentifiable identifiable : bag) assertTrue(rids.remove(identifiable));
assertTrue(rids.isEmpty());
for (OIdentifiable identifiable : bag) rids.add(identifiable);
doc.save();
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.id.ORecordId in project orientdb by orientechnologies.
the class ORidBagTest method testAdd.
public void testAdd() throws Exception {
ORidBag bag = new ORidBag();
bag.setAutoConvertToRecord(false);
bag.add(new ORecordId("#77:1"));
Assert.assertTrue(bag.contains(new ORecordId("#77:1")));
Assert.assertTrue(!bag.contains(new ORecordId("#78:2")));
Iterator<OIdentifiable> iterator = bag.iterator();
Assert.assertTrue(iterator.hasNext());
OIdentifiable identifiable = iterator.next();
Assert.assertEquals(identifiable, new ORecordId("#77:1"));
Assert.assertTrue(!iterator.hasNext());
assertEmbedded(bag.isEmbedded());
}
use of com.orientechnologies.orient.core.id.ORecordId in project orientdb by orientechnologies.
the class ORidBagTest method testAddRemove.
public void testAddRemove() {
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"));
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"));
Assert.assertTrue(bag.contains(new ORecordId("#77:3")));
Assert.assertTrue(bag.contains(new ORecordId("#77:4")));
Assert.assertTrue(bag.contains(new ORecordId("#77:5")));
Assert.assertTrue(!bag.contains(new ORecordId("#77:2")));
Assert.assertTrue(!bag.contains(new ORecordId("#77:6")));
Assert.assertTrue(!bag.contains(new ORecordId("#77:1")));
Assert.assertTrue(!bag.contains(new ORecordId("#77:0")));
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);
ODocument doc = new ODocument();
doc.field("ridbag", bag);
doc.save();
ORID rid = doc.getIdentity();
doc = database.load(rid);
doc.setLazyLoad(false);
bag = doc.field("ridbag");
assertEmbedded(bag.isEmbedded());
Assert.assertTrue(bag.contains(new ORecordId("#77:3")));
Assert.assertTrue(bag.contains(new ORecordId("#77:4")));
Assert.assertTrue(bag.contains(new ORecordId("#77:5")));
Assert.assertTrue(!bag.contains(new ORecordId("#77:2")));
Assert.assertTrue(!bag.contains(new ORecordId("#77:6")));
Assert.assertTrue(!bag.contains(new ORecordId("#77:1")));
Assert.assertTrue(!bag.contains(new ORecordId("#77:0")));
for (OIdentifiable identifiable : bag) assertTrue(rids.remove(identifiable));
assertTrue(rids.isEmpty());
}
Aggregations