来自Toplink表达式的SQL查询 [英] SQL query from Toplink expression
问题描述
我有一个使用oracle.toplink.expressions.ExpressionBuilder创建的oracle.toplink.expressions.Expression表达式对象.我想找到它的等效SQL查询(例如,从雇员emp中选择emp.empname,emp.empId),该查询最终将被触发以获取数据.我想找到它的等效Statement/PreparedStatement或任何可以帮助我获得即将被解雇的原始SQL语句的东西.
I have a oracle.toplink.expressions.Expression expression object with me which has been created using oracle.toplink.expressions.ExpressionBuilder. I want to find its equivalent SQL query(say select emp.empname,emp.empId from employee emp) which will be fired eventually in order to fetch data. I want to find its equivalent Statement/PreparedStatement or anything which will help me obtain the raw SQL statement about to be fired.
例如 以下是toplink表达式:
For e.g. Following is the toplink expression:
expressionBuilder.get("empName").equal("Eric");
我想获得等效的SQL查询:
and i want to get the equivalent SQL query:
select emp.empName,emp.emp_id,emp.sal from employee emp where emp.empName like 'Eric'
请让我知道是否有任何API可以获取此溶胶.我尝试了DatabaseQuery的实现类,但是找不到任何可以完成此操作的方法.
Please let me know if there is any API to get the sol. I tried the implmentation classes of DatabaseQuery but couldn't find any method which could accomplish this.
下面是我的toplink表达式:
Below is the toplink expression with me :
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
我想要类似
select otd.operationaltrx_id,otd.accountingCompany from OperationalTrxData otd where minEffectiveBegDate > to_date('','') ...
谢谢, 阿迪蒂亚.
推荐答案
使用ReportQuery选择所需的字段,然后准备"查询并打印出将要生成的SQL:
Using a ReportQuery to select the desired fields then "prepare" the query and print out the SQL that will be generated:
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();
这篇关于来自Toplink表达式的SQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!