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