Re: deleteByQuery does not cascade deletes

2004-06-13 Thread Jakob Braeuchi
hi bradford,
delete by query is using pure sql and works 'outside' ojb.
ojb does not know which objects are deleted, that's why you have to clear the 
cache manually afterwards.

hth
jakob
Bradford Pielech wrote:
Hello again:
I am writing some JUnit tests now and as part of the setup, I want 
to make sure the DB is empty, so I wrote a method to delete all relevant 
objects and their related objects:


public boolean deleteAllObjects(String classNameOfObject) {
boolean returnValue = true;
Class exampleClass = Class.forName(classNameOfObject);
Query query = QueryFactory.newQuery(exampleClass,

QueryByCriteria.CRITERIA_SELECT_ALL);
PersistenceBroker pbroker = PersistenceBrokerFactory.
defaultPersistenceBroker();
  pbroker.beginTransaction();
  pbroker.deleteByQuery(query);
  pbroker.commitTransaction();
}
---

However, when I run this, only the objects from the Primary class are 
deleted (see below) and not any associated ReferencedObjects.  This was 
confirmed by looking at the p6spy logI changed the code to deleteAll by 
first retrieving all objects of the type and then calling delete on each:

--
public boolean deleteAllObjects(String classNameOfObject) {
   PersistenceBroker pbroker = 
PersistenceBrokerFactory.defaultPersistenceBroker();
try {
  List objects = getObjectsOfType(classNameOfObject);  //uses 
getCollectionByQuery and CRITERIA_SELECT_ALL
  pbroker.beginTransaction();
  for (Iterator i = objects.iterator(); i.hasNext(); ) {
pbroker.delete(i.next());
  }
  pbroker.deleteByQuery(query);
  pbroker.commitTransaction();


And this version successfully deleted all objects and their associations 
(again confirmed by p6spy).  Now I know the mapping file is correct, 
otherwise the 2nd version would have failed.  I included relevant 
sections of it below, just in case.

Any ideas what I am doing wrong?
thanks,
Brad

class-descriptor
class=PrimaryClass
table=table1
 
reference-descriptor
name=tasks
class-ref=ReferencedClass
refresh=true
auto-retrieve=true
auto-update=true
auto-delete=object

foreignkey field-ref=fk_id/
field-descriptor
name=fk_id
column=fk_id
jdbc-type=VARCHAR
length=35

/class-descriptor
class-descriptor
class=ReferencedClass
table=table2
 
field-descriptor
name=ID
column=pk_id
jdbc-type=VARCHAR
primarykey=true
length=35

/class-descriptor


-
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: select distinct field (with OJB)

2004-06-13 Thread Jakob Braeuchi
hi marco,
it's just an example ;)
the importatnt thing is the 'true' in QueryFactory.newQuery
hth
jakob
Marco José wrote:
Hi Jakob,
I did not understand your answer. 
What has the addLike method in the Criteria to do with a distinct query?


Marco José
-Original Message-
From: Jakob Braeuchi [mailto:[EMAIL PROTECTED] 
Sent: sexta-feira, 11 de Junho de 2004 17:08
To: OJB Users List
Subject: Re: select distinct field (with OJB)

hi marco,
it's a flag in the query.
Criteria crit = new Criteria();
crit.addLike(allArticlesInGroup.articleName, C%);
// distinct
QueryByCriteria q = QueryFactory.newQuery(ProductGroup.class, crit,
true);
jakob
Marco José wrote:

Hi all,
Can anybody tell me in a few words how to execute the following SQL
(Oracle) instruction with OJB:
SELECT DISTINCT fieldname FROM tablename
I allready tried it with QueryBySQL QueryByCriteria and
ReportQueryByCriteria but it never worked.
Thank you in advance.

Marco José

--- This message may contain confidential information or privileged
material, and is intended only for the individual(s) named. If you are
not a named addressee you should not disseminate, distribute or copy
this e-mail. Please notify the sender immediately by e-mail if you have
received this e-mail by mistake and delete this e-mail from your system.
E-mail transmission cannot be guaranteed to be secure or error-free as
information could be intercepted, corrupted, lost, destroyed, arrive
late or incomplete, or contain viruses. The sender therefore does not
accept liability for any errors or omissions in the contents of this
message which arise as a result of e-mail transmission. If verification
is required please request a hard-copy version. Critical Software.

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--- This message may contain confidential information or privileged material, and is 
intended only for the individual(s) named. If you are not a named addressee you should 
not disseminate, distribute or copy this e-mail. Please notify the sender immediately 
by e-mail if you have received this e-mail by mistake and delete this e-mail from your 
system. E-mail transmission cannot be guaranteed to be secure or error-free as 
information could be intercepted, corrupted, lost, destroyed, arrive late or 
incomplete, or contain viruses. The sender therefore does not accept liability for any 
errors or omissions in the contents of this message which arise as a result of e-mail 
transmission. If verification is required please request a hard-copy version. Critical 
Software.



-
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: joining

2004-06-13 Thread Jakob Braeuchi
hi dennis,
you could try 'or-ing' the criteria for the 3 lists:
Criteria to = new Criteria();
Criteria cc = new Criteria();
Criteria bcc = new Criteria();
QueryByCriteria q;
Collection result;
// get all mails for contact 123
Integer id = new Integer(123);
to.addEqualTo(toList.id, id);
cc.addEqualTo(ccList.id, id);
bcc.addEqualTo(bccList.id, id);
to.addOrCriteria(cc);
to.addOrCriteria(bcc);
q = QueryFactory.newQuery(Mail.class, to, true);
result = broker.getCollectionByQuery(q);
i havn't tried it, but i think it should work ;)
btw. the field-descriptor no longer needs an id (as you still use in contact)
jakob
dennis bekkering wrote:
Jakob,
Thank you for your reacttion. The Contact descriptor =
class-descriptor class=nl.salesmakers.model.Contact table=Contact
  field-descriptor id=30 name=dateOfBirth column=dateofbirth
jdbc-type=DATE/
  field-descriptor id=31 name=email column=email
jdbc-type=VARCHAR/
  field-descriptor id=32 name=gender column=gender
jdbc-type=VARCHAR/
  field-descriptor id=33 name=mobilePhone column=mobilephone
jdbc-type=VARCHAR/
  field-descriptor id=34 name=firstName column=firstname
jdbc-type=VARCHAR/
  field-descriptor id=35 name=title column=title
jdbc-type=VARCHAR/
  field-descriptor id=35 name=type column=type jdbc-type=VARCHAR/
  field-descriptor id=36 name=companyId column=companyid
jdbc-type=INTEGER/
  field-descriptor id=37 name=function column=function
jdbc-type=VARCHAR/
  field-descriptor id=39 name=middleName column=middlename
jdbc-type=VARCHAR/
  field-descriptor id=40 name=initials column=initials
jdbc-type=VARCHAR/
  field-descriptor id=41 name=phone column=phone
jdbc-type=VARCHAR/
  field-descriptor id=42 name=id column=id jdbc-type=INTEGER
primarykey=true autoincrement=true/
  field-descriptor id=43 name=lastName column=lastname
jdbc-type=VARCHAR/
  field-descriptor id=44 name=creationDate column=creationdate
jdbc-type=DATE/
  field-descriptor id=45 name=searchName column=searchname
jdbc-type=VARCHAR/
  field-descriptor id=46 name=privat column=privat
jdbc-type=VARCHAR/
  field-descriptor id=47 name=userId column=userid
jdbc-type=INTEGER/
  field-descriptor id=48 name=mailFooter column=mailfooter
jdbc-type=VARCHAR/
  field-descriptor id=49 name=mailHeader column=mailheader
jdbc-type=VARCHAR/
  reference-descriptor name=user class-ref=nl.salesmakers.model.User
foreignkey field-ref=userId/
  /reference-descriptor
  reference-descriptor name=company
class-ref=nl.salesmakers.model.Company
foreignkey field-ref=companyId/
  /reference-descriptor
  field-descriptor name=online column=online jdbc-type=INTEGER/
/class-descriptor
Dennis
- Original Message - 
From: Jakob Braeuchi [EMAIL PROTECTED]
To: OJB Users List [EMAIL PROTECTED]
Sent: Wednesday, June 09, 2004 9:39 PM
Subject: Re: joining


hi dennis,
how does the classdescriptor for Contact look ?
jakob
dennis bekkering wrote:

Hello,
I have class Mail with some collections that return contacts.
public class Mail
{
private Collection attachementList = new ArrayList();
private Collection bccList = new ArrayList();
private Collection ccList = new ArrayList();
private Collection toList = new ArrayList();

}
descriptor :
 collection-descriptor name=toList
element-class-ref=nl.salesmakers.model.Contact auto-retrieve=true
auto-update=true auto-delete=false
indirection-table=MailTo2Contact
   fk-pointing-to-this-class column=mailid/
   fk-pointing-to-element-class column=contactId/
 /collection-descriptor
 collection-descriptor name=ccList
element-class-ref=nl.salesmakers.model.Contact auto-retrieve=true
auto-update=true auto-delete=false
indirection-table=MailCc2Contact
   fk-pointing-to-this-class column=mailid/
   fk-pointing-to-element-class column=contactId/
 /collection-descriptor
 collection-descriptor name=bccList
element-class-ref=nl.salesmakers.model.Contact auto-retrieve=true
auto-update=true auto-delete=false
indirection-table=MailBcc2Contact
   fk-pointing-to-this-class column=mailid/
   fk-pointing-to-element-class column=contactId/
 /collection-descriptor
My sql query for getting all mail messages send to a certain contact :
 SELECT distinct m.*  +
 FROM  +
  Mail m ,  +
  Contact c ,  +
  MailTo2Contact mtc , +
  MailCc2Contact mcc , +
  MailBcc2Contact mbc  +
 WHERE  +
   (( m.id = mtc.mailid +
   AND +
   c.id = mtc.contactid ) +
  OR  +
   (m.id = mcc.mailid +
   AND +
   c.id = mcc.contactid ) +
  OR  +
   (m.id = mbc.mailid +
   AND +
   mbc.contactid = c.id   )) +
  AND  +
  c.id =  + contact.getId() +
  AND  +
  m.flag = 'sent' +
  order by m.date desc+
 ;
I offcourse would like to use the pb API but dont know how. Any hints? I
cannot use select in , since mysql 4.0 does not support them and 4.1 is
not
in production.
regards,
Dennis
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]