这是我对Jooq查询的不满:
private List<UserEmailOrganisation> getEmailsAndOrgNames() {
Result<Record2<String, String>> r = dsl
.fetch(dsl
.select(I_USERS.EMAIL_ID, I_ORGANISATIONS.NAME)
.from(I_USERS)
.leftOuterJoin(I_ORGANISATIONS)
.on(I_USERS.ORGANISATION_ID.equal(I_ORGANISATIONS.ID))
.where(DSL.timestampAdd(I_USERS.UPDATED, MINIMUM_INACTIVE_DATE,
DatePart.DAY).lessOrEqual(DSL.currentTimestamp())));
logger.debug(r.toString());
return r.into(UserEmailOrganisation.class);
}
Run Code Online (Sandbox Code Playgroud)
logger.debug方法打印 -
|email_id |name |
+-----------------------------------+----------------+
|email1@some.com |org1 |
|email2@some.com |org2 |
Run Code Online (Sandbox Code Playgroud)
所以我的查询时返回了一定的成效.所以我认为问题不在于查询而在于into方法.
这是我的UserEmailOrganisation类
public class UserEmailOrganisation {
public String emailId;
public String name;
public UserEmailOrganisation(String emailId, String name) {
this.emailId = emailId;
this.name = name;
}
}
Run Code Online (Sandbox Code Playgroud)
来自JOOQ文档 http://www.jooq.org/javadoc/3.5.x/org/jooq/impl/DefaultRecordMapper.html
如果没有可用的默认构造函数,但至少有一个"匹配"构造函数可用,则使用该构造函数.
"匹配"构造函数的参数与此记录保持字段的参数完全相同当找到多个"匹配"构造函数时,会选择第一个构造函数(由Class.getDeclaredConstructors()报告当调用"匹配"构造函数时,值为转换为构造函数参数类型.
所以我的代码应该正常工作?因为它有一个匹配的构造函数.但事实并非如此.我得到以下异常.
org.jooq.exception.MappingException: No matching constructor found on type class com.kubera.insights.admin.jobs.BackOfficeUsersReminderJob$UserEmailOrganisation for record org.jooq.impl.DefaultRecordMapper@2ccd7880 …Run Code Online (Sandbox Code Playgroud) 我有TradeRequest使用以下架构 命名的集合
const TradeRequestSchema = mongoose.Schema({
status: {
type: String,
enum: ["opened", "rejected", "accepted"],
default: "opened"
},
_requester: {
required: true,
type: mongoose.Schema.Types.ObjectId
},
_requestedBook: {
required: true,
type: mongoose.Schema.Types.ObjectId
}
});
Run Code Online (Sandbox Code Playgroud)
我的数据库应该只有一个任何人对一本书的开放请求。
所以我添加了一个唯一索引,如下所示 -
TradeRequestSchema.index({_requester: 1, _requestedBook: 1, status: 1}, {unique: true});
Run Code Online (Sandbox Code Playgroud)
问题是这会阻止一些本应允许的数据输入到数据库中。
例如,它阻止我的数据库包含以下文档,这对于我的用例来说很好 -
{_id: 1, _requester: 12345, _requestedBook: 9871212, status: "opened"}
{_id: 2, _requester: 12345, _requestedBook: 9871212, status: "opened"}
Run Code Online (Sandbox Code Playgroud)
但它也可以防止以下情况对我的用例来说是错误的。
例如,如果我的数据库已有以下文档 -
{_id: 3, _requester: 12345, _requestedBook: 9871212, status: "closed"}
{_id: 4, _requester: 12345, …Run Code Online (Sandbox Code Playgroud)