| | 505 | } |
| | 506 | } |
| | 507 | } |
| | 508 | |
| | 509 | // test index() |
| | 510 | int cnt = 2; |
| | 511 | for (col in ['Predicate', 'RdfBag', 'RdfSeq', 'RdfAlt', 'RdfList']) { |
| | 512 | cls = rdf.class('Test' + cnt) { |
| | 513 | age (type:'xsd:int') |
| | 514 | names (className:'Name' + cnt, maxCard:-1, colMapping:col) { |
| | 515 | first () |
| | 516 | last () |
| | 517 | } |
| | 518 | } |
| | 519 | |
| | 520 | def nc = cls.getClassLoader().loadClass('Name' + cnt) |
| | 521 | cnt++; |
| | 522 | |
| | 523 | o1 = cls.newInstance(age:5, names:[nc.newInstance(first:'Bob', last:'Brown')]) |
| | 524 | o2 = cls.newInstance(age:6, names:[nc.newInstance(first:'Charly', last:'Chan'), |
| | 525 | nc.newInstance(first:'Joe', last:'Jackson')]) |
| | 526 | o3 = cls.newInstance(age:7, names:[nc.newInstance(first:'Charly', last:'Chan'), |
| | 527 | nc.newInstance(first:'Joe', last:'Jackson'), |
| | 528 | nc.newInstance(first:'Sally', last:'Sommer')]) |
| | 529 | |
| | 530 | doInTx { s -> |
| | 531 | s.saveOrUpdate(o1) |
| | 532 | s.saveOrUpdate(o2) |
| | 533 | s.saveOrUpdate(o3) |
| | 534 | } |
| | 535 | doInTx { s -> |
| | 536 | r = s.createQuery(""" |
| | 537 | select n.first f, n.last, index(n) from ${cls.name} t where |
| | 538 | t.age = '5'^^<xsd:int> and n := t.names order by f desc;""").execute() |
| | 539 | checker.verify(r) { |
| | 540 | row { string (o1.names[0].first); string(o1.names[0].last); string (0) } |
| | 541 | } |
| | 542 | |
| | 543 | r = s.createQuery(""" |
| | 544 | select n.first f, n.last, index(n) from ${cls.name} t where |
| | 545 | t.age = '6'^^<xsd:int> and n := t.names order by f desc;""").execute() |
| | 546 | checker.verify(r) { |
| | 547 | if (col == 'Predicate') { |
| | 548 | row { string (o2.names[1].first); string(o2.names[1].last); string (0) } |
| | 549 | row { string (o2.names[0].first); string(o2.names[0].last); string (1) } |
| | 550 | } else { |
| | 551 | row { string (o2.names[1].first); string(o2.names[1].last); string (1) } |
| | 552 | row { string (o2.names[0].first); string(o2.names[0].last); string (0) } |
| | 553 | } |
| | 554 | } |
| | 555 | |
| | 556 | r = s.createQuery(""" |
| | 557 | select n.first f, n.last, index(n) from ${cls.name} t where |
| | 558 | t.age = '7'^^<xsd:int> and n := t.names order by f desc;""").execute() |
| | 559 | checker.verify(r) { |
| | 560 | if (col == 'Predicate') { |
| | 561 | row { string (o3.names[2].first); string(o3.names[2].last); string ('0') } |
| | 562 | row { string (o3.names[1].first); string(o3.names[1].last); string ('1') } |
| | 563 | row { string (o3.names[0].first); string(o3.names[0].last); string ('2') } |
| | 564 | } else { |
| | 565 | row { string (o3.names[2].first); string(o3.names[2].last); string ('2') } |
| | 566 | row { string (o3.names[1].first); string(o3.names[1].last); string ('1') } |
| | 567 | row { string (o3.names[0].first); string(o3.names[0].last); string ('0') } |
| | 568 | } |