@@ -204,8 +204,7 @@ private Optional<Partition> evalPartition2(ViewDecorator vd, QueryContext ctx) {
204
204
205
205
//[view.]column[.operator]*
206
206
public DBColumn evalColumn (ViewDecorator td , QueryContext ctx , boolean requireTag ) {
207
- var r = chainColumnOperations (td , ctx , false )
208
- .orElseThrow (()-> noSuchViewColumnException (this ));
207
+ var r = chainColumnOperations (td , ctx , false );
209
208
r .entry .requireNoNext (); //check next only if column exists
210
209
if (nonNull (r .entry .tag )) {
211
210
return r .col .as (r .entry .tag );
@@ -218,8 +217,7 @@ public DBColumn evalColumn(ViewDecorator td, QueryContext ctx, boolean requireTa
218
217
219
218
//[view.]column[.operator]*[.order]
220
219
public DBOrder evalOrder (ViewDecorator td , QueryContext ctx ) {
221
- var r = chainColumnOperations (td , ctx , false )
222
- .orElseThrow (()-> noSuchViewColumnException (this ));
220
+ var r = chainColumnOperations (td , ctx , false );
223
221
if (r .entry .isLast ()) { // default order
224
222
return r .col .order ();
225
223
}
@@ -237,11 +235,7 @@ public DBFilter evalFilter(ViewDecorator td, QueryContext ctx) {
237
235
238
236
//[view.]criteria | [view.]column.criteria | [view.]column[.operator]*[.comparator][.and|or(comparator)]*
239
237
public DBFilter evalFilter (ViewDecorator vd , QueryContext ctx , List <RequestEntryChain > values ) { //use CD.parser
240
- var res = chainColumnOperations (vd , ctx , true );
241
- if (res .isEmpty ()) {
242
- throw noSuchViewColumnException (this );
243
- }
244
- var rc = res .get ();
238
+ var rc = chainColumnOperations (vd , ctx , true );
245
239
if (rc .isCriteria ()) {
246
240
var strArgs = toStringArray (rc .entry .assertOuterParameters (values ));
247
241
if (nonNull (rc .viewCrt )) { //view criteria
@@ -293,25 +287,24 @@ DBFilter chainComparator(ViewDecorator td, QueryContext ctx, DBFilter f) {
293
287
return f ;
294
288
}
295
289
296
- private Optional <ViewResource > chainColumnOperations (ViewDecorator vd , QueryContext ctx , boolean filter ) {
297
- return lookupResource (vd , ctx , filter ).map (r -> {
298
- if (!r .isFilter ()) { // !criteria & !comparator
299
- var e = r .entry .next ;
300
- while (nonNull (e )) { //chain until !operator
301
- var res = lookupOperator (e .value );
302
- if (res .isEmpty ()) {
303
- break ;
304
- }
305
- var fn = res .get ();
306
- var o = fn .operation (e .toArgs (vd , ctx , r .col , fn .getParameterSet ()));
307
- r .cd = null ;
308
- r .entry = e ;
309
- r .col = filter && "over" .equals (e .value ) ? windowColumn (r .vd , ctx , o ) : o ;
310
- e = e .next ;
290
+ private ViewResource chainColumnOperations (ViewDecorator vd , QueryContext ctx , boolean filter ) {
291
+ var r = lookupResource (vd , ctx , filter );
292
+ if (!r .isFilter ()) { // !criteria & !comparator
293
+ var e = r .entry .next ;
294
+ while (nonNull (e )) { //chain until !operator
295
+ var res = lookupOperator (e .value );
296
+ if (res .isEmpty ()) {
297
+ break ;
311
298
}
312
- } //else filter
313
- return r ;
314
- });
299
+ var fn = res .get ();
300
+ var o = fn .operation (e .toArgs (vd , ctx , r .col , fn .getParameterSet ()));
301
+ r .cd = null ;
302
+ r .entry = e ;
303
+ r .col = filter && "over" .equals (e .value ) ? windowColumn (r .vd , ctx , o ) : o ;
304
+ e = e .next ;
305
+ }
306
+ } //else filter
307
+ return r ;
315
308
}
316
309
317
310
private static DBColumn windowColumn (ViewDecorator vd , QueryContext ctx , DBColumn col ) {
@@ -322,21 +315,22 @@ private static DBColumn windowColumn(ViewDecorator vd, QueryContext ctx, DBColum
322
315
}
323
316
324
317
//view.resource | resource
325
- private Optional < ViewResource > lookupResource (ViewDecorator vd , QueryContext ctx , boolean filter ) { //do not change priority
318
+ private ViewResource lookupResource (ViewDecorator vd , QueryContext ctx , boolean filter ) { //do not change priority
326
319
if (hasNext ()) {
327
320
var rc = currentContext ().lookupRegisteredView (value );
328
321
if (rc .isPresent ()) {
329
322
var res = next .lookupQueryResource (rc .get ()) //declared query first
330
323
.or (()-> next .lookupViewResource (vd , ctx , rc .get (), filter ));
331
324
if (res .isPresent ()) {
332
325
requireNoArgs ();
333
- return res ;
326
+ return res . get () ;
334
327
}
335
328
}
336
329
} //view.id == column.id
337
330
return ctx .lookupDeclaredColumn (value )
338
331
.map (c -> new ViewResource (requireNoArgs (), null , null , c )) //declared column first
339
- .or (()-> lookupViewResource (vd , ctx , null , filter )); //registered column
332
+ .or (()-> lookupViewResource (vd , ctx , null , filter )) //registered column
333
+ .orElseThrow (()-> noSuchViewColumnException (this )); //no such resource
340
334
}
341
335
342
336
//query.column
@@ -353,23 +347,19 @@ private Optional<ViewResource> lookupQueryResource(ViewDecorator vd) {
353
347
//view[.operator|column[.criteria]|criteria]
354
348
private Optional <ViewResource > lookupViewResource (ViewDecorator vd , QueryContext ctx , ViewDecorator current , boolean filter ) {
355
349
var cur = requireNonNullElse (current , vd );
356
- var res = lookupOperation (vd , ctx , null , current )
350
+ var res = lookupViewOperation (vd , ctx , current )
357
351
.map (col -> new ViewResource (this , cur , null , col ))
358
352
.or (()-> lookupColumnResource (cur , filter ));
359
353
return filter ? res .or (()-> ofNullable (cur .criteria (value )).map (crt -> new ViewResource (this , cur , crt ))) : res ;
360
354
}
361
355
362
- private Optional <OperationColumn > lookupOperation (ViewDecorator vd , QueryContext ctx , DBColumn col , ViewDecorator current ) {
363
- var res = lookupOperator (value );
364
- if (isNull (col ) && nonNull (current )) { //view.[count|rank|rowNumber|danseRank]
365
- res = res .filter (op -> op .isCountFunction () || op .isWindowFunction ());
366
- }
367
- return res .map (fn -> {
368
- var c = col ;
369
- if (isNull (c ) && isEmpty (args ) && fn .isCountFunction ()) {
370
- c = allColumns (requireNonNullElse (current , vd ).view ());
371
- }
372
- return fn .operation (toArgs (vd , ctx , c , fn .getParameterSet ()));
356
+ private Optional <OperationColumn > lookupViewOperation (ViewDecorator vd , QueryContext ctx , ViewDecorator current ) {
357
+ //view.[count|rank|rowNumber|danseRank] only
358
+ return lookupOperator (value , isNull (current ) ? null : op -> op .isCountFunction () || op .isWindowFunction ()).map (fn -> {
359
+ var col = isEmpty (args ) && fn .isCountFunction ()
360
+ ? allColumns (requireNonNullElse (current , vd ).view ())
361
+ : null ;
362
+ return fn .operation (toArgs (vd , ctx , col , fn .getParameterSet ()));
373
363
});
374
364
}
375
365
@@ -384,7 +374,7 @@ private Optional<ViewResource> lookupColumnResource(ViewDecorator td, boolean fi
384
374
if (cmp .isPresent ()) {
385
375
return Optional .of (new ViewResource (requireNoArgs ().next , td , cd , col , cmp .get ()));
386
376
}
387
- var crt = cd .criteria (next .value );
377
+ var crt = cd .criteria (next .value ); //TD !operator
388
378
if (nonNull (crt )) {
389
379
return Optional .of (new ViewResource (requireNoArgs ().next , td , cd , col , crt ));
390
380
}
@@ -539,19 +529,19 @@ static final class ViewResource {
539
529
private TypedComparator cmp ;
540
530
541
531
public ViewResource (RequestEntryChain entry , ViewDecorator vd , ColumnDecorator cd , DBColumn col ) {
542
- this (entry , vd , cd , col , null , null , null );
532
+ this (entry , vd , cd , col , null , null , null ); //[view.]column
543
533
}
544
534
545
535
public ViewResource (RequestEntryChain entry , ViewDecorator vd , ColumnDecorator cd , DBColumn col , CriteriaBuilder <ComparisonExpression > colCrt ) {
546
- this (entry , vd , cd , col , null , colCrt , null );
536
+ this (entry , vd , cd , col , null , colCrt , null ); //[view.]colum.criteria
547
537
}
548
538
549
539
public ViewResource (RequestEntryChain entry , ViewDecorator vd , ColumnDecorator cd , DBColumn col , TypedComparator cmp ) {
550
- this (entry , vd , cd , col , null , null , cmp );
540
+ this (entry , vd , cd , col , null , null , cmp ); //[view.]colum.comparator
551
541
}
552
542
553
543
public ViewResource (RequestEntryChain entry , ViewDecorator vd , CriteriaBuilder <DBFilter > viewCrt ) {
554
- this (entry , vd , null , null , viewCrt , null , null );
544
+ this (entry , vd , null , null , viewCrt , null , null ); //[view.]criteria
555
545
}
556
546
557
547
boolean isFilter () {
0 commit comments