Announcement

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

    Loading Audit Datasource

    Version: Isomorphic SmartClient/SmartGWT Framework (v13.0p_2023-10-12/Enterprise Deployment 2023-10-12)

    I'm trying to use the automatic auditing feature. I have a SQL datasource where I added audit="true":

    Code:
    <DataSource ID="Customer" serverType="sql" tableName="customer" audit="true">
    The audit table is working fine, changes in the original datasource are being added to the audit table. When I try to query from the audit table, I'm using:

    Code:
    DataSource.get("audit_Customer")
    which is returning null. I'm following this guide: https://smartclient.com/smartgwtee/showcase/#auditing

    I don't see anything else declared to query the audit table. Is there something I'm missing?

    Thanks!

    #2
    DataSource.get() does not cause a DataSource to be loaded, so most likely, you simply didn't load the audit DataSource. DataSource.load(), or use of the DataSourceLoader servlet, is the way to do that.

    Also, as the docs note, the main DataSource must be loaded before attempting to retrieve an automatically created audit DataSource. So make sure you are also loading the "Customer" DataSource.

    Comment


      #3
      I added the "audit_Customer" data source to our index page to load it, that throws an error on the server when loading:

      Code:
      javax.servlet.ServletException: DataSource 'audit_Customer' failed to load due to an exception on the server:
      Unable to load DataSource for ID: audit_Customer
      See the server-side log for additional details.
          at com.isomorphic.servlet.DataSourceLoader.processRequest(DataSourceLoader.java:215)
          at com.isomorphic.servlet.DataSourceLoader.doGet(DataSourceLoader.java:112)
      ...
      I don't actually have a ds.xml file for this datasource, I'm making the assumption that it's derived from the Customer.ds.xml.

      Comment


        #4
        As mentioned above, you also need to load the "Customer" DataSource in order to load its audit DataSource. Did you do that?

        Comment


          #5
          Yes, this is an existing application with already functioning data sources. I added loading the audit_Customer data source right after the Customer data source.

          Comment


            #6
            OK, at this point, you're saying you're doing exactly what is shown working in the sample, and it just doesn't work. This is a good time to be checking for silly errors, like having updated the code and accidently retesting before having actually saved, or changing the code in one project but accidentally testing in another project - that kind of thing.

            Then, if you need further help with this, as noted in the error message itself, we'll need to see the rest of the log, not just the partial stack trace. Note it's best to just proactively provide this, so time isn't wasted asking for basic diagnostics.

            Comment


              #7
              Figured it out, switched this:

              Code:
              <script src="admin/sc/DataSourceLoader?dataSource=Customer"></script>
              <script src="admin/sc/DataSourceLoader?dataSource=audit_Customer"></script>
              to this:

              Code:
              <script src="admin/sc/DataSourceLoader?dataSource=Customer,audit_Customer"></script>

              Comment


                #8
                Yes, as we mentioned, you must load the Customer DataSource before audit_Customer.

                Two script tags are executed as two parallel requests by the browser, so your first request will fail.

                Note also that when using <script src=> tags with DataSourceLoader, you want to combine as much as you can, as that's much more efficient.

                Comment

                Working...
                X