Skip to content

Library for convenient reuse of joins when building queries using Spring Data Specifications

License

Notifications You must be signed in to change notification settings

koval666/springspecwrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring spec wrapper

Library for convenient reuse of joins when building queries using Spring Data Specifications

Inspired by this stackoverflow question: link to question

Maven:

<dependency>
    <groupId>ru.teadev</groupId>
    <artifactId>springspecwrapper</artifactId>
    <version>1.4.0</version>
</dependency>

Usage example:

public List<Task> findTasks(TaskFilterDto taskFilterDto) {

    Specification<Task> specification =
            where(specs.distinct(Task.class))

                    .and(specs.attributeEquals(
                            Task_.name,
                            taskFilterDto.getTaskName()))

                    .and(specs.attributeGreaterOrEquals(
                            single(join(Task_.employee)),
                            Employee_.salary,
                            taskFilterDto.getEmployeeSalaryGTE()))

                    .and(specs.attributeInOneOfRanges(
                            chain(join(Task_.employee), //the first created join will be reused
                                    join(Employee_.company)),
                            Company_.rating,
                            taskFilterDto.getCompanyRatingRanges()
                    ))

                    .and(specs.orderBy(
                            single(join(Task_.employee)), //the first created join will be reused
                            Employee_.birthDate,
                            Direction.ASC,
                            Nulls.LAST
                    ));

    return taskRepository.findAll(specification);
}

link to code

About

Library for convenient reuse of joins when building queries using Spring Data Specifications

Topics

Resources

License

Stars

Watchers

Forks

Languages