sample_clause
sample_clause可让您指示数据库从表的随机样本中进行选择,而不是从整个表中进行选择。
我想使用QueryDSL在查询下面运行
sample_clause
sample_clause允许您指示数据库从表的随机数据样本中进行选择,而不是从整个表中进行选择。
从测试t SAMPLE(80)中选择 t.test_id = 01和t.test_suite_id = 02 ;
条件是动态的,我正在使用queryDSL生成它,但是我不知道如何在DSL中添加SAMPLE关键字。
public Long getCount(TestDTO testDTO) {
JPAQuery<Tuple> query = new JPAQuery<>(entityManager);
QTest qTest=QTest.test;
//dynamic where condition.
OptionalBooleanBuilder where = buildCondition(testDTO);
List<BigDecimal> output=query
.select(qTest.testId)
.from(qTest)
.where(where.build()).fetch();
//finally return the output.
}
答案 0 :(得分:0)
SAMPLE
是数据库方言专用功能,JPPA(JPA的查询语言)中不提供该功能。因此,您需要使用ORM实现为您的方言注册一个自定义函数。您可以使用custom functions自己注册这些功能。
但是,此后,这些功能仍无法在QueryDSL中访问。为此,您必须实现自定义Operation
的实现,并将其与JPQLTemplates
的子类中的“模板”相关联。另外,您可以创建一个TemplateExpression
内联:Expressions.template(Integer.class, "SAMPLE({0})", arg1)
。