Search in sources :

Example 71 with OSQLSynchQuery

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

the class CollateTest method testCompositeIndexQueryCollateWasChanged.

public void testCompositeIndexQueryCollateWasChanged() {
    final OSchema schema = database.getMetadata().getSchema();
    OClass clazz = schema.createClass("CompositeIndexQueryCollateWasChangedTest");
    OProperty csp = clazz.createProperty("csp", OType.STRING);
    csp.setCollate(ODefaultCollate.NAME);
    clazz.createProperty("cip", OType.STRING);
    clazz.createIndex("collateCompositeIndexCollateWasChanged", OClass.INDEX_TYPE.NOTUNIQUE, "csp", "cip");
    for (int i = 0; i < 10; i++) {
        ODocument document = new ODocument("CompositeIndexQueryCollateWasChangedTest");
        if (i % 2 == 0) {
            document.field("csp", "VAL");
            document.field("cip", "VAL");
        } else {
            document.field("csp", "val");
            document.field("cip", "val");
        }
        document.save();
    }
    String query = "select from CompositeIndexQueryCollateWasChangedTest where csp = 'VAL'";
    List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>(query));
    Assert.assertEquals(result.size(), 5);
    for (ODocument document : result) Assert.assertEquals(document.field("csp"), "VAL");
    ODocument explain = database.command(new OCommandSQL("explain " + query)).execute();
    Assert.assertTrue(explain.<Set<String>>field("involvedIndexes").contains("collateCompositeIndexCollateWasChanged"));
    csp = clazz.getProperty("csp");
    csp.setCollate(OCaseInsensitiveCollate.NAME);
    query = "select from CompositeIndexQueryCollateWasChangedTest where csp = 'VaL'";
    result = database.query(new OSQLSynchQuery<ODocument>(query));
    Assert.assertEquals(result.size(), 10);
    for (ODocument document : result) Assert.assertEquals(document.<String>field("csp").toUpperCase(), "VAL");
    explain = database.command(new OCommandSQL("explain " + query)).execute();
    Assert.assertTrue(explain.<Set<String>>field("involvedIndexes").contains("collateCompositeIndexCollateWasChanged"));
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) Set(java.util.Set) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 72 with OSQLSynchQuery

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

the class CRUDObjectPhysicalTestSchemaFull method queryWithObjectAsParameter.

@Test(dependsOnMethods = "createLinked")
public void queryWithObjectAsParameter() {
    database.getMetadata().getSchema().reload();
    final OSQLSynchQuery<Profile> query = new OSQLSynchQuery<Profile>("select from Profile where name = :name and surname = :surname");
    HashMap<String, String> params = new HashMap<String, String>();
    params.put("name", "Barack");
    params.put("surname", "Obama");
    List<Profile> result = database.query(query, params);
    Assert.assertTrue(result.size() != 0);
    Profile obama = result.get(0);
    result = database.query(new OSQLSynchQuery<Profile>("select from Profile where followings contains ( @Rid = :who )"), obama);
    Assert.assertTrue(result.size() != 0);
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) Profile(com.orientechnologies.orient.test.domain.whiz.Profile) Test(org.testng.annotations.Test)

Example 73 with OSQLSynchQuery

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

the class ObjectTreeTest method testQueryMultiCircular.

@SuppressWarnings("unchecked")
@Test(dependsOnMethods = "testSaveMultiCircular")
public void testQueryMultiCircular() {
    Assert.assertEquals(database.countClass("Profile"), startRecordNumber + 3);
    List<ODocument> result = database.getUnderlying().command(new OSQLSynchQuery<ODocument>("select * from Profile where name = 'Barack' and surname = 'Obama'")).execute();
    Assert.assertEquals(result.size(), 1);
    for (ODocument profile : result) {
        System.out.println(profile.field("name") + " " + profile.field("surname"));
        final Collection<ODocument> followers = profile.field("followers");
        if (followers != null) {
            for (ODocument follower : followers) {
                Assert.assertTrue(((Collection<ODocument>) follower.field("followings")).contains(profile));
                System.out.println("- follower: " + follower.field("name") + " " + follower.field("surname") + " (parent: " + follower.field("name") + " " + follower.field("surname") + ")");
            }
        }
    }
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 74 with OSQLSynchQuery

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

the class RestrictedTest method testUpdateRestricted.

@Test(dependsOnMethods = "testTruncateUnderlyingCluster")
public void testUpdateRestricted() {
    database.open("admin", "admin");
    database.getMetadata().getSchema().createClass("TestUpdateRestricted", database.getMetadata().getSchema().getClass("ORestricted"));
    adminRecord = new ODocument("TestUpdateRestricted").field("user", "admin").save();
    database.close();
    database.open("writer", "writer");
    List<ODocument> result = database.query(new OSQLSynchQuery<Object>("select from TestUpdateRestricted"));
    Assert.assertTrue(result.isEmpty());
    database.close();
    database.open("admin", "admin");
    database.command(new OCommandSQL("update TestUpdateRestricted content {\"data\":\"My Test\"}")).execute();
    result = database.query(new OSQLSynchQuery<ODocument>("select from TestUpdateRestricted"));
    Assert.assertEquals(result.size(), 1);
    final ODocument doc = result.get(0);
    Assert.assertEquals(doc.field("data"), "My Test");
    doc.field("user", "admin");
    doc.save();
    database.close();
    database.open("writer", "writer");
    result = database.query(new OSQLSynchQuery<Object>("select from TestUpdateRestricted"));
    Assert.assertTrue(result.isEmpty());
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 75 with OSQLSynchQuery

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

the class SQLDeleteEdgeTest method testFromInString.

public void testFromInString() {
    database.command(new OCommandSQL("CREATE CLASS FromInStringE extends E")).execute();
    database.command(new OCommandSQL("CREATE CLASS FromInStringV extends V")).execute();
    OIdentifiable v1 = database.command(new OCommandSQL("create vertex FromInStringV set name = ' from '")).execute();
    OIdentifiable v2 = database.command(new OCommandSQL("create vertex FromInStringV set name = ' FROM '")).execute();
    OIdentifiable v3 = database.command(new OCommandSQL("create vertex FromInStringV set name = ' TO '")).execute();
    database.command(new OCommandSQL("create edge FromInStringE from " + v1.getIdentity() + " to " + v2.getIdentity())).execute();
    database.command(new OCommandSQL("create edge FromInStringE from " + v1.getIdentity() + " to " + v3.getIdentity())).execute();
    List<OIdentifiable> result = database.query(new OSQLSynchQuery<ODocument>("SELECT expand(out()[name = ' FROM ']) FROM FromInStringV"));
    Assert.assertEquals(result.size(), 1);
    result = database.query(new OSQLSynchQuery<ODocument>("SELECT expand(in()[name = ' from ']) FROM FromInStringV"));
    Assert.assertEquals(result.size(), 2);
    result = database.query(new OSQLSynchQuery<ODocument>("SELECT expand(out()[name = ' TO ']) FROM FromInStringV"));
    Assert.assertEquals(result.size(), 1);
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

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