import java.util.Arrays;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentContextList;
import com.teamcenter.rac.kernel.TCComponentQuery;
import com.teamcenter.rac.kernel.TCComponentQueryType;
import com.teamcenter.rac.kernel.TCQueryClause;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.ui.common.RACUIUtil;
/**
* @author lixx
*/
public class TCQueryUtils {
/**
* 调用查询构建器
* @param session
* @param queryName:A2_SearchItemRevision
* @param 用户条目本地化关键字keys:String[] keys = {"object_type","item_id","a2_dwgtype"};
* @param 真实值values:String[] values = {"A2_itemRevision","SH501A0-00*","1"};
* @return
*/
public static TCComponent[] queryWithUserEntryName(TCSession session, String queryName, String[] keys, String[] values) {
TCComponent[] component = (TCComponent[]) null;
try {
TCComponentQueryType queryType = (TCComponentQueryType) session.getTypeComponent("ImanQuery");
TCComponentQuery query = (TCComponentQuery) queryType.find(queryName);
TCQueryClause[] queryClauses=query.describe();
String[] userEntryNameDisplays = new String[keys.length];
int count=queryClauses.length;//全部条目个数
for (int k = 0; k < keys.length; k++) {
System.out.println("key["+k+"]:"+keys[k]);
// queryAttribute[k] = imantextservice.getTextValue(key[i]);//取不到个别的本地化值
for (int i = 0; i < count; i++) {
// System.out.println("属性:"+queryClauses[i].getAttributeName()+";用户条目本地化关键字:"+queryClauses[i].getUserEntryName()+";用户条目名称:"+queryClauses[i].getUserEntryNameDisplay());
if (keys[k].equals(queryClauses[i].getUserEntryName())) {
userEntryNameDisplays[k] = queryClauses[i].getUserEntryNameDisplay();
break;
}
}
}
// System.out.println(Arrays.toString(userEntryNameDisplays)+"---"+Arrays.toString(values));
TCComponentContextList tcComponentContextList = query.getExecuteResultsList(userEntryNameDisplays, values);
component = tcComponentContextList.toTCComponentArray();
} catch (Exception ex) {
ex.printStackTrace();
}
return component;
}
/**
* 调用查询构建器
* @param session
* @param queryName:A2_SearchItemRevision
* @param 用户条目名称keys:String[] keys = { "类型","ID","零部件类型" };
* @param 真实值values:String[] values = { "A2_itemRevision","SH501A0-00*","1"};
* @return
*/
public static TCComponent[] queryWithUserEntryNameDisplay(TCSession session,String queryName,String[] keys,String[] values){
TCComponent[] tcComponents = null;
try {
tcComponents = session.search(queryName, keys, values);
} catch (Exception e) {
e.printStackTrace();
}
return tcComponents;
}
public static void main(String[] args) {
TCSession session = RACUIUtil.getTCSession();
//推荐使用queryWithUserEntryName(),毕竟客户化的值可能会修改
String[] keys1=new String[]{ "object_type","item_id","a2_dwgtype" };
String[] keys2=new String[]{ "类型","ID","零部件类型" };
//请注意value的值一定要传真实值!!!
String[] values=new String[]{ "A2_itemRevision","*","1" };
TCComponent[] tcComponents1 = queryWithUserEntryName(session, "A2_SearchItemRevision", keys1, values);
System.out.println("根据“用户条目本地化关键字”查询结果:"+Arrays.toString(tcComponents1));
TCComponent[] tcComponents2 = queryWithUserEntryNameDisplay(session, "A2_SearchItemRevision", keys2, values);
System.out.println("根据“用户条目名称”查询结果:"+Arrays.toString(tcComponents2));
}
}
Java调用Teamcenter查询构建器公共类
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 层级关系:test(父级) 、 testComponent(子级) 代码示例: 注意:兄弟节点类的相互引用雷同