Skip to content

Commit 747c264

Browse files
authored
Merge pull request #23994 from OpenLiberty/revert-23919-22673-filter-with-or
Revert "filter with OR"
2 parents 478203c + ecb2fd0 commit 747c264

File tree

7 files changed

+13
-161
lines changed

7 files changed

+13
-161
lines changed

dev/io.openliberty.data.internal.persistence/src/io/openliberty/data/internal/persistence/RepositoryImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,7 @@ private StringBuilder generateWhereClause(QueryInfo queryInfo, Filter[] filters)
11381138
if (first)
11391139
first = false;
11401140
else
1141-
q.append(' ').append(filter.as().name()).append(' '); // AND / OR between conditions
1141+
q.append(" AND ");
11421142

11431143
String attribute = filter.by();
11441144
boolean ignoreCase = filter.ignoreCase();

dev/io.openliberty.data.internal_fat/test-applications/DataTestApp/src/test/jakarta/data/web/DataTestServlet.java

Lines changed: 5 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -2365,7 +2365,7 @@ public void testPartialQueryAnnotations() {
23652365

23662366
Shipment s5 = new Shipment();
23672367
s5.destination = "201 4th St SE, Rochester, MN 55904";
2368-
s5.location = "2800 37th St NW, Rochester, MN 55901";
2368+
s5.location = " 2800 37th St NW, Rochester, MN 55901";
23692369
s5.id = 5;
23702370
s5.orderedAt = OffsetDateTime.now().minusSeconds(50);
23712371
s5.status = "PREPARING";
@@ -2399,23 +2399,15 @@ public void testPartialQueryAnnotations() {
23992399
assertEquals(true, shipments.cancel(5, OffsetDateTime.now()));
24002400
assertEquals(false, shipments.cancel(10, OffsetDateTime.now()));
24012401

2402+
shipments.trim();
2403+
s = shipments.find(4);
2404+
assertEquals("2800 37th St NW, Rochester, MN 55901", s.location);
2405+
24022406
assertEquals(2, shipments.removeCanceled());
24032407

24042408
assertEquals(3, shipments.removeEverything());
24052409
}
24062410

2407-
/**
2408-
* Use a repository method that has both AND and OR keywords.
2409-
* The AND keywords should take precedence over OR and be computed first.
2410-
*/
2411-
@Test
2412-
public void testPrecedenceOfAndOverOr() {
2413-
assertIterableEquals(List.of(41L, 37L, 31L, 11L, 7L),
2414-
primes.lessThanWithSuffixOrBetweenWithSuffix(40L, "even", 30L, 50L, "one")
2415-
.map(p -> p.number)
2416-
.collect(Collectors.toList()));
2417-
}
2418-
24192411
/**
24202412
* Use the provided methods of a Repository<T, K> interface that is a copy of Jakarta NoSQL's.
24212413
*/
@@ -3633,106 +3625,6 @@ public void testTotalCountsWithKeysetPagination() {
36333625
assertEquals(null, page4.nextPageable());
36343626
}
36353627

3636-
/**
3637-
* Update multiple entries.
3638-
*/
3639-
@Test
3640-
public void testUpdateAnnotation() {
3641-
products.clear();
3642-
3643-
Product prod1 = new Product();
3644-
prod1.id = "UPD-ANNO-1";
3645-
prod1.name = "Fairly Priced TestUpdateAnnotation Item";
3646-
prod1.price = 5.00f;
3647-
products.save(prod1);
3648-
3649-
Product prod2 = new Product();
3650-
prod2.id = "UPD-ANNO-2";
3651-
prod2.name = "Highly Priced TestUpdateAnnotation Item";
3652-
prod2.price = 100.00f;
3653-
products.save(prod2);
3654-
3655-
Product prod3 = new Product();
3656-
prod3.id = "UPD-ANNO-3";
3657-
prod3.name = "Middle Priced TestUpdateAnnotation Item";
3658-
prod3.price = 40.00f;
3659-
products.save(prod3);
3660-
3661-
Product prod4 = new Product();
3662-
prod4.id = "UPD-ANNO-4";
3663-
prod4.name = "Inexpensive TestUpdateAnnotation Item";
3664-
prod4.price = 2.00f;
3665-
products.save(prod4);
3666-
3667-
Product prod5 = new Product();
3668-
prod5.id = "UPD-ANNO-5";
3669-
prod5.name = "Ridiculously High Priced TestUpdateAnnotation Item";
3670-
prod5.price = 500.00f;
3671-
products.save(prod5);
3672-
3673-
Product prod6 = new Product();
3674-
prod6.id = "UPD-ANNO-6";
3675-
prod6.name = "Lowest Priced TestUpdateAnnotation Item";
3676-
prod6.price = 1.00f;
3677-
products.save(prod6);
3678-
3679-
assertEquals(true, products.isNotEmpty());
3680-
assertEquals(6, products.total());
3681-
3682-
assertEquals(5, products.inflatePrices("Priced TestUpdateAnnotation Item", 1.07f)); // prod4 does not match
3683-
3684-
Product[] found = products.findByVersionGreaterThanEqualOrderByPrice(2);
3685-
3686-
assertEquals(Stream.of(found).map(p -> p.id).collect(Collectors.toList()).toString(),
3687-
5, found.length);
3688-
3689-
assertEquals(1.07f, found[0].price, 0.001f);
3690-
assertEquals(5.35f, found[1].price, 0.001f);
3691-
assertEquals(42.80f, found[2].price, 0.001f);
3692-
assertEquals(107.00f, found[3].price, 0.001f);
3693-
assertEquals(535.00f, found[4].price, 0.001f);
3694-
3695-
Product item = products.findItem("UPD-ANNO-4");
3696-
assertEquals(2.00f, item.price, 0.001f);
3697-
3698-
products.undoPriceIncrease(Set.of("UPD-ANNO-5", "UPD-ANNO-2", "UPD-ANNO-1"), 1.07f);
3699-
3700-
found = products.findByVersionGreaterThanEqualOrderByPrice(1);
3701-
3702-
assertEquals(Stream.of(found).map(p -> p.id).collect(Collectors.toList()).toString(),
3703-
6, found.length);
3704-
3705-
assertEquals(1.07f, found[0].price, 0.001f); // update remains in place
3706-
assertEquals(2.00f, found[1].price, 0.001f); // never updated
3707-
assertEquals(5.00f, found[2].price, 0.001f); // reverted
3708-
assertEquals(42.80f, found[3].price, 0.001f); // update remains in place
3709-
assertEquals(100.00f, found[4].price, 0.001f); // reverted
3710-
assertEquals(500.00f, found[5].price, 0.001f); // reverted
3711-
3712-
assertEquals(2, found[0].version); // update remains in place
3713-
assertEquals(1, found[1].version); // never updated
3714-
assertEquals(1, found[2].version); // reverted
3715-
assertEquals(2, found[3].version); // update remains in place
3716-
assertEquals(1, found[4].version); // reverted
3717-
assertEquals(1, found[5].version); // reverted
3718-
3719-
assertEquals(6, products.inflateAllPrices(1.05f));
3720-
3721-
found = products.findByVersionGreaterThanEqualOrderByPrice(2);
3722-
3723-
assertEquals(1.12f, found[0].price, 0.01f);
3724-
assertEquals(2.10f, found[1].price, 0.01f);
3725-
assertEquals(5.25f, found[2].price, 0.01f);
3726-
assertEquals(44.94f, found[3].price, 0.01f);
3727-
assertEquals(105.00f, found[4].price, 0.01f);
3728-
assertEquals(525.00f, found[5].price, 0.01f);
3729-
3730-
products.clear();
3731-
3732-
assertEquals(0, products.total());
3733-
assertEquals(false, products.isNotEmpty());
3734-
}
3735-
37363628
/**
37373629
* Update multiple entries.
37383630
*/

dev/io.openliberty.data.internal_fat/test-applications/DataTestApp/src/test/jakarta/data/web/Packages.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
import java.util.List;
1616

17-
import jakarta.data.repository.Condition;
18-
import jakarta.data.repository.Filter;
1917
import jakarta.data.repository.KeysetAwarePage;
2018
import jakarta.data.repository.KeysetAwareSlice;
2119
import jakarta.data.repository.OrderBy;
@@ -46,8 +44,7 @@ public interface Packages extends PageableRepository<Package, Integer> {
4644
long updateByLengthLessThanEqualAndHeightBetweenMultiplyLengthMultiplyWidthSetHeight(float maxLength, float minHeight, float maxHeight,
4745
float lengthMultiplier, float widthMultiplier, float newHeight);
4846

49-
@Filter(by = "height", op = Condition.LessThan, param = "min")
50-
@Filter(as = Filter.Type.OR, by = "height", op = Condition.GreaterThan, param = "max")
47+
@Query("SELECT o from Package o WHERE (o.height < :min OR o.height > :max)") // TODO @Filter with Or
5148
KeysetAwarePage<Package> whereHeightNotWithin(@Param("min") float minToExclude,
5249
@Param("max") float maxToExclude,
5350
Pageable pagination);

dev/io.openliberty.data.internal_fat/test-applications/DataTestApp/src/test/jakarta/data/web/Primes.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
*/
4747
@Repository
4848
public interface Primes {
49+
4950
@Exists
5051
@Filter(by = "binary", op = Compare.EndsWith, param = "bits")
5152
@Filter(by = "number", op = Compare.LessThan, param = "max")
@@ -180,14 +181,6 @@ public interface Primes {
180181
@Select("number")
181182
List<Long> inRangeHavingVNumeralAndSubstringOfName(long min, long max, String nameSuffix);
182183

183-
@Filter(by = "number", op = Condition.LessThan)
184-
@Filter(by = "name", op = Condition.EndsWith)
185-
@Filter(as = Filter.Type.OR, by = "number", op = Condition.Between)
186-
@Filter(by = "name", op = Condition.EndsWith)
187-
@OrderBy(value = "number", descending = true)
188-
Stream<Prime> lessThanWithSuffixOrBetweenWithSuffix(long numLessThan, String firstSuffix,
189-
long lowerLimit, long upperLimit, String secondSuffix);
190-
191184
@Query("SELECT MIN(o.number), MAX(o.number), SUM(o.number), COUNT(o.number), AVG(o.number) FROM Prime o WHERE o.number < ?1")
192185
Deque<Double> minMaxSumCountAverageDeque(long numBelow);
193186

dev/io.openliberty.data.internal_fat/test-applications/DataTestApp/src/test/jakarta/data/web/ProductRepo.java

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,7 @@
1515
import java.util.List;
1616
import java.util.Set;
1717

18-
import jakarta.data.repository.Condition;
19-
import jakarta.data.repository.Count;
20-
import jakarta.data.repository.Delete;
21-
import jakarta.data.repository.Exists;
2218
import jakarta.data.repository.Filter;
23-
import jakarta.data.repository.Operation;
2419
import jakarta.data.repository.OrderBy;
2520
import jakarta.data.repository.Param;
2621
import jakarta.data.repository.Query;
@@ -34,9 +29,6 @@
3429
*/
3530
@Repository
3631
public interface ProductRepo {
37-
@Delete
38-
void clear();
39-
4032
@Query("DELETE FROM Product o WHERE o.id IN ?1")
4133
int discontinueProducts(Set<String> ids);
4234

@@ -52,18 +44,6 @@ public interface ProductRepo {
5244
@Select(function = Aggregate.MAXIMUM, value = "price")
5345
float highestPrice();
5446

55-
@Update(attr = "price", op = Operation.Multiply)
56-
@Update(attr = "version", op = Operation.Add, value = "1")
57-
long inflateAllPrices(float rateOfIncrease);
58-
59-
@Filter(by = "name", op = Condition.Contains)
60-
@Update(attr = "price", op = Operation.Multiply)
61-
@Update(attr = "version", op = Operation.Add, value = "1")
62-
long inflatePrices(String nameContains, float rateOfIncrease);
63-
64-
@Exists
65-
boolean isNotEmpty();
66-
6747
@Select(function = Aggregate.MINIMUM, value = "price")
6848
float lowestPrice();
6949

@@ -83,14 +63,6 @@ public interface ProductRepo {
8363
@Select(function = Aggregate.COUNT, distinct = false, value = { "name", "description", "price" })
8464
ProductCount stats();
8565

86-
@Count
87-
int total();
88-
8966
@Select(function = Aggregate.SUM, distinct = true, value = "price")
9067
float totalOfDistinctPrices();
91-
92-
@Filter(by = "id", op = Condition.In)
93-
@Update(attr = "price", op = Operation.Divide)
94-
@Update(attr = "version", op = Operation.Subtract, value = "1")
95-
long undoPriceIncrease(Iterable<String> productIds, float divisor);
9668
}

dev/io.openliberty.data.internal_fat/test-applications/DataTestApp/src/test/jakarta/data/web/Shipments.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import jakarta.data.repository.Filter;
2121
import jakarta.data.repository.OrderBy;
2222
import jakarta.data.repository.Param;
23+
import jakarta.data.repository.Query;
2324
import jakarta.data.repository.Repository;
2425
import jakarta.data.repository.Select;
2526
import jakarta.data.repository.Update;
@@ -67,6 +68,10 @@ boolean cancel(@Param("shipmentId") long id,
6768

6869
void save(Shipment s);
6970

71+
// TODO @Update on its own instead of this
72+
@Query("UPDATE Shipment o SET o.location = TRIM(o.location)")
73+
void trim();
74+
7075
@Filter(by = "id")
7176
@Filter(by = "location")
7277
@Update(attr = "location")

dev/io.openliberty.jakarta.data.1.0/src/jakarta/data/repository/Filter.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
@Retention(RetentionPolicy.RUNTIME)
2323
@Target(ElementType.METHOD)
2424
public @interface Filter {
25-
Type as() default Type.AND;
26-
2725
String by();
2826

2927
boolean ignoreCase() default false;
@@ -45,9 +43,4 @@
4543
public @interface List {
4644
Filter[] value();
4745
}
48-
49-
public enum Type {
50-
AND,
51-
OR
52-
}
5346
}

0 commit comments

Comments
 (0)