Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Question regarding composite Primary Keys / fetch-Method used after add/update to DS

    Hello Isomorphic,

    from searching the forums (e.g. http://forums.smartclient.com/showth...e+Primary+Keys) and reading the docs (e.g. http://www.smartclient.com/smartgwte...imaryKey%28%29) I get that you strongly advise not to use composite primary keys.

    In my example I have a composite PK in the DB, but don't need it in SmartGWT (id=sequence, tenant_id=integer; "id" alone would be identifying, but to have all foreign keys to link only "inside the same tenant", I add the tenant_id to the PK).

    The PK in the DB is (tenant_id, id) not the other way around. In SmartGWT it is only id.

    What happens after an add to a DataSource is now that SmartGWT gets sequenceName.CurrVal and does a fetch with it. For update it already has the PK and does the fetch.
    I'd like to interfere here and add the tenant_id to the fetch. Is this somehow possible?
    I subclassed the IDACall Servlet
    Code:
    @Override
    public DSResponse handleDSRequest(DSRequest arg0, RPCManager arg1, RequestContext arg2) throws Exception {...}
    
    and
    
    @Override
    public void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {...}
    , but these methods are not used for the auto-fetch after the add/update.

    If I could @override here as well I could add the tenant_id and use only one sequence-PK in SmartGWT as you suggest.
    Is that somehow possible?

    The other possibility I see is using useForCacheSync (http://www.smartclient.com/smartgwte...seForCacheSync) with an additional <criteria>-clause in every DS, but this adds a lot of boilerplate code.

    Thank you & Best regards,
    Blama

    #2
    useForCacheSync or operationBinding.cacheSyncOperation is the right way to handle this.

    There's no reason this would add a bunch of "boilerplate" to multiple DataSources. It would be required at most only in the DataSource where you have a composite key.

    Comment


      #3
      Hi Isomorphic,

      thanks for the answer and pointing me into the right direction.
      For me it means boilerplate code, as really all tables have the composite PK (tenant_id, id) in Oracle and all FK link a column-pair (tenant_id, {parent_table_name}_id) to one of these PKs.
      I did it this way as I can then ensure on DB level, that information "never leaves a tenant".

      For me it is fine the way it is, even with the boilerplate code, but if it's possible sometime in the future to @override something here (most likely the "DataSourceDMI: no public method name: fetch available on class: xxx - defaulting to builtin operations"-method (sometimes seen in the log; don't know which internal class), it would be great to know.

      Best regards,
      Blama

      Comment


        #4
        Hello everyone,

        in case you are doing something similar, please see this thread for the solution: http://forums.smartclient.com/showthread.php?t=28646

        Best regards,
        Blama

        Comment

        Working...
        X