windchill中对于时间的比较查询

在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()); //项目开始时间
}
}

}

猜你喜欢

转载自fnasty.iteye.com/blog/764273