关于windchill中项目的高级查询

来源:原创 作者:云淡天晴 时间:2008-12-08
     在windchill中很多查询都是非常类似的,方法也是非常之多,不过只要会两三中查询方式就可以应付windchill中几乎所有的查询需要,

本次将再次提及一种非常方便的查询,不过对于这种查询方式需要对于数据库表有一定的了解。此实例中需要注意的是对于时间的

比较查询。

      import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import wt.fc.PersistenceHelper;
import wt.fc.QueryResult;
import wt.projmgmt.admin.Project2;
import wt.projmgmt.execution.ProjectPlan;
import wt.query.CompositeWhereExpression;
import wt.query.ConstantExpression;
import wt.query.DateExpression;
import wt.query.LogicalOperator;
import wt.query.QuerySpec;
import wt.query.SearchCondition;
import wt.query.TableColumn;
import wt.util.WTException;


public class Demo
{

 /**
  * @param args
  * @throws WTException
  * @throws ParseException
  */
 public static void main(String[] args) throws WTException, ParseException
 {
  String string="2009-05-01 00:00:00.000000";
  Timestamp time=Timestamp.valueOf(string);
  // TODO Auto-generated method stub
  QuerySpec qs = new QuerySpec(); 
  int a = qs.appendClassList(Project2.class, true);
        int b = qs.appendClassList(ProjectPlan.class, true);
        qs.setAdvancedQueryEnabled(true);
        String[] aliases = new String[2];
        aliases[0] = qs.getFromClause().getAliasAt(a);
        aliases[1] = qs.getFromClause().getAliasAt(b);
        TableColumn tc1 = new TableColumn(aliases[0], "IDA2A2");  //项目id
        TableColumn tc2 = new TableColumn(aliases[0], "STATECONTAINERTEAMMANAGEDINF");//项目状态
        TableColumn tc3 = new TableColumn(aliases[1], "IDA3B8");  //项目计划中引用项目id
        TableColumn tc4 = new TableColumn(aliases[1], "NAME");    //项目名称
        TableColumn tc5 = new TableColumn(aliases[1], "PERCENTCOMPLETE"); //项目完成进度
        TableColumn tc6 = new TableColumn(aliases[1], "TIMETOSTART");  //项目实际开始时间
        CompositeWhereExpression andExpression = new CompositeWhereExpression(LogicalOperator.AND);
        andExpression.append(new SearchCondition(tc1, "=", tc3));
        andExpression.append(new SearchCondition(tc2, "=", new ConstantExpression("RUNNING")));  //正在运行
        andExpression.append(new SearchCondition(tc4, "=", new ConstantExpression("上雪堂")));
        andExpression.append(new SearchCondition(tc5, ">=", new ConstantExpression(new Integer("89"))));
        andExpression.append(new SearchCondition(tc6, SearchCondition.GREATER_THAN_OR_EQUAL, new ConstantExpression(time)));
        qs.appendWhere(andExpression, null);
  QueryResult qr=PersistenceHelper.manager.find(qs);
  while (qr.hasMoreElements())
  {
   Object obj[] = (Object[]) qr.nextElement();
   Project2 project2 = (Project2)obj[0];
   System.out.println(project2.getName());    //项目名称
   System.out.println(project2.getCtmState());//项目状态
   ProjectPlan projectPlan = (ProjectPlan)obj[1];
   System.out.println(projectPlan.getPercentComplete());  //项目完成进度
   System.out.println(projectPlan.getStartTime()); //项目开始时间
  }
  
 }

}

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值