2013-10-30 82 views
1

這裏是我的問題..JOOQ排序依據與Case語句

SelectQuery<Record> selectQuery = transRefundFee.selectQuery(); 
selectQuery.addSelect(AccountBill.ACCOUNT_BILL.BILL_NUMBER,AccountBill.ACCOUNT_BILL.BILL_AMOUNT,AccountBill.ACCOUNT_BILL.TOTAL_PAID); 
selectQuery.addFrom(AccountBill.ACCOUNT_BILL); 
selectQuery.addConditions(AccountBill.ACCOUNT_BILL.FOLDER_RSN.eq(argFolderRSN)); 

我必須用Case語句添加排序依據我們如何能做到這一點我檢查Here,但它不是我的情況下工作,我添加任何其他方式這樣

selectQuery.addOrderBy(DSL.decode().when(AccountBill.ACCOUNT_BILL.BILL_AMOUNT.le(new BigDecimal(0)),AccountBill.ACCOUNT_BILL.BILL_AMOUNT).then(AccountBill.ACCOUNT_BILL.BILL_AMOUNT) .otherwise(AccountBill.ACCOUNT_BILL.BILL_NUMBER)); 

但它說The method then(TableField<AccountBillRecord,BigDecimal>) is undefined for the type CaseConditionStep<BigDecimal>

同樣的,下面的代碼

selectQueryFee.addOrderBy(DSL.decode().when(AccountBill.ACCOUNT_BILL.BILL_AMOUNT.le(new BigDecimal(0)) 
        .then(AccountBill.ACCOUNT_BILL.BILL_AMOUNT) 
        .otherwise(AccountBill.ACCOUNT_BILL.BILL_NUMBER))); 

然後,該方法(TableField)是未定義 爲類型條件

+0

你吃過看看['SelectQuery'(HTTP://www.jooq .org/javadoc/latest/org/jooq/SelectQuery.html)Javadoc?你有什麼嘗試?你在哪裏/爲什麼失敗? –

+0

@LuKas編輯的問題 –

+0

哎呦。我注意到我在[其他問題,你已經鏈接]給出了一個錯誤的答案(http://stackoverflow.com/a/19656354/521799) –

回答

2

作爲jOOQ 3.2中,CASE表達載體沒有實現when() ... then()結構,即沒有then()關鍵詞。相反,寫:

DSL.decode() 
    .when(AccountBill.ACCOUNT_BILL.BILL_AMOUNT.le(new BigDecimal(0)), 
     AccountBill.ACCOUNT_BILL.BILL_AMOUNT) 
    .otherwise(AccountBill.ACCOUNT_BILL.BILL_NUMBER) 

已經有上jOOQ路線圖掛起功能要求進行整治:#615

+0

我必須做鑄造在這裏? CaseConditionStep 類型的其他方法(BigDecimal)不適用於參數(TableField ) –

+1

@subodh:方法簽名爲:when(Condition,T).otherwise(T)'。所以'BILL_AMOUNT'和'BILL_NUMBER'必須是相同的類型。否則,你必須施放,是的 –