use of com.orientechnologies.orient.core.sql.OCommandSQL in project orientdb by orientechnologies.
the class BetweenConversionTest method testBetweenLeftIncludedReverseOrder.
public void testBetweenLeftIncludedReverseOrder() {
final String query = "select from BetweenConversionTest where a < 3 and a >= 1";
final List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>(query));
Assert.assertEquals(result.size(), 2);
List<Integer> values = new ArrayList<Integer>(Arrays.asList(1, 2));
for (ODocument document : result) {
Assert.assertTrue(values.remove((Integer) document.field("a")));
}
Assert.assertTrue(values.isEmpty());
ODocument explain = database.command(new OCommandSQL("explain " + query)).execute();
Assert.assertEquals(explain.field("rangeQueryConvertedInBetween"), 1);
}
use of com.orientechnologies.orient.core.sql.OCommandSQL in project orientdb by orientechnologies.
the class BetweenConversionTest method testBetweenRightLeftIncludedFieldChainLeft.
public void testBetweenRightLeftIncludedFieldChainLeft() {
final String query = "select from BetweenConversionTest where d.a >= 1 and a <= 3";
final List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>(query));
Assert.assertEquals(result.size(), 3);
List<Integer> values = new ArrayList<Integer>(Arrays.asList(1, 2, 3));
for (ODocument document : result) {
Assert.assertTrue(values.remove((Integer) document.field("a")));
}
Assert.assertTrue(values.isEmpty());
ODocument explain = database.command(new OCommandSQL("explain " + query)).execute();
Assert.assertNull(explain.field("rangeQueryConvertedInBetween"));
}
use of com.orientechnologies.orient.core.sql.OCommandSQL in project orientdb by orientechnologies.
the class ObjectDetachingTest method testReloadAndDetachAll.
public void testReloadAndDetachAll() {
// Create the address without country
Address anAddress = new Address("Godewaersvelde");
anAddress = database.save(anAddress);
Address realAddress = database.detachAll(anAddress, true);
// Create the person
Profile aPerson = new Profile("Jack", "Jack", "Black", null);
aPerson.setLocation(realAddress);
aPerson = database.save(aPerson);
// Update the address by another way (another process for example)
City aCity = new City("Paris");
aCity = database.save(aCity);
String command = "update " + anAddress.getId() + " set city = " + database.getIdentity(aCity);
database.command(new OCommandSQL(command)).execute();
realAddress = database.reload(anAddress, true);
Assert.assertNotNull(realAddress.getCity());
// At this point, in OrientDB Studio everything is fine
// The address has the good country @rid, with version +1
// Now reload and detachAll the person
Profile newPerson = database.reload(aPerson, "*:-1", true);
Profile finalPerson = database.detachAll(newPerson, true);
// But with the reload, the country is null
// out = null
Assert.assertNotNull(finalPerson.getLocation().getCity());
// Same problem with query and detachAll
String query = "select from Profile where name = 'Jack' and surname = 'Black'";
newPerson = (Profile) database.query(new OSQLSynchQuery<Object>(query), new Object[0]).get(0);
finalPerson = database.detachAll(newPerson, true);
// out = null
Assert.assertNotNull(finalPerson.getLocation().getCity());
// Close db
}
use of com.orientechnologies.orient.core.sql.OCommandSQL in project orientdb by orientechnologies.
the class MapIndexTest method testIndexMapRemoveInTxRollback.
public void testIndexMapRemoveInTxRollback() throws Exception {
Mapper mapper = new Mapper();
Map<String, Integer> map = new HashMap<String, Integer>();
map.put("key1", 10);
map.put("key2", 20);
mapper.setIntMap(map);
mapper = database.save(mapper);
database.begin();
database.delete(mapper);
database.rollback();
final List<ODocument> resultByKey = database.command(new OCommandSQL("select key, rid from index:mapIndexTestKey")).execute();
Assert.assertNotNull(resultByKey);
Assert.assertEquals(resultByKey.size(), 2);
for (ODocument d : resultByKey) {
Assert.assertTrue(d.containsField("key"));
Assert.assertTrue(d.containsField("rid"));
if (!d.field("key").equals("key1") && !d.field("key").equals("key2")) {
Assert.fail("Unknown key found: " + d.field("key"));
}
}
final List<ODocument> resultByValue = database.command(new OCommandSQL("select key, rid from index:mapIndexTestValue")).execute();
Assert.assertNotNull(resultByValue);
Assert.assertEquals(resultByValue.size(), 2);
for (ODocument d : resultByValue) {
Assert.assertTrue(d.containsField("key"));
Assert.assertTrue(d.containsField("rid"));
if (!d.field("key").equals(10) && !d.field("key").equals(20)) {
Assert.fail("Unknown key found: " + d.field("key"));
}
}
}
use of com.orientechnologies.orient.core.sql.OCommandSQL in project orientdb by orientechnologies.
the class LinkBagIndexTest method testIndexRidBagUpdateAddItem.
public void testIndexRidBagUpdateAddItem() {
final ODocument docOne = new ODocument();
docOne.save();
final ODocument docTwo = new ODocument();
docTwo.save();
final ODocument docThree = new ODocument();
docThree.save();
final ODocument document = new ODocument("RidBagIndexTestClass");
final ORidBag ridBag = new ORidBag();
ridBag.add(docOne);
ridBag.add(docTwo);
document.field("ridBag", ridBag);
document.save();
database.command(new OCommandSQL("UPDATE " + document.getIdentity() + " add ridBag = " + docThree.getIdentity())).execute();
List<ODocument> result = database.command(new OCommandSQL("select key, rid from index:ridBagIndex")).execute();
Assert.assertNotNull(result);
Assert.assertEquals(result.size(), 3);
for (ODocument d : result) {
Assert.assertTrue(d.containsField("key"));
Assert.assertTrue(d.containsField("rid"));
if (!d.field("key").equals(docOne.getIdentity()) && !d.field("key").equals(docTwo.getIdentity()) && !d.field("key").equals(docThree.getIdentity())) {
Assert.fail("Unknown key found: " + d.field("key"));
}
}
}
Aggregations