我正在尝试从DB2移植到ORACLE 11g,为了做到这一点,我要更改应用程序的代码(避免重写整个应用程序)。语句“WITH UR”(带有Uncommitted Read)不起作用 与ORACLE,因为它不支持脏读。是否有一种优雅而简单的方法或模式来避免在我的代码中放入一个带有文件属性集的“IF”(脏解决方案)?
@Override
public List<Object[]> receiptSummary(String idENTITY) {
List<Object[]> listObj = new ArrayList<Object[]>();
try {
StringBuilder sqlQuery = new StringBuilder();
sqlQuery.append("SELECT TE.DE_TRB AS TYPE_DEBT, COUNT(*) AS NUM_RECEIPTS, SUM(BBR.AMOUNT) AS AMOUNT ")
.append("FROM DRAFTS_TRANSFERS_CREDITING BBR, TRANSFERS_CREDITING BR, LISTS_CREDITING DR, CONDITIONS C, PAYINGS TE ")
.append("WHERE ");
if (idENTITY != null && !idENTITY.isEmpty()) {
sqlQuery.append("BBR.ID_ENTITY = :id_ENTITY AND ");
}
sqlQuery.append("BBR.ID_TRANSFERS_CREDITING=BR.ID ")
.append("AND BR.ID_LISTS_CREDITING = DR.ID ")
.append("AND C.ID_CONDITION = BBR.ID_CONDITION ")
.append("AND DR.STATE='DONE' ")
.append("AND TE.CD_TRB_ENTITY = C.CD_TRB_ENTITY ")
.append("GROUP BY TE.DE_TRB ")
.append("WITH UR"); //FIXME: FOR ORACLE
Query q = em.createNativeQuery(sqlQuery.toString());
if (idENTITY != null && !idENTITY.isEmpty()) {
q.setParameter("id_ENTITY", idENTITY);
}
String msg = "DAO - receiptSummary - id_ENTITY:" + idENTITY;
if (Tracer.isDebugEnabled(this.getClass().getName())) {
Tracer.debug(this.getClass().getName(), "receiptSummary", msg);
Tracer.debug(this.getClass().getName(), "receiptSummary", sqlQuery.toString());
}
System.out.println("receiptSummary - " + msg);
System.out.println("receiptSummary - " + sqlQuery.toString());
listObj = (List<Object[]>) q.getResultList();
} catch (Exception e) {
Tracer.error(this.getClass().getName(), "receiptSummary", e.getMessage());
e.printStackTrace();
}
return listObj;
}