AssertUtil.assertEquals(getURL("readAssocWhere2.xml"), list, attributes);
query.setMaxCount(1000000);
Cursor cursor = query.openCursor();
try
{
int i = 0;
while ((instance = cursor.next()) != null)
{
assertSame(list.getInstance(i++), instance);
}
assertEquals(list.size(), i);
}
finally
{
cursor.close();
}
attributes = parse("(addresses)");
cursor = Query.createRead(getMetadata().getMetaclass("Contact"), attributes,
parse("(= classCode \"CON\")"), null, -1, 0, false, Query.SEC_NONE, m_context).openCursor();
try
{
cursor.next();
cursor.next();
instance = cursor.next();
assertEquals(2, ((InstanceList)instance.getValue("addresses")).size());
}
finally
{
cursor.close();
}
attributes = parse("(fullName)");
query = Query.createRead(getMetadata().getMetaclass("Contact"), attributes,
parse("(any (= (@ addresses city) \"Toronto\"))"),
parse("((firstName . #t)(lastName . #t)((@ addresses) . #t))"),
-1, 0, false, Query.SEC_NONE, m_context);
AssertUtil.assertEquals(getURL("readAny.xml"), query.read(), attributes);
query = Query.createRead(getMetadata().getMetaclass("Contact"), attributes,
parse("(any (= (@ businessAddress3 city) \"Toronto\"))"),
parse("((firstName . #t)(lastName . #t)((@ addresses) . #t))"),
-1, 0, false, Query.SEC_NONE, m_context);
AssertUtil.assertEquals(getURL("readAny2.xml"), query.read(), attributes);
query = Query.createRead(getMetadata().getMetaclass("Contact"), attributes,
parse("(any (= (@) ()))"), parse("((firstName . #t)(lastName . #t)((@ addresses) . #t))"),
-1, 0, false, Query.SEC_NONE, m_context);
assertEquals(0, query.read().size());
attributes = parse("(name typeCode)");
query = Query.createRead(getMetadata().getMetaclass("Principal"), attributes, null,
parse("((name . #t))"), -1, 0, false, Query.SEC_NONE, m_context);
AssertUtil.assertEquals(getURL("readPolymorphic.xml"), query.read(), attributes);
attributes = parse("(fullName)");
query = Query.createRead(getMetadata().getMetaclass("Contact"), attributes,
parse("(instance? (@) Patient)"),
parse("((firstName . #t)(lastName . #t)((@ addresses) . #t))"),
-1, 0, false, Query.SEC_NONE, m_context);
AssertUtil.assertEquals(getURL("readSubclass.xml"), query.read(), attributes);
query = Query.createRead(getMetadata().getMetaclass("Contact"), attributes,
parse("(and (instance? (@) Patient) (not (like? (@ lastName) \"[S]*\")))"),
parse("((firstName . #t)(lastName . #t)((@ addresses) . #t))"),
-1, 0, false, Query.SEC_NONE, m_context);
AssertUtil.assertEquals(getURL("readSubclass.xml"), query.read(), attributes);
query = Query.createRead(getMetadata().getMetaclass("Address"), null,
parse("(= typeEnum (oid \"address\" \"en\" \"Business\"))"),
parse("(((@) . #t))"), -1, 0, false, Query.SEC_NONE, m_context);
AssertUtil.assertEquals(getURL("readEnum.xml"), query.read(), null);
query = Query.createRead(getMetadata().getMetaclass("Address"), null,
parse("(= (@ typeEnum type) \"Business\")"),
parse("(((@) . #t))"), -1, 0, false, Query.SEC_NONE, m_context);
AssertUtil.assertEquals(getURL("readEnum.xml"), query.read(), null);
query = Query.createRead(getMetadata().getMetaclass("Address"), null,
parse("(and (= typeEnum (oid \"address\" \"en\" \"Business\")) (= (@ typeEnum type) \"Business\"))"),
parse("(((@) . #t))"), -1, 0, false, Query.SEC_NONE, m_context);
AssertUtil.assertEquals(getURL("readEnum.xml"), query.read(), null);
query = Query.createRead(getMetadata().getMetaclass("Address"), null,
parse("(and (= typeEnum (oid \"address\" \"en\" \"Business\")) (= (@ typeEnum type) \"1\"))"),
parse("(((@) . #t))"), -1, 0, false, Query.SEC_NONE, m_context);
assertEquals(0, query.read().getCount());
query = Query.createRead(getMetadata().getMetaclass("ExternalVisit"), null,
parse("(= patient (oid #z00000000000000000000000000000006))"),
parse("(((@) . #t))"), -1, 0, false, Query.SEC_NONE, m_context);
AssertUtil.assertEquals(getURL("readExternal.xml"), query.read(), null);
query = Query.createRead(getMetadata().getMetaclass("Patient"), parse("(externalVisits)"),
parse("(and (= firstName \"Sarah\") (= lastName \"Johnson\"))"),
null, -1, 0, false, Query.SEC_NONE, m_context);
assertEquals(3, ((InstanceList)query.read().getInstance(0).getValue("externalVisits")).size());
// Comparison of LOB values, class is not important as long as the attribute is LOB
Query.createRead(getMetadata().getMetaclass("SysRule"), parse("(name)"),
parse("(= action \"test\")"),
null, -1, 0, false, Query.SEC_NONE, m_context).read();
Query.createRead(getMetadata().getMetaclass("SysRule"), parse("(name)"),
parse("(not (= action \"test\"))"),
null, -1, 0, false, Query.SEC_NONE, m_context).read();
Query.createRead(getMetadata().getMetaclass("SysTimer"), parse("(period)"),
parse("(= data #z0)"),
null, -1, 0, false, Query.SEC_NONE, m_context).read();
Query.createRead(getMetadata().getMetaclass("SysTimer"), parse("(period)"),
parse("(not (= data #z0))"),
null, -1, 0, false, Query.SEC_NONE, m_context).read();
// Dynamic derived associations
attributes = parse("(contact)");
query = Query.createRead(getMetadata().getMetaclass("Address"), attributes,
parse("(!= (@ contact (instance? (@) Patient) birthdate) ())"),
parse("(((@) . #t))"), -1, 0, false, Query.SEC_NONE, m_context);
AssertUtil.assertEquals(getURL("readDynDerived.xml"), query.read(), attributes);
attributes = parse("(lastName)");
query = Query.createRead(getMetadata().getMetaclass("Contact"), attributes,
parse("(!= (@ (instance? (@) Patient) birthdate) ())"),
parse("(((@) . #t))"), -1, 0, false, Query.SEC_NONE, m_context);
AssertUtil.assertEquals(getURL("readDynTypeCast.xml"), query.read(), attributes);
list = Query.createRead(getMetadata().getMetaclass("Contact"), parse("(lastName)"),
parse("(!= (@ addresses (= (@ country) \"Canada\") contact (= (@ firstName) \"Joe\") addresses) ())"),
parse("(((@) . #t))"), -1, 0, false, Query.SEC_NONE, m_context).read();
assertEquals(1, list.size());
assertEquals("Joe", list.getInstance(0).getValue("firstName"));
query = Query.createRead(getMetadata().getMetaclass("Visit"), null,
parse("(= (@@ Address contact (instance? (@) Patient) visits) (oid #z00000000000000000000000000000008))"),
parse("(((@) . #t))"), -1, 0, false, Query.SEC_NONE, m_context);
AssertUtil.assertEquals(getURL("readDynReverse.xml"), query.read(), null);
// Calculated attributes
attributes = parse("(isTorontoBasedEmployee tax lastNameLengthPlus1 lastNameInitial)");
query = Query.createRead(getMetadata().getMetaclass("Contact"), attributes,
parse("(= classCode \"CON\")"),
parse("(((@) . #t))"), -1, 0, false, Query.SEC_NONE, m_context);
AssertUtil.assertEquals(getURL("readCalculated.xml"), query.read(), attributes);
attributes = parse("((businessAddress3 deletable))");
query = Query.createRead(getMetadata().getMetaclass("Contact"), attributes,
parse("(= classCode \"CON\")"),
parse("(((@) . #t))"), -1, 0, false, Query.SEC_NONE, m_context);
AssertUtil.assertEquals(getURL("readCalculatedSubq.xml"), query.read(), attributes);
Query.createRead(getMetadata().getMetaclass("Patient"), parse("(visibleDescription)"),
null, null, 1, 0, false, Query.SEC_NONE, m_context);
list = Query.createRead(getMetadata().getMetaclass("Contact"), null,
Pair.attribute("visible"), null, -1, 0, false, Query.SEC_NONE, m_context).read();
for (int i = 0; i < list.size(); ++i)
{
assertEquals(Boolean.TRUE, list.getInstance(i).getValue("visible"));
}
assertEquals(2, Query.createRead(getMetadata().getMetaclass("Contact"), null,
parse("(and (= classCode \"CON\") (> (/ businessAddressCount 2) 0))"), null, -1, 0, false,
Query.SEC_NONE, m_context).read().size());
assertEquals(2, Query.createRead(getMetadata().getMetaclass("Address"), null,
parse("(= (@@ User addresses) (oid #z00000000000000000000000000000001))"), null, -1, 0, false,
Query.SEC_NONE, m_context).read().size());
// Annotations
attributes = parse("(firstName (: _fnLen (string-length (@ firstName))) (: _n 123) (: _ln (@ lastName)) (: _x2 (let ((x 2)) (* x x))) (: _f (lambda (x) 1)))");
query = Query.createRead(getMetadata().getMetaclass("Contact"), attributes,
parse("(= classCode \"CON\")"),
parse("(((@) . #t))"), -1, 0, false, Query.SEC_NONE, m_context);
AssertUtil.assertEquals(getURL("readAnnotations.xml"), query.read(), attributes);
// Annotated queries with cached classes (no caching)
attributes = parse("((: l (string-length (@ name))))");
query = Query.createRead(getMetadata().getMetaclass("Country"), attributes,
null, parse("(((@) . #t))"), -1, 0, false, Query.SEC_NONE, m_context);
AssertUtil.assertEquals(getURL("readAnnotationsCached.xml"), query.read(), attributes);
// Aggregate functions
attributes = parse("(firstName lastName addressCount (: _countryCnt (count (@ addresses country))) " +
"(: _uniqueCountryCnt (count (unique (@ addresses country)))) (: _nullCodeCnt (count (null? (@ addresses code)))) " +
"(: _avg (average (string-length (@ addresses city)))) (: _min (minimum (string-length (@ addresses city)))) " +
"(: _max (maximum (@ addresses city))) (: _sum (sum (string-length (@ addresses city)))))");
query = Query.createRead(getMetadata().getMetaclass("Contact"), attributes,
parse("(= classCode \"CON\")"), parse("(((@) . #t))"),
-1, 0, false, Query.SEC_NONE, m_context);
AssertUtil.assertEquals(getURL("readAggregate.xml"), query.read(), attributes);
// Aggregate queries
list = Query.createAggregate(getMetadata().getMetaclass("Contact"), null,
parse("(= classCode \"CON\")"), null, null, null, -1, 0, Query.SEC_NONE, m_context).read();
assertEquals(1, list.size());
instance = list.getInstance(0);
assertEquals("Object", instance.getClassName());
assertNull(instance.getOID());
attributes = parse("((: c (count (@))) (: n 1))");
query = Query.createAggregate(getMetadata().getMetaclass("Contact"), attributes,
parse("(= classCode \"CON\")"), null, null, null, -1, 0, Query.SEC_NONE, m_context);
AssertUtil.assertEquals(getURL("readGroupByCountAll.xml"), query.read(), attributes);
attributes = parse("((: c (* 2 (count (@)))))");
query = Query.createAggregate(getMetadata().getMetaclass("Contact"), attributes,
parse("(= classCode \"CON\")"), parse("((@))"), null, parse("(((@) . #t))"), -1, 0, Query.SEC_NONE, m_context);
AssertUtil.assertEquals(getURL("readGroupByIndentity.xml"), query.read(), attributes);
query = Query.createAggregate(getMetadata().getMetaclass("Contact"), parse("(classCode (: c (* 2 (count (@)))) (: n 1))"),
parse("(= classCode \"CON\")"), parse("(classCode)"), null, parse("((classCode . #t))"),
-1, 0, Query.SEC_NONE, m_context);
AssertUtil.assertEquals(getURL("readGroupByAttribute.xml"), query.read(),
parse("((: classCode (@ classCode)) (: c (* 2 (count (@)))) (: n 1))"));
attributes = parse("((: fnl (string-length (@ firstName))))");
query = Query.createAggregate(getMetadata().getMetaclass("Contact"), attributes,
parse("(= classCode \"CON\")"), parse("(classCode (string-length (@ firstName)))"), null,
parse("((classCode . #t) ((string-length (@ firstName)) . #t))"), -1, 0, Query.SEC_NONE, m_context);
AssertUtil.assertEquals(getURL("readGroupByExpr.xml"), query.read(), attributes);
attributes = parse("((: c (* 2 (count (@)))) (: ac (count (@ addresses))))");
query = Query.createAggregate(getMetadata().getMetaclass("Contact"), attributes,
parse("(= classCode \"CON\")"), parse("((@))"), null,
parse("(((@) . #t))"), -1, 0, Query.SEC_NONE, m_context);
AssertUtil.assertEquals(getURL("readGroupByIdentityCountAssoc.xml"), query.read(), attributes);
attributes = parse("((: classCode (@ classCode)) (: c (* 2 (count (@)))) (: ac (count (@ addresses))))");
query = Query.createAggregate(getMetadata().getMetaclass("Contact"), attributes,
parse("(= classCode \"CON\")"), parse("(classCode)"), parse("(> (count (@ addresses)) 1)"),
parse("((classCode . #t))"), -1, 0, Query.SEC_NONE, m_context);
AssertUtil.assertEquals(getURL("readGroupByCountAssoc.xml"), query.read(), attributes);
attributes = parse("((: c (* 2 (count (@)))) (: a (@ addresses)))");
query = Query.createAggregate(getMetadata().getMetaclass("Contact"), attributes,
parse("(= classCode \"CON\")"), parse("((@) addresses)"), null,
parse("((addresses . #t) ((@) . #t))"), -1, 0, Query.SEC_NONE, m_context);
AssertUtil.assertEquals(getURL("readGroupByAssoc.xml"), query.read(), attributes);
query = Query.createAggregate(getMetadata().getMetaclass("Contact"),
parse("(firstName (: c (count (@))))"),
parse("(= classCode \"CON\")"), parse("(firstName)"), null,
parse("((firstName . #t))"), -1, 0, Query.SEC_NONE, m_context);
AssertUtil.assertEquals(getURL("readGroupByCase.xml"), query.read(),
parse("((: firstName (@ firstName)) (: c (count (@))))"));
attributes = parse("((: c (* 2 (count (@)))))");
query = Query.createAggregate(getMetadata().getMetaclass("Contact"), attributes,
parse("(= classCode \"CON\")"), parse("(addresses)"), null,
parse("((addresses . #t))"), -1, 0, Query.SEC_NONE, m_context);
cursor = query.openCursor();
try
{
AssertUtil.assertEquals(getURL("readGroupByCursorCol.xml"), cursor.next(1024), attributes);
}
finally
{
cursor.close();
}
// Aggregate queries with cached classes (no caching)
query = Query.createAggregate(getMetadata().getMetaclass("Country"), null,