Search in sources :

Example 61 with OCommandSQL

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);
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) Company(com.orientechnologies.orient.test.domain.business.Company) Address(com.orientechnologies.orient.test.domain.business.Address) Test(org.testng.annotations.Test)

Example 62 with OCommandSQL

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

Example 63 with OCommandSQL

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

Example 64 with OCommandSQL

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

Example 65 with OCommandSQL

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

Aggregations

OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)621 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)422 Test (org.junit.Test)97 Test (org.testng.annotations.Test)93 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)83 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)79 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)78 ORID (com.orientechnologies.orient.core.id.ORID)64 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)61 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)54 Set (java.util.Set)53 HashMap (java.util.HashMap)45 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)42 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)41 List (java.util.List)25 Before (org.junit.Before)24 OStorage (com.orientechnologies.orient.core.storage.OStorage)23 OrientGraphNoTx (com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)23 ORecordId (com.orientechnologies.orient.core.id.ORecordId)21 Vertex (com.tinkerpop.blueprints.Vertex)19