3

我有一个 oracle.toplink.expressions.Expression 表达式对象,它是使用 oracle.toplink.expressions.ExpressionBuilder 创建的。我想找到它的等效 SQL 查询(比如从员工 emp 中选择 emp.empname,emp.empId),它最终将被触发以获取数据。我想找到它的等价 Statement/PreparedStatement 或任何可以帮助我获得即将被触发的原始​​ SQL 语句的东西。

例如,以下是 toplink 表达式:

expressionBuilder.get("empName").equal("Eric");

我想获得等效的 SQL 查询:

select emp.empName,emp.emp_id,emp.sal from employee emp where emp.empName like 'Eric'

请让我知道是否有任何 API 可以获取溶胶。我尝试了 DatabaseQuery 的实现类,但找不到任何可以实现这一点的方法。

下面是我的 toplink 表达式:

Logical operator  AND 
   Logical operator  AND 
      Logical operator  AND 
         Logical operator  AND 
            Logical operator  AND 
               Logical operator  AND 
                  Logical operator  AND 
                     Logical operator  AND 
                        Relation operator  < 
                           Query Key minEffectiveBegDate
                              Base com.altra.common.data.OperationalTrxData
                           Constant Tue Feb 01 08:00:00 CST 2011
                        Relation operator  > 
                           Query Key maxEffectiveEndDate
                              Base com.altra.common.data.OperationalTrxData
                           Constant Sat Jan 01 08:00:00 CST 2011
                     Relation operator  < 
                        Query Key begDate
                           Query Key calculatedQuantityDataList
                              Query Key qtyClassificationDataList
                                 Query Key operationalQuantityDataList
                                    Base com.altra.common.data.OperationalTrxData
                        Constant Tue Feb 01 08:00:00 CST 2011
                  Relation operator  > 
                     Query Key endDate
                        Query Key calculatedQuantityDataList
                           Query Key qtyClassificationDataList
                              Query Key operationalQuantityDataList
                                 Base com.altra.common.data.OperationalTrxData
                     Constant Sat Jan 01 08:00:00 CST 2011
               Relation operator  = 
                  Query Key opsTrxClassification
                     Base com.altra.common.data.OperationalTrxData
                  Constant -5001579
            Relation operator  = 
               Query Key accountingCompany
                  Base com.altra.common.data.OperationalTrxData
               Constant 1196
         Logical operator  OR 
            Logical operator  AND 
               Relation operator  = 
                  Query Key sourceRelatedNodeObjType
                     Base com.altra.common.data.OperationalTrxData
                  Constant -2094
               Relation operator  IN 
                  Query Key sourceRelatedNodeObjId
                     Base com.altra.common.data.OperationalTrxData
                  Constant [4187]
            Logical operator  AND 
               Relation operator  = 
                  Query Key dispositionRelatedNodeObjType
                     Base com.altra.common.data.OperationalTrxData
                  Constant -2094
               Relation operator  IN 
                  Query Key dispositionRelatedNodeObjId
                     Base com.altra.common.data.OperationalTrxData
                  Constant [4187]
      Relation operator  = 
         Query Key qtyType
            Query Key operationalQuantityDataList
               Base com.altra.common.data.OperationalTrxData
         Constant -5000328
   Relation operator  = 
      Query Key qtyStatus
         Query Key qtyClassificationDataList
            Query Key operationalQuantityDataList
               Base com.altra.common.data.OperationalTrxData
      Constant -5000316

我想要 SQL 等价物

select otd.operationaltrx_id,otd.accountingCompany from OperationalTrxData otd where minEffectiveBegDate > to_date('','') ...

谢谢,阿迪西亚。

4

2 回答 2

2

使用 ReportQuery 选择所需的字段,然后“准备”查询并打印出将生成的 SQL:

ExpressionBuilder emp = new ExpressionBuilder(Employee.class);
ReportQuery query = new ReportQuery(Employee.class, emp);
query.addAttribute("empName");
query.addAttribute("emp_id");
query.addAttribute("sal");

query.setSelectionCriteria(emp.get("empName").equal("Eric"););
query.prepareCall(session, new DatbaseRecord());
String sql = query.getSQLString();
于 2011-04-07T01:10:42.083 回答
1

You need to use a ReportQuery.

ExpressionBuilder emp = new ExpressionBuilder();
ReportQuery query = new ReportQuery(Employee.class, emp);
query.addAttribute("empName");
query.addAttribute("emp_id");
query.addAttribute("sal");

query.setSelectionCriteria(emp.get("empName").equal("Eric"););
List reports = (List) session.executeQuery(query);
于 2011-03-28T13:07:23.447 回答