1 /* Copyright 2004-2005 the original author or authors.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
15 package org
.codehaus
.groovy
.grails
.commons
;
18 * A property of a GrailsDomainClass instance
20 * @author Graeme Rocher
23 public interface GrailsDomainClassProperty
{
25 String IDENTITY
= "id";
26 String VERSION
= "version";
27 String TRANSIENT
= "transients";
28 String CONSTRAINTS
= "constraints";
29 String EVANESCENT
= "evanescent";
30 String RELATES_TO_MANY
= "relatesToMany";
31 String META_CLASS
= "metaClass";
32 String CLASS
= "class";
33 String MAPPING_STRATEGY
= "mapWith";
34 String MAPPED_BY
= "mappedBy";
35 String BELONGS_TO
= "belongsTo";
36 String HAS_MANY
= "hasMany";
37 String FETCH_MODE
= "fetchMode";
38 String DATE_CREATED
= "dateCreated";
39 String MAPPING
= "mapping";
40 String LAST_UPDATED
= "lastUpdated";
42 String EMBEDDED
= "embedded";
48 * Returns the configured fetch mode for the property
50 public int getFetchMode();
53 * Returns the name of the property
54 * @return The property name
56 public String
getName();
58 * Returns the type for the domain class
59 * @return The property type
61 public Class
getType();
64 * <p>Returns the referenced property type. This differs from getType() in that in
65 * the case of an Association it will return the type of the elements contained within the Collection,
66 * otherwise it will delegate to getType();</p>
68 * @return The referenced type
70 public Class
getReferencedPropertyType();
73 * <p>Returns the other side of a bidirectional association
75 * @return The other side of the relationship or null if not known
77 public GrailsDomainClassProperty
getOtherSide();
80 * Returns the class type as a property name representation
82 * @return The property name representation
84 public String
getTypePropertyName();
87 * Returns the parent domain class of the property instance
88 * @return The parent domain class
90 public GrailsDomainClass
getDomainClass();
92 * Returns true if the domain class property is a persistent property
93 * @return Whether the property is persistent
95 public boolean isPersistent();
97 * Returns true if the property is required
98 * @return Whether the property is optional
100 public boolean isOptional();
102 * Returns true of the property is an identifier
103 * @return Whether the property is the identifier
105 public boolean isIdentity();
108 * Returns true if the property is a one-to-many relationship
109 * @return Whether it is a oneToMany
111 public boolean isOneToMany();
114 * Returns true if the property is a many-to-one relationship
115 * @return Whether it is a manyToOne
117 public boolean isManyToOne();
120 * Returns true if the property is a many-to-many relationship
121 * @return True if it is a manyToMany
123 public boolean isManyToMany();
126 * Returns true if the property is a bi-directional relationship
127 * @return A boolean value
129 public boolean isBidirectional();
131 * Returns the domain field name for this property
133 public String
getFieldName();
135 * Returns true if the property is a one-to-one relationship
136 * @return True if it is a one-to-one relationship
138 public boolean isOneToOne();
140 * Returns the GrailsDomainClass of a relationship property or null
141 * if the property is not a relationship property
143 * @return The GrailsDomainClass
145 public GrailsDomainClass
getReferencedDomainClass();
148 * Returns true if this property is a relationship property
149 * @return True if it is an associative property
151 public boolean isAssociation();
154 * Returns true if this properties type is an enum
155 * @return True if it is
157 public boolean isEnum();
160 * @return The natural name representation of the property (eg. 'lastName' becomes 'Last Name'
162 public String
getNaturalName();
165 * Sets the references domain class on the property
166 * @param referencedGrailsDomainClass
168 void setReferencedDomainClass(GrailsDomainClass referencedGrailsDomainClass
);
171 * Sets the other side of an associative property
172 * @param referencedProperty
174 void setOtherSide(GrailsDomainClassProperty referencedProperty
);
177 * Whether the property is inherited from a super class
178 * @return True if its inherited
180 boolean isInherited();
183 * Whether this side of the association is the "owning" side
185 * @return True if it is the owning side
187 public boolean isOwningSide();
190 * Whether the relationship is cirucular
192 * @return True if it is
194 public boolean isCircular();
197 * Retrieves the name of property referenced by this property if it is
198 * an association and is known, otherwise null
200 * @return The name of the prop
202 public String
getReferencedPropertyName();
205 * Returns true if this propert is an embedded component
207 * @return True if it is, false otherwise
209 boolean isEmbedded();
212 * If #isEmbedded returns true then this method can be called to obtain a reference to the embedded component, which implements the GrailsDomainClass
215 * @see org.codehaus.groovy.grails.commons.GrailsDomainClass
216 * @see GrailsDomainClassProperty#isEmbedded()
218 * @return The component or null if it is not an embedded component
220 GrailsDomainClass
getComponent();
222 void setOwningSide(boolean b
);