thank you, Marcin:)
2006/6/28, Marcin Skladaniec <marci..sh.com.au>:
>
>
> What I had in mind was (using your example) :
>
> SelectQuery selQueryTab1 = new SelectQuery("Tab1");
> DataObjectList dataObjectsInTab1 = new DataObjectList(dataContext
> .performQuery(selQueryInterface));
>
> int nSize = dataObjectsInTab1.size();
> for(int i=0; i<nSize; i++)
> {
> dataObjectTab1 = (Tab1) dataObjectsInTab1.get(i)
> dataObjectTab2 = (Tab2) dataContext.createAndRegisterNewObject
> ("Tab2");
> //here copy data from dataObjectTab1 into dataObjectTab2
>
>
> ValidationResult validationResult = new ValidationResult();
> dataObjectTab2.validateForSave(validationResult);
>
> if (validationResult.hasFailures()) {
> //log failures
> }
> }
> dataContext.setValidatingObjectsOnCommit(false);
> dataContext.commitChanges();
>
> Remember that in your "Tab2" object you can override validateForSave
> (...) method to add more validation rules to your object. (dont
> forget to call super.validateForSave(...) otherwise you might get
> unexpected results)
>
> Marcin
>
>
>
> On 28/06/2006, at 7:15 PM, Nikolai Raitsev wrote:
>
> > Thanks for your answer, Marcin!
> >
> > 2006/6/28, Marcin Skladaniec <marci..sh.com.au>:
> >>
> >> Welcome Nikolai !
> >>
> >> If I get you right, you want to commit data regardless of validation,
> >> but log all validation exceptions.
> >
> >
> > yes, that is correct :)
> >
> > You can call validateForSave() manually, get the failures, and than
> >> commit with setValidatingObjectsOnCommit flag off.
> >
> >
> > this proceed i have already implemented, in the moment like that:
> >
> > SelectQuery selQueryTab1 = new SelectQuery("Tab1");
> > DataObjectList dataObjectsInTab1 = new DataObjectList(dataContext
> > .performQuery(selQueryInterface));
> >
> > int nSize = dataObjectsInTab1.size();
> > for(int i=0; i<nSize; i++)
> > {
> > dataObjectTab1 = (Tab1) dataObjectsInTab1.get(i)
> > dataObjectTab2 = (Tab2) dataContext.createAndRegisterNewObject
> > ("Tab2");
> > //here copy data from dataObjectTab1 into dataObjectTab2
> > try
> > {
> > dataObjectTab2.validateData();
> > }
> > catch(ValidationException vex)
> > {
> > //here log validation faults
> > }
> >
> > }
> >
> > //and hier commitChanges
> > dataContext.commitChanges();
> >
> > //////////////////////////////////////////////
> > the validationData()-Method looks like that:
> >
> > public void validate() throws ValidationException
> > {
> > //here data validation, and if that faults throw new
> > ValidationException...
> > }
> >
> > ////////////////////////////////////////////////////
> >
> >
> > thus, I use not the validationForSave()-Method, but i find it
> > unfortunate,
> > that cayenne have this automated mechanism, which i cannot use...:(
> >
> > Therefore was also my ask, whether it can be automated with the
> > validationForSave()-method...
> >
> >
> > Marcin
> >> PS: this might be helpful http://objectstyle.org/confluence/display/
> >> CAYDOC/DataObject+Validation
> >
> >
> > thank you for the tip ;), the doku i saw;)
> >
> > Nikolai
> >
> > On 28/06/2006, at 5:01 PM, Nikolai Raitsev wrote:
> >>
> >> > Hello
> >> > I am new here
> >> > and sorry for my English:)
> >> >
> >> > I have searched the mailing lists, but not found possible answer
> >> > for my
> >> > question.
> >> > Here is my question, maybe everybody can help me:
> >> >
> >> > how can I execute commitChanges()-Method, with a lot of
> >> > ValidationExceptions?
> >> >
> >> > For the moment I implemented validateForSave-Method for my
> >> > CayenneDataObject.
> >> >
> >> > the following happens:
> >> >
> >> > I have 2 tables: 1. table with 1000 datasets and 2. table without
> >> > data.
> >> >
> >> > on DataObject from 2. table i have validateForSave-method
> >> >
> >> > if i copy data from 1.table into 2.table and make commit like this:
> >> > try
> >> > {
> >> > dataContext.commitChanges();
> >> > }
> >> > catch(ValidationException vex)
> >> > {
> >> > System.out.println(vex.getValidationResult().getFailures().size());
> >> > }
> >> > i have a correct number from validation faults... but the 2.table
> >> > is empty.
> >> >
> >> > if i call (before commitChanges())
> >> > dataContext.setValidatingObjectsOnCommit(false);
> >> >
> >> > then i have 1000 datasets in second table, but no information above
> >> > the
> >> > validation faults
> >> >
> >> > Wat can I do? I need the data in 2. table and the information about
> >> > validation faults I would like only log...
> >> >
> >> > i hope i have my question clear verbalized...
> >> > thanks for help,
> >> >
> >> > Nikolai Raitsev
> >>
> >> -------------------------->
> >> ish
> >> http://www.ish.com.au
> >> Level 1, 30 Wilson Street Newtown 2042 Australia
> >> phone +61 2 9550 5001 fax +61 2 9550 4001
> >>
> >>
> >>
>
>
This archive was generated by hypermail 2.0.0 : Wed Jun 28 2006 - 10:53:57 EDT