use of com.orientechnologies.orient.core.sql.OCommandSQL in project orientdb by orientechnologies.
the class CRUDObjectInheritanceTest method create.
@Test
public void create() {
database.getEntityManager().registerEntityClasses("com.orientechnologies.orient.test.domain.business");
database.command(new OCommandSQL("delete from Company")).execute();
startRecordNumber = database.countClass("Company");
Company company;
for (long i = startRecordNumber; i < startRecordNumber + TOT_RECORDS; ++i) {
company = database.newInstance(Company.class, (int) i, "Microsoft" + i);
company.setEmployees((int) (100000 + i));
company.getAddresses().add(new Address("Headquarter", redmond, "WA 98073-9717"));
database.save(company);
}
}
use of com.orientechnologies.orient.core.sql.OCommandSQL in project orientdb by orientechnologies.
the class AutoShardingTest method testQuery.
@Test
public void testQuery() {
create();
for (int i = 0; i < ITERATIONS; ++i) {
final int selectedClusterId = clusterIds[((int) (Math.abs(hashFunction.hashCode(i)) % clusterIds.length))];
Iterable<ODocument> resultSet = database.command(new OCommandSQL("select from AutoShardingTest where id = ?")).execute(i);
Assert.assertTrue(resultSet.iterator().hasNext());
final ODocument sqlRecord = resultSet.iterator().next();
Assert.assertEquals(sqlRecord.getIdentity().getClusterId(), selectedClusterId);
}
}
use of com.orientechnologies.orient.core.sql.OCommandSQL in project orientdb by orientechnologies.
the class AutoShardingTest method create.
private void create() {
for (int i = 0; i < ITERATIONS; ++i) {
final int selectedClusterId = clusterIds[((int) (Math.abs(hashFunction.hashCode(i)) % clusterIds.length))];
ODocument sqlRecord = database.command(new OCommandSQL("insert into AutoShardingTest (id) values (" + i + ")")).execute();
Assert.assertEquals(sqlRecord.getIdentity().getClusterId(), selectedClusterId);
ODocument apiRecord = new ODocument("AutoShardingTest").field("id", i).save();
Assert.assertEquals(apiRecord.getIdentity().getClusterId(), selectedClusterId);
}
// TEST ALL CLUSTER HAVE RECORDS
for (int clusterId : cls.getClusterIds()) {
Assert.assertTrue(database.countClusterElements(clusterId) > 0);
}
}
use of com.orientechnologies.orient.core.sql.OCommandSQL in project orientdb by orientechnologies.
the class BetweenConversionTest method testBetweenLeftIncludedReverseOrderIndex.
public void testBetweenLeftIncludedReverseOrderIndex() {
final String query = "select from BetweenConversionTest where ai < 3 and ai >= 1";
final List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>(query));
Assert.assertEquals(result.size(), 2);
List<Integer> values = new ArrayList<Integer>(Arrays.asList(1, 2));
for (ODocument document : result) {
Assert.assertTrue(values.remove((Integer) document.field("ai")));
}
Assert.assertTrue(values.isEmpty());
ODocument explain = database.command(new OCommandSQL("explain " + query)).execute();
Assert.assertEquals(explain.field("rangeQueryConvertedInBetween"), 1);
Assert.assertTrue(((Set<String>) explain.field("involvedIndexes")).contains("BetweenConversionTestIndex"));
}
use of com.orientechnologies.orient.core.sql.OCommandSQL in project orientdb by orientechnologies.
the class BetweenConversionTest method testBetweenLeftIncluded.
public void testBetweenLeftIncluded() {
final String query = "select from BetweenConversionTest where a >= 1 and a < 3";
final List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>(query));
Assert.assertEquals(result.size(), 2);
List<Integer> values = new ArrayList<Integer>(Arrays.asList(1, 2));
for (ODocument document : result) {
Assert.assertTrue(values.remove((Integer) document.field("a")));
}
Assert.assertTrue(values.isEmpty());
ODocument explain = database.command(new OCommandSQL("explain " + query)).execute();
Assert.assertEquals(explain.field("rangeQueryConvertedInBetween"), 1);
}
Aggregations