use of com.orientechnologies.orient.core.record.impl.ODocument in project orientdb by orientechnologies.
the class OCommandExecutorSQLCreateEdgeTest method testSubqueryParametersBinding.
@Test
public void testSubqueryParametersBinding() throws Exception {
final HashMap<String, Object> params = new HashMap<String, Object>();
params.put("foo", "bar");
params.put("fromId", 1);
params.put("toId", 2);
db.command(new OCommandSQL("CREATE EDGE link from (select from Owner where id = :fromId) TO (select from Owner where id = :toId) SET foo = :foo")).execute(params);
final List<ODocument> list = db.query(new OSQLSynchQuery<Object>("SELECT FROM link"));
Assert.assertEquals(list.size(), 1);
final ODocument edge = list.get(0);
Assert.assertEquals(edge.field("foo"), "bar");
Assert.assertEquals(edge.field("out"), owner1.getIdentity());
Assert.assertEquals(edge.field("in"), owner2.getIdentity());
}
use of com.orientechnologies.orient.core.record.impl.ODocument in project orientdb by orientechnologies.
the class OCommandExecutorSQLDeleteEdgeTest method testDeleteEdgeWithVertexRid.
@Test
public void testDeleteEdgeWithVertexRid() throws Exception {
List<ODocument> vertexes = db.command(new OCommandSQL("select from v limit 1")).execute();
try {
final int res = (Integer) db.command(new OCommandSQL("delete edge [" + vertexes.get(0).getIdentity() + "]")).execute();
Assert.fail("Error on deleting an edge with a rid of a vertex");
} catch (Exception e) {
// OK
}
}
use of com.orientechnologies.orient.core.record.impl.ODocument in project orientdb by orientechnologies.
the class OCommandExecutorSQLDeleteVertexTest method testDeleteVertexWithEdgeRid.
@Test
public void testDeleteVertexWithEdgeRid() throws Exception {
List<ODocument> edges = db.command(new OCommandSQL("select from e limit 1")).execute();
try {
final int res = (Integer) db.command(new OCommandSQL("delete vertex [" + edges.get(0).getIdentity() + "]")).execute();
Assert.fail("Error on deleting a vertex with a rid of an edge");
} catch (Exception e) {
// OK
}
}
use of com.orientechnologies.orient.core.record.impl.ODocument in project orientdb by orientechnologies.
the class LuceneTransactionQueryTest method txRemoveTest.
@Test
public void txRemoveTest() {
db.begin();
ODocument doc = new ODocument("c1");
doc.field("p1", "abc");
OIndex<?> index = db.getMetadata().getIndexManager().getIndex("C1.p1");
db.save(doc);
String query = "select from C1 where p1 lucene \"abc\" ";
List<ODocument> vertices = ODatabaseRecordThreadLocal.INSTANCE.get().command(new OSQLSynchQuery<ODocument>(query)).execute();
Assert.assertEquals(vertices.size(), 1);
Assert.assertEquals(index.getSize(), 1);
db.commit();
query = "select from C1 where p1 lucene \"abc\" ";
vertices = db.command(new OSQLSynchQuery<ODocument>(query)).execute();
Assert.assertEquals(vertices.size(), 1);
Assert.assertEquals(index.getSize(), 1);
db.begin();
doc = new ODocument("c1");
doc.field("p1", "abc");
db.delete(vertices.get(0));
query = "select from C1 where p1 lucene \"abc\" ";
vertices = db.command(new OSQLSynchQuery<ODocument>(query)).execute();
Collection coll = (Collection) index.get("abc");
Assert.assertEquals(vertices.size(), 0);
Assert.assertEquals(coll.size(), 0);
Iterator iterator = coll.iterator();
int i = 0;
while (iterator.hasNext()) {
iterator.next();
i++;
}
Assert.assertEquals(i, 0);
Assert.assertEquals(index.getSize(), 0);
db.rollback();
query = "select from C1 where p1 lucene \"abc\" ";
vertices = db.command(new OSQLSynchQuery<ODocument>(query)).execute();
Assert.assertEquals(vertices.size(), 1);
Assert.assertEquals(index.getSize(), 1);
}
use of com.orientechnologies.orient.core.record.impl.ODocument in project orientdb by orientechnologies.
the class LuceneVsLuceneTest method testLuceneVsLucene.
@Test
public void testLuceneVsLucene() throws IOException, ParseException {
for (ODocument oDocument : db.browseClass("Song")) {
String title = oDocument.field("title");
if (title != null) {
Document d = new Document();
d.add(new TextField("title", title, Field.Store.YES));
d.add(new TextField("Song.title", title, Field.Store.YES));
indexWriter.addDocument(d);
}
}
indexWriter.commit();
indexWriter.close();
IndexReader reader = DirectoryReader.open(getDirectory());
assertThat(reader.numDocs()).isEqualTo(Long.valueOf(db.countClass("Song")).intValue());
IndexSearcher searcher = new IndexSearcher(reader);
Query query = new MultiFieldQueryParser(new String[] { "title" }, analyzer).parse("down the");
final TopDocs docs = searcher.search(query, Integer.MAX_VALUE);
ScoreDoc[] hits = docs.scoreDocs;
List<ODocument> oDocs = db.query(new OSQLSynchQuery<ODocument>("select *,$score from Song where title LUCENE \"down the\""));
Assert.assertEquals(oDocs.size(), hits.length);
int i = 0;
for (ScoreDoc hit : hits) {
Assert.assertEquals(oDocs.get(i).field("$score"), hit.score);
i++;
}
reader.close();
}
Aggregations