use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.
the class JSONTest method testNestedLinkCreationFieldTypes.
public void testNestedLinkCreationFieldTypes() {
ODocument jaimeDoc = new ODocument("NestedLinkCreationFieldTypes");
jaimeDoc.field("name", "jaime");
jaimeDoc.save();
// The link between jaime and cersei is saved properly - the #2263 test case
ODocument cerseiDoc = new ODocument("NestedLinkCreationFieldTypes");
cerseiDoc.fromJSON("{\"@type\":\"d\",\"@fieldTypes\":\"valonqar=x\",\"name\":\"cersei\",\"valonqar\":" + jaimeDoc.getIdentity() + "}");
cerseiDoc.save();
// The link between jamie and tyrion is not saved properly
ODocument tyrionDoc = new ODocument("NestedLinkCreationFieldTypes");
tyrionDoc.fromJSON("{\"@type\":\"d\",\"name\":\"tyrion\",\"emergency_contact\":{\"@type\":\"d\", \"@fieldTypes\":\"contact=x\",\"relationship\":\"brother\",\"contact\":" + jaimeDoc.getIdentity() + "}}");
tyrionDoc.save();
final Map<ORID, ODocument> contentMap = new HashMap<ORID, ODocument>();
ODocument jaime = new ODocument("NestedLinkCreationFieldTypes");
jaime.field("name", "jaime");
contentMap.put(jaimeDoc.getIdentity(), jaime);
ODocument cersei = new ODocument("NestedLinkCreationFieldTypes");
cersei.field("name", "cersei");
cersei.field("valonqar", jaimeDoc.getIdentity());
contentMap.put(cerseiDoc.getIdentity(), cersei);
ODocument tyrion = new ODocument("NestedLinkCreationFieldTypes");
tyrion.field("name", "tyrion");
ODocument embeddedDoc = new ODocument();
embeddedDoc.field("relationship", "brother");
embeddedDoc.field("contact", jaimeDoc.getIdentity());
tyrion.field("emergency_contact", embeddedDoc);
contentMap.put(tyrionDoc.getIdentity(), tyrion);
final Map<ORID, List<ORID>> traverseMap = new HashMap<ORID, List<ORID>>();
List<ORID> jaimeTraverse = new ArrayList<ORID>();
jaimeTraverse.add(jaimeDoc.getIdentity());
traverseMap.put(jaimeDoc.getIdentity(), jaimeTraverse);
List<ORID> cerseiTraverse = new ArrayList<ORID>();
cerseiTraverse.add(cerseiDoc.getIdentity());
cerseiTraverse.add(jaimeDoc.getIdentity());
traverseMap.put(cerseiDoc.getIdentity(), cerseiTraverse);
List<ORID> tyrionTraverse = new ArrayList<ORID>();
tyrionTraverse.add(tyrionDoc.getIdentity());
tyrionTraverse.add(jaimeDoc.getIdentity());
traverseMap.put(tyrionDoc.getIdentity(), tyrionTraverse);
for (ODocument o : database.browseClass("NestedLinkCreationFieldTypes")) {
ODocument content = contentMap.get(o.getIdentity());
Assert.assertTrue(content.hasSameContentOf(o));
List<ORID> traverse = traverseMap.remove(o.getIdentity());
for (OIdentifiable id : new OSQLSynchQuery<ODocument>("traverse * from " + o.getIdentity().toString())) {
Assert.assertTrue(traverse.remove(id.getIdentity()));
}
Assert.assertTrue(traverse.isEmpty());
}
Assert.assertTrue(traverseMap.isEmpty());
}
use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.
the class OSQLFunctionConvertTest method testSQLConversions.
@Test
public void testSQLConversions() {
ODatabaseDocument db = new ODatabaseDocumentTx("memory:testSQLConvert");
try {
db.create();
db.command(new OCommandSQL("create class TestConversion")).execute();
db.command(new OCommandSQL("insert into TestConversion set string = 'Jay', date = sysdate(), number = 33")).execute();
ODocument doc = (ODocument) db.query(new OSQLSynchQuery<ODocument>("select from TestConversion limit 1")).get(0);
db.command(new OCommandSQL("update TestConversion set selfrid = 'foo" + doc.getIdentity() + "'")).execute();
List<ODocument> results = db.query(new OSQLSynchQuery<ODocument>("select string.asString() as convert from TestConversion"));
assertNotNull(results);
assertEquals(results.size(), 1);
assertTrue(results.get(0).field("convert") instanceof String);
results = db.query(new OSQLSynchQuery<ODocument>("select number.asDate() as convert from TestConversion"));
assertNotNull(results);
assertEquals(results.size(), 1);
assertTrue(results.get(0).field("convert") instanceof Date);
results = db.query(new OSQLSynchQuery<ODocument>("select number.asDateTime() as convert from TestConversion"));
assertNotNull(results);
assertEquals(results.size(), 1);
assertTrue(results.get(0).field("convert") instanceof Date);
results = db.query(new OSQLSynchQuery<ODocument>("select number.asInteger() as convert from TestConversion"));
assertNotNull(results);
assertEquals(results.size(), 1);
assertTrue(results.get(0).field("convert") instanceof Integer);
results = db.query(new OSQLSynchQuery<ODocument>("select number.asLong() as convert from TestConversion"));
assertNotNull(results);
assertEquals(results.size(), 1);
assertTrue(results.get(0).field("convert") instanceof Long);
results = db.query(new OSQLSynchQuery<ODocument>("select number.asFloat() as convert from TestConversion"));
assertNotNull(results);
assertEquals(results.size(), 1);
assertTrue(results.get(0).field("convert") instanceof Float);
results = db.query(new OSQLSynchQuery<ODocument>("select number.asDecimal() as convert from TestConversion"));
assertNotNull(results);
assertEquals(results.size(), 1);
assertTrue(results.get(0).field("convert") instanceof BigDecimal);
results = db.query(new OSQLSynchQuery<ODocument>("select number.convert('LONG') as convert from TestConversion"));
assertNotNull(results);
assertEquals(results.size(), 1);
assertTrue(results.get(0).field("convert") instanceof Long);
results = db.query(new OSQLSynchQuery<ODocument>("select number.convert('SHORT') as convert from TestConversion"));
assertNotNull(results);
assertEquals(results.size(), 1);
assertTrue(results.get(0).field("convert") instanceof Short);
results = db.query(new OSQLSynchQuery<ODocument>("select number.convert('DOUBLE') as convert from TestConversion"));
assertNotNull(results);
assertEquals(results.size(), 1);
assertTrue(results.get(0).field("convert") instanceof Double);
results = db.query(new OSQLSynchQuery<ODocument>("select selfrid.substring(3).convert('LINK').string as convert from TestConversion"));
assertNotNull(results);
assertEquals(results.size(), 1);
assertEquals(results.get(0).field("convert"), "Jay");
} finally {
db.drop();
}
}
use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.
the class OCommandExecutorSQLSelectTest method testLimitOrdered.
@Test
public void testLimitOrdered() {
OSQLSynchQuery sql = new OSQLSynchQuery("SELECT from alphabet ORDER BY letter LIMIT 9");
List<ODocument> results = db.query(sql);
assertEquals(9, results.size());
}
use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.
the class OCommandExecutorSQLSelectTest method testBacktick.
@Test
public void testBacktick() {
OSQLSynchQuery sql = new OSQLSynchQuery("SELECT `foo-bar` as r from TestBacktick");
List<ODocument> results = db.query(sql);
assertEquals(results.size(), 1);
ODocument doc = results.get(0);
assertEquals(doc.field("r"), 10);
}
use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.
the class OCommandExecutorSQLSelectTest method testMatchesWithQuotes2.
@Test
public void testMatchesWithQuotes2() {
// issue #5229
OSQLSynchQuery sql = new OSQLSynchQuery("SELECT FROM matchesstuff WHERE (name matches '\\\\Qadm\\\\E.*' and not ( name matches '(.*)foo(.*)' ) )");
List<ODocument> results = db.query(sql);
assertEquals(results.size(), 1);
}
Aggregations