A snippet from some of my code where parties with a certain prefix are 
deleted, perhaps this helps:

                // delete history
                EntityExpr exprParty = new EntityExpr("partyId", 
EntityOperator.LIKE, prefix.concat("%"));
                EntityExpr exprContent = new EntityExpr("contentId", 
EntityOperator.LIKE, prefix.concat("%"));
                // delete all serverHits related to the visits to be deleted
                List visits = delegator.findByCondition("Visit", 
exprParty,null,null);
                if (visits != null && visits.size() > 0) {
                    Iterator h = (Iterator) visits.iterator();
                    while(h.hasNext()) {
                        GenericValue visit = (GenericValue) h.next();
                        List serverHits = visit.getRelated("ServerHit");
                        if (serverHits != null && serverHits.size() > 0) {
                            Iterator s = serverHits.iterator();
                            while (s.hasNext()) {
                                ((GenericValue) s.next()).remove();
                            }
                        }
                        visit.remove(); // delete visit
                    }
                }
                
                delegator.removeByCondition( "Visitor", exprParty );
//                delegator.removeByCondition( "UserLoginSession", 
exprUserLogin );
                delegator.removeByCondition( "UserLoginHistory", exprParty );
                delegator.removeByCondition( "ServerHitBin", exprContent );
       



On Friday 21 July 2006 01:29, Amit Shinde wrote:
> Hello,
>       I want to remove all the records relating to a party. I have entries in
> user_login, server_hit and visit tables. I was able to remove all the
> records from all the entities till I hit server_hit and visit problem.
>
>       First, I delete all the records of Server_Hit table having userLoginId 
> as
> 'test'. Notice below that 10150 and 10151 record remains in Server_Hit
> table.
>       Now, I delete all the records of Visit table having userLoginId as 
> 'test'.
> This gives me a foreign key constraint to Server Hit (Visit Ids - 10150 and
> 10151), which is right.
>       Also, notice that 10150 in Visit table has a different party than 10150 
> in
> Server_Hit.
>
>
> Visit Table
>
> Visit Id      User Login Id   Party Id
> 10150           test          10070
> 10151           test          10070
> 10152          <NULL>        <NULL>
>
>
> Server Hit Table
>
> Visit Id      Content Id        User Login Id Party Id
> 10150      admin.logout            manager     10050
> 10151      admin.login             <NULL>           <NULL>
> 10151      admin.ListOrders   test           10070
> 10151      admin.processOrder test           10070
> 10152      admin.logout       test           10070
>
>
>       I dont know if this is a bug or this is how it is supposed to work. I 
> just
> need to remove anything related to a party especially user_login,
> Server_Hit and Visit records. I tried to look for a delete service but
> couldnt find one. How should I go about deleting records of a party from
> Server_Hit and Visit table?
>
>       Thanks in advance for your help and suggestions.
>
>
> Amit Shinde
> --
> No virus found in this outgoing message.
> Checked by AVG Free Edition.
> Version: 7.1.394 / Virus Database: 268.10.1/390 - Release Date: 7/17/2006

-- 
Regards,
Hans Bakker
ANT Websystems Co.,Ltd (http://www.antwebsystems.com)

If you want to verify that this message really originates from
from the above person, download the public key from:
http://www.antwebsystems.com/hbakkerAntwebsystems.asc

Attachment: pgpgAO1urqMr5.pgp
Description: PGP signature

Reply via email to