Hello,
I have simple framework to work with Castor as simplicity.
Someone ask me why method JDOWorker.update look like:
public void update(JDOObject o) {
Database db = null;
try {
db = getDatabase();
db.begin();
// Get persistence object
JDOObject persistent = (JDOObject)db.load(o.getClass(),
getIdentity(o));
// Copy fields to persistense object
jdoObjectCopy(o, persistent);
db.commit();
} catch (Exception ex) {
throw new JDOException("jdo.updateError", new Object[]{o}, ex);
} finally {
closeDatabase(db);
}
}
But not simple:
public void update(Object o) {
Database db = null;
try {
db = getDatabase();
db.begin();
db.update(o);
db.commit();
} catch (Exception ex) {
throw new JDOException("jdo.updateError", new Object[]{o}, ex);
} finally {
closeDatabase(db);
}
}
I have long time inspecting what is method Database.update is, and I
have two test that not work correctly on Castor 0.9.5:
public void testUpdate_LockNotGranted() {
Database db1 = null;
Database db2 = null;
try {
TestJDOObject jdoObject =
(TestJDOObject)jdoWorker.load(TestJDOObject.class, "3");
db1 = jdoWorker.getDatabase();
db2 = jdoWorker.getDatabase();
db1.begin();
db2.begin();
jdoObject.setData("this is current Timestamp " +
System.currentTimeMillis());
db1.update(jdoObject);
jdoObject.setData("this is current Timestamp " +
System.currentTimeMillis());
db2.update(jdoObject);
db1.commit();
db2.commit();
assertTrue(true);
} catch (Exception ex) {
ex.printStackTrace();
assertFalse(true);
} finally {
jdoWorker.closeDatabase(db1);
jdoWorker.closeDatabase(db2);
}
}
public void testUpdate_DuplicateIdentity() {
Database db = null;
try {
// Construct copy of existing object in database
TestJDOObject jdoObject = new TestJDOObject();
jdoObject.setId("3");
jdoObject.setData("this is current Timestamp " +
System.currentTimeMillis());
db = jdoWorker.getDatabase();
db.begin();
db.update(jdoObject);
db.commit();
assertTrue(true);
} catch (Exception ex) {
ex.printStackTrace();
assertFalse(true);
} finally {
jdoWorker.closeDatabase(db);
}
}
Fisrt method always throw LockNotGrantedException and second always
throw DuplicateIdentityException.
Also I find, that method Database.update work correctly only in ONE
thread (object must be updated only in ONE Database at one time), and
also before calling db.update the user MUST have call db.load. So, I
have save my method without changes, becose Database.update is not
stable, I guess...
Some body have any information about such reaction of this method
(Database.update)?
Thanks!
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev