> From: "Akmal Sarhan" <[EMAIL PROTECTED]>
>
> Using b3,I have a table "AGENT" that has a one-to-many relation to a table
> "CAR". I have noticed that the performance
> degregates dramatically whenever I want to add a new Car to the
> Agent.Debuging the code, I found that every time a Car
> is added to the Agent, all the old Cars of this agent are resaved, which
> means that if the agent has 999 cars already and
> I want to add just a new car, the save() method of the Car is called 1000
> times?!!!!!!!!!
> here is the generated save method of the Agent that causes this problem. So
> my question is why would I need to save
> the old "not-changed" Cars every car is added, Am I missing something, or is
> this a bug?
The code below is from Agent, so I assume you are doing something like this:
Car car = new Car();
// populate car
agent.addCar(car);
agent.save();
So:
1. The saves are not happening when you add the car, but when you save the
agent - you can add multiple cars and save them all in the one hit.
2. The code below will indeed iterate through all 1000 Cars invoking their
save(dbCon) method - that method will however look fairly similar to the one
below in that it will only save the car if it is new, or has been modified -
i.e. In your case it should only save 1 Car. Now if you would like to
provide some specific tests that illustrate that invoking this method 1000
times is causing significant performance degradation then please do so - I
think however that you will find it is fairly insignificant.
3. An alternative is to go:
Car car = new Car();
// populate car
car.setAgentId(agent.getAgentId());
car.save();
>
> public void save(DBConnection dbCon)
> throws TorqueException
> {
> if (!alreadyInSave)
> {
> alreadyInSave = true;
>
> // If this object has been modified, then save it to the
> database.
> if (isModified())
> {
> if (isNew())
> {
> AgentPeer.doInsert((Agent) this, dbCon);
> setNew(false);
> }
> else
> {
> AgentPeer.doUpdate((Agent) this, dbCon);
> }
> }
>
> if (collCars != null)
> {
> for (int i = 0; i < collCars.size(); i++)
> {
> ((Car) collCars.get(i)).save(dbCon);
> }
> }
>
> alreadyInSave = false;
> }
> }
>
> best regards
> Akmal
HTH,
Scott
--
Scott Eade
Backstage Technologies Pty. Ltd.
http://www.backstagetech.com.au
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>