QueryDSL减去日期

时间:2015-12-28 15:58:30

标签: java mysql date querydsl

我想在状态为0的表间隔的元素中将字段state更新为1,并且相关延迟小于表Mm的参数化时间戳的减法以及表的相关时间戳EventPackage。这将是查询:

select * from intervals i
join eventpackage e on i.end = e.eventpackage_id
join mm m on i.state = 0 and i.mm_id = m.mm_id
where i.state = 0
and m.latency < (<timestamp_parametrized> - e.timestamp);

我正在尝试使用QueryDSL,但Date sub。

有问题
QInterval interval = QInterval.interval;
QEventPackage eventpackage = QEventPackage.eventPackage;
QMaintenanceMessage mm = QMaintenanceMessage.maintenanceMessage;
JPAQuery<?> query = new JPAQuery<Void>(em);

BooleanExpression ideq0 = interval.state.eq(0);     

// Actual timestamp less interval.end timestamp
SimpleOperation<Long> a = Expressions.operation(Long.class, Ops.SUB, 
                Expressions.constant(<timestamp_parametrized>), eventpackage.timestamp);    

new JPAUpdateClause(em, interval).where(interval.in((List<Interval>) query.from(interval)
                    .innerJoin(interval.end,eventpackage)
                    .innerJoin(interval.mm,mm)
                    .where(ideq0.and(mm.latency.lt(a)))
                    .fetchResults().getResults())).set(interval.state,Expressions.constant(1)).execute();

如何使用Java参数和Date创建一个Date子,以便在几毫秒内获得正确的长度?感谢。

0 个答案:

没有答案