db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arne.sie...@pta.de
Subject Antwort: AW: Antwort: blocking calls, query timeout
Date Thu, 09 Sep 2004 14:16:01 GMT

Hi Tino,

good question . . .

One would like to be able to override the createQueryString method of the
XxxPeer class, but - alas! - it is a static method :-(

The only solution I see is implement some additional methods in your
XxxPeer class that do everything that's already in the BaseXxxPeer class,
but with the modified select statement (please note that I have appended
"ForUpdateNowait" to the method names):

    public static Xxx retrieveByPKForUpdateNowait(ObjectKey pk, Connection
con)
        throws TorqueException, NoRowsException, TooManyRowsException
    {
        Criteria criteria = buildCriteria(pk);
        List v = doSelectForUpdateNowait(criteria, con);
        if (v.size() == 0)
        {
            throw new NoRowsException("Failed to select a row.");
        }
        else if (v.size() > 1)
        {
            throw new TooManyRowsException("Failed to select only one
row.");
        }
        else
        {
            return (Xxx)v.get(0);
        }
    }

    public static List doSelectForUpdateNowait(Criteria criteria,
Connection con)
        throws TorqueException
    {
        return
populateObjects(doSelectForUpdateNowaitVillageRecords(criteria, con));
    }

    public static List doSelectForUpdateNowaitVillageRecords(Criteria
criteria, Connection con)
        throws TorqueException
    {
        if (criteria.getSelectColumns().size() == 0)
        {
            addSelectColumns(criteria);
        }


        // Set the correct dbName if it has not been overridden
        // criteria.getDbName will return the same object if not set to
        // another value so == check is okay and faster
        if (criteria.getDbName() == Torque.getDefaultDB())
        {
            criteria.setDbName(DATABASE_NAME);
        }
        // BasePeer returns a List of Value (Village) arrays.  The array
        // order follows the order columns were placed in the Select
clause.
//        if (con == null)
//        {
//            return BasePeer.doSelect(criteria);
//        }
//        else
//        {
//            return BasePeer.doSelect(criteria, con);
//        }

        return BasePeer.executeQuery(
            createQueryString(criteria) + " FOR UPDATE NOWAIT",
            criteria.getOffset(),
            criteria.getLimit(),
            criteria.isSingleRecord(),
            con);
    }

Please note that this code presumes you have a non-null Connection con when
invoking retrieveByPKForUpdateNowait.

I have not tested if this code actually works, but perhaps you've got the
time to do this and report your experience back...

Gruss
Arne


"Sperlich, Tino" wrote:


Hi Arne,

thanks for your replies.
The nowait option really
seems to be doing what is required:
return if the row is blocked by
smbd. else.

excuse me if I keep asking, but
how would I code that with Torque?

Do I have to create a custom query
or even raw sql? that would be the
very last choice since then
I would loose torque mapping db-stuff
to my objects...

I saw that in Hibernate the criteria object
has the setQueryTimeout option, and
I have also looked at the torque source
and it seems to me that adding that to
torque/village is quite an effort...

Gruesse,

Tino




**********************************************************************
http://www.pta.de
Mit 1006 Erfahrungsberichten aus 35 Jahren erfolgreicher Projektarbeit!
**********************************************************************



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Mime
View raw message