Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ import org.springframework.data.jpa.domain.Specification;
public class GuitarPedalSpecifications {

public Specification<GuitarPedal> pedalsNotSoldWithValueGreaterThan(final Integer usedValue) {
return SpecificationBuilder.withRoot(GuitarPedal.class)
return SpecificationBuilder.from(GuitarPedal.class)
.where().isNull(GuitarPedal_.dateSold)
.and().isGreaterThan(GuitarPedal_.usedValue, usedValue)
.toSpecification();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ public SpecificationBuilder() {
// no-op
}

@Deprecated
public static <T> SpecificationBuilder<T> withRoot(final Class<T> root) {
return from(root);
}

public static <T> SpecificationBuilder<T> from(final Class<T> root) {
Objects.requireNonNull(root, "Argument 'root' cannot be null.");
return new SpecificationBuilder<>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ void andWhere() {
@Test
void where_withSpecification() {
var pedals = guitarPedalRepository.findAll(
SpecificationBuilder.withRoot(GuitarPedal.class)
.where(SpecificationBuilder.withRoot(GuitarPedal.class)
SpecificationBuilder.from(GuitarPedal.class)
.where(SpecificationBuilder.from(GuitarPedal.class)
.where().isNull(GuitarPedal_.dateSold)
.toSpecification())
.and().isLike(GuitarPedal_.name, "%and%")
Expand All @@ -285,9 +285,9 @@ void where_withSpecification() {
@Test
void and_withSpecification() {
var pedals = guitarPedalRepository.findAll(
SpecificationBuilder.withRoot(GuitarPedal.class)
SpecificationBuilder.from(GuitarPedal.class)
.where().isLike(GuitarPedal_.name, "%and%")
.and(SpecificationBuilder.withRoot(GuitarPedal.class)
.and(SpecificationBuilder.from(GuitarPedal.class)
.where().isNull(GuitarPedal_.dateSold)
.toSpecification())
.toSpecification(), Sort.by("name"));
Expand All @@ -300,9 +300,9 @@ void and_withSpecification() {
@Test
void or_withSpecification() {
var pedals = guitarPedalRepository.findAll(
SpecificationBuilder.withRoot(GuitarPedal.class)
SpecificationBuilder.from(GuitarPedal.class)
.where().isEqualTo(GuitarPedal_.id, 2L)
.or(SpecificationBuilder.withRoot(GuitarPedal.class)
.or(SpecificationBuilder.from(GuitarPedal.class)
.where().isEqualTo(GuitarPedal_.id, 3L)
.toSpecification())
.toSpecification(), Sort.by("name"));
Expand All @@ -316,7 +316,7 @@ void or_withSpecification() {
@Test
void isEqualTo() {
var optionalPedal = guitarPedalRepository.findOne(
SpecificationBuilder.withRoot(GuitarPedal.class)
SpecificationBuilder.from(GuitarPedal.class)
.isEqualTo(GuitarPedal_.id, 3L)
.toSpecification());
assertTrue(optionalPedal.isPresent());
Expand All @@ -327,7 +327,7 @@ void isEqualTo() {
@Test
void isNotEqualTo() {
var pedals = guitarPedalRepository.findAll(
SpecificationBuilder.withRoot(GuitarPedal.class)
SpecificationBuilder.from(GuitarPedal.class)
.isNotEqualTo(GuitarPedal_.id, 3L)
.toSpecification());
assertEquals(3, pedals.size());
Expand All @@ -340,7 +340,7 @@ void isNotEqualTo() {
@Test
void isLike() {
var pedals = guitarPedalRepository.findAll(
SpecificationBuilder.withRoot(GuitarPedal.class)
SpecificationBuilder.from(GuitarPedal.class)
.isLike(GuitarPedal_.name, "%and%")
.toSpecification(), Sort.by("name"));
assertEquals(2, pedals.size());
Expand All @@ -351,7 +351,7 @@ void isLike() {
@Test
void isNotLike() {
var pedals = guitarPedalRepository.findAll(
SpecificationBuilder.withRoot(GuitarPedal.class)
SpecificationBuilder.from(GuitarPedal.class)
.isNotLike(GuitarPedal_.name, "%and%")
.toSpecification(), Sort.by("name"));
assertEquals(2, pedals.size());
Expand All @@ -361,7 +361,7 @@ void isNotLike() {

@Test
void isEqualToOrLike() {
var pedals = guitarPedalRepository.findAll(SpecificationBuilder.withRoot(GuitarPedal.class)
var pedals = guitarPedalRepository.findAll(SpecificationBuilder.from(GuitarPedal.class)
.isEqualToOrLike(GuitarPedal_.name, "Deco%")
.toSpecification(), Sort.by("name"));
assertEquals(1, pedals.size());
Expand All @@ -371,7 +371,7 @@ void isEqualToOrLike() {
@Test
void isNull() {
var pedals = guitarPedalRepository.findAll(
SpecificationBuilder.withRoot(GuitarPedal.class)
SpecificationBuilder.from(GuitarPedal.class)
.isNull(GuitarPedal_.dateSold)
.toSpecification(), Sort.by("name"));
assertEquals(3, pedals.size());
Expand All @@ -386,7 +386,7 @@ void isNull() {
@Test
void isNotNull() {
var pedals = guitarPedalRepository.findAll(
SpecificationBuilder.withRoot(GuitarPedal.class)
SpecificationBuilder.from(GuitarPedal.class)
.isNotNull(GuitarPedal_.dateSold)
.toSpecification(), Sort.by("name"));
assertEquals(1, pedals.size());
Expand All @@ -397,7 +397,7 @@ void isNotNull() {
@Test
void isTrue() {
var pedals = guitarPedalRepository.findAll(
SpecificationBuilder.withRoot(GuitarPedal.class)
SpecificationBuilder.from(GuitarPedal.class)
.isTrue(GuitarPedal_.hasStereoOutput)
.toSpecification(), Sort.by("name"));
assertEquals(1, pedals.size());
Expand All @@ -409,7 +409,7 @@ void isTrue() {
@Test
void isFalse() {
var pedals = guitarPedalRepository.findAll(
SpecificationBuilder.withRoot(GuitarPedal.class)
SpecificationBuilder.from(GuitarPedal.class)
.isFalse(GuitarPedal_.hasStereoOutput)
.toSpecification(), Sort.by("name"));
assertEquals(3, pedals.size());
Expand All @@ -424,7 +424,7 @@ void isFalse() {
@Test
void isGreaterThan() {
var pedals = guitarPedalRepository.findAll(
SpecificationBuilder.withRoot(GuitarPedal.class)
SpecificationBuilder.from(GuitarPedal.class)
.isGreaterThan(GuitarPedal_.usedValue, 200)
.toSpecification(), Sort.by("name"));
assertEquals(1, pedals.size());
Expand All @@ -435,7 +435,7 @@ void isGreaterThan() {
@Test
void isGreaterThanOrEqualTo() {
var pedals = guitarPedalRepository.findAll(
SpecificationBuilder.withRoot(GuitarPedal.class)
SpecificationBuilder.from(GuitarPedal.class)
.isGreaterThanOrEqualTo(GuitarPedal_.usedValue, 200)
.toSpecification(), Sort.by("name"));
assertEquals(2, pedals.size());
Expand All @@ -448,7 +448,7 @@ void isGreaterThanOrEqualTo() {
@Test
void isLessThan() {
var pedals = guitarPedalRepository.findAll(
SpecificationBuilder.withRoot(GuitarPedal.class)
SpecificationBuilder.from(GuitarPedal.class)
.isLessThan(GuitarPedal_.usedValue, 150)
.toSpecification(), Sort.by("name"));
assertEquals(1, pedals.size());
Expand All @@ -459,7 +459,7 @@ void isLessThan() {
@Test
void isLessThanOrEqualTo() {
var pedals = guitarPedalRepository.findAll(
SpecificationBuilder.withRoot(GuitarPedal.class)
SpecificationBuilder.from(GuitarPedal.class)
.isLessThanOrEqualTo(GuitarPedal_.usedValue, 150)
.toSpecification(), Sort.by("name"));
assertEquals(2, pedals.size());
Expand All @@ -472,7 +472,7 @@ void isLessThanOrEqualTo() {
@Test
void isBetween() {
var pedals = guitarPedalRepository.findAll(
SpecificationBuilder.withRoot(GuitarPedal.class)
SpecificationBuilder.from(GuitarPedal.class)
.isBetween(
GuitarPedal_.datePurchased,
LocalDate.of(2021, 7, 19),
Expand All @@ -488,7 +488,7 @@ void isBetween() {
@Test
void isIn_collection() {
var pedals = guitarPedalRepository.findAll(
SpecificationBuilder.withRoot(GuitarPedal.class)
SpecificationBuilder.from(GuitarPedal.class)
.isIn(GuitarPedal_.id, List.of(2L, 3L))
.toSpecification(), Sort.by("name"));
assertEquals(2, pedals.size());
Expand All @@ -501,7 +501,7 @@ void isIn_collection() {
@Test
void isIn_array() {
var pedals = guitarPedalRepository.findAll(
SpecificationBuilder.withRoot(GuitarPedal.class)
SpecificationBuilder.from(GuitarPedal.class)
.isIn(GuitarPedal_.id, 2L, 3L)
.toSpecification(), Sort.by("name"));
assertEquals(2, pedals.size());
Expand Down
Loading