fix boot 2 upgrade, rename package
This commit is contained in:
parent
340a502d7c
commit
412136b8db
|
@ -1,4 +1,4 @@
|
||||||
server.contextPath=/
|
server.servlet.contextPath=/
|
||||||
spring.h2.console.enabled=true
|
spring.h2.console.enabled=true
|
||||||
logging.level.org.hibernate.SQL=info
|
logging.level.org.hibernate.SQL=info
|
||||||
spring.jpa.hibernate.ddl-auto=none
|
spring.jpa.hibernate.ddl-auto=none
|
|
@ -1,3 +1,3 @@
|
||||||
server.port=8082
|
server.port=8082
|
||||||
server.servlet.context-path=/spring-rest-full
|
server.context-path=/spring-rest-full
|
||||||
endpoints.metrics.enabled=true
|
endpoints.metrics.enabled=true
|
|
@ -1,4 +1,4 @@
|
||||||
package org.baeldung.persistence.dao;
|
package com.baeldung.persistence.dao;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -8,10 +8,10 @@ import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.baeldung.web.util.SearchOperation;
|
|
||||||
import org.baeldung.web.util.SpecSearchCriteria;
|
|
||||||
import org.springframework.data.jpa.domain.Specification;
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
import org.springframework.data.jpa.domain.Specifications;
|
|
||||||
|
import com.baeldung.web.util.SearchOperation;
|
||||||
|
import com.baeldung.web.util.SpecSearchCriteria;
|
||||||
|
|
||||||
public class GenericSpecificationsBuilder<U> {
|
public class GenericSpecificationsBuilder<U> {
|
||||||
|
|
||||||
|
@ -61,11 +61,12 @@ public class GenericSpecificationsBuilder<U> {
|
||||||
for (int idx = 1; idx < specs.size(); idx++) {
|
for (int idx = 1; idx < specs.size(); idx++) {
|
||||||
result = params.get(idx)
|
result = params.get(idx)
|
||||||
.isOrPredicate()
|
.isOrPredicate()
|
||||||
? Specifications.where(result)
|
? Specification.where(result)
|
||||||
.or(specs.get(idx))
|
.or(specs.get(idx))
|
||||||
: Specifications.where(result)
|
: Specification.where(result)
|
||||||
.and(specs.get(idx));
|
.and(specs.get(idx));
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,10 +85,10 @@ public class GenericSpecificationsBuilder<U> {
|
||||||
Specification<U> operand1 = specStack.pop();
|
Specification<U> operand1 = specStack.pop();
|
||||||
Specification<U> operand2 = specStack.pop();
|
Specification<U> operand2 = specStack.pop();
|
||||||
if (mayBeOperand.equals(SearchOperation.AND_OPERATOR))
|
if (mayBeOperand.equals(SearchOperation.AND_OPERATOR))
|
||||||
specStack.push(Specifications.where(operand1)
|
specStack.push(Specification.where(operand1)
|
||||||
.and(operand2));
|
.and(operand2));
|
||||||
else if (mayBeOperand.equals(SearchOperation.OR_OPERATOR))
|
else if (mayBeOperand.equals(SearchOperation.OR_OPERATOR))
|
||||||
specStack.push(Specifications.where(operand1)
|
specStack.push(Specification.where(operand1)
|
||||||
.or(operand2));
|
.or(operand2));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package org.baeldung.persistence.dao;
|
package com.baeldung.persistence.dao;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.baeldung.persistence.model.User;
|
import com.baeldung.persistence.model.User;
|
||||||
import org.baeldung.web.util.SearchCriteria;
|
import com.baeldung.web.util.SearchCriteria;
|
||||||
|
|
||||||
public interface IUserDAO {
|
public interface IUserDAO {
|
||||||
List<User> searchUser(List<SearchCriteria> params);
|
List<User> searchUser(List<SearchCriteria> params);
|
|
@ -1,8 +1,7 @@
|
||||||
package org.baeldung.persistence.dao;
|
package com.baeldung.persistence.dao;
|
||||||
|
|
||||||
import org.baeldung.persistence.model.MyUser;
|
|
||||||
import org.baeldung.web.util.SearchCriteria;
|
|
||||||
|
|
||||||
|
import com.baeldung.persistence.model.MyUser;
|
||||||
|
import com.baeldung.web.util.SearchCriteria;
|
||||||
import com.querydsl.core.types.dsl.BooleanExpression;
|
import com.querydsl.core.types.dsl.BooleanExpression;
|
||||||
import com.querydsl.core.types.dsl.NumberPath;
|
import com.querydsl.core.types.dsl.NumberPath;
|
||||||
import com.querydsl.core.types.dsl.PathBuilder;
|
import com.querydsl.core.types.dsl.PathBuilder;
|
|
@ -1,12 +1,11 @@
|
||||||
package org.baeldung.persistence.dao;
|
package com.baeldung.persistence.dao;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.baeldung.web.util.SearchCriteria;
|
import com.baeldung.web.util.SearchCriteria;
|
||||||
|
|
||||||
import com.querydsl.core.types.dsl.BooleanExpression;
|
import com.querydsl.core.types.dsl.BooleanExpression;
|
||||||
import com.querydsl.core.types.dsl.Expressions;
|
import com.querydsl.core.types.dsl.Expressions;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package org.baeldung.persistence.dao;
|
package com.baeldung.persistence.dao;
|
||||||
|
|
||||||
import org.baeldung.persistence.model.MyUser;
|
|
||||||
import org.baeldung.persistence.model.QMyUser;
|
import org.baeldung.persistence.model.QMyUser;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
|
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
|
||||||
|
@ -8,6 +7,7 @@ import org.springframework.data.querydsl.binding.QuerydslBinderCustomizer;
|
||||||
import org.springframework.data.querydsl.binding.QuerydslBindings;
|
import org.springframework.data.querydsl.binding.QuerydslBindings;
|
||||||
import org.springframework.data.querydsl.binding.SingleValueBinding;
|
import org.springframework.data.querydsl.binding.SingleValueBinding;
|
||||||
|
|
||||||
|
import com.baeldung.persistence.model.MyUser;
|
||||||
import com.querydsl.core.types.dsl.StringExpression;
|
import com.querydsl.core.types.dsl.StringExpression;
|
||||||
import com.querydsl.core.types.dsl.StringPath;
|
import com.querydsl.core.types.dsl.StringPath;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.baeldung.persistence.dao;
|
package com.baeldung.persistence.dao;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -9,10 +9,11 @@ import javax.persistence.criteria.CriteriaQuery;
|
||||||
import javax.persistence.criteria.Predicate;
|
import javax.persistence.criteria.Predicate;
|
||||||
import javax.persistence.criteria.Root;
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.baeldung.persistence.model.User;
|
|
||||||
import org.baeldung.web.util.SearchCriteria;
|
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import com.baeldung.persistence.model.User;
|
||||||
|
import com.baeldung.web.util.SearchCriteria;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public class UserDAO implements IUserDAO {
|
public class UserDAO implements IUserDAO {
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
package org.baeldung.persistence.dao;
|
package com.baeldung.persistence.dao;
|
||||||
|
|
||||||
import org.baeldung.persistence.model.User;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
|
|
||||||
|
import com.baeldung.persistence.model.User;
|
||||||
|
|
||||||
public interface UserRepository extends JpaRepository<User, Long>, JpaSpecificationExecutor<User> {
|
public interface UserRepository extends JpaRepository<User, Long>, JpaSpecificationExecutor<User> {
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package org.baeldung.persistence.dao;
|
package com.baeldung.persistence.dao;
|
||||||
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ import javax.persistence.criteria.CriteriaBuilder;
|
||||||
import javax.persistence.criteria.Predicate;
|
import javax.persistence.criteria.Predicate;
|
||||||
import javax.persistence.criteria.Root;
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.baeldung.web.util.SearchCriteria;
|
import com.baeldung.web.util.SearchCriteria;
|
||||||
|
|
||||||
public class UserSearchQueryCriteriaConsumer implements Consumer<SearchCriteria>{
|
public class UserSearchQueryCriteriaConsumer implements Consumer<SearchCriteria>{
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
package org.baeldung.persistence.dao;
|
package com.baeldung.persistence.dao;
|
||||||
|
|
||||||
import org.baeldung.persistence.model.User;
|
|
||||||
import org.baeldung.web.util.SpecSearchCriteria;
|
|
||||||
import org.springframework.data.jpa.domain.Specification;
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
|
|
||||||
|
import com.baeldung.persistence.model.User;
|
||||||
|
import com.baeldung.web.util.SpecSearchCriteria;
|
||||||
|
|
||||||
import javax.persistence.criteria.CriteriaBuilder;
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
import javax.persistence.criteria.CriteriaQuery;
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
import javax.persistence.criteria.Predicate;
|
import javax.persistence.criteria.Predicate;
|
|
@ -1,14 +1,13 @@
|
||||||
package org.baeldung.persistence.dao;
|
package com.baeldung.persistence.dao;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import org.baeldung.persistence.model.User;
|
|
||||||
import org.baeldung.web.util.SearchOperation;
|
|
||||||
import org.baeldung.web.util.SpecSearchCriteria;
|
|
||||||
import org.springframework.data.jpa.domain.Specification;
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
import org.springframework.data.jpa.domain.Specifications;
|
|
||||||
|
import com.baeldung.persistence.model.User;
|
||||||
|
import com.baeldung.web.util.SearchOperation;
|
||||||
|
import com.baeldung.web.util.SpecSearchCriteria;
|
||||||
|
|
||||||
public final class UserSpecificationsBuilder {
|
public final class UserSpecificationsBuilder {
|
||||||
|
|
||||||
|
@ -52,8 +51,8 @@ public final class UserSpecificationsBuilder {
|
||||||
|
|
||||||
for (int i = 1; i < params.size(); i++) {
|
for (int i = 1; i < params.size(); i++) {
|
||||||
result = params.get(i).isOrPredicate()
|
result = params.get(i).isOrPredicate()
|
||||||
? Specifications.where(result).or(new UserSpecification(params.get(i)))
|
? Specification.where(result).or(new UserSpecification(params.get(i)))
|
||||||
: Specifications.where(result).and(new UserSpecification(params.get(i)));
|
: Specification.where(result).and(new UserSpecification(params.get(i)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
|
@ -1,4 +1,4 @@
|
||||||
package org.baeldung.persistence.dao.rsql;
|
package com.baeldung.persistence.dao.rsql;
|
||||||
|
|
||||||
import org.springframework.data.jpa.domain.Specification;
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package org.baeldung.persistence.dao.rsql;
|
package com.baeldung.persistence.dao.rsql;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.springframework.data.jpa.domain.Specifications;
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
|
|
||||||
import cz.jirutka.rsql.parser.ast.ComparisonNode;
|
import cz.jirutka.rsql.parser.ast.ComparisonNode;
|
||||||
import cz.jirutka.rsql.parser.ast.LogicalNode;
|
import cz.jirutka.rsql.parser.ast.LogicalNode;
|
||||||
|
@ -13,7 +13,7 @@ import cz.jirutka.rsql.parser.ast.Node;
|
||||||
|
|
||||||
public class GenericRsqlSpecBuilder<T> {
|
public class GenericRsqlSpecBuilder<T> {
|
||||||
|
|
||||||
public Specifications<T> createSpecification(final Node node) {
|
public Specification<T> createSpecification(final Node node) {
|
||||||
if (node instanceof LogicalNode) {
|
if (node instanceof LogicalNode) {
|
||||||
return createSpecification((LogicalNode) node);
|
return createSpecification((LogicalNode) node);
|
||||||
}
|
}
|
||||||
|
@ -23,31 +23,31 @@ public class GenericRsqlSpecBuilder<T> {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Specifications<T> createSpecification(final LogicalNode logicalNode) {
|
public Specification<T> createSpecification(final LogicalNode logicalNode) {
|
||||||
|
|
||||||
List<Specifications<T>> specs = logicalNode.getChildren()
|
List<Specification<T>> specs = logicalNode.getChildren()
|
||||||
.stream()
|
.stream()
|
||||||
.map(node -> createSpecification(node))
|
.map(node -> createSpecification(node))
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
Specifications<T> result = specs.get(0);
|
Specification<T> result = specs.get(0);
|
||||||
if (logicalNode.getOperator() == LogicalOperator.AND) {
|
if (logicalNode.getOperator() == LogicalOperator.AND) {
|
||||||
for (int i = 1; i < specs.size(); i++) {
|
for (int i = 1; i < specs.size(); i++) {
|
||||||
result = Specifications.where(result).and(specs.get(i));
|
result = Specification.where(result).and(specs.get(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (logicalNode.getOperator() == LogicalOperator.OR) {
|
else if (logicalNode.getOperator() == LogicalOperator.OR) {
|
||||||
for (int i = 1; i < specs.size(); i++) {
|
for (int i = 1; i < specs.size(); i++) {
|
||||||
result = Specifications.where(result).or(specs.get(i));
|
result = Specification.where(result).or(specs.get(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Specifications<T> createSpecification(final ComparisonNode comparisonNode) {
|
public Specification<T> createSpecification(final ComparisonNode comparisonNode) {
|
||||||
return Specifications.where(new GenericRsqlSpecification<T>(comparisonNode.getSelector(), comparisonNode.getOperator(), comparisonNode.getArguments()));
|
return Specification.where(new GenericRsqlSpecification<T>(comparisonNode.getSelector(), comparisonNode.getOperator(), comparisonNode.getArguments()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package org.baeldung.persistence.dao.rsql;
|
package com.baeldung.persistence.dao.rsql;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
|
@ -1,4 +1,4 @@
|
||||||
package org.baeldung.persistence.dao.rsql;
|
package com.baeldung.persistence.dao.rsql;
|
||||||
|
|
||||||
import cz.jirutka.rsql.parser.ast.ComparisonOperator;
|
import cz.jirutka.rsql.parser.ast.ComparisonOperator;
|
||||||
import cz.jirutka.rsql.parser.ast.RSQLOperators;
|
import cz.jirutka.rsql.parser.ast.RSQLOperators;
|
|
@ -1,4 +1,4 @@
|
||||||
package org.baeldung.persistence.model;
|
package com.baeldung.persistence.model;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import javax.persistence.GeneratedValue;
|
|
@ -1,4 +1,4 @@
|
||||||
package org.baeldung.persistence.model;
|
package com.baeldung.persistence.model;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import javax.persistence.GeneratedValue;
|
|
@ -1,4 +1,4 @@
|
||||||
package org.baeldung.persistence.model;
|
package com.baeldung.persistence.model;
|
||||||
|
|
||||||
import javax.persistence.metamodel.SingularAttribute;
|
import javax.persistence.metamodel.SingularAttribute;
|
||||||
import javax.persistence.metamodel.StaticMetamodel;
|
import javax.persistence.metamodel.StaticMetamodel;
|
|
@ -1,4 +1,4 @@
|
||||||
package org.baeldung.spring;
|
package com.baeldung.spring;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
|
@ -1,4 +1,4 @@
|
||||||
package org.baeldung.spring;
|
package com.baeldung.spring;
|
||||||
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.baeldung.spring;
|
package com.baeldung.spring;
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
@ -14,10 +14,6 @@ import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
||||||
@EnableWebMvc
|
@EnableWebMvc
|
||||||
public class WebConfig implements WebMvcConfigurer {
|
public class WebConfig implements WebMvcConfigurer {
|
||||||
|
|
||||||
public WebConfig() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public ViewResolver viewResolver() {
|
public ViewResolver viewResolver() {
|
||||||
final InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
|
final InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
|
|
@ -1,4 +1,4 @@
|
||||||
package org.baeldung.web.controller;
|
package com.baeldung.web.controller;
|
||||||
|
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
@ -1,23 +1,10 @@
|
||||||
package org.baeldung.web.controller;
|
package com.baeldung.web.controller;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.baeldung.persistence.dao.GenericSpecificationsBuilder;
|
|
||||||
import org.baeldung.persistence.dao.IUserDAO;
|
|
||||||
import org.baeldung.persistence.dao.MyUserPredicatesBuilder;
|
|
||||||
import org.baeldung.persistence.dao.MyUserRepository;
|
|
||||||
import org.baeldung.persistence.dao.UserRepository;
|
|
||||||
import org.baeldung.persistence.dao.UserSpecification;
|
|
||||||
import org.baeldung.persistence.dao.UserSpecificationsBuilder;
|
|
||||||
import org.baeldung.persistence.dao.rsql.CustomRsqlVisitor;
|
|
||||||
import org.baeldung.persistence.model.MyUser;
|
|
||||||
import org.baeldung.persistence.model.User;
|
|
||||||
import org.baeldung.web.util.CriteriaParser;
|
|
||||||
import org.baeldung.web.util.SearchCriteria;
|
|
||||||
import org.baeldung.web.util.SearchOperation;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.jpa.domain.Specification;
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
import org.springframework.data.querydsl.binding.QuerydslPredicate;
|
import org.springframework.data.querydsl.binding.QuerydslPredicate;
|
||||||
|
@ -31,6 +18,19 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||||
|
|
||||||
|
import com.baeldung.persistence.dao.GenericSpecificationsBuilder;
|
||||||
|
import com.baeldung.persistence.dao.IUserDAO;
|
||||||
|
import com.baeldung.persistence.dao.MyUserPredicatesBuilder;
|
||||||
|
import com.baeldung.persistence.dao.MyUserRepository;
|
||||||
|
import com.baeldung.persistence.dao.UserRepository;
|
||||||
|
import com.baeldung.persistence.dao.UserSpecification;
|
||||||
|
import com.baeldung.persistence.dao.UserSpecificationsBuilder;
|
||||||
|
import com.baeldung.persistence.dao.rsql.CustomRsqlVisitor;
|
||||||
|
import com.baeldung.persistence.model.MyUser;
|
||||||
|
import com.baeldung.persistence.model.User;
|
||||||
|
import com.baeldung.web.util.CriteriaParser;
|
||||||
|
import com.baeldung.web.util.SearchCriteria;
|
||||||
|
import com.baeldung.web.util.SearchOperation;
|
||||||
import com.google.common.base.Joiner;
|
import com.google.common.base.Joiner;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.querydsl.core.types.Predicate;
|
import com.querydsl.core.types.Predicate;
|
|
@ -1,8 +1,7 @@
|
||||||
package org.baeldung.web.error;
|
package com.baeldung.web.error;
|
||||||
|
|
||||||
import javax.persistence.EntityNotFoundException;
|
import javax.persistence.EntityNotFoundException;
|
||||||
|
|
||||||
import org.baeldung.web.exception.MyResourceNotFoundException;
|
|
||||||
import org.hibernate.exception.ConstraintViolationException;
|
import org.hibernate.exception.ConstraintViolationException;
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
import org.springframework.dao.DataIntegrityViolationException;
|
import org.springframework.dao.DataIntegrityViolationException;
|
||||||
|
@ -17,6 +16,8 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
import org.springframework.web.context.request.WebRequest;
|
import org.springframework.web.context.request.WebRequest;
|
||||||
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
|
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
|
||||||
|
|
||||||
|
import com.baeldung.web.exception.MyResourceNotFoundException;
|
||||||
|
|
||||||
@ControllerAdvice
|
@ControllerAdvice
|
||||||
public class RestResponseEntityExceptionHandler extends ResponseEntityExceptionHandler {
|
public class RestResponseEntityExceptionHandler extends ResponseEntityExceptionHandler {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.baeldung.web.exception;
|
package com.baeldung.web.exception;
|
||||||
|
|
||||||
public final class MyResourceNotFoundException extends RuntimeException {
|
public final class MyResourceNotFoundException extends RuntimeException {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.baeldung.web.util;
|
package com.baeldung.web.util;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
|
@ -1,4 +1,4 @@
|
||||||
package org.baeldung.web.util;
|
package com.baeldung.web.util;
|
||||||
|
|
||||||
public class SearchCriteria {
|
public class SearchCriteria {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.baeldung.web.util;
|
package com.baeldung.web.util;
|
||||||
|
|
||||||
public enum SearchOperation {
|
public enum SearchOperation {
|
||||||
EQUALITY, NEGATION, GREATER_THAN, LESS_THAN, LIKE, STARTS_WITH, ENDS_WITH, CONTAINS;
|
EQUALITY, NEGATION, GREATER_THAN, LESS_THAN, LIKE, STARTS_WITH, ENDS_WITH, CONTAINS;
|
|
@ -1,4 +1,4 @@
|
||||||
package org.baeldung.web.util;
|
package com.baeldung.web.util;
|
||||||
|
|
||||||
public class SpecSearchCriteria {
|
public class SpecSearchCriteria {
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
package org.baeldung;
|
package com.baeldung;
|
||||||
|
|
||||||
import org.baeldung.spring.Application;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
import com.baeldung.spring.Application;
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(classes = Application.class)
|
@SpringBootTest(classes = Application.class)
|
||||||
public class SpringContextIntegrationTest {
|
public class SpringContextIntegrationTest {
|
|
@ -1,4 +1,4 @@
|
||||||
package org.baeldung.persistence.query;
|
package com.baeldung.persistence.query;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.collection.IsIn.isIn;
|
import static org.hamcrest.collection.IsIn.isIn;
|
||||||
|
@ -7,10 +7,6 @@ import static org.hamcrest.core.IsNot.not;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.baeldung.persistence.dao.IUserDAO;
|
|
||||||
import org.baeldung.persistence.model.User;
|
|
||||||
import org.baeldung.spring.PersistenceConfig;
|
|
||||||
import org.baeldung.web.util.SearchCriteria;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
@ -20,6 +16,11 @@ import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import com.baeldung.persistence.dao.IUserDAO;
|
||||||
|
import com.baeldung.persistence.model.User;
|
||||||
|
import com.baeldung.spring.PersistenceConfig;
|
||||||
|
import com.baeldung.web.util.SearchCriteria;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(classes = { PersistenceConfig.class })
|
@ContextConfiguration(classes = { PersistenceConfig.class })
|
||||||
@Transactional
|
@Transactional
|
|
@ -1,4 +1,4 @@
|
||||||
package org.baeldung.persistence.query;
|
package com.baeldung.persistence.query;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.collection.IsEmptyIterable.emptyIterable;
|
import static org.hamcrest.collection.IsEmptyIterable.emptyIterable;
|
||||||
|
@ -6,10 +6,6 @@ import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInA
|
||||||
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
|
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
|
||||||
import static org.hamcrest.core.IsNot.not;
|
import static org.hamcrest.core.IsNot.not;
|
||||||
|
|
||||||
import org.baeldung.persistence.dao.MyUserPredicatesBuilder;
|
|
||||||
import org.baeldung.persistence.dao.MyUserRepository;
|
|
||||||
import org.baeldung.persistence.model.MyUser;
|
|
||||||
import org.baeldung.spring.PersistenceConfig;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
@ -19,6 +15,11 @@ import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import com.baeldung.persistence.dao.MyUserPredicatesBuilder;
|
||||||
|
import com.baeldung.persistence.dao.MyUserRepository;
|
||||||
|
import com.baeldung.persistence.model.MyUser;
|
||||||
|
import com.baeldung.spring.PersistenceConfig;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(classes = { PersistenceConfig.class })
|
@ContextConfiguration(classes = { PersistenceConfig.class })
|
||||||
@Transactional
|
@Transactional
|
|
@ -1,25 +1,25 @@
|
||||||
package org.baeldung.persistence.query;
|
package com.baeldung.persistence.query;
|
||||||
|
|
||||||
import org.baeldung.persistence.dao.GenericSpecificationsBuilder;
|
|
||||||
import org.baeldung.persistence.dao.UserRepository;
|
|
||||||
import org.baeldung.persistence.dao.UserSpecification;
|
|
||||||
import org.baeldung.persistence.dao.UserSpecificationsBuilder;
|
|
||||||
import org.baeldung.persistence.model.User;
|
|
||||||
import org.baeldung.spring.PersistenceConfig;
|
|
||||||
import org.baeldung.web.util.CriteriaParser;
|
|
||||||
import org.baeldung.web.util.SearchOperation;
|
|
||||||
import org.baeldung.web.util.SpecSearchCriteria;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.jpa.domain.Specification;
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
import org.springframework.data.jpa.domain.Specifications;
|
|
||||||
import org.springframework.test.annotation.Rollback;
|
import org.springframework.test.annotation.Rollback;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import com.baeldung.persistence.dao.GenericSpecificationsBuilder;
|
||||||
|
import com.baeldung.persistence.dao.UserRepository;
|
||||||
|
import com.baeldung.persistence.dao.UserSpecification;
|
||||||
|
import com.baeldung.persistence.dao.UserSpecificationsBuilder;
|
||||||
|
import com.baeldung.persistence.model.User;
|
||||||
|
import com.baeldung.spring.PersistenceConfig;
|
||||||
|
import com.baeldung.web.util.CriteriaParser;
|
||||||
|
import com.baeldung.web.util.SearchOperation;
|
||||||
|
import com.baeldung.web.util.SpecSearchCriteria;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ public class JPASpecificationIntegrationTest {
|
||||||
public void givenFirstAndLastName_whenGettingListOfUsers_thenCorrect() {
|
public void givenFirstAndLastName_whenGettingListOfUsers_thenCorrect() {
|
||||||
final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("firstName", SearchOperation.EQUALITY, "john"));
|
final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("firstName", SearchOperation.EQUALITY, "john"));
|
||||||
final UserSpecification spec1 = new UserSpecification(new SpecSearchCriteria("lastName", SearchOperation.EQUALITY, "doe"));
|
final UserSpecification spec1 = new UserSpecification(new SpecSearchCriteria("lastName", SearchOperation.EQUALITY, "doe"));
|
||||||
final List<User> results = repository.findAll(Specifications
|
final List<User> results = repository.findAll(Specification
|
||||||
.where(spec)
|
.where(spec)
|
||||||
.and(spec1));
|
.and(spec1));
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ public class JPASpecificationIntegrationTest {
|
||||||
@Test
|
@Test
|
||||||
public void givenFirstNameInverse_whenGettingListOfUsers_thenCorrect() {
|
public void givenFirstNameInverse_whenGettingListOfUsers_thenCorrect() {
|
||||||
final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("firstName", SearchOperation.NEGATION, "john"));
|
final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("firstName", SearchOperation.NEGATION, "john"));
|
||||||
final List<User> results = repository.findAll(Specifications.where(spec));
|
final List<User> results = repository.findAll(Specification.where(spec));
|
||||||
|
|
||||||
assertThat(userTom, isIn(results));
|
assertThat(userTom, isIn(results));
|
||||||
assertThat(userJohn, not(isIn(results)));
|
assertThat(userJohn, not(isIn(results)));
|
||||||
|
@ -136,7 +136,7 @@ public class JPASpecificationIntegrationTest {
|
||||||
@Test
|
@Test
|
||||||
public void givenMinAge_whenGettingListOfUsers_thenCorrect() {
|
public void givenMinAge_whenGettingListOfUsers_thenCorrect() {
|
||||||
final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("age", SearchOperation.GREATER_THAN, "25"));
|
final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("age", SearchOperation.GREATER_THAN, "25"));
|
||||||
final List<User> results = repository.findAll(Specifications.where(spec));
|
final List<User> results = repository.findAll(Specification.where(spec));
|
||||||
assertThat(userTom, isIn(results));
|
assertThat(userTom, isIn(results));
|
||||||
assertThat(userJohn, not(isIn(results)));
|
assertThat(userJohn, not(isIn(results)));
|
||||||
}
|
}
|
||||||
|
@ -170,7 +170,7 @@ public class JPASpecificationIntegrationTest {
|
||||||
public void givenAgeRange_whenGettingListOfUsers_thenCorrect() {
|
public void givenAgeRange_whenGettingListOfUsers_thenCorrect() {
|
||||||
final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("age", SearchOperation.GREATER_THAN, "20"));
|
final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("age", SearchOperation.GREATER_THAN, "20"));
|
||||||
final UserSpecification spec1 = new UserSpecification(new SpecSearchCriteria("age", SearchOperation.LESS_THAN, "25"));
|
final UserSpecification spec1 = new UserSpecification(new SpecSearchCriteria("age", SearchOperation.LESS_THAN, "25"));
|
||||||
final List<User> results = repository.findAll(Specifications
|
final List<User> results = repository.findAll(Specification
|
||||||
.where(spec)
|
.where(spec)
|
||||||
.and(spec1));
|
.and(spec1));
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
package org.baeldung.persistence.query;
|
package com.baeldung.persistence.query;
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import io.restassured.RestAssured;
|
import io.restassured.RestAssured;
|
||||||
import io.restassured.response.Response;
|
import io.restassured.response.Response;
|
||||||
|
|
||||||
import org.baeldung.persistence.model.User;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
|
|
||||||
|
import com.baeldung.persistence.model.User;
|
||||||
|
|
||||||
//@RunWith(SpringJUnit4ClassRunner.class)
|
//@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
//@ContextConfiguration(classes = { ConfigTest.class,
|
//@ContextConfiguration(classes = { ConfigTest.class,
|
||||||
// PersistenceConfig.class }, loader = AnnotationConfigContextLoader.class)
|
// PersistenceConfig.class }, loader = AnnotationConfigContextLoader.class)
|
|
@ -1,4 +1,4 @@
|
||||||
package org.baeldung.persistence.query;
|
package com.baeldung.persistence.query;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.collection.IsIn.isIn;
|
import static org.hamcrest.collection.IsIn.isIn;
|
||||||
|
@ -6,10 +6,6 @@ import static org.hamcrest.core.IsNot.not;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.baeldung.persistence.dao.UserRepository;
|
|
||||||
import org.baeldung.persistence.dao.rsql.CustomRsqlVisitor;
|
|
||||||
import org.baeldung.persistence.model.User;
|
|
||||||
import org.baeldung.spring.PersistenceConfig;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
@ -20,6 +16,11 @@ import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import com.baeldung.persistence.dao.UserRepository;
|
||||||
|
import com.baeldung.persistence.dao.rsql.CustomRsqlVisitor;
|
||||||
|
import com.baeldung.persistence.model.User;
|
||||||
|
import com.baeldung.spring.PersistenceConfig;
|
||||||
|
|
||||||
import cz.jirutka.rsql.parser.RSQLParser;
|
import cz.jirutka.rsql.parser.RSQLParser;
|
||||||
import cz.jirutka.rsql.parser.ast.Node;
|
import cz.jirutka.rsql.parser.ast.Node;
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
package org.baeldung.web;
|
package com.baeldung.web;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import io.restassured.RestAssured;
|
import io.restassured.RestAssured;
|
||||||
import io.restassured.response.Response;
|
import io.restassured.response.Response;
|
||||||
import io.restassured.specification.RequestSpecification;
|
import io.restassured.specification.RequestSpecification;
|
||||||
|
|
||||||
import org.baeldung.persistence.model.MyUser;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
|
|
||||||
|
import com.baeldung.persistence.model.MyUser;
|
||||||
|
|
||||||
@ActiveProfiles("test")
|
@ActiveProfiles("test")
|
||||||
public class MyUserLiveTest {
|
public class MyUserLiveTest {
|
||||||
|
|
Loading…
Reference in New Issue