11package my .bookshop .handlers ;
22
3+ import static cds .gen .catalogservice .CatalogService_ .GENRE_HIERARCHY ;
4+
35import java .util .ArrayDeque ;
46import java .util .Comparator ;
57import java .util .Deque ;
2123import com .sap .cds .ql .cqn .CqnSelect ;
2224import com .sap .cds .ql .cqn .CqnValue ;
2325import com .sap .cds .ql .cqn .Modifier ;
24- import com .sap .cds .ql .cqn .transformation .CqnTopLevelsTransformation ;
2526import com .sap .cds .ql .cqn .transformation .CqnAncestorsTransformation ;
2627import com .sap .cds .ql .cqn .transformation .CqnDescendantsTransformation ;
2728import com .sap .cds .ql .cqn .transformation .CqnFilterTransformation ;
28- import com .sap .cds .ql .cqn .transformation .CqnSearchTransformation ;
2929import com .sap .cds .ql .cqn .transformation .CqnOrderByTransformation ;
30+ import com .sap .cds .ql .cqn .transformation .CqnSearchTransformation ;
31+ import com .sap .cds .ql .cqn .transformation .CqnTopLevelsTransformation ;
3032import com .sap .cds .ql .cqn .transformation .CqnTransformation ;
3133import com .sap .cds .services .cds .CdsReadEventContext ;
3234import com .sap .cds .services .cds .CqnService ;
3537import com .sap .cds .services .handler .annotations .ServiceName ;
3638import com .sap .cds .services .persistence .PersistenceService ;
3739
40+ import cds .gen .adminservice .AdminService_ ;
3841import cds .gen .catalogservice .CatalogService_ ;
3942import cds .gen .catalogservice .GenreHierarchy ;
4043import cds .gen .catalogservice .GenreHierarchy_ ;
4144
42- import static cds .gen .catalogservice .CatalogService_ .GENRE_HIERARCHY ;
43-
4445@ Component
4546@ Profile ("default" ) // non-HANA
46- @ ServiceName (CatalogService_ .CDS_NAME )
47+ @ ServiceName ({ CatalogService_ .CDS_NAME , AdminService_ . CDS_NAME } )
4748/**
4849 * On HANA, requests for GenreHierarchy are handled generically.
4950 *
@@ -62,7 +63,7 @@ public class HierarchyHandler implements EventHandler {
6263 this .db = db ;
6364 }
6465
65- @ Before (event = CqnService .EVENT_READ , entity = GenreHierarchy_ . CDS_NAME )
66+ @ Before (event = CqnService .EVENT_READ )
6667 public void readGenreHierarchy (CdsReadEventContext event ) {
6768 List <CqnTransformation > trafos = event .getCqn ().transformations ();
6869 List <GenreHierarchy > result = null ;
@@ -71,6 +72,12 @@ public void readGenreHierarchy(CdsReadEventContext event) {
7172 return ;
7273 }
7374
75+ // Fallback for draft-enabled scenario: plain table
76+ if (cds .gen .adminservice .GenreHierarchy_ .CDS_NAME .equals (event .getTarget ().getQualifiedName ())) {
77+ event .setResult (db .run (Select .from (cds .gen .adminservice .GenreHierarchy_ .class )));
78+ return ;
79+ }
80+
7481 if (getTopLevels (trafos ) instanceof CqnTopLevelsTransformation topLevels ) {
7582 result = topLevels (topLevels , CQL .TRUE );
7683 } else if (trafos .get (0 ) instanceof CqnDescendantsTransformation descendants ) {
0 commit comments