Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X
Hi.
I have my own classes for ParentObject, ChildObject and MyOwnLink for the first two.
I need to construct QuerySpec (for TableBuilder) which would return all childs for given parent.
Can anyone provide me java code example for this?
Thanks.
The next code seems to be appropriate:
Parent parentInstance = some given parent
QuerySpec querySpec = new QuerySpec();
int parentIndex = querySpec.appendClassList(Parent.class, false);
int linkIndex = querySpec.appendClassList(ParentChildLink.class, false);
int childIndex = querySpec.appendClassList(Child.class, false);
querySpec.appendSelect(new ClassAttribute(Child.class, Child.NAME), new int[]{childIndex}, true);
querySpec.appendJoin(linkIndex, ParentChildLink.CHILD_ROLE, childIndex);
querySpec.appendJoin(linkIndex, ParentChildLink.PARENT_ROLE, parentIndex);
CompositeWhereExpression whereExpression = new CompositeWhereExpression(LogicalOperator.AND);
whereExpression.append(new SearchCondition(Parent.class, Parent.NAME, SearchCondition.EQUAL, parentInstance.getName()), new int[]{0});
querySpec.appendWhere(whereExpression, new int[]{0});
But:
1) I need to get child objects, not some of their fields.
2) I specified parent name in where clause, the field of parent class i declared myself. Does windchill provide any unique field by default that would be more appropriate?
Resolved setting second parameter of querySpec.appendClassList method to true for Child.class.
Now in UI table i see right number of rows, but columns are empty.
For example, if i define querySpec = new QuerySpec(Child.class) (and without any joins), then columns of table filled with values.
What's the difference, if SELECT in querySpec looks the same in both cases?
Hi Vasiliy ,
Can you kindly specify your process of creating your own parent ,child and link class
?
When you are writing
QuerySpec querySpec = new QuerySpec();
int parentIndex = querySpec.appendClassList(Parent.class, false);
int linkIndex = querySpec.appendClassList(ParentChildLink.class, false);
int childIndex = querySpec.appendClassList(Child.class, false);
that means the QuerySpec will query the above listed tables but as the second paramete is false it will return no object at all.
When we write like QuerySpec qr = new QuerySpec(Child.class); It means it will query the table and return Child object.
You can also write it like QuerySpec qr = new QuerySpec();
int index = qr.appendClassList(Child.class,true);
Thanks and Regards,
Kaushik