@@ -112,65 +112,103 @@ private void returnArgument(StringBuilder declaration) {
112112
113113 private void delegateCall (StringBuilder declaration ) {
114114 if ( isReactive () ) {
115+ // TODO: handle the case of an iterable parameter
116+ delegateReactively ( declaration );
117+ }
118+ else {
119+ delegateBlockingly ( declaration );
120+ }
121+ }
122+
123+ private void delegateBlockingly (StringBuilder declaration ) {
124+ if ( isGeneratedIdUpsert () ) {
115125 declaration
116- .append ("\t return " )
117- .append (sessionName );
118- if ( isReactiveSessionAccess () ) {
119- declaration
120- .append (".chain(" )
121- .append (localSessionName ())
122- .append (" -> " )
123- .append (localSessionName ());
124- }
125- declaration
126+ .append ("\t \t if (" )
127+ .append (sessionName )
128+ .append (".getIdentifier(" )
129+ .append (parameterName )
130+ .append (") == null)\n " )
131+ .append ("\t \t \t " )
132+ .append (sessionName )
126133 .append ('.' )
127- .append (operationName )
134+ .append ("insert" )
128135 .append ('(' )
129- .append (parameterName )
130- .append (')' );
131- if ( isReactiveSessionAccess () ) {
132- declaration
133- .append (')' );
134- }
135- }
136- else {
136+ .append (parameterName );
137137 if ( iterateParameter ) {
138138 declaration
139- .append ("\t \t for (var _entity : " )
140- .append (parameterName )
141- .append (") {\n \t " );
142- }
143- if ( "upsert" .equals (operationName ) && hasGeneratedId ) {
144- declaration
145- .append ("\t \t if (" )
146- .append (sessionName )
147- .append (".getIdentifier(" )
148- .append (iterateParameter ? "_entity" : parameterName )
149- .append (") == null)\n " )
150- .append ("\t \t \t " )
151- .append (sessionName )
152- .append ('.' )
153- .append ("insert" )
154- .append ('(' )
155- .append (iterateParameter ? "_entity" : parameterName )
156- .append (')' )
157- .append (";\n " )
158- .append ("\t \t else\n \t " );
139+ .append ("Multiple" );
159140 }
160141 declaration
161- .append ("\t \t " )
142+ .append (')' )
143+ .append (";\n " )
144+ .append ("\t \t else\n \t " );
145+ }
146+ declaration
147+ .append ("\t \t " )
148+ .append (sessionName )
149+ .append ('.' )
150+ .append (operationName );
151+ if ( iterateParameter ) {
152+ declaration
153+ .append ("Multiple" );
154+ }
155+ declaration
156+ .append ('(' )
157+ .append (parameterName )
158+ .append (')' )
159+ .append (";\n " );
160+ }
161+
162+ private void delegateReactively (StringBuilder declaration ) {
163+ declaration
164+ .append ("\t return " );
165+ if ( isReactiveSessionAccess () ) {
166+ declaration
162167 .append (sessionName )
168+ .append (".chain(" )
169+ .append (localSessionName ())
170+ .append (" -> " );
171+ }
172+ if ( isGeneratedIdUpsert () ) {
173+ declaration
174+ .append ("\t \t (" )
175+ .append (localSessionName ())
176+ .append (".getIdentifier(" )
177+ .append (parameterName )
178+ .append (") == null ? " )
179+ .append (localSessionName ())
163180 .append ('.' )
164- .append (operationName )
181+ .append ("insert" )
165182 .append ('(' )
166- .append (iterateParameter ? "_entity" : parameterName )
183+ .append (parameterName )
167184 .append (')' )
168- .append (";\n " );
169- if ( iterateParameter ) {
170- declaration
171- .append ("\t \t }\n " );
172- }
185+ .append (" : " );
173186 }
187+ declaration
188+ .append (localSessionName ())
189+ .append ( '.' )
190+ .append ( operationName );
191+ if ( iterateParameter ) {
192+ // note that there is no upsertAll() method
193+ declaration
194+ .append ( "All" );
195+ }
196+ declaration
197+ .append ( '(' )
198+ .append ( parameterName )
199+ .append ( ')' );
200+ if ( isGeneratedIdUpsert () ) {
201+ declaration
202+ .append (')' );
203+ }
204+ if ( isReactiveSessionAccess () ) {
205+ declaration
206+ .append (')' );
207+ }
208+ }
209+
210+ private boolean isGeneratedIdUpsert () {
211+ return "upsert" .equals ( operationName ) && hasGeneratedId ;
174212 }
175213
176214 private void preamble (StringBuilder declaration ) {
0 commit comments