Changes for page EOF-Using EOF-EOGenerator

Last modified by Pascal Robert on 2012/01/21 22:03

From version 23.1
edited by Pascal Robert
on 2007/09/03 13:44
Change comment: There is no comment for this version
To version 31.1
edited by Pascal Robert
on 2012/01/21 22:03
Change comment: Migrated to Confluence 4.0

Summary

Details

Page properties
Content
... ... @@ -1,53 +1,63 @@
1 -|= Contents
2 -| {{toc style="disc" minLevel="2"}}{{/toc}}
1 +{{warning}}
2 +This is deprecated information!
3 +{{/warning}}
3 3  
5 +|=(((
6 +Contents
7 +)))
8 +|(((
9 +{{toc style="disc" minLevel="2"/}}
10 +)))
11 +
4 4  == Overview ==
5 5  
6 -If you've ever used EOModeler's Java source code generator, you know how much of a pain it can be when you make changes to your model objects and have to merge changes in later. One solution for this is to use [[EOGenerator>>http://www.rubicode.com/Software/EOGenerator/]], an application developed by Rubicode Software, which uses the Generation Gap pattern to create your Java files from your EOModels. EOGenerator produces TWO java files for each Entity rather than one. Take the example of a Person entity. The first java file is Person.java, which contains all of the autogenerated methods. The second java file is Person.java, and Person extends Person. The second file is where you place all of your customizations. Any time your model changes, only your Xxx.java files are updated, and your customizations are left untouched. Additionally, EOGenerator allows for the creation of extensive custom templates for your files, which provides the ability to place convenience methods in your Xxx.java files.
14 +If you've ever used EOModeler's Java source code generator, you know how much of a pain it can be when you make changes to your model objects and have to merge changes in later. One solution for this is to use [[EOGenerator>>url:http://www.rubicode.com/Software/EOGenerator/||shape="rect"]], an application developed by Rubicode Software, which uses the Generation Gap pattern to create your Java files from your EOModels. EOGenerator produces TWO java files for each Entity rather than one. Take the example of a Person entity. The first java file is _Person.java, which contains all of the autogenerated methods. The second java file is Person.java, and Person extends _Person. The second file is where you place all of your customizations. Any time your model changes, only your _Xxx.java files are updated, and your customizations are left untouched. Additionally, EOGenerator allows for the creation of extensive custom templates for your files, which provides the ability to place convenience methods in your _Xxx.java files.
7 7  
16 +{{warning}}
17 +EOGenerator doesn't work on Mac OS X 10.5. You have to use [[JavaEOGenerator>>url:http://developer.apple.com/samplecode/JavaEOGenerator/||shape="rect"]] or [[Velocity EOGenerator>>doc:WOL.Velocity EOGenerator (Veogen)]].
18 +{{/warning}}
19 +
8 8  == Advantages ==
9 9  
10 10  There are several advantages to using EOGenerator over EOModeler's default Java file generation and merging with FileMerge.
11 11  
12 -* EOGenerator uses the Generation Gap pattern, which provides a much cleaner separation of autogenerated vs customized code with no need to deal with merging at all. There are border cases with FileMerge that can cause you to deal with annoying conflicts.
13 -* EOGenerator uses the MiscMerge language for its templates. This allows you to extend the core templates with extensive customizations (see the EOGenerator Mods section below), better supporting your own custom development process and workflow.
24 +* EOGenerator uses the Generation Gap pattern, which provides a much cleaner separation of autogenerated vs customized code with no need to deal with merging at all. There are border cases with FileMerge that can cause you to deal with annoying conflicts.
25 +* EOGenerator uses the MiscMerge language for its templates. This allows you to extend the core templates with extensive customizations (see the EOGenerator Mods section below), better supporting your own custom development process and workflow.
14 14  * As David LaBer put it, "all the cool kids use it - and we all know looking cool is the **most** important criteria".
15 15  
16 16  == How To Use It ==
17 17  
18 -Kieran Kelleher has writtten an [[Introduction to EOGenerator>>http://homepage.mac.com/kelleherk/iblog/C1837526061/E1908382110/index.html]] on his blog.
30 +Kieran Kelleher has writtten an [[Introduction to EOGenerator>>url:http://homepage.mac.com/kelleherk/iblog/C1837526061/E1908382110/index.html||shape="rect"]] on his blog.
19 19  
20 -It's actually very simple to use. The quick start is:
32 +It's actually very simple to use. The quick start is:
21 21  
22 22  * Download and untar EOGenerator from the Rubicode site
23 23  * Run the following command:
24 24  
25 25  {{panel}}
26 -
27 -eogenerator \-model /path/to/model/YourModel.eomodeld \-destination /path/to/source/folder
28 -\-subclassDestination /path/to/source/folder \-templatedir /path/to/EOGenerator/templates \-java \-packagedirs
29 -
38 +eogenerator -model /path/to/model/YourModel.eomodeld -destination /path/to/source/folder
39 + -subclassDestination /path/to/source/folder -templatedir /path/to/EOGenerator/templates -java -packagedirs
30 30  {{/panel}}
31 31  
32 -Voila. EOGenerator will spit out your Java files for you. Let's break down the commands you can pass in:
42 +Voila. EOGenerator will spit out your Java files for you. Let's break down the commands you can pass in:
33 33  
34 -* define-EOGenericRecord <class>, allows you to specify the Person class's superclass. For instance, if you use Project Wonder, you would specify define-EOGenericRecord er.extensions.ERXGenericRecord
35 -* destination <path>, the folder that Person.java-style java files will be produced in (the non-editable files)
36 -* java, produce java files
37 -* javaTemplate <filename>, the name of the Java template to use inside of the template dir (//Person)//
38 -* model <path>, Passes in the path of a .eomodeld you would like to generate Java files for. You can actually include multiple model commands on the commandline
39 -* packagedirs, produce package directory for any package statements defined in your Java files (not necessary if you don't specify package names on your entities. By the way, you should specify packages on your entities :-) )
40 -* refmodel <path>, Passes in the path of an .eomodeld that is required for generating Java files, but that won't actually have Java files generated for it. For instance, you should refmodel any prototypes, or any models in other frameworks that you depend on
41 -* subclassDestination <path>, the folder that Person.java-style java files will be produced in (the editable files)
42 -* subclassJavaTemplate <filename>, the name of the Java subclass template to use inside of the template dir (Person)
43 -* templatedir <path>, the path to the folder that contains EOGenerator templates
44 -* verbose, turn on verbose output
44 +* -define-EOGenericRecord <class>, allows you to specify the _Person class's superclass. For instance, if you use Project Wonder, you would specify -define-EOGenericRecord er.extensions.ERXGenericRecord
45 +* -destination <path>, the folder that _Person.java-style java files will be produced in (the non-editable files)
46 +* -java, produce java files
47 +* -javaTemplate <filename>, the name of the Java template to use inside of the template dir (_Person)
48 +* -model <path>, Passes in the path of a .eomodeld you would like to generate Java files for. You can actually include multiple -model commands on the commandline
49 +* -packagedirs, produce package directory for any package statements defined in your Java files (not necessary if you don't specify package names on your entities. By the way, you should specify packages on your entities )
50 +* -refmodel <path>, Passes in the path of an .eomodeld that is required for generating Java files, but that won't actually have Java files generated for it. For instance, you should -refmodel any prototypes, or any models in other frameworks that you depend on
51 +* -subclassDestination <path>, the folder that Person.java-style java files will be produced in (the editable files)
52 +* -subclassJavaTemplate <filename>, the name of the Java subclass template to use inside of the template dir (Person)
53 +* -templatedir <path>, the path to the folder that contains EOGenerator templates
54 +* -verbose, turn on verbose output
45 45  
46 46  == Custom EOGenerator Mods ==
47 47  
48 48  === Zak Burke ===
49 49  
50 -Allow setting nulls on a to-one relationship (and turn it into a remove). Note, this is also included in Jonathan Rentzsch's templates.
60 +Allow setting nulls on a to-one relationship (and turn it into a remove). Note, this is also included in Jonathan Rentzsch's templates.
51 51  
52 52  {{code}}
53 53  
... ... @@ -84,12 +84,12 @@
84 84  
85 85  Jonathan Rentzsch has provided his base EOGenerator templates, which are a must-have:
86 86  
87 -[[http://rentzsch.com/share/eogenerator52templates.zip]]
97 +[[http:~~/~~/rentzsch.com/share/eogenerator52templates.zip>>url:http://rentzsch.com/share/eogenerator52templates.zip||shape="rect"]]
88 88  
89 89  === Markus Ruggiero ===
90 90  
91 91  Constants for all attributes and relationships. This allows compile time error checking in situations like
92 -addObjecttoBothSidesOfRelationshipWithKey(myObject, Person.TO//MANY//Children)
102 + addObjecttoBothSidesOfRelationshipWithKey(myObject, Person.TO_MANY_Children)
93 93  
94 94  {{code}}
95 95  
... ... @@ -133,7 +133,7 @@
133 133  
134 134  === Mike Schrag ===
135 135  
136 -Add a constant that represents the name of the entity so that you can refer to Person.ENTITY//NAME in fetches rather than the String (allows refactoring support in Eclipse)~://
146 +Add a constant that represents the name of the entity so that you can refer to Person.ENTITY_NAME in fetches rather than the String (allows refactoring support in Eclipse):
137 137  
138 138  {{code}}
139 139  
... ... @@ -154,7 +154,7 @@
154 154  
155 155  {{/code}}
156 156  
157 -Here's a little bitty fancier (read: nastier) version that also handles superclass mandatory attributes and fields (one level). It skips any attribute that is referenced in the restricting qualifier of your subclass (since you are probably going to set that in your awakeFromInsertion):
167 +Here's a little bitty fancier (read: nastier) version that also handles superclass mandatory attributes and fields (one level). It skips any attribute that is referenced in the restricting qualifier of your subclass (since you are probably going to set that in your awakeFromInsertion):
158 158  
159 159  {{code}}
160 160  
... ... @@ -169,26 +169,21 @@
169 169  
170 170  {{/code}}
171 171  
172 -Add a bunch of convience fetch methods (fetchAllPersons, fetchRequiredPerson, and other variants). It's not smart about pluralization, so it's just going to put an "s" on the end of the entity name:
182 +Add a bunch of convience fetch methods (fetchAllPersons, fetchRequiredPerson, and other variants). It's not smart about pluralization, so it's just going to put an "s" on the end of the entity name:
173 173  
174 174  {{code}}
175 -
176 176  public static NSArray fetchAll<$classNameWithoutPackage$>s(EOEditingContext _editingContext) {
177 177   return <$GEN_PREFIX$><$classNameWithoutPackage$>.fetchAll<$classNameWithoutPackage$>s(_editingContext, null);
178 178   }
188 +{{/code}}
179 179  
180 -{{/code}}
181 -
182 182  {{code}}
183 -
184 184  public static NSArray fetchAll<$classNameWithoutPackage$>s(EOEditingContext _editingContext, NSArray _sortOrderings) {
185 185   return <$GEN_PREFIX$><$classNameWithoutPackage$>.fetch<$classNameWithoutPackage$>s(_editingContext, null, _sortOrderings);
186 186   }
194 +{{/code}}
187 187  
188 -{{/code}}
189 -
190 190  {{code}}
191 -
192 192  public static NSArray fetch<$classNameWithoutPackage$>s(EOEditingContext _editingContext, EOQualifier _qualifier, NSArray _sortOrderings) {
193 193   EOFetchSpecification fetchSpec = new EOFetchSpecification(<$GEN_PREFIX$><$classNameWithoutPackage$>.ENTITY_NAME, _qualifier, _sortOrderings);
194 194   fetchSpec.setIsDeep(true);
... ... @@ -195,19 +195,15 @@
195 195   NSArray eoObjects = _editingContext.objectsWithFetchSpecification(fetchSpec);
196 196   return eoObjects;
197 197   }
203 +{{/code}}
198 198  
199 -{{/code}}
200 -
201 201  {{code}}
202 -
203 203  public static <$classNameWithoutPackage$> fetch<$classNameWithoutPackage$>(EOEditingContext _editingContext, String _keyName, Object _value) {
204 204   return <$GEN_PREFIX$><$classNameWithoutPackage$>.fetch<$classNameWithoutPackage$>(_editingContext, new EOKeyValueQualifier(_keyName, EOQualifier.QualifierOperatorEqual, _value));
205 205   }
209 +{{/code}}
206 206  
207 -{{/code}}
208 -
209 209  {{code}}
210 -
211 211  public static <$classNameWithoutPackage$> fetch<$classNameWithoutPackage$>(EOEditingContext _editingContext, EOQualifier _qualifier) {
212 212   NSArray eoObjects = <$GEN_PREFIX$><$classNameWithoutPackage$>.fetch<$classNameWithoutPackage$>s(_editingContext, _qualifier, null);
213 213   <$classNameWithoutPackage$> eoObject;
... ... @@ -223,17 +223,14 @@
223 223   }
224 224   return eoObject;
225 225   }
227 +{{/code}}
226 226  
227 -{{/code}}
228 -
229 229  {{code}}
230 -
231 231  public static <$classNameWithoutPackage$> fetchRequired<$classNameWithoutPackage$>(EOEditingContext _editingContext, String _keyName, Object _value) {
232 232   return <$GEN_PREFIX$><$classNameWithoutPackage$>.fetchRequired<$classNameWithoutPackage$>(_editingContext, new EOKeyValueQualifier(_keyName, EOQualifier.QualifierOperatorEqual, _value));
233 233   }
233 +{{/code}}
234 234  
235 -{{/code}}
236 -
237 237  {{code}}
238 238  
239 239  public static <$classNameWithoutPackage$> fetchRequired<$classNameWithoutPackage$>(EOEditingContext _editingContext, EOQualifier _qualifier) {
... ... @@ -246,16 +246,14 @@
246 246  
247 247  {{/code}}
248 248  
249 -Add methods for getting local instances of EO's. The static one is handy if you have a reference to an EO that might be null (it does a null check first):
247 +Add methods for getting local instances of EO's. The static one is handy if you have a reference to an EO that might be null (it does a null check first):
250 250  
251 251  {{code}}
252 -
253 253  public <$classNameWithoutPackage$> localInstanceOf<$classNameWithoutPackage$>(EOEditingContext _editingContext) {
254 254   return (<$classNameWithoutPackage$>)EOUtilities.localInstanceOfObject(_editingContext, this);
255 255   }
253 +{{/code}}
256 256  
257 -{{/code}}
258 -
259 259  {{code}}
260 260  
261 261  public static <$classNameWithoutPackage$> localInstanceOf<$classNameWithoutPackage$>(EOEditingContext _editingContext, <$classNameWithoutPackage$> _eo) {
... ... @@ -320,7 +320,7 @@
320 320  
321 321  === John Huss ===
322 322  
323 -I wanted to share a wonderful bit of knowledge I learned today. If you're using Java 1.5 you can add @SuppressWarnings("all") to the template for your EO base classes and eliminate annoying compiler messages (usually uneeded import statements).
319 +I wanted to share a wonderful bit of knowledge I learned today. If you're using Java 1.5 you can add @SuppressWarnings("all") to the template for your _EO base classes and eliminate annoying compiler messages (usually uneeded import statements).
324 324  
325 325  {{code}}
326 326