-
Notifications
You must be signed in to change notification settings - Fork 168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: Register JpaFilterConverter in a way that can be overridden #20745
Closed
+975
−2
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,36 @@ | ||
/* | ||
* Copyright 2000-2022 Vaadin Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package com.vaadin.flow; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Annotation to mark either field, method, parameter or type parameter as | ||
* non-nullable. It is used by Typescript Generator as a source of type | ||
* nullability information. | ||
* | ||
* This annotation exists because the traditional `jakarta.annotation.Nonnull` | ||
* annotation is not applicable to type parameters. | ||
*/ | ||
@Documented | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ ElementType.TYPE_USE }) | ||
public @interface Nonnull { | ||
} |
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,36 @@ | ||
/* | ||
* Copyright 2000-2022 Vaadin Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package com.vaadin.flow; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Annotation to mark either field, method, parameter or type parameter as | ||
* nullable. It is used by Typescript Generator as a source of type nullability | ||
* information. | ||
* | ||
* This annotation exists because the traditional `jakarta.annotation.Nullable` | ||
* annotation is not applicable to type parameters. | ||
*/ | ||
@Documented | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ ElementType.TYPE_USE }) | ||
public @interface Nullable { | ||
} |
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
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
21 changes: 21 additions & 0 deletions
21
vaadin-spring/src/main/java/com/vaadin/flow/spring/data/CountService.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,21 @@ | ||
package com.vaadin.flow.spring.data; | ||
|
||
import com.vaadin.flow.Nullable; | ||
|
||
import com.vaadin.flow.spring.data.filter.Filter; | ||
|
||
/** | ||
* A service that can count the given type of objects with a given filter. | ||
*/ | ||
public interface CountService { | ||
|
||
/** | ||
* Counts the number of entities that match the given filter. | ||
* | ||
* @param filter | ||
* the filter, or {@code null} to use no filter | ||
* @return | ||
*/ | ||
public long count(@Nullable Filter filter); | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
vaadin-spring/src/main/java/com/vaadin/flow/spring/data/CrudService.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,7 @@ | ||
package com.vaadin.flow.spring.data; | ||
|
||
/** | ||
* A service that can create, read, update, and delete a given type of object. | ||
*/ | ||
public interface CrudService<T, ID> extends ListService<T>, FormService<T, ID> { | ||
} |
30 changes: 30 additions & 0 deletions
30
vaadin-spring/src/main/java/com/vaadin/flow/spring/data/FormService.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,30 @@ | ||
package com.vaadin.flow.spring.data; | ||
|
||
import com.vaadin.flow.Nullable; | ||
|
||
/** | ||
* A service that can create, update, and delete a given type of object. | ||
*/ | ||
public interface FormService<T, ID> { | ||
|
||
/** | ||
* Saves the given object and returns the (potentially) updated object. | ||
* <p> | ||
* If you store the object in a SQL database, the returned object might have | ||
* a new id or updated consistency version. | ||
* | ||
* @param value | ||
* the object to save | ||
* @return the fresh object or {@code null} if no object was found to update | ||
*/ | ||
@Nullable | ||
T save(T value); | ||
|
||
/** | ||
* Deletes the object with the given id. | ||
* | ||
* @param id | ||
* the id of the object to delete | ||
*/ | ||
void delete(ID id); | ||
} |
30 changes: 30 additions & 0 deletions
30
vaadin-spring/src/main/java/com/vaadin/flow/spring/data/GetService.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,30 @@ | ||
package com.vaadin.flow.spring.data; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* A service that can fetch the given type of object. | ||
*/ | ||
public interface GetService<T, ID> { | ||
|
||
/** | ||
* Gets the object with the given id. | ||
* | ||
* @param id | ||
* the id of the object | ||
* @return the object, or an empty optional if no object with the given id | ||
*/ | ||
Optional<T> get(ID id); | ||
|
||
/** | ||
* Checks if an object with the given id exists. | ||
* | ||
* @param id | ||
* the id of the object | ||
* @return {@code true} if the object exists, {@code false} otherwise | ||
*/ | ||
default boolean exists(ID id) { | ||
return get(id).isPresent(); | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
vaadin-spring/src/main/java/com/vaadin/flow/spring/data/ListService.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,28 @@ | ||
package com.vaadin.flow.spring.data; | ||
|
||
import java.util.List; | ||
|
||
import com.vaadin.flow.Nullable; | ||
import com.vaadin.flow.Nonnull; | ||
|
||
import com.vaadin.flow.spring.data.filter.Filter; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
/** | ||
* A service that can list the given type of object. | ||
*/ | ||
public interface ListService<T> { | ||
/** | ||
* Lists objects of the given type using the paging, sorting and filtering | ||
* options provided in the parameters. | ||
* | ||
* @param pageable | ||
* contains information about paging and sorting | ||
* @param filter | ||
* the filter to apply or {@code null} to not filter | ||
* @return a list of objects or an empty list if no objects were found | ||
*/ | ||
@Nonnull | ||
List<@Nonnull T> list(Pageable pageable, @Nullable Filter filter); | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
vaadin-spring/src/main/java/com/vaadin/flow/spring/data/filter/AndFilter.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,27 @@ | ||
package com.vaadin.flow.spring.data.filter; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* A filter that requires all children to pass. | ||
* <p> | ||
* Custom filter implementations need to handle this filter by running all child | ||
* filters and verifying that all of them pass. | ||
*/ | ||
public class AndFilter extends Filter { | ||
private List<Filter> children; | ||
|
||
public List<Filter> getChildren() { | ||
return children; | ||
} | ||
|
||
public void setChildren(List<Filter> children) { | ||
this.children = children; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "AndFilter [children=" + children + "]"; | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
vaadin-spring/src/main/java/com/vaadin/flow/spring/data/filter/Filter.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,27 @@ | ||
package com.vaadin.flow.spring.data.filter; | ||
|
||
import java.io.Serializable; | ||
|
||
import com.fasterxml.jackson.annotation.JsonSubTypes; | ||
import com.fasterxml.jackson.annotation.JsonSubTypes.Type; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
|
||
/** | ||
* Superclass for all filters to be used with CRUD services. This specific class | ||
* is never used, instead a filter instance will be one of the following types: | ||
* <ul> | ||
* <li>{@link AndFilter} - Contains a list of nested filters, all of which need | ||
* to pass.</li> | ||
* <li>{@link OrFilter} - Contains a list of nested filters, of which at least | ||
* one needs to pass.</li> | ||
* <li>{@link PropertyStringFilter} - Matches a specific property, or nested | ||
* property path, against a filter value, using a specific operator.</li> | ||
* </ul> | ||
*/ | ||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY) | ||
@JsonSubTypes({ @Type(value = OrFilter.class, name = "or"), | ||
@Type(value = AndFilter.class, name = "and"), | ||
@Type(value = PropertyStringFilter.class, name = "propertyString") }) | ||
public class Filter implements Serializable { | ||
|
||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not want this Bean as flow user. Additionally it might be problematic for projects without JPA because of the EntityManager (so conditional on missing bean is not enough)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And wait.. is this the code that made "Hilla utterly broken with multiple Data sources"? I'm strict against this in flow!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like this is something personal. Can we discuss the merits of the code instead and what it is useful for
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you can see from the description, it is supposed to fix vaadin/hilla#2569, not introduce it to all Flow users
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's added to "SpringBootAutoConfiguration" which effects flow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, that is the point of this PR. To add the features to Flow and not only restrict them to Hilla
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your last two comments are kinda conflicting?
But nevertheless back to code - this JPAFilter probably has to be added in a second AutoConfiguration class to ensure it's only loaded with JPA and Spring Data in use.. or does it have to be a bean at all? It looks just like some helper methods that need access to the EntityManager.. with the "move" to flow and re-creating of all classes.. it's binary incompatible anyway so perfect timing for breaking changes.
Just a quick note on the other code:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's see first where #20743 ends up. The original version in Hilla contained quite a bit of magic and this PR now contains way less of it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The point is to introduce the features to all Flow users but not to introduce the problem to all Flow users