Windchill高级查询之多表查询

Windchill高级查询之多表查询

前言

实际开发场景中,需要查询所有带有BOM结构的部件,并且部件的阶段(IBA属性)为指定值。了解上篇”根据IBA属性查询部件“的同学,不难想到子查询可以解决部件阶段为指定值,那么存在BOM结构怎么过滤?本章主要讲述Windchill之间的多表连接查询ClassTableExpression类的使用。

在此之前我们需先了解TableExpression和ClassTableExpression。

一、TableExpression
  1. 定义:TableExpression是一个抽象类,代表的是数据库表的表达。这个类是构建SQL查询的基础组件之一。
  2. 用途:
    • 提供一个公共的接口,供具体的表表达式(如ClassTableExpression)进行扩展。
    • 用于支持查询的生成和条件的添加。
  3. 特点:作为一个抽象类,TableExpression 不直接实现任何具体的表或视图功能,而是为子类提供了一些公共的方法和属性。
二、ClassTableExpression
  1. 定义:ClassTableExpression是TableExpression 的一个具体实现,专门用于表示与 Java 类相对应的数据库表。每个业务对象通常都有一个对应的ClassTableExpression。

  2. 用途:

    • 允许开发者在构建查询时以面向对象的方式处理数据库表。
    • 提供对特定类的属性的引用,使得查询可以直接使用 Java 对象的属性名,而不是数据库字段名。
  3. 特点:

    • 包含了与类映射相关的信息,例如类名、表名、字段名等。
    • 支持创建和管理表的别名,方便进行复杂查询。
  4. 总结:

    TableExpression是一个抽象的概念,提供了构建查询的基础,而ClassTableExpression是其具体实现,专门用于表示与Java类相关的数据库表。

三、QuerySpec的方法appendWhere
public void appendWhere(WhereExpression  a_whereExpression,
			TableExpression[] a_tableExpressions,
			String[] a_aliases)throws  QueryException
  1. 含义:增加where子句

  2. 参数:

    • a_whereExpression-一个查询条件
    • a_tableExpressions -一个数组,数组里面的值是from后面的表(类)
    • a_aliases-一个数组,数组里面的值是类的位置
  3. 代码

    public class TestAppendWhere3 {
         
    	/**
    	 * @param args
    	 * @throws WTException 
    	 * @throws WTPropertyVetoException 
    	 */
    	public static void main(String[] args) throws WTPropertyVetoException, WTException {
         
    		QueryResult qr=getQr();
    	}
    	public static String CLASSNAME=TestClass.class.getName();
    	public static QueryResult getQr() throws WTException, WTPropertyVetoException{
         
    		if (!RemoteMethodServer.ServerFlag) {
         
    			String method = "getQr";
    			try {
         
    				return (QueryResult) RemoteMethodServer.getDefault().invoke
    						(method, CLASSNAME, null, new Class[]
    				        {
          }, new Object[]
    				        {
          });
    			} catch (Exception exp) {
         
    				exp.printStackTrace();
    			}
    		}	
    		QuerySpec select = new QuerySpec();
    		int partIndex = select.appendClassList(wt.part.WTPartMaster.class, true);
    		QuerySpec subSelect = new QuerySpec();
    		subSelect.getFromClause().setAliasPrefix("B");
    		int altIndex = subSelect.appendClassList(wt.part.WTPartAlternateLink.class,
    		false);
    		subSelect.appendSelect(new ClassAttribute(
    		wt.part.WTPartAlternateLink.class, "thePersistInfo.theObjectIdentifier.id"),
    		new int[] {
          altIndex }, true);
    		TableExpression[] tables = new TableExpression[2];
    		String[] aliases = new String[2];
    		tables
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值