-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #325 from turkraft/3.x.x
Added ListExpression as an alternative to cb.in('...')
- Loading branch information
Showing
4 changed files
with
122 additions
and
1 deletion.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
jpa/src/main/java/com/turkraft/springfilter/transformer/ConvertibleExpression.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.turkraft.springfilter.transformer; | ||
|
||
import jakarta.persistence.criteria.Expression; | ||
|
||
public interface ConvertibleExpression { | ||
|
||
Expression<?> convertTo(Class<?> type); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
jpa/src/main/java/com/turkraft/springfilter/transformer/ListExpression.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package com.turkraft.springfilter.transformer; | ||
|
||
import jakarta.persistence.criteria.Expression; | ||
import jakarta.persistence.criteria.Predicate; | ||
import jakarta.persistence.criteria.Selection; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class ListExpression<T> implements Expression<T>, ConvertibleExpression { | ||
|
||
private List<Expression<T>> values; | ||
|
||
public ListExpression(List<Expression<T>> values) { | ||
this.values = values; | ||
} | ||
|
||
public List<Expression<T>> getValues() { | ||
return values; | ||
} | ||
|
||
public void setValues(List<Expression<T>> values) { | ||
this.values = values; | ||
} | ||
|
||
@Override | ||
public Predicate isNull() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public Predicate isNotNull() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public Predicate in(Object... values) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public Predicate in(Expression<?>... values) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Predicate in(Collection<?> values) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Predicate in(Expression<Collection<?>> values) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public <X> Expression<X> as(Class<X> type) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public Selection<T> alias(String name) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean isCompoundSelection() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public List<Selection<?>> getCompoundSelectionItems() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Class<? extends T> getJavaType() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getAlias() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public Expression<T> convertTo(Class<?> type) { | ||
return new ListExpression(values.stream().map( | ||
v -> v != null && v.getJavaType() != null && !type.isAssignableFrom(v.getJavaType()) ? v.as( | ||
type) : v).collect( | ||
Collectors.toList())); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters