使用适用于 Android 的 ORMLite,我需要构建一个按订单 ID 或客户名称返回订单的查询。请考虑以下类声明:
@DatabaseTable(tableName = "order")
public class Order {
@DatabaseField(generatedId = true)
private Long id;
@DatabaseField(foreign = true, canBeNull = false, foreignAutoRefresh = true, columnName = "customer_id")
private Customer customer;
// default constructor, getters and setters...
}
@DatabaseTable(tableName = "customer")
public class Customer {
@DatabaseField(generatedId = true)
private Long id;
@DatabaseField
private String name;
// default constructor, getters and setters...
}
我正在寻找的原始 SQL 是这样的:
SELECT
o.*
FROM
order o
JOIN customer c on
o.customer_id = c.id
WHERE
(o.id = ?) OR (c.name = ?)
使用 ORMLite 的最佳方法是什么?