44 */
55package org .hibernate .type .format ;
66
7+ import org .hibernate .internal .util .collections .StandardStack ;
78import org .hibernate .metamodel .mapping .EmbeddableMappingType ;
89import org .hibernate .metamodel .mapping .SelectableMapping ;
910import org .hibernate .type .BasicPluralType ;
1819import java .time .ZoneId ;
1920import java .util .ArrayList ;
2021import java .util .List ;
21- import java . util . Stack ;
22+
2223
2324/**
2425 * Implementation of <code>JsonDocumentHandler</code> for OSON document.
@@ -42,11 +43,11 @@ public class ObjectArrayOsonDocumentHandler implements JsonDocumentHandler {
4243 // Each mapping definition may contain sub mappings (sub embeddable mapping)
4344 // This stack is used to keep a pointer on the current mapping to be used to assign correct types.
4445 // see onStartObject()/onEndObject() methods
45- Stack <EmbeddableMappingType > embeddableMappingTypes = new Stack <>();
46+ StandardStack <EmbeddableMappingType > embeddableMappingTypes = new StandardStack <>();
4647 // As for mapping definitions, when "sub embeddable" is encountered, the array
4748 // that needs to be filled with Objects is the one we allocate in the final result array slot.
4849 // We use a stack to keep track of array ref
49- Stack <Object []> objectArrays = new Stack <>();
50+ StandardStack <Object []> objectArrays = new StandardStack <>();
5051
5152
5253 WrapperOptions wrapperOptions ;
@@ -75,18 +76,20 @@ public void onStartObject() {
7576 // We are dealing with a sub-object, allocate space for it then,
7677 // otherwise, we have nothing to do.
7778 // Push the new (sub)mapping definition.
78- this .currentSelectableIndexInResultArray = embeddableMappingTypes .peek ().getSelectableIndex ( currentKeyName );
79+ assert embeddableMappingTypes .getCurrent () != null ;
80+ this .currentSelectableIndexInResultArray = embeddableMappingTypes .getCurrent ().getSelectableIndex ( currentKeyName );
7981 assert currentSelectableIndexInResultArray != -1 : "Cannot get index of " + currentKeyName ;
8082
81- final SelectableMapping selectable = embeddableMappingTypes .peek ().getJdbcValueSelectable (
83+ final SelectableMapping selectable = embeddableMappingTypes .getCurrent ().getJdbcValueSelectable (
8284 currentSelectableIndexInResultArray );
8385 final AggregateJdbcType aggregateJdbcType = (AggregateJdbcType ) selectable .getJdbcMapping ()
8486 .getJdbcType ();
8587 final EmbeddableMappingType subMappingType = aggregateJdbcType .getEmbeddableMappingType ();
86- this .objectArrays .peek ()[currentSelectableIndexInResultArray ] =
88+ assert this .objectArrays .getCurrent () != null ;
89+ this .objectArrays .getCurrent ()[currentSelectableIndexInResultArray ] =
8790 new Object [subMappingType .getJdbcValueCount ()];
8891 this .embeddableMappingTypes .push ( subMappingType );
89- this .objectArrays .push ( (Object []) this .objectArrays .peek ()[currentSelectableIndexInResultArray ] );
92+ this .objectArrays .push ( (Object []) this .objectArrays .getCurrent ()[currentSelectableIndexInResultArray ] );
9093 }
9194 }
9295
@@ -113,7 +116,7 @@ public void onStartArray() {
113116 public void onEndArray () {
114117 assert (subArrayObjectList != null && subArrayObjectTypes != null ) : "onEndArray called before onStartArray" ;
115118 // flush array values
116- this .objectArrays .peek ()[currentSelectableIndexInResultArray ] = subArrayObjectTypes .getJdbcJavaType ().wrap ( subArrayObjectList , wrapperOptions );
119+ this .objectArrays .getCurrent ()[currentSelectableIndexInResultArray ] = subArrayObjectTypes .getJdbcJavaType ().wrap ( subArrayObjectList , wrapperOptions );
117120 // reset until we encounter next array element
118121 subArrayObjectList = null ;
119122 subArrayObjectTypes = null ;
@@ -123,17 +126,17 @@ public void onEndArray() {
123126 public void onObjectKey (String key ) {
124127 this .currentKeyName = key ;
125128
126- currentSelectableIndexInResultArray = embeddableMappingTypes .peek ().getSelectableIndex ( currentKeyName );
129+ currentSelectableIndexInResultArray = embeddableMappingTypes .getCurrent ().getSelectableIndex ( currentKeyName );
127130 if ( currentSelectableIndexInResultArray >= 0 ) {
128131 // we may not have a selectable mapping for that key
129- currentSelectableMapping = embeddableMappingTypes .peek ().getJdbcValueSelectable ( currentSelectableIndexInResultArray );
132+ currentSelectableMapping = embeddableMappingTypes .getCurrent ().getJdbcValueSelectable ( currentSelectableIndexInResultArray );
130133 }
131134 else {
132135 throw new IllegalArgumentException (
133136 String .format (
134137 "Could not find selectable [%s] in embeddable type [%s] for JSON processing." ,
135138 currentKeyName ,
136- embeddableMappingTypes .peek ().getMappedJavaType ().getJavaTypeClass ().getName ()
139+ embeddableMappingTypes .getCurrent ().getMappedJavaType ().getJavaTypeClass ().getName ()
137140 )
138141 );
139142 }
@@ -146,7 +149,7 @@ public void onNullValue() {
146149 subArrayObjectList .add ( null );
147150 }
148151 else {
149- this .objectArrays .peek ()[currentSelectableIndexInResultArray ] = null ;
152+ this .objectArrays .getCurrent ()[currentSelectableIndexInResultArray ] = null ;
150153 }
151154 }
152155
@@ -157,7 +160,7 @@ public void onBooleanValue(boolean value) {
157160 subArrayObjectList .add ( value ?Boolean .TRUE :Boolean .FALSE );
158161 }
159162 else {
160- this .objectArrays .peek ()[currentSelectableIndexInResultArray ] = value ?Boolean .TRUE :Boolean .FALSE ;
163+ this .objectArrays .getCurrent ()[currentSelectableIndexInResultArray ] = value ?Boolean .TRUE :Boolean .FALSE ;
161164 }
162165 }
163166
@@ -169,7 +172,7 @@ public void onStringValue(String value) {
169172 subArrayObjectTypes .getElementType ().getJdbcJavaType ().fromEncodedString ( value ,0 ,value .length ()) );
170173 }
171174 else {
172- this .objectArrays .peek ()[currentSelectableIndexInResultArray ] =
175+ this .objectArrays .getCurrent ()[currentSelectableIndexInResultArray ] =
173176 currentSelectableMapping .getJdbcMapping ().getJdbcJavaType ().fromEncodedString ( value ,0 ,value .length ());
174177 }
175178 }
@@ -190,7 +193,7 @@ public <T> void onOsonValue(T value) {
190193 subArrayObjectList .add ( value );
191194 }
192195 else {
193- this .objectArrays .peek ()[currentSelectableIndexInResultArray ] =
196+ this .objectArrays .getCurrent ()[currentSelectableIndexInResultArray ] =
194197 currentSelectableMapping .getJdbcMapping ().convertToDomainValue (
195198 currentSelectableMapping .getJdbcMapping ().getJdbcJavaType ()
196199 .wrap ( value , wrapperOptions ) );
@@ -223,7 +226,7 @@ public void onOsonBinaryValue(byte[] bytes) {
223226 subArrayObjectList .add ( theOneToBeUsed );
224227 }
225228 else {
226- this .objectArrays .peek ()[currentSelectableIndexInResultArray ] = theOneToBeUsed ;
229+ this .objectArrays .getCurrent ()[currentSelectableIndexInResultArray ] = theOneToBeUsed ;
227230 }
228231 }
229232
@@ -270,7 +273,7 @@ else if ( java.util.Date.class.isAssignableFrom( underlyingType ) ) {
270273 subArrayObjectList .add ( theOneToBeUsed );
271274 }
272275 else {
273- this .objectArrays .peek ()[currentSelectableIndexInResultArray ] = theOneToBeUsed ;
276+ this .objectArrays .getCurrent ()[currentSelectableIndexInResultArray ] = theOneToBeUsed ;
274277 }
275278 }
276279}
0 commit comments