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();
}
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);
}
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);
}
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);
}
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);
}
Aggregations