Windchill 高階查詢 獲取分類節點可例項化設定
阿新 • • 發佈:2020-12-20
Windchill 高階查詢 獲取分類節點可例項化設定
開發環境:windchill 11.0 M030
如題,目標是查詢partsLink模組中,分類節點的可例項化設定。
執行sql如下:
select a2.value
from LWCPropertyDefinition a1, LWCPropertyValue a2, LWCStructEnumAttTemplate a3
where a1.ida2a2=a2.ida3a4 and a2.ida3b4=a3.ida2a2 and
a3.deletedid is null and a1.name='instantiable' and a3.name='分類節點內部名稱'
需要注意:
如果可例項化的值,不是手動設定的,而是繼承得到的,則上面的sql查不出來。
使用高階查詢,程式碼實現如下
import com.ptc.core.lwc.server.LWCPropertyDefinition;
import com.ptc.core.lwc.server.LWCPropertyValue;
import com.ptc.core.lwc.server.LWCStructEnumAttTemplate;
import wt.fc.PersistenceHelper;
import wt.fc.QueryResult;
import wt.query.ClassAttribute;
import wt.query.QuerySpec;
import wt.query.SearchCondition;
import wt.query.TableColumn;
/**
* @author 彭秉浪 [email protected]
*/
public class TestUtil {
public static boolean getInstantiableByClassificationNode(String internalName) {
try {
QuerySpec qs = new QuerySpec();
qs.setAdvancedQueryEnabled(true);// 設定為高階查詢
int a1 = qs.addClassList(LWCPropertyDefinition.class, false);
int a2 = qs.addClassList(LWCPropertyValue.class, true);
int a3 = qs.addClassList(LWCStructEnumAttTemplate.class, false);
ClassAttribute value = new ClassAttribute(LWCPropertyValue.class, LWCPropertyValue.VALUE);
qs.appendSelect(value, new int[] { a2 }, true);
String a1Column = qs.getFromClause().getAliasAt(a1);
String a2Column = qs.getFromClause().getAliasAt(a2);
String a3Column = qs.getFromClause().getAliasAt(a3);
// 新增表之間的連結條件
TableColumn a1_ida2a2 = new TableColumn(a1Column, "ida2a2");
TableColumn a3_ida2a2 = new TableColumn(a3Column, "ida2a2");
TableColumn a2_ida3a4 = new TableColumn(a2Column, "ida3a4");
TableColumn a2_ida3b4 = new TableColumn(a2Column, "ida3b4");
SearchCondition join1 = new SearchCondition(a2_ida3a4, SearchCondition.EQUAL, a1_ida2a2);
qs.appendWhere(join1, new int[] { a2, a1 });
qs.appendAnd();
SearchCondition join2 = new SearchCondition(a2_ida3b4, SearchCondition.EQUAL, a3_ida2a2);
qs.appendWhere(join2, new int[] { a2, a3 });
qs.appendAnd();
// 新增查詢條件
// deletedid為空表示分類節點沒有被刪除
TableColumn deletedid = new TableColumn(a3Column, "deletedid");
SearchCondition sc1 = new SearchCondition(deletedid, SearchCondition.IS_NULL);
qs.appendWhere(sc1, new int[] { a3 });
qs.appendAnd();
SearchCondition sc2 = new SearchCondition(LWCPropertyDefinition.class, LWCPropertyDefinition.NAME, SearchCondition.EQUAL, "instantiable");
qs.appendWhere(sc2, new int[] { a1 });
qs.appendAnd();
SearchCondition sc3 = new SearchCondition(LWCStructEnumAttTemplate.class, LWCStructEnumAttTemplate.NAME, SearchCondition.EQUAL, internalName);
qs.appendWhere(sc3, new int[] { a3 });
QueryResult qr = PersistenceHelper.manager.find(qs);
while (qr.hasMoreElements()) {
Object[] objectArr = (Object[]) qr.nextElement();
if (objectArr[0] instanceof LWCPropertyValue) {
LWCPropertyValue propertyValue = (LWCPropertyValue) objectArr[0];
if ("true".equals(propertyValue.getValue())) {
return true;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
}
上面的sql查詢,表結構是自己工作之餘摸索出來的,目前只在測試庫測試通過,如果有錯誤,請留言評論或發站內私信,謝謝。