The testcase I've submitted below fails. The problem, I think, is that before a save() 
is called on an object whose collection has been modified, the modification is 
basically lost because of the way Torque caches the previous Criteria's dbhit. 
Attention to Line 1 and Line 2.

This situation would be possible in a high-load environment with lots of concurrent 
hits.

public class TorqueRunner
{
    /**
     * Category used for logging in the runtime test class.
     */
    private static Category cat =
            Category.getInstance(TorqueRunner.class.getName());

    public static void main(String[] args)
            throws TorqueException, Exception
    {
        String configurationFile = "/schema/Torque.properties";

        // initializing Torque
        try
        {
            Torque.init(configurationFile);
        }
        catch (Exception e)
        {
            throw new TorqueException("Can't initialize Torque!", e);
        }

        // run the tests
        TorqueRunner tr = new TorqueRunner();

        //tr.insertData();
        //tr.retrieveData();
        tr.test();
        Runtime.getRuntime().exit(0);
    }

    private void test() throws Exception
    {
        Civilization civ = new Civilization();
        civ.setCivId("1");
        civ.setName("Civilization");
        civ.save();

        int newCivPeopleSize = civ.getCivPeoples(new Criteria()).size();

        CivPeople cp = new CivPeople();
        cp.setCivId(civ.getCivId());
        People p = new People();
        p.setPeopleId("1");
        p.setName("peoplename");
        p.save();
        cp.setPeopleId(p.getPeopleId());
        //cp.save(); // Line 1
        civ.addCivPeople(cp);
        civ.getCivPeoples(new Criteria()).size(); // Line 2
        civ.save();
        civ = (Civilization) CivilizationPeer.doSelect(civ).firstElement();
        int newerCivPeopleSize = civ.getCivPeoples(new Criteria()).size();
        if (newerCivPeopleSize != (newCivPeopleSize + 1))
            throw new Exception("Added people not reflected! Expected:"
                                + (newCivPeopleSize + 1) + " but was:"
                                + newerCivPeopleSize);
    }
}


Regards,
Kelvin Tan

Relevanz Pte Ltd
http://www.relevanz.com

180B Bencoolen St.
The Bencoolen, #04-01
S(189648)

Tel: 238 6229
Fax: 337 4417

Reply via email to