Search code examples
odatasapui5

Is it better to have just one OData dataSource?


My app's controllers mostly call one dataSource with no issues.

One of them, however uses three seperate datasources, and sometime returns 403 Forbidden errors when accessing them.

"dataSources": {
  "ZSV_SURVEY_SRV": {
    "uri": "/SAPUI5-ABAP-SFI/sap/opu/odata/sap/ZSV_SURVEY_SR/",
    "type": "OData",
    "settings": {
      "odataVersion": "2.0",
      "localUri": "localService/metadata.xml"
    }
  },
  "ZRUI_COMMON_SRV": {
    "uri": "/SAPUI5-ABAP-SFI/sap/opu/odata/sap/ZRUI_COMMON_SRV/",
    "type": "OData",
    "settings": {
      "odataVersion": "2.0",
      "localUri": "localService/ZRUI_COMMON_SRV/metadata.xml"
    }
  },
  "ZTC_SHOP_TRADING_CALENDAR_SRV": {
    "uri": "/SAPUI5-ABAP-SFI/sap/opu/odata/sap/ZTC_SHOP_TRADING_CALENDAR_SRV/",
    "type": "OData",
    "settings": {
      "odataVersion": "2.0",
      "localUri": "localService/ZTC_SHOP_TRADING_CALENDAR_SRV/metadata.xml"
    }
  }
}

Would it be better to incorporate the methods all into one dataSource (e.g. ZSV_SURVEY_SRV? Or should three separate dataSources be fine and present no problems?

If three dataSources are fine, why do I sometime get the 403 error?

Is there a performance advantage either way?


Solution

  • Apart from the 403 Forbidden error you are facing, having everything in the same service has its advantages:

    Design perspective

    1. OData supports multiple data sources inside the same service (entity sets)
    2. You can easily implement navigation properties between your entities
    3. You will need just one ODataModel instance inside your UI5 app
    4. There is no need to implement Promises or any other mechanism to make sure that all services are loaded successfully
    5. There would be no need to use complex bindings in UI5 taking data from two different models
    6. It's easy to imagine that a particular property should is present in more that one OData services. It's also possible to believe that you might also have errors due to inconsistencies between them (length, precision, scale, annotations, etc)

    Performance perspective

    1. As there would be only one metadata, there would be one only roundtrip to get it
    2. The changes of having your metadata cached for all services is smaller

    There are definitely more reason for using just one service. As a general rule a Fiori app uses only on service. Also, this service is only used by the Fiori app mentioned. This makes maintenance way easier.

    Of course there are exceptions for that, specially when it comes to annotation services.

    If you really need three different services for a good reason consider as well creating a 4th one combining all three. In SEGW you can combine other services inside a project by right-clicking in Data Model folder and using Include >> OData Service (GW) option

    But in any case make use of different entity sets in the same service. It's worth it.