Hello,
I do this myself, updating only selected foreign keys or relationships (and fetching also). I give the code below, since i appreciate to have some feedback. This rely on modifying the meta datas at runtime, after having set enableChangePerThread (or something like this) to true in the initialization of OJB.
I anybody could say if i could remove the "i hope" from my commentary, i will appreciate.
Regards,
Ludo
This work and is implemented in a wrapper around pb api like this :
public synchronized Object store(Object o, String[] filter)
throws SQLException, DAOException {
String[] refs = getCurrentBean().getPersistentReferencesNames();
//first index: refs index, second index: 0: cascade store, 1: cascade delete
int[][] state = new int[refs.length][2];
ObjectReferenceDescriptor[] ords = new ObjectReferenceDescriptor[refs.length];
PBKey key = OJBHelper.getDefaultKey();
MetadataManager manager = OJBHelper.getManager();
DescriptorRepository dr = manager.copyOfGlobalRepository();
ClassDescriptor cld = dr.getDescriptorFor(currentBean);
Property p;
//create array of references and save state
for (int i = 0; i < refs.length; i++) {
ObjectReferenceDescriptor ord = cld
.getCollectionDescriptorByName(refs[i]);
if (ord == null)
ord = cld.getObjectReferenceDescriptorByName(refs[i]);
if (ord != null) {
ords[i] = ord;
p = getCurrentBean().getProperty(ord.getAttributeName());
state[i][0] = ord.getCascadingStore();
state[i][1] = ord.getCascadingDelete();
if (ArrayUtils.contains(filter, ord.getAttributeName())) {
if (p.getBean().isStatic()) { ord.setCascadingStore(ObjectReferenceDescriptor.CASCADE_LINK);
ord.setCascadingDelete(ObjectReferenceDescriptor.CASCADE_LINK);
} else {
ord.setCascadingStore(ObjectReferenceDescriptor.CASCADE_OBJECT);
ord.setCascadingDelete(ObjectReferenceDescriptor.CASCADE_OBJECT);
}
} else {
ord.setCascadingStore(ObjectReferenceDescriptor.CASCADE_NONE);
ord.setCascadingDelete(ObjectReferenceDescriptor.CASCADE_NONE);
}
//log.info(ord.getClassDescriptor().getRepository().getDescriptorFor(ord.getItemClassName()));
} else
log.error("No reference descriptor found for " + refs[i]);
}
manager.setDescriptor(dr);
PersistenceBroker broker = PersistenceBrokerFactory
.createPersistenceBroker(key);
broker.beginTransaction(); broker.store(o); broker.commitTransaction();
if (broker != null) broker.close();
//restore old state (i hope) for (int i = 0; i < ords.length; i++) { //if (ords[i] != null) { ords[i].setCascadingStore(state[i][0]); ords[i].setCascadingDelete(state[i][1]); //} } return o; }
Thomas Franke wrote:
Parvathi Rajaraman wrote:
Does anyone know how to update selected columns of a table using OJB. We are
using the PersistanceBroker API's store method that will either insert or
update all the columns based on the primary key value. But I want to update
only a few columns for multiple records based on a key value. Is this
possible??
No, at the time all columns will be updatet. Or you must write a special class with the columns you want to update.
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]