mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-13 21:01:01 +08:00
Improve validation logic
This commit is contained in:
parent
119411c359
commit
4deee3125b
@ -13,31 +13,17 @@
|
||||
*/
|
||||
package com.mysema.query;
|
||||
|
||||
import static com.mysema.query.util.CollectionUtils.add;
|
||||
import static com.mysema.query.util.CollectionUtils.addSorted;
|
||||
import static com.mysema.query.util.CollectionUtils.copyOf;
|
||||
import static com.mysema.query.util.CollectionUtils.copyOfSorted;
|
||||
import static com.mysema.query.util.CollectionUtils.put;
|
||||
import static com.mysema.query.util.CollectionUtils.removeSorted;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.mysema.query.types.Expression;
|
||||
import com.mysema.query.types.ExpressionUtils;
|
||||
import com.mysema.query.types.OrderSpecifier;
|
||||
import com.mysema.query.types.ParamExpression;
|
||||
import com.mysema.query.types.ParamsVisitor;
|
||||
import com.mysema.query.types.Path;
|
||||
import com.mysema.query.types.Predicate;
|
||||
import com.mysema.query.types.ValidatingVisitor;
|
||||
import com.mysema.query.types.*;
|
||||
import static com.mysema.query.util.CollectionUtils.*;
|
||||
|
||||
/**
|
||||
* DefaultQueryMetadata is the default implementation of the {@link QueryMetadata} interface
|
||||
@ -128,7 +114,8 @@ public class DefaultQueryMetadata implements QueryMetadata, Cloneable {
|
||||
@Override
|
||||
public void addGroupBy(Expression<?> o) {
|
||||
addLastJoin();
|
||||
validate(o);
|
||||
// group by elements can't be validated, since they can refer to projection elements
|
||||
// that are declared later
|
||||
groupBy = add(groupBy, o);
|
||||
}
|
||||
|
||||
|
||||
@ -13,19 +13,15 @@
|
||||
*/
|
||||
package com.mysema.query;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.mysema.query.QueryFlag.Position;
|
||||
import com.mysema.query.types.ConstantImpl;
|
||||
import com.mysema.query.types.Predicate;
|
||||
import com.mysema.query.types.expr.Param;
|
||||
import com.mysema.query.types.path.StringPath;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class DefaultQueryMetadataTest {
|
||||
|
||||
@ -58,7 +54,7 @@ public class DefaultQueryMetadataTest {
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void Validation() {
|
||||
metadata.addGroupBy(str);
|
||||
metadata.addWhere(str.isNull());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@ -571,6 +571,15 @@ public class SelectBase extends AbstractBaseTest {
|
||||
.list(employee.id.count());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void GroupBy_Validate() {
|
||||
NumberPath<BigDecimal> alias = new NumberPath<BigDecimal>(BigDecimal.class, "alias");
|
||||
query().from(employee)
|
||||
.groupBy(alias)
|
||||
.list(employee.salary.multiply(100).as(alias),
|
||||
employee.salary.avg());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void IllegalUnion() throws SQLException {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user