You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cayenne.apache.org by Michael Gentry <bl...@gmail.com> on 2006/10/11 17:11:02 UTC

Cocoa Cayenne Class Generation?

Hi Tore,

I just checked out the Cocoa Cayenne project from the sandbox and have
a question about the Objective-C class generation.  How were
Artist.h/m created?  Have you created a velocity template for this
yet?

Thanks,

/dev/mrg

PS. A co-worker is also interested in contributing to this -- he just
subscribed to everything.

Re: Re: Cocoa Cayenne Class Generation?

Posted by Klajd Deda <cl...@gmail.com>.
On 10/11/06, Tore Halset <ha...@pvv.ntnu.no> wrote:
> On Oct 11, 2006, at 17:11, Michael Gentry wrote:
>
> > I just checked out the Cocoa Cayenne project from the sandbox and have
> > a question about the Objective-C class generation.  How were
> > Artist.h/m created?
>
> By hand..
>
> > Have you created a velocity template for this yet?
>
> No. Are you able to take a look at it?
>
> I hoped to do all the needed stuff for initWithCoder and
> encodeWithCoder in CAYPersistentObject. The problem is that I do not
> know witch attributes to decode at the stage of initWithCoder. What
> do you think?
I was thinking to use the meta data from the model.
and write a template that iterates through them to populate the methods.
i have done similar with the EOGen and EOModel.
The question is how flexible are the templates in cayenne ?

>
> > PS. A co-worker is also interested in contributing to this -- he just
> > subscribed to everything.
>
> Cool :)
>
>   - Tore.
>

Re: Cocoa Cayenne Class Generation?

Posted by Andrus Adamchik <an...@objectstyle.org>.
Interesting ... this happened to me occasionally (and randomly) when  
running an Ant task. Let's investigate if this happens again - could  
be a bug.

Andrus


On Oct 11, 2006, at 3:03 PM, Michael Gentry wrote:

> Nevermind (for now).  Got it to work somehow ...
>
>
>
> On 10/11/06, Michael Gentry <bl...@gmail.com> wrote:
>> OK, maybe I spoke too soon.  Does the Advanced generation actually
>> work?  I just looked at the output (I knew it would be Java, so I
>> didn't look before) and it wasn't what I was expecting.  For example:
>>
>> /tmp> more _Customer.mm
>> /** Class ${classGen.superPrefix}${classGen.className} was  
>> generated by Cayenne.
>>   * It is probably a good idea to avoid changing this class manually,
>>   * since it may be overwritten next time code is regenerated.
>>   * If you need to make any customizations, please use subclass.
>>   */
>> public class ${classGen.superPrefix}${classGen.className} extends
>> $classGen.superClassName {
>>
>>
>>
>> }
>>
>>
>> This isn't actually Java -- it didn't process the template.  I tried
>> changing the output pattern back to *.java and got:
>>
>> /tmp> more Customer.java
>>
>>
>> public class ${classGen.className} extends
>> ${classGen.superPrefix}${classGen.className} {
>>
>> }
>>
>>
>> Any thoughts?
>>
>> Thanks,
>>
>> /dev/mrg
>>
>> PS. For Objective-C, it'll have to be done in two passes since a .h
>> and a .m is required.
>>
>>
>> On 10/11/06, Michael Gentry <bl...@gmail.com> wrote:
>> > You know, I tried the Advanced option as a test, but got  
>> discouraged
>> > because it generated an entire path for the package, but I just  
>> went
>> > back in and noticed there is a "Use Package Path" checkbox.  Turned
>> > that off and it works perfectly.  I'll make some templates now.
>> >
>> > Thanks!
>> >
>> > /dev/mrg
>> >
>> >
>> > On 10/11/06, Andrus Adamchik <an...@objectstyle.org> wrote:
>> > >
>> > > On Oct 11, 2006, at 2:19 PM, Michael Gentry wrote:
>> > >
>> > > > I think the template will be the easy part.  Proper  
>> integration with
>> > > > Cayenne Modeler will be the hard part -- and Cayenne Modeler is
>> > > > outside of the sandbox, so that could be a little touchy.   
>> Perhaps we
>> > > > need a separate generator for testing/etc prior to merging with
>> > > > Cayenne Modeler.
>> > >
>> > > While code is in the sandbox, you can use "Advanced"  
>> generation mode,
>> > > and select the templates manually (selection will be  
>> remembered in
>> > > the Modeler preferences). And once the code is moved to the  
>> trunk,
>> > > we'll do a proper UI integration.
>> > >
>> > > Andrus
>> > >
>> > >
>> >
>>
>


Re: Re: Re: Re: Cocoa Cayenne Class Generation?

Posted by Michael Gentry <bl...@gmail.com>.
Nevermind (for now).  Got it to work somehow ...



On 10/11/06, Michael Gentry <bl...@gmail.com> wrote:
> OK, maybe I spoke too soon.  Does the Advanced generation actually
> work?  I just looked at the output (I knew it would be Java, so I
> didn't look before) and it wasn't what I was expecting.  For example:
>
> /tmp> more _Customer.mm
> /** Class ${classGen.superPrefix}${classGen.className} was generated by Cayenne.
>   * It is probably a good idea to avoid changing this class manually,
>   * since it may be overwritten next time code is regenerated.
>   * If you need to make any customizations, please use subclass.
>   */
> public class ${classGen.superPrefix}${classGen.className} extends
> $classGen.superClassName {
>
>
>
> }
>
>
> This isn't actually Java -- it didn't process the template.  I tried
> changing the output pattern back to *.java and got:
>
> /tmp> more Customer.java
>
>
> public class ${classGen.className} extends
> ${classGen.superPrefix}${classGen.className} {
>
> }
>
>
> Any thoughts?
>
> Thanks,
>
> /dev/mrg
>
> PS. For Objective-C, it'll have to be done in two passes since a .h
> and a .m is required.
>
>
> On 10/11/06, Michael Gentry <bl...@gmail.com> wrote:
> > You know, I tried the Advanced option as a test, but got discouraged
> > because it generated an entire path for the package, but I just went
> > back in and noticed there is a "Use Package Path" checkbox.  Turned
> > that off and it works perfectly.  I'll make some templates now.
> >
> > Thanks!
> >
> > /dev/mrg
> >
> >
> > On 10/11/06, Andrus Adamchik <an...@objectstyle.org> wrote:
> > >
> > > On Oct 11, 2006, at 2:19 PM, Michael Gentry wrote:
> > >
> > > > I think the template will be the easy part.  Proper integration with
> > > > Cayenne Modeler will be the hard part -- and Cayenne Modeler is
> > > > outside of the sandbox, so that could be a little touchy.  Perhaps we
> > > > need a separate generator for testing/etc prior to merging with
> > > > Cayenne Modeler.
> > >
> > > While code is in the sandbox, you can use "Advanced" generation mode,
> > > and select the templates manually (selection will be remembered in
> > > the Modeler preferences). And once the code is moved to the trunk,
> > > we'll do a proper UI integration.
> > >
> > > Andrus
> > >
> > >
> >
>

Re: Re: Re: Cocoa Cayenne Class Generation?

Posted by Michael Gentry <bl...@gmail.com>.
OK, maybe I spoke too soon.  Does the Advanced generation actually
work?  I just looked at the output (I knew it would be Java, so I
didn't look before) and it wasn't what I was expecting.  For example:

/tmp> more _Customer.mm
/** Class ${classGen.superPrefix}${classGen.className} was generated by Cayenne.
  * It is probably a good idea to avoid changing this class manually,
  * since it may be overwritten next time code is regenerated.
  * If you need to make any customizations, please use subclass.
  */
public class ${classGen.superPrefix}${classGen.className} extends
$classGen.superClassName {



}


This isn't actually Java -- it didn't process the template.  I tried
changing the output pattern back to *.java and got:

/tmp> more Customer.java


public class ${classGen.className} extends
${classGen.superPrefix}${classGen.className} {

}


Any thoughts?

Thanks,

/dev/mrg

PS. For Objective-C, it'll have to be done in two passes since a .h
and a .m is required.


On 10/11/06, Michael Gentry <bl...@gmail.com> wrote:
> You know, I tried the Advanced option as a test, but got discouraged
> because it generated an entire path for the package, but I just went
> back in and noticed there is a "Use Package Path" checkbox.  Turned
> that off and it works perfectly.  I'll make some templates now.
>
> Thanks!
>
> /dev/mrg
>
>
> On 10/11/06, Andrus Adamchik <an...@objectstyle.org> wrote:
> >
> > On Oct 11, 2006, at 2:19 PM, Michael Gentry wrote:
> >
> > > I think the template will be the easy part.  Proper integration with
> > > Cayenne Modeler will be the hard part -- and Cayenne Modeler is
> > > outside of the sandbox, so that could be a little touchy.  Perhaps we
> > > need a separate generator for testing/etc prior to merging with
> > > Cayenne Modeler.
> >
> > While code is in the sandbox, you can use "Advanced" generation mode,
> > and select the templates manually (selection will be remembered in
> > the Modeler preferences). And once the code is moved to the trunk,
> > we'll do a proper UI integration.
> >
> > Andrus
> >
> >
>

Re: Re: Cocoa Cayenne Class Generation?

Posted by Michael Gentry <bl...@gmail.com>.
You know, I tried the Advanced option as a test, but got discouraged
because it generated an entire path for the package, but I just went
back in and noticed there is a "Use Package Path" checkbox.  Turned
that off and it works perfectly.  I'll make some templates now.

Thanks!

/dev/mrg


On 10/11/06, Andrus Adamchik <an...@objectstyle.org> wrote:
>
> On Oct 11, 2006, at 2:19 PM, Michael Gentry wrote:
>
> > I think the template will be the easy part.  Proper integration with
> > Cayenne Modeler will be the hard part -- and Cayenne Modeler is
> > outside of the sandbox, so that could be a little touchy.  Perhaps we
> > need a separate generator for testing/etc prior to merging with
> > Cayenne Modeler.
>
> While code is in the sandbox, you can use "Advanced" generation mode,
> and select the templates manually (selection will be remembered in
> the Modeler preferences). And once the code is moved to the trunk,
> we'll do a proper UI integration.
>
> Andrus
>
>

Re: Cocoa Cayenne Class Generation?

Posted by Andrus Adamchik <an...@objectstyle.org>.
On Oct 11, 2006, at 2:19 PM, Michael Gentry wrote:

> I think the template will be the easy part.  Proper integration with
> Cayenne Modeler will be the hard part -- and Cayenne Modeler is
> outside of the sandbox, so that could be a little touchy.  Perhaps we
> need a separate generator for testing/etc prior to merging with
> Cayenne Modeler.

While code is in the sandbox, you can use "Advanced" generation mode,  
and select the templates manually (selection will be remembered in  
the Modeler preferences). And once the code is moved to the trunk,  
we'll do a proper UI integration.

Andrus


Re: Cocoa Cayenne Class Generation?

Posted by Tore Halset <ha...@pvv.ntnu.no>.
On Oct 12, 2006, at 00:19, Tore Halset wrote:

> my basic idea was to start with key value coding and let the user  
> create set and/or get methods if custom logic was needed. Looks  
> like this is not working for now, but it should be fixed..

Fixed. See updated Artist.m for example on how to create custom set/get.

I have implemented setValue:forUndefinedKey: and  
valueForUndefinedKey: in CAYPersistentObject that are used if a  
specific set/get are not implemented in the entity class. See the  
following document on "Accessor Search Implementation Details":

http://developer.apple.com/documentation/Cocoa/Conceptual/ 
KeyValueCoding/Concepts/SearchImplementation.html

I do not know if the Undefined-key stuff are the best way to  
implement this, but it is working. I have posted about this on cocoa- 
dev:

http://lists.apple.com/archives/Cocoa-dev/2006/Oct/msg00489.html

  - Tore.

Re: Cocoa Cayenne Class Generation?

Posted by Tore Halset <ha...@pvv.ntnu.no>.
On Oct 11, 2006, at 20:19, Michael Gentry wrote:

> I think there need to be two classes, also.  _Artist and Artist.  Just
> like with the regular Cayenne Modeler (and EOGenerator).

That is fine with me, but my basic idea was to start with key value  
coding and let the user create set and/or get methods if custom logic  
was needed. Looks like this is not working for now, but it should be  
fixed..

Core Data does it the same way. CD has a NSManagedObject that are  
like our CAYPersistentObject. From the documentation of  
NSManagedObject's setValue:forKey:

"This method is overridden by NSManagedObject to access the managed  
object’s generic dictionary storage unless the receiver’s class  
explicitly provides key-value coding compliant accessor methods for  
key."

file:///Developer/ADC%20Reference%20Library/documentation/Cocoa/ 
Reference/CoreDataFramework/Classes/NSManagedObject_Class/Reference/ 
Reference.html

So _Artist are ok for me, but not that important as in java.

  - Tore.

Re: Re: Cocoa Cayenne Class Generation?

Posted by Michael Gentry <bl...@gmail.com>.
I think the template will be the easy part.  Proper integration with
Cayenne Modeler will be the hard part -- and Cayenne Modeler is
outside of the sandbox, so that could be a little touchy.  Perhaps we
need a separate generator for testing/etc prior to merging with
Cayenne Modeler.

I think there need to be two classes, also.  _Artist and Artist.  Just
like with the regular Cayenne Modeler (and EOGenerator).

/dev/mrg


On 10/11/06, Tore Halset <ha...@pvv.ntnu.no> wrote:
> On Oct 11, 2006, at 17:11, Michael Gentry wrote:
>
> > I just checked out the Cocoa Cayenne project from the sandbox and have
> > a question about the Objective-C class generation.  How were
> > Artist.h/m created?
>
> By hand..
>
> > Have you created a velocity template for this yet?
>
> No. Are you able to take a look at it?
>
> I hoped to do all the needed stuff for initWithCoder and
> encodeWithCoder in CAYPersistentObject. The problem is that I do not
> know witch attributes to decode at the stage of initWithCoder. What
> do you think?
>
> > PS. A co-worker is also interested in contributing to this -- he just
> > subscribed to everything.
>
> Cool :)
>
>   - Tore.
>

Re: Cocoa Cayenne Class Generation?

Posted by Tore Halset <ha...@pvv.ntnu.no>.
On Oct 11, 2006, at 17:11, Michael Gentry wrote:

> I just checked out the Cocoa Cayenne project from the sandbox and have
> a question about the Objective-C class generation.  How were
> Artist.h/m created?

By hand..

> Have you created a velocity template for this yet?

No. Are you able to take a look at it?

I hoped to do all the needed stuff for initWithCoder and  
encodeWithCoder in CAYPersistentObject. The problem is that I do not  
know witch attributes to decode at the stage of initWithCoder. What  
do you think?

> PS. A co-worker is also interested in contributing to this -- he just
> subscribed to everything.

Cool :)

  - Tore.