Search in sources :

Example 76 with OSQLSynchQuery

use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.

the class PolymorphicQueryTest method testSubclassesIndexes.

@Test
public void testSubclassesIndexes() throws Exception {
    database.begin();
    OProfiler profiler = Orient.instance().getProfiler();
    long indexUsage = profiler.getCounter("db.demo.query.indexUsed");
    long indexUsageReverted = profiler.getCounter("db.demo.query.indexUseAttemptedAndReverted");
    if (indexUsage < 0) {
        indexUsage = 0;
    }
    if (indexUsageReverted < 0) {
        indexUsageReverted = 0;
    }
    profiler.startRecording();
    for (int i = 0; i < 10000; i++) {
        final ODocument doc1 = new ODocument("IndexInSubclassesTestChild1");
        doc1.field("name", "name" + i);
        doc1.save();
        final ODocument doc2 = new ODocument("IndexInSubclassesTestChild2");
        doc2.field("name", "name" + i);
        doc2.save();
        if (i % 100 == 0) {
            database.commit();
        }
    }
    database.commit();
    List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>("select from IndexInSubclassesTestBase where name > 'name9995' and name < 'name9999' order by name ASC"));
    Assert.assertEquals(result.size(), 6);
    String lastName = result.get(0).field("name");
    for (int i = 1; i < result.size(); i++) {
        ODocument current = result.get(i);
        String currentName = current.field("name");
        Assert.assertTrue(lastName.compareTo(currentName) <= 0);
        lastName = currentName;
    }
    Assert.assertEquals(profiler.getCounter("db.demo.query.indexUsed"), indexUsage + 2);
    long reverted = profiler.getCounter("db.demo.query.indexUseAttemptedAndReverted");
    Assert.assertEquals(reverted < 0 ? 0 : reverted, indexUsageReverted);
    result = database.query(new OSQLSynchQuery<ODocument>("select from IndexInSubclassesTestBase where name > 'name9995' and name < 'name9999' order by name DESC"));
    Assert.assertEquals(result.size(), 6);
    lastName = result.get(0).field("name");
    for (int i = 1; i < result.size(); i++) {
        ODocument current = result.get(i);
        String currentName = current.field("name");
        Assert.assertTrue(lastName.compareTo(currentName) >= 0);
        lastName = currentName;
    }
    profiler.stopRecording();
}
Also used : OProfiler(com.orientechnologies.common.profiler.OProfiler) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 77 with OSQLSynchQuery

use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.

the class PreparedStatementTest method testNamedParamInArray.

@Test
public void testNamedParamInArray() {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("name", "foo1");
    Iterable<ODocument> result = database.command(new OSQLSynchQuery<ODocument>("select from PreparedStatementTest1 where name in [:name]")).execute(params);
    boolean found = false;
    for (ODocument doc : result) {
        found = true;
        Assert.assertEquals(doc.field("name"), "foo1");
    }
    Assert.assertTrue(found);
}
Also used : HashMap(java.util.HashMap) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 78 with OSQLSynchQuery

use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.

the class PreparedStatementTest method testUnnamedParamTargetDocument.

@Test
public void testUnnamedParamTargetDocument() {
    Iterable<ODocument> result = database.command(new OSQLSynchQuery<ODocument>("select from PreparedStatementTest1 limit 1")).execute();
    ODocument record = result.iterator().next();
    result = database.command(new OSQLSynchQuery<ODocument>("select from ?")).execute(record);
    boolean found = false;
    for (ODocument doc : result) {
        found = true;
        Assert.assertEquals(doc.getIdentity(), record.getIdentity());
        Assert.assertEquals(doc.field("name"), record.field("name"));
    }
    Assert.assertTrue(found);
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 79 with OSQLSynchQuery

use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.

the class PreparedStatementTest method testNamedParamFlat.

@Test
public void testNamedParamFlat() {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("name", "foo1");
    Iterable<ODocument> result = database.command(new OSQLSynchQuery<ODocument>("select from PreparedStatementTest1 where name = :name")).execute(params);
    boolean found = false;
    for (ODocument doc : result) {
        found = true;
        Assert.assertEquals(doc.field("name"), "foo1");
    }
    Assert.assertTrue(found);
}
Also used : HashMap(java.util.HashMap) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 80 with OSQLSynchQuery

use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.

the class PreparedStatementTest method testUnnamedParamTarget.

@Test
public void testUnnamedParamTarget() {
    Iterable<ODocument> result = database.command(new OSQLSynchQuery<ODocument>("select from ?")).execute("PreparedStatementTest1");
    Set<String> expected = new HashSet<String>();
    expected.add("foo1");
    expected.add("foo2");
    boolean found = false;
    for (ODocument doc : result) {
        found = true;
        Assert.assertTrue(expected.contains(doc.field("name")));
    }
    Assert.assertTrue(found);
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)506 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)426 Test (org.testng.annotations.Test)282 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)78 Test (org.junit.Test)60 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)57 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)47 ORID (com.orientechnologies.orient.core.id.ORID)34 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)31 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)22 List (java.util.List)21 HashMap (java.util.HashMap)20 ORecordId (com.orientechnologies.orient.core.id.ORecordId)19 Profile (com.orientechnologies.orient.test.domain.whiz.Profile)19 DatabaseAbstractTest (com.orientechnologies.DatabaseAbstractTest)16 Collection (java.util.Collection)15 OrientTest (com.orientechnologies.orient.test.database.base.OrientTest)13 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)13 Set (java.util.Set)12 OCommandScript (com.orientechnologies.orient.core.command.script.OCommandScript)11