软属性文档类型的最新文档

本次例子依然延续了前几次查询的模式,虽然该范例只是查询WTDocument,但是对于WTPart的查询也是适用了。
      import com.ptc.core.meta.type.mgmt.server.impl.WTTypeDefinition;
import com.ptc.core.meta.type.mgmt.server.impl.WTTypeDefinitionMaster;
import wt.doc.WTDocument;
import wt.fc.ObjectVector;
import wt.fc.PersistenceHelper;
import wt.fc.QueryResult;
import wt.query.CompositeWhereExpression;
import wt.query.ConstantExpression;
import wt.query.LogicalOperator;
import wt.query.QuerySpec;
import wt.query.SearchCondition;
import wt.query.TableColumn;
import wt.util.WTException;
import wt.vc.config.ConfigSpec;
import wt.vc.config.LatestConfigSpec;


public class Demo {
/**
* @param args
* @throws WTException
*/
public static void main(String[] args) throws WTException {
// TODO Auto-generated method stub
QueryResult qr = queryLatestIBADocument("wt.doc.WTDocument|cn.shangxuetang.TestPart");
while (qr.hasMoreElements()) {
   WTDocument doc = (WTDocument) qr.nextElement();
   System.out.println(doc.getName());
   //获取该文档的版本信息
   System.out.println(doc.getIterationDisplayIdentifier().toString());
}
}
/**
* 查询所有属于该软属性文档类型的最新文档
* @param documentType  
* @return    
* @throws WTException
*/
public static QueryResult queryLatestIBADocument(String documentType) throws WTException {
QuerySpec qs = new QuerySpec();
int a = qs.appendClassList(WTDocument.class, true);
int b = qs.appendClassList(WTTypeDefinition.class, false);
int c = qs.appendClassList(WTTypeDefinitionMaster.class, false);
qs.setAdvancedQueryEnabled(true);
String[] aliases = new String[4];
aliases[0] = qs.getFromClause().getAliasAt(a);
aliases[1] = qs.getFromClause().getAliasAt(b);
aliases[2] = qs.getFromClause().getAliasAt(c);
TableColumn tc1 = new TableColumn(aliases[0], "IDA2TYPEDEFINITIONREFERENCE");
TableColumn tc2 = new TableColumn(aliases[0], "LATESTITERATIONINFO");
TableColumn tc3 = new TableColumn(aliases[1], "IDA2A2");
TableColumn tc4 = new TableColumn(aliases[1], "IDA3MASTERREFERENCE");
TableColumn tc5 = new TableColumn(aliases[2], "IDA2A2");
TableColumn tc6 = new TableColumn(aliases[2], "INTHID");

CompositeWhereExpression andExpression = new CompositeWhereExpression(LogicalOperator.AND);
andExpression.append(new SearchCondition(tc1, "=", tc3));
andExpression.append(new SearchCondition(tc2, "=", new ConstantExpression("1")));
andExpression.append(new SearchCondition(tc4, "=", tc5));
andExpression.append(new SearchCondition(tc6, "=", new ConstantExpression(documentType)));
qs.appendWhere(andExpression, null);
QueryResult qr = PersistenceHelper.manager.find(qs);
//对于查寻到的集合进行处理以适应LatestConfigSpec
ObjectVector obj = new ObjectVector();
while (qr.hasMoreElements()) {
   Object obj2[] = (Object[]) qr.nextElement();
   obj.addElement(obj2[0]);
}
QueryResult qr2 = new QueryResult((wt.fc.ObjectVectorIfc) obj);
ConfigSpec cs = new LatestConfigSpec();
//用LatestConfigSpec过滤查询到的集合
return cs.process(qr2);
}
}

你可能感兴趣的:(C++,c,C#,vc++)