Suppose I have Person who owns Cars:
<composed selector='Person'>
<mapped selector='cars'>
<ref selector='car' m:href='Car'/>
</mapped>
</composed>
Lets say I want to add a new car to this person's collection:
Transaction<Person> txPerson = repo.connect(this);
Person p = txPerson.retrieve("Person", "1");
Transaction<Car> txCar = repo.connect(this);
Car c = txCar.create("Car");
p.getCars().put("carname", c);
txPerson.post();
Will posting just the Person Transaction be enough to ensure that the new car is posted to the database, or should txCar.post be called after creating it?
Can a new Car be created using the txPerson transaction like so:
Car s = (Car) txPerson.create("Car");
Will this work, is it considered poor form, will there be any unintended side-effects?
Should txCar be closed after creating the Car, or should it be left open until the changes to Person are posted?
If the changes to Person are posted, and then the Car is modified and posted using txCar, will everything update as expected?
If I execute the following code:
Transaction<Person> txPerson1 = repo.connect(this);
Person p1 = txPerson1.retrieve("Person", "1");
Transaction<Car> txCar = repo.connect(this);
Car c1 = txCar.create("Car");
Car c2 = txCar.create("Car");
p1.getCars().put("carname", c1);
Transaction<Person> txPerson2 = repo.connect(this);
Person p2 = txPerson2.retrieve("Person", "1");
p2.getCars().put("carname", c2);
txPerson2.post();
will txPerson2 retrieve an in-memory, modified instance of person-1, or a fresh copy from the database? When I post txPerson2, will it add c1 to the list of cars, or just c2?
Diff: