* The old bug in ODMG wouldn't trigger an update if an object reference changed.
*/
public void testContractReassignment() throws Exception
{
Transaction tx = odmg.newTransaction();
Contract contract = new Contract();
contract.setPk("contract1");
contract.setContractValue1("contract1value1");
contract.setContractValue2(1);
contract.setContractValue3("contract1value3");
contract.setContractValue4(new Timestamp(System.currentTimeMillis()));
Version version = new Version();
version.setPk("version1");
version.setVersionValue1("version1value1");
version.setVersionValue2(1);
version.setVersionValue3(new Timestamp(System.currentTimeMillis()));
version.setContract(contract);
Effectiveness eff = new Effectiveness();
eff.setPk("eff1");
eff.setEffValue1("eff1value1");
eff.setEffValue2(1);
eff.setEffValue3(new Timestamp(System.currentTimeMillis()));
eff.setVersion(version);
Contract contract2 = new Contract();
contract2.setPk("contract2");
contract2.setContractValue1("contract2value1");
contract2.setContractValue2(1);
contract2.setContractValue3("contractvalue3");
contract2.setContractValue4(new Timestamp(System.currentTimeMillis()));
Version version2 = new Version();
version2.setPk("version2");
version2.setVersionValue1("version2value1");
version2.setVersionValue2(1);
version2.setVersionValue3(new Timestamp(System.currentTimeMillis()));
version2.setContract(contract2);
Effectiveness eff2 = new Effectiveness();
eff2.setPk("eff2");
eff2.setEffValue1("eff2value1");
eff2.setEffValue2(1);
eff2.setEffValue3(new Timestamp(System.currentTimeMillis()));
eff2.setVersion(version2);
/**
* make them persistent
*/
tx.begin();
database.makePersistent(eff2);
database.makePersistent(eff);
tx.commit();
/**
* do the reassignment
*/
tx.begin();
tx.lock(version, Transaction.WRITE);
tx.lock(version2, Transaction.WRITE);
version.setContract(contract2);
version2.setContract(contract);
tx.commit();
/**
* query and check values
*/
OQLQuery query = odmg.newOQLQuery();
String sql = "select version from " + org.apache.ojb.broker.Version.class.getName() + " where pk=$1";
query.create(sql);
query.bind("version1");
tx.begin();
ManageableCollection results = (ManageableCollection) query.execute();
// Iterator over the restricted articles objects
java.util.Iterator it = results.ojbIterator();
Version ver1 = null;
while (it.hasNext())
{
ver1 = (Version) it.next();
if (!ver1.getContract().getPk().equals(contract2.getPk()))
{
fail(ver1.getPk() + " should have pointed to contract2 instead it pointed to: " + ver1.getContract().getPk());
}
}
tx.commit();