0
我有兩個與CustomerRefId字段綁定的CustomerBalance和Customer表。 我希望CustomerBalance記錄可以說大於100的表格的字段平衡。我也想在我的結果中包含符合該標準的特定客戶的姓名。我創建了以下可用的方法!在ormlite中編寫連接查詢的更好方法
public List<CustomerBalance> getCustomerBalanceFilter(String filterVal) {
try {
PreparedQuery<CustomerBalance> preparedQuery = mDbHelper.getCustomerBalanceDao().queryBuilder()
.where().gt(CustomerBalance.DB_COL_CUSTOMER_BALANCE, filterVal)
.prepare();
List<CustomerBalance> result = mDbHelper.getCustomerBalanceDao().query(preparedQuery);
for(CustomerBalance alert : result) {
PreparedQuery<Customer> getCustQuery = mDbHelper.getCustomerDao().queryBuilder()
.where().eq(Customer.DB_COL_CUSTOMER_REF_ID, alert.getCustomerID())
.prepare();
List<Customer> customer = mDbHelper.getCustomerDao().query(getCustQuery);
alert.setCustomer(customer.size() == 1 ? customer.get(0) : null);
}
return result;
} catch(Exception ex) {
return null;
}
}
這種方法工作,這是寫這種查詢的最好方法嗎?還是有更合適的方法?
非常感謝你灰色!我只是爲了獲取數據而使用這種方法,所以暫時不需要更新操作。 – Antonis
因此,嵌套查詢是解決ORMLite無法獲得「連接」對象的問題的推薦方法嗎? – BornToCode