Search code examples
javasqljdodatanucleusintercept

Is it possible to intercept all DataNucleus' JDO SQL queries?


Assuming one has an operational Java application using DataNucleus's implementation of JDO to access a database, is it possible to intercept all SQL queries made to the database? The intention is to run statistics on them and keep a log/trace.


Solution

  • You may easily get logs of all SQL statements from DataNucleus by turning on the category DataNucleus.Datastore.Native (see http://www.datanucleus.org/products/datanucleus/logging.html)

    JDO2 InstanceLifecycleListeners would allow you to intercept events, but I don't think the SQL statements would be available there...

    You can also look to your app server for SQL profiling tools. For example GlassFish allows you to attach SQLTraceListener implementations to your connection pools. See http://docs.oracle.com/cd/E18930_01/html/821-2418/giyck.html#giygg