You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Cyp her <cy...@hotmail.com> on 2006/04/04 16:58:30 UTC

cayenne get accessors

Hi

Does Cayenne force you to have *get* before your property name to create 
your get accessor e.g. getName().

I have a table like this

PERSON
   id
   firstName
   lastName

and the Modeler creates these accessors

public class _Person extends CayenneDataObject {

   public String getFirstName() ...
   public String getLastName() ...

}

Which is fine. I have read you can get custom templates to change this and I 
did try by grabbing the default templates from the jar and modifying them 
but this did not work. Does anybody know how?

My real problems start here however. In the subclass Person I have this code

public class Person extends _Person {

	public String fullName() {
		return this.getFirstName() + “ “ + this.getLastName();
	}
}

and when I try and use and Expression to get a particular Person like this

Expression fullNameQualifier = ExpressionFactory.matchExp("fullName", “John 
Doe”);

List filteredPersons = fullNameQualifier.filterObjects(personsList);

The List is always empty even though I do have a person named John Doe in my 
database (MySQL). But oddly enough if I change my method in the Person class 
to be this

public class Person extends _Person {

	public String getFullName() {
		return this.getFirstName + “ “ + this.getLastName;
	}
}

i.e. change the method name to be getFullName instead of just fullName.

Why must I prefix all my get accessors with *get*? I want to get rid of 
*get* in all the super classes too so does anyone have a template I can use 
to oust them?

Lawrence

_________________________________________________________________
Be the first to hear what's new at MSN - sign up to our free newsletters! 
http://www.msn.co.uk/newsletters


Re: cayenne get accessors

Posted by Andrus Adamchik <an...@objectstyle.org>.
Unlike WO key-value coding, Java standard convention (called  
JavaBeans) is to use the "getXyz" for an accessor method of a logical  
property "xyz". All the Expression classes (and endless other Java  
libraries) follow this convention, so I'd strongly recommend not to  
modify the getters. You'll have to get used to it, it took me quite  
some time to adapt too :-)

Andrus


On Apr 4, 2006, at 6:58 PM, Cyp her wrote:

> Hi
>
> Does Cayenne force you to have *get* before your property name to  
> create your get accessor e.g. getName().
>
> I have a table like this
>
> PERSON
>   id
>   firstName
>   lastName
>
> and the Modeler creates these accessors
>
> public class _Person extends CayenneDataObject {
>
>   public String getFirstName() ...
>   public String getLastName() ...
>
> }
>
> Which is fine. I have read you can get custom templates to change  
> this and I did try by grabbing the default templates from the jar  
> and modifying them but this did not work. Does anybody know how?
>
> My real problems start here however. In the subclass Person I have  
> this code
>
> public class Person extends _Person {
>
> 	public String fullName() {
> 		return this.getFirstName() + “ “ + this.getLastName();
> 	}
> }
>
> and when I try and use and Expression to get a particular Person  
> like this
>
> Expression fullNameQualifier = ExpressionFactory.matchExp 
> ("fullName", “John Doe”);
>
> List filteredPersons = fullNameQualifier.filterObjects(personsList);
>
> The List is always empty even though I do have a person named John  
> Doe in my database (MySQL). But oddly enough if I change my method  
> in the Person class to be this
>
> public class Person extends _Person {
>
> 	public String getFullName() {
> 		return this.getFirstName + “ “ + this.getLastName;
> 	}
> }
>
> i.e. change the method name to be getFullName instead of just  
> fullName.
>
> Why must I prefix all my get accessors with *get*? I want to get  
> rid of *get* in all the super classes too so does anyone have a  
> template I can use to oust them?
>
> Lawrence
>
> _________________________________________________________________
> Be the first to hear what's new at MSN - sign up to our free  
> newsletters! http://www.msn.co.uk/newsletters
>
>


Re: cayenne get accessors

Posted by Cypher her <cy...@hotmail.com>.
Thank all you very much for your help. I guess I am still in a WO frame of 
mind and just need to get over it. Thanks again.


From: "Mike Kienenberger" <mk...@gmail.com>
Reply-To: cayenne-user@incubator.apache.org
To: cayenne-user@incubator.apache.org
Subject: Re: cayenne get accessors
Date: Tue, 4 Apr 2006 11:07:42 -0400

On 4/4/06, Cyp her <cy...@hotmail.com> wrote:
 > Does Cayenne force you to have *get* before your property name to create
 > your get accessor e.g. getName().

No, you don't even have to generate subclasses if you don't want to.
It's just a convenience class.

http://www.objectstyle.org/confluence/display/CAYDOC/Generic+Persistent+Class

However, some of the "extras" like in-memory filterObjects won't work
if your DataObjects aren't in JavaBean form.   This is one of those
defacto standards that you probably want to follow, because you'll
eventually need a feature of some java library that requires it.

_________________________________________________________________
Are you using the latest version of MSN Messenger? Download MSN Messenger 
7.5 today! http://join.msn.com/messenger/overview


Re: cayenne get accessors

Posted by Mike Kienenberger <mk...@gmail.com>.
On 4/4/06, Cyp her <cy...@hotmail.com> wrote:
> Does Cayenne force you to have *get* before your property name to create
> your get accessor e.g. getName().

No, you don't even have to generate subclasses if you don't want to. 
It's just a convenience class.

http://www.objectstyle.org/confluence/display/CAYDOC/Generic+Persistent+Class

However, some of the "extras" like in-memory filterObjects won't work
if your DataObjects aren't in JavaBean form.   This is one of those
defacto standards that you probably want to follow, because you'll
eventually need a feature of some java library that requires it.