Search in sources :

Example 46 with ODatabaseDocumentTx

use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.

the class LuceneMiscTest method testDoubleLucene.

// TODO Re-enable when removed check syntax on ODB
public void testDoubleLucene() {
    OrientGraphNoTx graph = new OrientGraphNoTx("memory:doubleLucene");
    try {
        ODatabaseDocumentTx db = graph.getRawGraph();
        db.command(new OCommandSQL("create class Test extends V")).execute();
        db.command(new OCommandSQL("create property Test.attr1 string")).execute();
        db.command(new OCommandSQL("create index Test.attr1 on Test (attr1) fulltext engine lucene")).execute();
        db.command(new OCommandSQL("create property Test.attr2 string")).execute();
        db.command(new OCommandSQL("create index Test.attr2 on Test (attr2) fulltext engine lucene")).execute();
        db.command(new OCommandSQL("insert into Test set attr1='foo', attr2='bar'")).execute();
        db.command(new OCommandSQL("insert into Test set attr1='bar', attr2='foo'")).execute();
        List<ODocument> results = db.command(new OCommandSQL("select from Test where attr1 lucene 'foo*' OR attr2 lucene 'foo*'")).execute();
        Assert.assertEquals(results.size(), 2);
        results = db.command(new OCommandSQL("select from Test where attr1 lucene 'bar*' OR attr2 lucene 'bar*'")).execute();
        Assert.assertEquals(results.size(), 2);
        results = db.command(new OCommandSQL("select from Test where attr1 lucene 'foo*' AND attr2 lucene 'bar*'")).execute();
        Assert.assertEquals(results.size(), 1);
        results = db.command(new OCommandSQL("select from Test where attr1 lucene 'bar*' AND attr2 lucene 'foo*'")).execute();
        Assert.assertEquals(results.size(), 1);
    } finally {
        graph.drop();
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 47 with ODatabaseDocumentTx

use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.

the class LuceneMiscTest method testNamedParams.

@Test
public void testNamedParams() {
    OrientGraphNoTx graph = new OrientGraphNoTx("memory:doubleLucene");
    try {
        ODatabaseDocumentTx db = graph.getRawGraph();
        db.command(new OCommandSQL("create class Test extends V")).execute();
        db.command(new OCommandSQL("create property Test.attr1 string")).execute();
        db.command(new OCommandSQL("create index Test.attr1 on Test (attr1) fulltext engine lucene")).execute();
        db.command(new OCommandSQL("insert into Test set attr1='foo', attr2='bar'")).execute();
        OSQLSynchQuery query = new OSQLSynchQuery("select from Test where attr1 lucene :name");
        Map params = new HashMap();
        params.put("name", "FOO or");
        List results = db.command(query).execute(params);
        Assert.assertEquals(results.size(), 1);
    } finally {
        graph.drop();
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) HashMap(java.util.HashMap) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 48 with ODatabaseDocumentTx

use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.

the class LuceneNullTest method testNullChangeToNotNullWithLists.

@Test
public void testNullChangeToNotNullWithLists() {
    OrientGraphNoTx graph = new OrientGraphNoTx("memory:testNullChangeToNotNull");
    try {
        ODatabaseDocumentTx db = graph.getRawGraph();
        db.command(new OCommandSQL("create class Test extends V")).execute();
        db.command(new OCommandSQL("create property Test.names EMBEDDEDLIST STRING")).execute();
        db.command(new OCommandSQL("create index Test.names on Test (names) fulltext engine lucene")).execute();
        db.begin();
        ODocument doc = new ODocument("Test");
        db.save(doc);
        db.commit();
        db.begin();
        doc.field("names", new String[] { "foo" });
        db.save(doc);
        db.commit();
        OIndex<?> index = db.getMetadata().getIndexManager().getIndex("Test.names");
        Assert.assertEquals(index.getSize(), 1);
    } finally {
        graph.drop();
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 49 with ODatabaseDocumentTx

use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.

the class LuceneTransactionEmbeddedQueryTest method txUpdateTestComplex.

@Test
public void txUpdateTestComplex() {
    ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:updateTxTest");
    db.create();
    createSchema(db);
    try {
        OIndex<?> index = db.getMetadata().getIndexManager().getIndex("C1.p1");
        Assert.assertEquals(index.getSize(), 0);
        db.begin();
        ODocument doc = new ODocument("c1");
        doc.field("p1", new String[] { "abc" });
        ODocument doc1 = new ODocument("c1");
        doc1.field("p1", new String[] { "abc" });
        db.save(doc1);
        db.save(doc);
        db.commit();
        db.begin();
        doc.field("p1", new String[] { "removed" });
        db.save(doc);
        String query = "select from C1 where p1 lucene \"abc\"";
        List<ODocument> vertices = db.command(new OSQLSynchQuery<ODocument>(query)).execute();
        Collection coll = (Collection) index.get("abc");
        Assert.assertEquals(vertices.size(), 1);
        Assert.assertEquals(coll.size(), 1);
        Iterator iterator = coll.iterator();
        int i = 0;
        ORecordId rid = null;
        while (iterator.hasNext()) {
            rid = (ORecordId) iterator.next();
            i++;
        }
        Assert.assertEquals(i, 1);
        Assert.assertEquals(doc1.getIdentity().toString(), rid.getIdentity().toString());
        Assert.assertEquals(index.getSize(), 2);
        query = "select from C1 where p1 lucene \"removed\" ";
        vertices = db.command(new OSQLSynchQuery<ODocument>(query)).execute();
        coll = (Collection) index.get("removed");
        Assert.assertEquals(vertices.size(), 1);
        Assert.assertEquals(coll.size(), 1);
        db.rollback();
        query = "select from C1 where p1 lucene \"abc\" ";
        vertices = db.command(new OSQLSynchQuery<ODocument>(query)).execute();
        Assert.assertEquals(vertices.size(), 2);
        Assert.assertEquals(index.getSize(), 2);
    } finally {
        db.drop();
    }
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) Iterator(java.util.Iterator) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) Collection(java.util.Collection) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 50 with ODatabaseDocumentTx

use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.

the class LuceneTransactionEmbeddedQueryTest method txRemoveTest.

@Test
public void txRemoveTest() {
    ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:updateTxTest");
    db.create();
    createSchema(db);
    try {
        db.begin();
        ODocument doc = new ODocument("c1");
        doc.field("p1", new String[] { "abc" });
        OIndex<?> index = db.getMetadata().getIndexManager().getIndex("C1.p1");
        db.save(doc);
        String query = "select from C1 where p1 lucene \"abc\" ";
        List<ODocument> vertices = db.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();
        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);
    } finally {
        db.drop();
    }
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) Iterator(java.util.Iterator) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) Collection(java.util.Collection) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Aggregations

ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)590 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)257 Test (org.testng.annotations.Test)182 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)120 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)81 Test (org.junit.Test)79 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)61 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)47 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)46 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)41 ORID (com.orientechnologies.orient.core.id.ORID)39 ORecordId (com.orientechnologies.orient.core.id.ORecordId)34 Before (org.junit.Before)34 File (java.io.File)33 OProperty (com.orientechnologies.orient.core.metadata.schema.OProperty)25 ArrayList (java.util.ArrayList)25 BeforeClass (org.testng.annotations.BeforeClass)23 BeforeMethod (org.testng.annotations.BeforeMethod)23 OStorage (com.orientechnologies.orient.core.storage.OStorage)21 List (java.util.List)20