Re: soft-deleting objects
his.addEqualTo( "deleted", bValue ); } } Works for me. I usually create a Criteria object for each OJB Object that I have. I add a bunch of convenience methods to add values to the criteria. Charlie Tino Schöllhorn wrote: Hallo Daniel, that sound great. But still I do have one question: how could you then load all non-deleted object *without* using the deleted-flag. I mean something like Criteria crit = new Criteria(); // I can use any criteria here but I don't want to have to use "deleted" Query q = QueryFactory.newQuery(MyClass, myCriteria); Collection objects = pb.getCollectionByQuery(q); // the result are all Objects which have the deleted-flag == false Any suggestions? regards Tino Daniel Perry wrote: I am using this in a complex app (due to idiot admin users deleting stuff they shouldnt!). All objects have a boolean (mapped to int) "deleted". For all queries i look for objects with deleted=false. For relationships, i wrote a querycustomizer which adds deleted=false to collections. (see below example) It;s very simple and works a treat! If you have a 'base' bean, which all other beans inherit, you can put the 'deleted' attribute there, and can use a delete method for deleting any beans! (note: i dont use extents for this in the repository, just map it for all beans) element-class-ref="com.netcase.pdp.bo.JobSubFamily" proxy="true"> class="com.netcase.pdp.ojb.NestedElementCustomQuery"> attribute-value="deleted"/> -Original Message- From: Brian McCallister [mailto:[EMAIL PROTECTED] Sent: 23 March 2004 14:01 To: OJB Users List Subject: Re: soft-deleting objects If you have a "deleted" style flag in the database for the soft delete you can probably accomplish this via a query customizer. If you mean to not flag the delete in the database at all, but only treat it as such in the application -- that is a bit trickier, but can probably be done via pb callbacks/row readers. -Brian On Mar 23, 2004, at 6:21 AM, Tino Schöllhorn wrote: Hi, I want to implement something like a soft-delete: Objects should be marked as "deleted" in its corresponing table and OJB should just ignore them when it is materializing or querying them. Where would be the best point to start when I want to implement this feature? I just played around with the RowReader-Concept - but I have the feeling that this is not the right place to start, because I think I have to modify the queries OJB is submitting to the database. Any ideas? Regards Tino - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: soft-deleting objects
something like Criteria crit = new Criteria(); // I can use any criteria here but I don't want to have to use "deleted" Query q = QueryFactory.newQuery(MyClass, myCriteria); Collection objects = pb.getCollectionByQuery(q); // the result are all Objects which have the deleted-flag == false Any suggestions? regards Tino Daniel Perry wrote: I am using this in a complex app (due to idiot admin users deleting stuff they shouldnt!). All objects have a boolean (mapped to int) "deleted". For all queries i look for objects with deleted=false. For relationships, i wrote a querycustomizer which adds deleted=false to collections. (see below example) It;s very simple and works a treat! If you have a 'base' bean, which all other beans inherit, you can put the 'deleted' attribute there, and can use a delete method for deleting any beans! (note: i dont use extents for this in the repository, just map it for all beans) element-class-ref="com.netcase.pdp.bo.JobSubFamily" proxy="true"> class="com.netcase.pdp.ojb.NestedElementCustomQuery"> attribute-value="deleted"/> -Original Message- From: Brian McCallister [mailto:[EMAIL PROTECTED] Sent: 23 March 2004 14:01 To: OJB Users List Subject: Re: soft-deleting objects If you have a "deleted" style flag in the database for the soft delete you can probably accomplish this via a query customizer. If you mean to not flag the delete in the database at all, but only treat it as such in the application -- that is a bit trickier, but can probably be done via pb callbacks/row readers. -Brian On Mar 23, 2004, at 6:21 AM, Tino Schöllhorn wrote: Hi, I want to implement something like a soft-delete: Objects should be marked as "deleted" in its corresponing table and OJB should just ignore them when it is materializing or querying them. Where would be the best point to start when I want to implement this feature? I just played around with the RowReader-Concept - but I have the feeling that this is not the right place to start, because I think I have to modify the queries OJB is submitting to the database. Any ideas? Regards Tino - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: soft-deleting objects
If you have a 'base' bean, which all other beans inherit, you can put the 'deleted' attribute there, and can use a delete method for deleting any beans! (note: i dont use extents for this in the repository, just map it for all beans) element-class-ref="com.netcase.pdp.bo.JobSubFamily" proxy="true"> class="com.netcase.pdp.ojb.NestedElementCustomQuery"> attribute-value="deleted"/> -----Original Message- From: Brian McCallister [mailto:[EMAIL PROTECTED] Sent: 23 March 2004 14:01 To: OJB Users List Subject: Re: soft-deleting objects If you have a "deleted" style flag in the database for the soft delete you can probably accomplish this via a query customizer. If you mean to not flag the delete in the database at all, but only treat it as such in the application -- that is a bit trickier, but can probably be done via pb callbacks/row readers. -Brian On Mar 23, 2004, at 6:21 AM, Tino Schöllhorn wrote: Hi, I want to implement something like a soft-delete: Objects should be marked as "deleted" in its corresponing table and OJB should just ignore them when it is materializing or querying them. Where would be the best point to start when I want to implement this feature? I just played around with the RowReader-Concept - but I have the feeling that this is not the right place to start, because I think I have to modify the queries OJB is submitting to the database. Any ideas? Regards Tino - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: soft-deleting objects
I don't think you can tell OJB to always use a certain Criteria object. From your example below, I would change it to this: MyCriteria crit = new MyCriteria(); Query q = QueryFactory.newQuery( MyClass, crit ); Collection objects = pb.getCollectionByQuery( q ); As long as you always do "new MyCriteria()" instead of "new Criteria()" you should be fine. The only other thing I would suggest is to abstract the PersistenceBroker into a general use class so you don't have to instantiate it all the time. --- public class MyRepository { public MyRepository getInstance() { return new MyRepository(); } protected PersistenceBroker getPersistenceBroker() { PersistenceBroker broker = PersistenceBrokerFactory.createPersistenceBroker( this.pbKey ); return broker; } protected void releasePersistenceBroker( PersistenceBroker broker ) { if( broker != null ) broker.close(); } public Collection selectMyObjects( Class myClass ) throws OJBException {MyCriteria crit = new MyCriteria(); Query q = QueryFactory.newQuery( myClass, crit ); return selectObjects( q ); } public Collection selectObjects( Query query ) throws OJBException { PersistenceBroker broker = null; try { broker = this.getPersistenceBroker(); return broker.getCollectionByQuery( query ); } catch( Throwable e ) { throw new OJBException( e ); } finally { this.releasePersistenceBroker( broker ); } } } --- Then, your queries would be as simple as this: MyRepository repo = MyRepository.getInstance(); Collection objects = repo.selectMyObjects( MyClass.class ); Well, that's how I do it anyway. You might not like that as much. But that makes sure your queries are always the same, and I really like not having to fuss about with the PersistenceBroker all the time. Charlie Tino Schöllhorn wrote: Hi, that sounds great. Is there a way to tell OJB that it always should use MyCriteria from the QueryFactory? Or do I have to implement an own version of it? Regards Tino Charles N. Harvey III wrote: Extend Criteria with a MyCriteria. public class MyCriteria extends Criteria { public MyCriteria() { addDeletedEqualTo( true ); } public addDeletedEqualTo( boolean bValue ) { this.addEqualTo( "deleted", bValue ); } } Works for me. I usually create a Criteria object for each OJB Object that I have. I add a bunch of convenience methods to add values to the criteria. Charlie Tino Schöllhorn wrote: Hallo Daniel, that sound great. But still I do have one question: how could you then load all non-deleted object *without* using the deleted-flag. I mean something like Criteria crit = new Criteria(); // I can use any criteria here but I don't want to have to use "deleted" Query q = QueryFactory.newQuery(MyClass, myCriteria); Collection objects = pb.getCollectionByQuery(q); // the result are all Objects which have the deleted-flag == false Any suggestions? regards Tino Daniel Perry wrote: I am using this in a complex app (due to idiot admin users deleting stuff they shouldnt!). All objects have a boolean (mapped to int) "deleted". For all queries i look for objects with deleted=false. For relationships, i wrote a querycustomizer which adds deleted=false to collections. (see below example) It;s very simple and works a treat! If you have a 'base' bean, which all other beans inherit, you can put the 'deleted' attribute there, and can use a delete method for deleting any beans! (note: i dont use extents for this in the repository, just map it for all beans) element-class-ref="com.netcase.pdp.bo.JobSubFamily" proxy="true"> class="com.netcase.pdp.ojb.NestedElementCustomQuery"> attribute-value="deleted"/> -Original Message- From: Brian McCallister [mailto:[EMAIL PROTECTED] Sent: 23 March 2004 14:01 To: OJB Users List Subject: Re: soft-deleting objects If you have a "deleted" style flag in the database for the soft delete you can probably accomplish this via a query customizer. If you mean to not flag the delete in the database at all, but only treat it as such in the application -- that is a bit trickier, but can probably be done via pb callbacks/row readers. -Brian On Mar 23, 2004, at 6:21 AM, Tino Schöllhorn wrote: Hi, I want to implement something like a soft-delete: Objects should be marked as "deleted" in its corresponing table and OJB should just ignore them when it is materializing or querying them. Where would be the best point to start when I want to implement this feature? I
Re: soft-deleting objects
Hi, that sounds great. Is there a way to tell OJB that it always should use MyCriteria from the QueryFactory? Or do I have to implement an own version of it? Regards Tino Charles N. Harvey III wrote: Extend Criteria with a MyCriteria. public class MyCriteria extends Criteria { public MyCriteria() { addDeletedEqualTo( true ); } public addDeletedEqualTo( boolean bValue ) { this.addEqualTo( "deleted", bValue ); } } Works for me. I usually create a Criteria object for each OJB Object that I have. I add a bunch of convenience methods to add values to the criteria. Charlie Tino Schöllhorn wrote: Hallo Daniel, that sound great. But still I do have one question: how could you then load all non-deleted object *without* using the deleted-flag. I mean something like Criteria crit = new Criteria(); // I can use any criteria here but I don't want to have to use "deleted" Query q = QueryFactory.newQuery(MyClass, myCriteria); Collection objects = pb.getCollectionByQuery(q); // the result are all Objects which have the deleted-flag == false Any suggestions? regards Tino Daniel Perry wrote: I am using this in a complex app (due to idiot admin users deleting stuff they shouldnt!). All objects have a boolean (mapped to int) "deleted". For all queries i look for objects with deleted=false. For relationships, i wrote a querycustomizer which adds deleted=false to collections. (see below example) It;s very simple and works a treat! If you have a 'base' bean, which all other beans inherit, you can put the 'deleted' attribute there, and can use a delete method for deleting any beans! (note: i dont use extents for this in the repository, just map it for all beans) element-class-ref="com.netcase.pdp.bo.JobSubFamily" proxy="true"> class="com.netcase.pdp.ojb.NestedElementCustomQuery"> attribute-value="deleted"/> -Original Message- From: Brian McCallister [mailto:[EMAIL PROTECTED] Sent: 23 March 2004 14:01 To: OJB Users List Subject: Re: soft-deleting objects If you have a "deleted" style flag in the database for the soft delete you can probably accomplish this via a query customizer. If you mean to not flag the delete in the database at all, but only treat it as such in the application -- that is a bit trickier, but can probably be done via pb callbacks/row readers. -Brian On Mar 23, 2004, at 6:21 AM, Tino Schöllhorn wrote: Hi, I want to implement something like a soft-delete: Objects should be marked as "deleted" in its corresponing table and OJB should just ignore them when it is materializing or querying them. Where would be the best point to start when I want to implement this feature? I just played around with the RowReader-Concept - but I have the feeling that this is not the right place to start, because I think I have to modify the queries OJB is submitting to the database. Any ideas? Regards Tino - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: soft-deleting objects
Extend Criteria with a MyCriteria. public class MyCriteria extends Criteria { public MyCriteria() { addDeletedEqualTo( true ); } public addDeletedEqualTo( boolean bValue ) { this.addEqualTo( "deleted", bValue ); } } Works for me. I usually create a Criteria object for each OJB Object that I have. I add a bunch of convenience methods to add values to the criteria. Charlie Tino Schöllhorn wrote: Hallo Daniel, that sound great. But still I do have one question: how could you then load all non-deleted object *without* using the deleted-flag. I mean something like Criteria crit = new Criteria(); // I can use any criteria here but I don't want to have to use "deleted" Query q = QueryFactory.newQuery(MyClass, myCriteria); Collection objects = pb.getCollectionByQuery(q); // the result are all Objects which have the deleted-flag == false Any suggestions? regards Tino Daniel Perry wrote: I am using this in a complex app (due to idiot admin users deleting stuff they shouldnt!). All objects have a boolean (mapped to int) "deleted". For all queries i look for objects with deleted=false. For relationships, i wrote a querycustomizer which adds deleted=false to collections. (see below example) It;s very simple and works a treat! If you have a 'base' bean, which all other beans inherit, you can put the 'deleted' attribute there, and can use a delete method for deleting any beans! (note: i dont use extents for this in the repository, just map it for all beans) element-class-ref="com.netcase.pdp.bo.JobSubFamily" proxy="true"> class="com.netcase.pdp.ojb.NestedElementCustomQuery"> attribute-value="deleted"/> -Original Message- From: Brian McCallister [mailto:[EMAIL PROTECTED] Sent: 23 March 2004 14:01 To: OJB Users List Subject: Re: soft-deleting objects If you have a "deleted" style flag in the database for the soft delete you can probably accomplish this via a query customizer. If you mean to not flag the delete in the database at all, but only treat it as such in the application -- that is a bit trickier, but can probably be done via pb callbacks/row readers. -Brian On Mar 23, 2004, at 6:21 AM, Tino Schöllhorn wrote: Hi, I want to implement something like a soft-delete: Objects should be marked as "deleted" in its corresponing table and OJB should just ignore them when it is materializing or querying them. Where would be the best point to start when I want to implement this feature? I just played around with the RowReader-Concept - but I have the feeling that this is not the right place to start, because I think I have to modify the queries OJB is submitting to the database. Any ideas? Regards Tino - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: soft-deleting objects
Hallo Daniel, that sound great. But still I do have one question: how could you then load all non-deleted object *without* using the deleted-flag. I mean something like Criteria crit = new Criteria(); // I can use any criteria here but I don't want to have to use "deleted" Query q = QueryFactory.newQuery(MyClass, myCriteria); Collection objects = pb.getCollectionByQuery(q); // the result are all Objects which have the deleted-flag == false Any suggestions? regards Tino Daniel Perry wrote: I am using this in a complex app (due to idiot admin users deleting stuff they shouldnt!). All objects have a boolean (mapped to int) "deleted". For all queries i look for objects with deleted=false. For relationships, i wrote a querycustomizer which adds deleted=false to collections. (see below example) It;s very simple and works a treat! If you have a 'base' bean, which all other beans inherit, you can put the 'deleted' attribute there, and can use a delete method for deleting any beans! (note: i dont use extents for this in the repository, just map it for all beans) -Original Message- From: Brian McCallister [mailto:[EMAIL PROTECTED] Sent: 23 March 2004 14:01 To: OJB Users List Subject: Re: soft-deleting objects If you have a "deleted" style flag in the database for the soft delete you can probably accomplish this via a query customizer. If you mean to not flag the delete in the database at all, but only treat it as such in the application -- that is a bit trickier, but can probably be done via pb callbacks/row readers. -Brian On Mar 23, 2004, at 6:21 AM, Tino Schöllhorn wrote: Hi, I want to implement something like a soft-delete: Objects should be marked as "deleted" in its corresponing table and OJB should just ignore them when it is materializing or querying them. Where would be the best point to start when I want to implement this feature? I just played around with the RowReader-Concept - but I have the feeling that this is not the right place to start, because I think I have to modify the queries OJB is submitting to the database. Any ideas? Regards Tino - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: soft-deleting objects
I am using this in a complex app (due to idiot admin users deleting stuff they shouldnt!). All objects have a boolean (mapped to int) "deleted". For all queries i look for objects with deleted=false. For relationships, i wrote a querycustomizer which adds deleted=false to collections. (see below example) It;s very simple and works a treat! If you have a 'base' bean, which all other beans inherit, you can put the 'deleted' attribute there, and can use a delete method for deleting any beans! (note: i dont use extents for this in the repository, just map it for all beans) -Original Message- From: Brian McCallister [mailto:[EMAIL PROTECTED] Sent: 23 March 2004 14:01 To: OJB Users List Subject: Re: soft-deleting objects If you have a "deleted" style flag in the database for the soft delete you can probably accomplish this via a query customizer. If you mean to not flag the delete in the database at all, but only treat it as such in the application -- that is a bit trickier, but can probably be done via pb callbacks/row readers. -Brian On Mar 23, 2004, at 6:21 AM, Tino Schöllhorn wrote: > Hi, > > I want to implement something like a soft-delete: > > Objects should be marked as "deleted" in its corresponing table and > OJB should just ignore them when it is materializing or querying them. > > Where would be the best point to start when I want to implement this > feature? I just played around with the RowReader-Concept - but I have > the feeling that this is not the right place to start, because I think > I have to modify the queries OJB is submitting to the database. > > Any ideas? > > Regards > Tino > > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: soft-deleting objects
I have implemented the very same thing via a custom RowReader. I just extended the default RowReader, and read in the value from that super. After that, I just my criteria to see if I should avoid it, and return based on that. Here is my method that I implemnted that extended RowReaderDefaultImpl public Object readObjectFrom(Map row) throws PersistenceBrokerException { Object o = super.readObjectFrom(row); if (o instanceof AuditableBusinessObject) { if (((AuditableBusinessObject)o).getDeletedDate() != null) return null; } return o; } Hope this helps. -Original Message- From: news [mailto:[EMAIL PROTECTED] On Behalf Of Tino Schöllhorn Sent: Tuesday, March 23, 2004 6:21 AM To: [EMAIL PROTECTED] Subject: soft-deleting objects Hi, I want to implement something like a soft-delete: Objects should be marked as "deleted" in its corresponing table and OJB should just ignore them when it is materializing or querying them. Where would be the best point to start when I want to implement this feature? I just played around with the RowReader-Concept - but I have the feeling that this is not the right place to start, because I think I have to modify the queries OJB is submitting to the database. Any ideas? Regards Tino - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: soft-deleting objects
If you have a "deleted" style flag in the database for the soft delete you can probably accomplish this via a query customizer. If you mean to not flag the delete in the database at all, but only treat it as such in the application -- that is a bit trickier, but can probably be done via pb callbacks/row readers. -Brian On Mar 23, 2004, at 6:21 AM, Tino Schöllhorn wrote: Hi, I want to implement something like a soft-delete: Objects should be marked as "deleted" in its corresponing table and OJB should just ignore them when it is materializing or querying them. Where would be the best point to start when I want to implement this feature? I just played around with the RowReader-Concept - but I have the feeling that this is not the right place to start, because I think I have to modify the queries OJB is submitting to the database. Any ideas? Regards Tino - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]