Search in sources :

Example 86 with ODocument

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());
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) HashMap(java.util.HashMap) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 87 with ODocument

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
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 88 with ODocument

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
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 89 with ODocument

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);
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) Iterator(java.util.Iterator) Collection(java.util.Collection) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 90 with ODocument

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();
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) Query(org.apache.lucene.search.Query) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) MultiFieldQueryParser(org.apache.lucene.queryparser.classic.MultiFieldQueryParser) Document(org.apache.lucene.document.Document) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) ScoreDoc(org.apache.lucene.search.ScoreDoc) TopDocs(org.apache.lucene.search.TopDocs) IndexReader(org.apache.lucene.index.IndexReader) TextField(org.apache.lucene.document.TextField) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Aggregations

ODocument (com.orientechnologies.orient.core.record.impl.ODocument)2200 Test (org.testng.annotations.Test)651 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)426 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)422 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)277 Test (org.junit.Test)267 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)257 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)244 ORID (com.orientechnologies.orient.core.id.ORID)196 ORecordId (com.orientechnologies.orient.core.id.ORecordId)139 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)122 ArrayList (java.util.ArrayList)118 ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)103 HashMap (java.util.HashMap)103 HashSet (java.util.HashSet)96 ORecord (com.orientechnologies.orient.core.record.ORecord)80 Set (java.util.Set)76 OETLBaseTest (com.orientechnologies.orient.etl.OETLBaseTest)75 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)68 Collection (java.util.Collection)55