@@ -56,75 +56,6 @@ public class JsonHelper {
5656 */
5757 private static <X > X consumeJsonDocumentItems (JsonDocumentReader reader , EmbeddableMappingType embeddableMappingType , boolean returnEmbeddable , WrapperOptions options )
5858 throws SQLException {
59- record SelectableData (String selectableName , int selectableIndex , SelectableMapping selectableMapping ){}
60- record ParseLevel (
61- @ Nullable SelectableData selectableData ,
62- @ Nullable EmbeddableMappingType embeddableMappingType ,
63- @ Nullable BasicPluralType <?, ?> arrayType ,
64- @ Nullable List <Object > subArrayObjectList ,
65- @ Nullable Object [] objectArray
66- ) {
67- ParseLevel (EmbeddableMappingType embeddableMappingType ) {
68- this (null , embeddableMappingType );
69- }
70- ParseLevel (@ Nullable SelectableData selectableData , EmbeddableMappingType embeddableMappingType ) {
71- this (
72- selectableData ,
73- embeddableMappingType ,
74- null ,
75- null ,
76- new Object [embeddableMappingType .getJdbcValueCount ()+ ( embeddableMappingType .isPolymorphic () ? 1 : 0 )]
77- );
78- }
79- ParseLevel (@ Nullable SelectableData selectableData , BasicPluralType <?, ?> arrayType ) {
80- this ( selectableData , null , arrayType , new ArrayList <>(), null );
81- }
82-
83- public void addValue (@ Nullable SelectableData selectableData , @ Nullable Object value ) {
84- if ( embeddableMappingType != null ) {
85- assert selectableData != null ;
86- objectArray [selectableData .selectableIndex ] = value ;
87- }
88- else {
89- assert subArrayObjectList != null ;
90- subArrayObjectList .add (value );
91- }
92- }
93-
94- public JdbcMapping determineJdbcMapping (@ Nullable SelectableData currentSelectableData ) {
95- if ( currentSelectableData != null ) {
96- return currentSelectableData .selectableMapping .getJdbcMapping ();
97- }
98- else if ( arrayType != null ) {
99- return arrayType .getElementType ();
100- }
101- else {
102- assert selectableData != null ;
103- return selectableData .selectableMapping .getJdbcMapping ();
104- }
105- }
106-
107- public static String determineSelectablePath (StandardStack <ParseLevel > parseLevel , @ Nullable SelectableData currentSelectableData ) {
108- if ( currentSelectableData != null ) {
109- return currentSelectableData .selectableName ;
110- }
111- else {
112- return determineSelectablePath ( parseLevel , 0 );
113- }
114- }
115-
116- private static String determineSelectablePath (StandardStack <ParseLevel > stack , int level ) {
117- final ParseLevel parseLevel = stack .peek ( level );
118- assert parseLevel != null ;
119- if ( parseLevel .selectableData != null ) {
120- return parseLevel .selectableData .selectableName ;
121- }
122- else {
123- assert parseLevel .arrayType != null ;
124- return determineSelectablePath ( stack , level + 1 ) + ".{element}" ;
125- }
126- }
127- }
12859 final StandardStack <ParseLevel > parseLevel = new StandardStack <>();
12960 final JsonValueJDBCTypeAdapter adapter = JsonValueJDBCTypeAdapterFactory .getAdapter (reader ,returnEmbeddable );
13061
@@ -458,4 +389,74 @@ public <T> T[] toArray(T[] a) {
458389 }
459390 }
460391
392+ private record SelectableData (String selectableName , int selectableIndex , SelectableMapping selectableMapping ){}
393+ private record ParseLevel (
394+ @ Nullable SelectableData selectableData ,
395+ @ Nullable EmbeddableMappingType embeddableMappingType ,
396+ @ Nullable BasicPluralType <?, ?> arrayType ,
397+ @ Nullable List <Object > subArrayObjectList ,
398+ @ Nullable Object [] objectArray
399+ ) {
400+ ParseLevel (EmbeddableMappingType embeddableMappingType ) {
401+ this (null , embeddableMappingType );
402+ }
403+ ParseLevel (@ Nullable SelectableData selectableData , EmbeddableMappingType embeddableMappingType ) {
404+ this (
405+ selectableData ,
406+ embeddableMappingType ,
407+ null ,
408+ null ,
409+ new Object [embeddableMappingType .getJdbcValueCount ()+ ( embeddableMappingType .isPolymorphic () ? 1 : 0 )]
410+ );
411+ }
412+ ParseLevel (@ Nullable SelectableData selectableData , BasicPluralType <?, ?> arrayType ) {
413+ this ( selectableData , null , arrayType , new ArrayList <>(), null );
414+ }
415+
416+ public void addValue (@ Nullable SelectableData selectableData , @ Nullable Object value ) {
417+ if ( embeddableMappingType != null ) {
418+ assert selectableData != null ;
419+ objectArray [selectableData .selectableIndex ] = value ;
420+ }
421+ else {
422+ assert subArrayObjectList != null ;
423+ subArrayObjectList .add (value );
424+ }
425+ }
426+
427+ public JdbcMapping determineJdbcMapping (@ Nullable SelectableData currentSelectableData ) {
428+ if ( currentSelectableData != null ) {
429+ return currentSelectableData .selectableMapping .getJdbcMapping ();
430+ }
431+ else if ( arrayType != null ) {
432+ return arrayType .getElementType ();
433+ }
434+ else {
435+ assert selectableData != null ;
436+ return selectableData .selectableMapping .getJdbcMapping ();
437+ }
438+ }
439+
440+ public static String determineSelectablePath (StandardStack <ParseLevel > parseLevel , @ Nullable SelectableData currentSelectableData ) {
441+ if ( currentSelectableData != null ) {
442+ return currentSelectableData .selectableName ;
443+ }
444+ else {
445+ return determineSelectablePath ( parseLevel , 0 );
446+ }
447+ }
448+
449+ private static String determineSelectablePath (StandardStack <ParseLevel > stack , int level ) {
450+ final ParseLevel parseLevel = stack .peek ( level );
451+ assert parseLevel != null ;
452+ if ( parseLevel .selectableData != null ) {
453+ return parseLevel .selectableData .selectableName ;
454+ }
455+ else {
456+ assert parseLevel .arrayType != null ;
457+ return determineSelectablePath ( stack , level + 1 ) + ".{element}" ;
458+ }
459+ }
460+ }
461+
461462}
0 commit comments