Re: query timeout needed

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Mon Nov 28 2005 - 07:51:54 EST

  • Next message: Andrus Adamchik: "Re: How to model Abstract Entities"

    Hi Fabien,

    Currently Cayenne doesn't support timeouts directly (might be a nice
    future addition), but you can take advantage of the new 1.2 Query API
    that allows query itself to control its execution at the JDBC level.
    The code below should give you a rough idea of how to customize JDBC
    calls with new query life-cycle API and SQLActions:

    class TimeoutAction extends
    org.objectstyle.cayenne.access.jdbc.SelectAction {
        int timeout;

        TimeoutAction(SelectQuery query, DbAdapter adapter,
                 EntityResolver entityResolver, int timeout) {
           super(query, adapter, entityResolver);

           this.timeout = timeout;
        }

        // override 'createTranslator' or 'performAction' to set
    PreparedStatement timeout
        // see superlcass source code for details.
    }

    class TimeoutQuery extends SelectQuery {

         public void route(QueryRouter router, EntityResolver resolver) {
            super.route(router, resolver);

            // store EntityResolver and DbAdapter to use later in
    'createSQLAction'
         }

         public SQLAction createSQLAction(SQLActionVisitor visitor) {
             // in constructor use parameters obtained in 'route'
             return new TimeoutAction(this, ....);
         }
    }

    Andrus

    On Nov 25, 2005, at 4:58 PM, fabien brunacci wrote:

    > hello,
    >
    > i need to get an excepetion when some query are to long
    >
    > i use a dataContext.performQuery(...)
    >
    >
    > is there a way to set a query timeout for this query
    >
    > (like in jdbc using statement.setQueryTimeout)
    >



    This archive was generated by hypermail 2.0.0 : Mon Nov 28 2005 - 07:51:52 EST