Well, yeah, the query is translated at the lower level of the stack,
so the generated SQL is not available from the query object directly.
You can probably intercept the generated SQL by wrapping DataSource/
Connection/PreparedStatement. Or maybe use Log4J API with a custom
Log4J appender for the QueryLogger logger. SQLException may or may
not contain the info you are looking for - worse checking of course.
Andrus
On Aug 18, 2006, at 8:04 AM, Andreas Pardeike wrote:
> Hi,
>
> I am trying to set up an error page in my web application that
> sends error
> details to me. I can easily get the stack trace and other variables
> but
> I can't the heck find out how to get the last query cayenne has
> executed.
>
> So far, I have managed to set up a DataContextDelegate that is
> called for
> every query but I cannot get it to store some valuable info from
> the current
> query.
>
> What I want is to retrieve similar information as to what the
> QueryLogger
> writes into the log.
>
>> INFO QueryLogger: SELECT t0.SOMPR1, t0.SOMPR2, t0.SOM .. [bind....]
>
> Is that possible?
>
> Or is there an even easier way to retrieve information about the
> querie
> at the place where the SQLException is thrown by accessing the
> exception
> itself?
>
> Thanks,
> Andreas Pardeike
>
>
>
> Here's my DataContextDelegate code in my global application object:
>
>> dataContext = DataContext.createDataContext();
>> dataContextDelegate = new DataContextDelegate()
>> {
>> public void finishedMergeChanges(DataObject object) {}
>> public void finishedProcessDelete(DataObject object) {}
>> public boolean shouldProcessDelete(DataObject object) { return
>> true; }
>> public boolean shouldMergeChanges(DataObject object, DataRow
>> snapshotInStore) { return true; }
>>
>> private void store(String type, DataContext c, Query q)
>> {
>> // TODO - get and store info about the current query
>> // so it can be fetched later at the exception
>> displaying page
>> }
>>
>> public org.objectstyle.cayenne.query.GenericSelectQuery
>> willPerformSelect(DataContext context,
>> org.objectstyle.cayenne.query.GenericSelectQuery query)
>> {
>> store("GenericSelectQuery", context, query);
>> lastQuery = query;
>> return query;
>> }
>>
>> public Query willPerformQuery(DataContext context, Query query)
>> {
>> store("Query", context, query);
>> lastQuery = query;
>> return query;
>> }
>>
>> public Query willPerformGenericQuery(DataContext context, Query
>> query)
>> {
>> store("GenericQuery", context, query);
>> lastQuery = query;
>> return query;
>> }
>> };
>>
>> dataContext.setDelegate(dataContextDelegate);
>
This archive was generated by hypermail 2.0.0 : Fri Aug 18 2006 - 10:12:04 EDT