-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
HHH-19610 make GraphParser support subTypeSubGraph #10521
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
Open
Asanio06
wants to merge
1
commit into
hibernate:main
Choose a base branch
from
Asanio06:HHH-19610
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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 hidden or 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 hidden or 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
66 changes: 66 additions & 0 deletions
66
...rnate-core/src/main/antlr/org/hibernate/grammars/graph/legacy/LegacyGraphLanguageLexer.g4
This file contains hidden or 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,66 @@ | ||
| lexer grammar LegacyGraphLanguageLexer; | ||
|
|
||
| @header { | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * Copyright Red Hat Inc. and Hibernate Authors | ||
| */ | ||
| package org.hibernate.grammars.graph.legacy; | ||
| } | ||
|
|
||
| @members { | ||
| /* | ||
| * Lexer for the Hibernate EntityGraph Language | ||
| * | ||
| * It is generated by Antlr via the lexer grammar file `LegacyGraphLanguageLexer.g4` | ||
| */ | ||
| } | ||
|
|
||
| channels { | ||
| WHITESPACE_CHANNEL | ||
| } | ||
|
|
||
| WS : ( ' ' | '\t' | '\f' | EOL ) -> channel(WHITESPACE_CHANNEL); | ||
|
|
||
| fragment EOL : [\r\n]+; | ||
|
|
||
| COLON: ':'; | ||
|
|
||
| COMMA: ','; | ||
|
|
||
| DOT: '.'; | ||
|
|
||
| LPAREN: '('; | ||
|
|
||
| RPAREN: ')'; | ||
|
|
||
| /** | ||
| * In this grammar, basically any string since we (atm) have no keywords | ||
| */ | ||
| ATTR_NAME : ATTR_NAME_START NAME_CONTINUATION*; | ||
|
|
||
| TYPE_NAME : TYPE_NAME_START NAME_CONTINUATION*; | ||
|
|
||
| fragment NON_ALPHANUM_EXTENTION | ||
| : '_' | ||
| | '$' | ||
| // HHH-558 : Allow unicode chars in identifiers | ||
| //| '\u0080'..'\ufffe' | ||
| ; | ||
|
|
||
| fragment ATTR_NAME_START | ||
| : NON_ALPHANUM_EXTENTION | ||
| | 'a'..'z' | ||
| ; | ||
|
|
||
| fragment TYPE_NAME_START | ||
| : NON_ALPHANUM_EXTENTION | ||
| | 'A'..'Z' | ||
| ; | ||
|
|
||
| fragment NAME_CONTINUATION | ||
| : NON_ALPHANUM_EXTENTION | ||
| | 'a'..'z' | ||
| | 'A'..'Z' | ||
| | '0'..'9' | ||
| ; |
50 changes: 50 additions & 0 deletions
50
...nate-core/src/main/antlr/org/hibernate/grammars/graph/legacy/LegacyGraphLanguageParser.g4
This file contains hidden or 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,50 @@ | ||
| parser grammar LegacyGraphLanguageParser; | ||
|
|
||
| options { | ||
| tokenVocab=LegacyGraphLanguageLexer; | ||
| } | ||
|
|
||
| @header { | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * Copyright Red Hat Inc. and Hibernate Authors | ||
| */ | ||
| package org.hibernate.grammars.graph.legacy; | ||
| } | ||
|
|
||
| @members { | ||
| /* | ||
| * Antlr grammar describing the Hibernate EntityGraph Language - for parsing a structured | ||
| * textual representation of an entity graph | ||
| * | ||
| * `LegacyGraphLanguageParser.g4` | ||
| */ | ||
| } | ||
|
|
||
| graph | ||
| : typeIndicator? attributeList | ||
| ; | ||
|
|
||
| typeIndicator | ||
| : TYPE_NAME COLON | ||
| ; | ||
|
|
||
| attributeList | ||
| : attributeNode (COMMA attributeNode)* | ||
| ; | ||
|
|
||
| attributeNode | ||
| : attributePath subGraph? | ||
| ; | ||
|
|
||
| attributePath | ||
| : ATTR_NAME attributeQualifier? | ||
| ; | ||
|
|
||
| attributeQualifier | ||
| : DOT ATTR_NAME | ||
| ; | ||
|
|
||
| subGraph | ||
| : LPAREN typeIndicator? attributeList RPAREN | ||
| ; |
62 changes: 62 additions & 0 deletions
62
hibernate-core/src/main/java/org/hibernate/GraphParserMode.java
This file contains hidden or 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,62 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * Copyright Red Hat Inc. and Hibernate Authors | ||
| */ | ||
| package org.hibernate; | ||
|
|
||
| /** | ||
| * Enumeration of available graph parser syntax modes. | ||
| * | ||
| */ | ||
| public enum GraphParserMode { | ||
| /** | ||
| * Legacy syntax: attribute(SubType: attributes) | ||
| * This is the legacy syntax. | ||
| */ | ||
| LEGACY( "legacy" ), | ||
|
|
||
| /** | ||
| * Modern syntax: attribute:SubType(attributes) | ||
| * This is the preferred new syntax. | ||
| */ | ||
| MODERN( "modern" ); | ||
|
|
||
| private final String configValue; | ||
|
|
||
| GraphParserMode(String configValue) { | ||
| this.configValue = configValue; | ||
| } | ||
|
|
||
| public String getConfigValue() { | ||
| return configValue; | ||
| } | ||
|
|
||
| /** | ||
| * Interpret the configured valueHandlingMode value. | ||
| * Valid values are either a {@link GraphParserMode} object or its String representation. | ||
| * For string values, the matching is case insensitive, so you can use either {@code MODERN} or {@code modern}. | ||
| * | ||
| * @param graphParserMode configured {@link GraphParserMode} representation | ||
| * | ||
| * @return associated {@link GraphParserMode} object | ||
| */ | ||
| public static GraphParserMode interpret(Object graphParserMode) { | ||
| if ( graphParserMode == null ) { | ||
| return LEGACY; | ||
| } | ||
| else if ( graphParserMode instanceof GraphParserMode mode ) { | ||
| return mode; | ||
| } | ||
| else if ( graphParserMode instanceof String string ) { | ||
| for ( GraphParserMode value : values() ) { | ||
| if ( value.name().equalsIgnoreCase( string ) ) { | ||
| return value; | ||
| } | ||
| } | ||
| } | ||
| throw new HibernateException( | ||
| "Unrecognized graph_parser_mode value : " + graphParserMode | ||
| + ". Supported values include 'modern' and 'legacy'." | ||
| ); | ||
| } | ||
| } |
This file contains hidden or 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
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 was a bit torn whether we want to consider
String rootEntityName() ...here to support dynamic models. The annotation can appear at the package level and apply to any entity...But for posterity, I think this definition is fine.