Announcement

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

    Injecting dynamically generated SQL in DSRequest

    Hi,

    Using SmartGWT Power Edition 4.0, I'm looking for a way to append dynamically generated SQL statements in SQL generated by SmartGWT.
    I can see SQLDataSource.getSQLClause() can return generated select, table and where clauses, so I can append SQL to it.
    But then, is there a way to reinject modified SQL somewhere?

    For now I can add what I want to the velocity template context (DSRequest.addToTemplateContext) and use it in the template through $rawValue, but that requires I create an operation binding for every method in that case, which is far from an ideal solution.

    Thanks in advance
    Regards
    Antoine

    #2
    If you have recurring Java logic across multiple DataSources, you can declare a Custom DataSource (see QuickStart Guide) and put Java the logic there, for example in an override of executeFetch().

    It's unclear how you can avoid adding an <operationBinding> each time you want to use this custom-generated SQL however. If you can give us some details on what the SQL is that you need to apply pervasively, we may be able to suggest other approaches (such as dataSourceField.customSelectExpression).

    Comment


      #3
      Hi,

      I have a custom datasource where all common java logic is done.

      In that datasource, I'd like to be able to inject some SQL generated outside of SmartGWT objects in DSRequests.
      For instance, I want to automatically add security clauses to the where clause when some datasource fields are present, or when a specific criteria is added to the DSRequest.

      Comment


        #4
        Sorry, that's too vague for us to help further. But we'd recommend a second look at dataSourceField.customSelectExpression.

        Also, if your modifications to the where clause simply introduce additional, fixed criteria, just use dsRequest.setCriteriaValue() to enforce fixed criteria. Or for more complex cases, use getAdvancedCriteria(), modify it, then setAdvancedCriteria().

        Comment


          #5
          Ok let's simplify the requirement a bit.
          Let's say I have third party code that generates SQL, and I want to add it to what SmartGWT generates.
          What are my options except passing it to the velocity template or parsing the SQL to build Criteria/AdvancedCriteria?

          Comment


            #6
            Your third option is direct execution of the SQL, which can be done in the context of the current transaction (see this sample).

            Comment

            Working...
            X