本文整理了Java中org.infinispan.query.dsl.Query
类的一些代码示例,展示了Query
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query
类的具体详情如下:
包路径:org.infinispan.query.dsl.Query
类名称:Query
[英]An immutable object representing both the query and the result. The result is obtained lazily when one of the methods in this interface is executed first time. The query is executed only once. Further calls will just return the previously cached results. If you intend to re-execute the query to obtain fresh data you need to build another instance using a QueryBuilder.
[中]表示查询和结果的不可变对象。当第一次执行此接口中的一个方法时,将延迟获得结果。查询只执行一次。进一步的调用只会返回以前缓存的结果。如果要重新执行查询以获取新数据,则需要使用QueryBuilder构建另一个实例。
代码示例来源:origin: org.infinispan/infinispan-query
@Test(expectedExceptions = ParsingException.class, expectedExceptionsMessageRegExp = "ISPN028515: Cannot have aggregate functions in the WHERE clause : SUM.")
public void testDisallowAggregatesInWhereClause() {
Query q = buildQuery("select name from org.infinispan.query.dsl.embedded.testdomain.hsearch.UserHS where sum(age) > 33 group by name");
q.list();
}
代码示例来源:origin: org.infinispan/infinispan-query
public void testUnorderedPagination5() {
QueryFactory qf = getQueryFactory();
Query q = qf.from(getModelFactory().getUserImplClass())
.startOffset(20)
.build();
List<User> list = q.list();
assertEquals(3, q.getResultSize());
assertEquals(0, list.size());
}
代码示例来源:origin: org.infinispan/infinispan-query
public void testParam() {
Query q = createQueryFromString("from " + getModelFactory().getTransactionTypeName() + " where id = :idParam");
q.setParameter("idParam", 1);
List<Transaction> list = q.list();
assertEquals(1, list.size());
assertEquals(1, list.get(0).getId());
q.setParameter("idParam", 2);
list = q.list();
assertEquals(1, list.size());
assertEquals(2, list.get(0).getId());
}
代码示例来源:origin: org.infinispan/infinispan-query
/**
* Create an event filter out of an Ickle query.
*/
public static <K, V> CacheEventFilterConverter<K, V, ObjectFilter.FilterResult> makeFilter(Query query) {
return makeFilter(query.getQueryString(), query.getParameters());
}
代码示例来源:origin: org.infinispan/infinispan-query
@Test(expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "ISPN014825: Query parameter 'param2' was not set")
public void testMissingParamWithParameterMap() {
QueryFactory qf = getQueryFactory();
Query q = qf.from(getModelFactory().getUserImplClass())
.having("name").eq(param("param1"))
.and().having("gender").eq(param("param2"))
.build();
Map<String, Object> parameterMap = new HashMap<>(1);
parameterMap.put("param1", "John");
q.setParameters(parameterMap);
q.list();
}
代码示例来源:origin: org.hibernate.ogm/hibernate-ogm-infinispan-remote
private void applyNamedParameters(QueryParameters queryParameters, Query query) {
for ( Map.Entry<String, TypedGridValue> param : queryParameters.getNamedParameters().entrySet() ) {
query.setParameter( param.getKey(), getValue( param ) );
}
}
代码示例来源:origin: org.infinispan/infinispan-query
@Test(expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "ISPN014804: Query does not have parameters")
public void testQueryWithNoParams() {
QueryFactory qf = getQueryFactory();
qf.from(getModelFactory().getUserImplClass())
.having("name").eq("John")
.build()
.setParameter("param1", "John");
}
代码示例来源:origin: org.infinispan/infinispan-query
@Test(expectedExceptions = ParsingException.class, expectedExceptionsMessageRegExp = "ISPN014026: The expression 'name' must be part of an aggregate function or it should be included in the GROUP BY clause")
public void testDisallowNonAggregatedProjectionWithGlobalAggregation() {
Query q = buildQuery("select name, count(name) from org.infinispan.query.dsl.embedded.testdomain.hsearch.UserHS");
q.list();
}
代码示例来源:origin: org.infinispan/infinispan-query
public void testUnorderedPagination4() {
QueryFactory qf = getQueryFactory();
Query q = qf.from(getModelFactory().getUserImplClass())
.maxResults(5)
.build();
List<User> list = q.list();
assertEquals(3, q.getResultSize());
assertEquals(3, list.size());
}
代码示例来源:origin: org.infinispan/infinispan-query
public void testDateParam() throws Exception {
QueryFactory qf = getQueryFactory();
Query q = qf.from(getModelFactory().getAccountImplClass())
.having("creationDate").eq(param("param1"))
.build().setParameter("param1", makeDate("2013-01-03"));
List<Account> list = q.list();
assertEquals(1, list.size());
assertEquals(1, list.get(0).getId());
}
代码示例来源:origin: org.infinispan/infinispan-query
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "ISPN014803: Parameter name cannot be null or empty")
public void testNullParamName() {
QueryFactory qf = getQueryFactory();
Query q = qf.from(getModelFactory().getUserImplClass())
.having("name").eq(param(null))
.build();
q.setParameter(null, "John");
}
代码示例来源:origin: org.infinispan/infinispan-query
@Test(expectedExceptions = ParsingException.class, expectedExceptionsMessageRegExp = "ISPN028516: Cannot have aggregate functions in the GROUP BY clause : SUM.")
public void testDisallowAggregationInGroupBy() {
Query q = buildQuery("select sum(age) from org.infinispan.query.dsl.embedded.testdomain.hsearch.UserHS group by sum(age) ");
q.list();
}
代码示例来源:origin: org.infinispan/infinispan-query
private void executeQueries() {
String q = getQuery();
caches().forEach(c -> {
Query allNodesQuery = Search.getQueryFactory(c).create(q, getIndexedQueryMode());
assertAllNodesQueryResults(allNodesQuery.getResultSize());
});
Query singleNodeQuery = Search.getQueryFactory(cache(0)).create(q);
assertSingleNodeQueryResults(singleNodeQuery.list().size());
}
代码示例来源:origin: org.infinispan/infinispan-query
@Test(expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "ISPN014825: Query parameter 'param2' was not set")
public void testMissingParam() {
QueryFactory qf = getQueryFactory();
Query q = qf.from(getModelFactory().getUserImplClass())
.having("name").eq(param("param1"))
.and().having("gender").eq(param("param2"))
.build();
q.setParameter("param1", "John");
q.list();
}
代码示例来源:origin: org.infinispan/infinispan-query
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "ISPN014805: No parameter named 'param2' was found")
public void testUnknownParam() {
QueryFactory qf = getQueryFactory();
Query q = qf.from(getModelFactory().getUserImplClass())
.having("name").eq(param("param1"))
.build();
q.setParameter("param2", "John");
}
代码示例来源:origin: org.infinispan/infinispan-query
@Test(expectedExceptions = ParsingException.class, expectedExceptionsMessageRegExp = "ISPN014026: The expression 'age' must be part of an aggregate function or it should be included in the GROUP BY clause")
public void testHavingClauseAllowsAggregationsAndGroupByColumnsOnly() {
Query q = buildQuery("select name from org.infinispan.query.dsl.embedded.testdomain.hsearch.UserHS group by name having age >= 18");
q.list();
}
代码示例来源:origin: org.infinispan/infinispan-query
public void testUnorderedPagination7() {
QueryFactory qf = getQueryFactory();
Query q = qf.from(getModelFactory().getUserImplClass())
.startOffset(1).maxResults(10)
.build();
List<User> list = q.list();
assertEquals(3, q.getResultSize());
assertEquals(2, list.size());
}
代码示例来源:origin: org.infinispan/infinispan-query
public void testEqHybridQueryWithParam() {
QueryFactory qf = getQueryFactory();
Query q = qf.from(getModelFactory().getUserImplClass())
.having("notes").eq("Lorem ipsum dolor sit amet")
.and().having("surname").eq(param("surnameParam"))
.build();
q.setParameter("surnameParam", "Doe");
List<User> list = q.list();
assertEquals(1, list.size());
assertEquals(1, list.get(0).getId());
}
代码示例来源:origin: org.infinispan/infinispan-query
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "ISPN014803: Parameter name cannot be null or empty")
public void testEmptyParamName() {
QueryFactory qf = getQueryFactory();
Query q = qf.from(getModelFactory().getUserImplClass())
.having("name").eq(param(""))
.build();
q.setParameter("", "John");
}
代码示例来源:origin: org.infinispan/infinispan-query
public void testGrouping() {
Query q = buildQuery("select name from org.infinispan.query.dsl.embedded.testdomain.hsearch.UserHS " +
"where surname is not null group by name having name >= 'A'");
List<User> list = q.list();
assertEquals(2, list.size());
}
内容来源于网络,如有侵权,请联系作者删除!