use of com.orientechnologies.orient.core.sql.OCommandSQL in project orientdb by orientechnologies.
the class FunctionsTest method testMapParamToFunction.
@Test
public void testMapParamToFunction() {
database.command(new OCommandSQL("create function testMapParamToFunction \"return mapParam.get('foo')[0];\" PARAMETERS [mapParam] LANGUAGE Javascript")).execute();
Map<String, Object> params = new HashMap<String, Object>();
List theList = new ArrayList();
theList.add("bar");
Map theMap = new HashMap();
theMap.put("foo", theList);
params.put("theParam", theMap);
OResultSet<OIdentifiable> res1 = database.command(new OCommandSQL("select testMapParamToFunction(:theParam) as a")).execute(params);
Assert.assertNotNull(res1);
Assert.assertNotNull(res1.get(0));
Assert.assertEquals(((ODocument) res1.get(0)).field("a"), "bar");
}
use of com.orientechnologies.orient.core.sql.OCommandSQL in project orientdb by orientechnologies.
the class GraphDatabaseTest method testDeleteOfVerticesAndEdgesWithDeleteCommandAndUnsafe.
public void testDeleteOfVerticesAndEdgesWithDeleteCommandAndUnsafe() {
Iterable<OIdentifiable> deletedVertices = database.command(new OCommandSQL("delete from GraphVehicle return before limit 1 unsafe")).execute();
Assert.assertTrue(deletedVertices.iterator().hasNext());
OrientVertex v = (OrientVertex) deletedVertices.iterator().next();
Integer confirmDeleted = database.command(new OCommandSQL("delete from " + v.getIdentity() + " unsafe")).execute();
Assert.assertFalse(deletedVertices.iterator().hasNext());
Assert.assertEquals(confirmDeleted.intValue(), 0);
Iterable<Edge> edges = v.getEdges(Direction.BOTH);
for (Edge e : edges) {
Integer deletedEdges = database.command(new OCommandSQL("delete from " + ((OrientEdge) e).getIdentity() + " unsafe")).execute();
Assert.assertEquals(deletedEdges.intValue(), 1);
}
}
use of com.orientechnologies.orient.core.sql.OCommandSQL in project orientdb by orientechnologies.
the class IndexClusterTest method indexAfterRebuildShouldIncludeAllClusters.
@Test
public void indexAfterRebuildShouldIncludeAllClusters() {
// given
OSchema schema = database.getMetadata().getSchema();
String className = "IndexClusterTest";
OClass oclass = schema.createClass(className);
oclass.createProperty("key", OType.STRING);
oclass.createProperty("value", OType.INTEGER);
oclass.createIndex(className + "index1", OClass.INDEX_TYPE.NOTUNIQUE, "key");
database.newInstance(className).field("key", "a").field("value", 1).save();
int clId = database.addCluster(className + "secondCluster");
oclass.addClusterId(clId);
database.newInstance(className).field("key", "a").field("value", 2).save(className + "secondCluster");
// when
database.command(new OCommandSQL("rebuild index " + className + "index1")).execute();
assertEquals(database.query(new OSQLSynchQuery<Object>("select from " + className + " where key = 'a'")).size(), 2);
}
use of com.orientechnologies.orient.core.sql.OCommandSQL in project orientdb by orientechnologies.
the class LinkListIndexTest method testIndexCollectionUpdateInTx.
public void testIndexCollectionUpdateInTx() throws Exception {
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("LinkListIndexTestClass");
document.field("linkCollection", new ArrayList<ORID>(Arrays.asList(docOne.getIdentity(), docTwo.getIdentity())));
document.save();
try {
database.begin();
document.field("linkCollection", new ArrayList<ORID>(Arrays.asList(docOne.getIdentity(), docThree.getIdentity())));
document.save();
database.commit();
} catch (Exception e) {
database.rollback();
throw e;
}
List<ODocument> result = database.command(new OCommandSQL("select key, rid from index:linkCollectionIndex")).execute();
Assert.assertNotNull(result);
Assert.assertEquals(result.size(), 2);
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(docThree.getIdentity())) {
Assert.fail("Unknown key found: " + d.field("key"));
}
}
}
use of com.orientechnologies.orient.core.sql.OCommandSQL in project orientdb by orientechnologies.
the class LinkListIndexTest method testIndexCollectionUpdateRemoveItemInTxRollback.
public void testIndexCollectionUpdateRemoveItemInTxRollback() throws Exception {
final ODocument docOne = new ODocument();
docOne.save();
final ODocument docTwo = new ODocument();
docTwo.save();
final ODocument document = new ODocument("LinkListIndexTestClass");
document.field("linkCollection", new ArrayList<ORID>(Arrays.asList(docOne.getIdentity(), docTwo.getIdentity())));
document.save();
database.begin();
ODocument loadedDocument = database.load(document.getIdentity());
loadedDocument.<List>field("linkCollection").remove(docTwo.getIdentity());
loadedDocument.save();
database.rollback();
List<ODocument> result = database.command(new OCommandSQL("select key, rid from index:linkCollectionIndex")).execute();
Assert.assertNotNull(result);
Assert.assertEquals(result.size(), 2);
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())) {
Assert.fail("Unknown key found: " + d.field("key"));
}
}
}
Aggregations