You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Parvathi Rajaraman <Pa...@metcash.com> on 2004/10/11 06:15:40 UTC
Regd Updating Selected Columns
Hi,
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??
Cheers
Paru
#####################################################################################
This e-mail message has been scanned for Viruses and Content and cleared
by NetIQ MailMarshal
#####################################################################################
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: Regd Updating Selected Columns
Posted by Armin Waibel <ar...@apache.org>.
Parvathi Rajaraman wrote:
> Hi,
>
> 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??
>
Sorry, currently this will be not supported.
Will be possible in OJB1.1 but maybe we can do a backport to OJB 1.0.x
for this feature.
regards,
Armin
> Cheers
> Paru
>
> #####################################################################################
> This e-mail message has been scanned for Viruses and Content and cleared
> by NetIQ MailMarshal
> #####################################################################################
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: Regd Updating Selected Columns
Posted by Edson Carlos Ericksson Richter <ed...@mgrinformatica.com.br>.
Just my 2c (dont blame me if it's too simplistic):
I've implemented "selective updates" in current OJB 1.0.1 creating two
beans to same table. I 've used PropertyUtils.copyProperties to
transport info from one bean to another.
This will work for references, collections supers and so on. To let you
know, my "mini" bean has no collections, and references to only objects
desired by the project.
In real, my most selective bean is extended by the less restrictive bean.
Then I don't put <extent-class> in ojb repository, and make two mappings.
Was relativelly easy (but I'll recommend you make a class diagrams for
every thing, because inherace make projects starts to be highly
complex), and make no need to change OJB at all.
Best regards,
Edson Richter
Armin Waibel escreveu:
> Hi Ludo,
>
> Ludovic Maitre (POP - Factory Part) wrote:
>
>> Hello Armin,
>>
>> This is tried. The code is good but only for updating selected fields
>> not the reference objects (foreign keys and collections).
>
>
> right, the intention is to allow update of "normal" fields.
>
>> In fact, if we add the necessary code to fetch also the object
>> references descriptors, the collection descriptors, the corresponding
>> class descriptors, the anonymous fields corresponding to the object
>> references descriptors... this become heavy. As i have understand the
>> update method in OJB 1.1, it operate only on fields also, isn't it ?
>
>
> yep
>
>> The "hasMultiMappedReference" at the end of the update method is for
>> fetching somethink like a super class no ? It isn't for fetching (and
>> filtering) the objects reference descriptors to update ?
>
>
> right, references will be ignored (except the "super"-references to
> support fields of inherited fields).
> I think you need another feature scheduled for OJB1.1 which will allow
> runtime changes of the auto-xxx settings of references. I not started
> work today (my prototype was lost in a hard-disk crash some month ago
> ;-)). Here is a post made to this subject
>
> http://nagoya.apache.org/eyebrowse/ReadMsg?listName=ojb-dev@db.apache.org&msgNo=6912
>
>
> regards,
> Armin
>
>> Regards,
>> Ludo
>>
>> Armin Waibel wrote:
>>
>>> Hi Ludo,
>>>
>>> if "enableChangePerThread" is set true, your workaround should be
>>> valid.
>>>
>>> The only drawback is the
>>> > DescriptorRepository dr = manager.copyOfGlobalRepository();
>>> call. If you have thousands of objects this method is costly
>>> (serialization of the DescriptorRepository instance).
>>>
>>> Think to make it faster (but more complex) you can try to use a
>>> temporary DescriptorRepository instance with temp ClassDescriptor
>>> (not tested, only suggestion, does not work when using multiple
>>> joined table):
>>>
>>> Seems to be complex, but should be faster than serialize the whole
>>> global DescriptorRepository on each method call.
>>>
>>> public void update(Object target, String[] fieldsToUpdate)
>>> {
>>> DescriptorRepository temp = createTempRepositoryFor(
>>> manager.getRepository().getDescriptorFor(target.getClass()),
>>> fieldsToUpdate);
>>> manager.setDescriptor(temp);
>>> PersistenceBroker broker = getBroker();
>>> try
>>> {
>>> /*
>>> now we can store the object to update
>>> */
>>> //...
>>> broker.beginTransaction();
>>> broker.store(target);
>>> broker.commitTransaction();
>>> //... cleanup broker, exception handling
>>> }
>>> finally
>>> {
>>> manager.setDescriptor(null);
>>> }
>>> }
>>>
>>> private DescriptorRepository createTempRepositoryFor(ClassDescriptor
>>> target, String[] fieldsToUpdate)
>>> {
>>> DescriptorRepository temp = new DescriptorRepository();
>>> ClassDescriptor cld = new ClassDescriptor(temp);
>>> temp.setClassDescriptor(cld);
>>> // if an schema was used this method need more tweak to resolve
>>> table name
>>> cld.setTableName(target.getFullTableName());
>>> FieldDescriptor[] fields = getFieldsToUpdate(cld, fieldsToUpdate);
>>> for(int i = 0; i < fields.length; i++)
>>> {
>>> FieldDescriptor field = fields[i];
>>> cld.addFieldDescriptor(field);
>>> }
>>> return temp;
>>> }
>>>
>>>
>>> private FieldDescriptor[] getFieldsToUpdate(ClassDescriptor target,
>>> String[] fieldsToUpdate)
>>> {
>>> ArrayList result = new ArrayList();
>>> FieldDescriptor[] fields = target.getFieldDescriptions();
>>> for(int i = 0; i < fieldsToUpdate.length; i++)
>>> {
>>> String fieldName = fieldsToUpdate[i];
>>> for(int k = 0; k < fields.length; k++)
>>> {
>>> FieldDescriptor field = fields[k];
>>>
>>> if(field.getPersistentField().getName().equalsIgnoreCase(fieldName))
>>> {
>>> // make deep copy of used field
>>> result.add(SerializationUtils.clone(field));
>>> break;
>>> }
>>> }
>>> }
>>> if(fieldsToUpdate.length != result.size())
>>> {
>>> // throw exception, not all fields could be found
>>> }
>>> return (FieldDescriptor[]) result.toArray(new
>>> FieldDescriptor[result.size()]);
>>> }
>>>
>>> regards,
>>> Armin
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: Regd Updating Selected Columns
Posted by Armin Waibel <ar...@apache.org>.
Hi Ludo,
Ludovic Maitre (POP - Factory Part) wrote:
> Hello Armin,
>
> This is tried. The code is good but only for updating selected fields
> not the reference objects (foreign keys and collections).
right, the intention is to allow update of "normal" fields.
> In fact, if we add the necessary code to fetch also the object
> references descriptors, the collection descriptors, the corresponding
> class descriptors, the anonymous fields corresponding to the object
> references descriptors... this become heavy. As i have understand the
> update method in OJB 1.1, it operate only on fields also, isn't it ?
yep
> The "hasMultiMappedReference" at the end of the update method is for
> fetching somethink like a super class no ? It isn't for fetching (and
> filtering) the objects reference descriptors to update ?
right, references will be ignored (except the "super"-references to
support fields of inherited fields).
I think you need another feature scheduled for OJB1.1 which will allow
runtime changes of the auto-xxx settings of references. I not started
work today (my prototype was lost in a hard-disk crash some month ago
;-)). Here is a post made to this subject
http://nagoya.apache.org/eyebrowse/ReadMsg?listName=ojb-dev@db.apache.org&msgNo=6912
regards,
Armin
> Regards,
> Ludo
>
> Armin Waibel wrote:
>
>> Hi Ludo,
>>
>> if "enableChangePerThread" is set true, your workaround should be valid.
>>
>> The only drawback is the
>> > DescriptorRepository dr = manager.copyOfGlobalRepository();
>> call. If you have thousands of objects this method is costly
>> (serialization of the DescriptorRepository instance).
>>
>> Think to make it faster (but more complex) you can try to use a
>> temporary DescriptorRepository instance with temp ClassDescriptor (not
>> tested, only suggestion, does not work when using multiple joined table):
>>
>> Seems to be complex, but should be faster than serialize the whole
>> global DescriptorRepository on each method call.
>>
>> public void update(Object target, String[] fieldsToUpdate)
>> {
>> DescriptorRepository temp = createTempRepositoryFor(
>> manager.getRepository().getDescriptorFor(target.getClass()),
>> fieldsToUpdate);
>> manager.setDescriptor(temp);
>> PersistenceBroker broker = getBroker();
>> try
>> {
>> /*
>> now we can store the object to update
>> */
>> //...
>> broker.beginTransaction();
>> broker.store(target);
>> broker.commitTransaction();
>> //... cleanup broker, exception handling
>> }
>> finally
>> {
>> manager.setDescriptor(null);
>> }
>> }
>>
>> private DescriptorRepository createTempRepositoryFor(ClassDescriptor
>> target, String[] fieldsToUpdate)
>> {
>> DescriptorRepository temp = new DescriptorRepository();
>> ClassDescriptor cld = new ClassDescriptor(temp);
>> temp.setClassDescriptor(cld);
>> // if an schema was used this method need more tweak to resolve
>> table name
>> cld.setTableName(target.getFullTableName());
>> FieldDescriptor[] fields = getFieldsToUpdate(cld, fieldsToUpdate);
>> for(int i = 0; i < fields.length; i++)
>> {
>> FieldDescriptor field = fields[i];
>> cld.addFieldDescriptor(field);
>> }
>> return temp;
>> }
>>
>>
>> private FieldDescriptor[] getFieldsToUpdate(ClassDescriptor target,
>> String[] fieldsToUpdate)
>> {
>> ArrayList result = new ArrayList();
>> FieldDescriptor[] fields = target.getFieldDescriptions();
>> for(int i = 0; i < fieldsToUpdate.length; i++)
>> {
>> String fieldName = fieldsToUpdate[i];
>> for(int k = 0; k < fields.length; k++)
>> {
>> FieldDescriptor field = fields[k];
>>
>> if(field.getPersistentField().getName().equalsIgnoreCase(fieldName))
>> {
>> // make deep copy of used field
>> result.add(SerializationUtils.clone(field));
>> break;
>> }
>> }
>> }
>> if(fieldsToUpdate.length != result.size())
>> {
>> // throw exception, not all fields could be found
>> }
>> return (FieldDescriptor[]) result.toArray(new
>> FieldDescriptor[result.size()]);
>> }
>>
>> regards,
>> Armin
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: Regd Updating Selected Columns
Posted by "Ludovic Maitre (POP - Factory Part)" <lm...@factory-part.com>.
Hello Armin,
This is tried. The code is good but only for updating selected fields
not the reference objects (foreign keys and collections).
In fact, if we add the necessary code to fetch also the object
references descriptors, the collection descriptors, the corresponding
class descriptors, the anonymous fields corresponding to the object
references descriptors... this become heavy. As i have understand the
update method in OJB 1.1, it operate only on fields also, isn't it ?
The "hasMultiMappedReference" at the end of the update method is for
fetching somethink like a super class no ? It isn't for fetching (and
filtering) the objects reference descriptors to update ?
Regards,
Ludo
Armin Waibel wrote:
> Hi Ludo,
>
> if "enableChangePerThread" is set true, your workaround should be valid.
>
> The only drawback is the
> > DescriptorRepository dr = manager.copyOfGlobalRepository();
> call. If you have thousands of objects this method is costly
> (serialization of the DescriptorRepository instance).
>
> Think to make it faster (but more complex) you can try to use a
> temporary DescriptorRepository instance with temp ClassDescriptor (not
> tested, only suggestion, does not work when using multiple joined table):
>
> Seems to be complex, but should be faster than serialize the whole
> global DescriptorRepository on each method call.
>
> public void update(Object target, String[] fieldsToUpdate)
> {
> DescriptorRepository temp = createTempRepositoryFor(
> manager.getRepository().getDescriptorFor(target.getClass()),
> fieldsToUpdate);
> manager.setDescriptor(temp);
> PersistenceBroker broker = getBroker();
> try
> {
> /*
> now we can store the object to update
> */
> //...
> broker.beginTransaction();
> broker.store(target);
> broker.commitTransaction();
> //... cleanup broker, exception handling
> }
> finally
> {
> manager.setDescriptor(null);
> }
> }
>
> private DescriptorRepository createTempRepositoryFor(ClassDescriptor
> target, String[] fieldsToUpdate)
> {
> DescriptorRepository temp = new DescriptorRepository();
> ClassDescriptor cld = new ClassDescriptor(temp);
> temp.setClassDescriptor(cld);
> // if an schema was used this method need more tweak to resolve
> table name
> cld.setTableName(target.getFullTableName());
> FieldDescriptor[] fields = getFieldsToUpdate(cld, fieldsToUpdate);
> for(int i = 0; i < fields.length; i++)
> {
> FieldDescriptor field = fields[i];
> cld.addFieldDescriptor(field);
> }
> return temp;
> }
>
>
> private FieldDescriptor[] getFieldsToUpdate(ClassDescriptor target,
> String[] fieldsToUpdate)
> {
> ArrayList result = new ArrayList();
> FieldDescriptor[] fields = target.getFieldDescriptions();
> for(int i = 0; i < fieldsToUpdate.length; i++)
> {
> String fieldName = fieldsToUpdate[i];
> for(int k = 0; k < fields.length; k++)
> {
> FieldDescriptor field = fields[k];
>
> if(field.getPersistentField().getName().equalsIgnoreCase(fieldName))
> {
> // make deep copy of used field
> result.add(SerializationUtils.clone(field));
> break;
> }
> }
> }
> if(fieldsToUpdate.length != result.size())
> {
> // throw exception, not all fields could be found
> }
> return (FieldDescriptor[]) result.toArray(new
> FieldDescriptor[result.size()]);
> }
>
> regards,
> Armin
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: Regd Updating Selected Columns
Posted by "Ludovic Maitre (POP - Factory Part)" <lm...@factory-part.com>.
Hello Armin,
And thanks for your response, we will try your suggestion soon, seems to
be more fast, as you have described. And the code that you give show me
some useful utilities methods.
Also, we will work on the issue on inheritance on multiple tables. As
you can imagine we have also other works so it could take some time
before we do it.
Sorry for this late response but i was teaching the last days,
Regards,
Ludo
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: Regd Updating Selected Columns
Posted by Armin Waibel <ar...@apache.org>.
Hi Ludo,
if "enableChangePerThread" is set true, your workaround should be valid.
The only drawback is the
> DescriptorRepository dr = manager.copyOfGlobalRepository();
call. If you have thousands of objects this method is costly
(serialization of the DescriptorRepository instance).
Think to make it faster (but more complex) you can try to use a
temporary DescriptorRepository instance with temp ClassDescriptor (not
tested, only suggestion, does not work when using multiple joined table):
Seems to be complex, but should be faster than serialize the whole
global DescriptorRepository on each method call.
public void update(Object target, String[] fieldsToUpdate)
{
DescriptorRepository temp = createTempRepositoryFor(
manager.getRepository().getDescriptorFor(target.getClass()),
fieldsToUpdate);
manager.setDescriptor(temp);
PersistenceBroker broker = getBroker();
try
{
/*
now we can store the object to update
*/
//...
broker.beginTransaction();
broker.store(target);
broker.commitTransaction();
//... cleanup broker, exception handling
}
finally
{
manager.setDescriptor(null);
}
}
private DescriptorRepository createTempRepositoryFor(ClassDescriptor
target, String[] fieldsToUpdate)
{
DescriptorRepository temp = new DescriptorRepository();
ClassDescriptor cld = new ClassDescriptor(temp);
temp.setClassDescriptor(cld);
// if an schema was used this method need more tweak to resolve
table name
cld.setTableName(target.getFullTableName());
FieldDescriptor[] fields = getFieldsToUpdate(cld, fieldsToUpdate);
for(int i = 0; i < fields.length; i++)
{
FieldDescriptor field = fields[i];
cld.addFieldDescriptor(field);
}
return temp;
}
private FieldDescriptor[] getFieldsToUpdate(ClassDescriptor target,
String[] fieldsToUpdate)
{
ArrayList result = new ArrayList();
FieldDescriptor[] fields = target.getFieldDescriptions();
for(int i = 0; i < fieldsToUpdate.length; i++)
{
String fieldName = fieldsToUpdate[i];
for(int k = 0; k < fields.length; k++)
{
FieldDescriptor field = fields[k];
if(field.getPersistentField().getName().equalsIgnoreCase(fieldName))
{
// make deep copy of used field
result.add(SerializationUtils.clone(field));
break;
}
}
}
if(fieldsToUpdate.length != result.size())
{
// throw exception, not all fields could be found
}
return (FieldDescriptor[]) result.toArray(new
FieldDescriptor[result.size()]);
}
regards,
Armin
Ludovic Maitre (POP - Factory Part) wrote:
> 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: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: Regd Updating Selected Columns
Posted by "Ludovic Maitre (POP - Factory Part)" <lm...@factory-part.com>.
The end of the code should be read (commentary before test for null for
ord[i] are removed:
//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]);
}
}
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: Regd Updating Selected Columns
Posted by "Ludovic Maitre (POP - Factory Part)" <lm...@factory-part.com>.
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: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: Regd Updating Selected Columns
Posted by Thomas Franke <fr...@mhr.de>.
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.
--
Mit freundlichen Grüßen
Thomas Franke
Projektleiter WIS-Projekt
----------------------------
Wissen Innovation Sicherheit
----------------------------
MedienHaus Rostock GmbH
Platz der Freundschaft 1
18059 Rostock
----------------------------
fon: +49 381 40 587 535
fax: +49 381 40 587 552
mobil: +49 1715222015
http://www.mhr.de/wis
mail: wis-info@mhr.de
----------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org