0

我正在尝试从 DB2 移植到 ORACLE 11g,为了做到这一点,我必须更改应用程序的代码(避免重写整个应用程序)。语句“WITH UR”(带有未提交的读取)不适用于 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;
}
4

0 回答 0