Changes for page EOF-Using EOF-EOGenerator
Last modified by Pascal Robert on 2012/01/21 22:03
From version 21.1
edited by Pascal Robert
on 2007/12/21 20:55
on 2007/12/21 20:55
Change comment:
There is no comment for this version
To version 24.1
edited by Quinton Dolan
on 2007/07/16 22:42
on 2007/07/16 22:42
Change comment:
There is no comment for this version
Summary
-
Page properties (3 modified, 0 added, 0 removed)
Details
- Page properties
-
- Title
-
... ... @@ -1,1 +1,1 @@ 1 -EOF-Using EOF-EOGenerator 1 +Programming__WebObjects-EOF-Using EOF-EOGenerator - Author
-
... ... @@ -1,1 +1,1 @@ 1 -XWiki. probert1 +XWiki.qdolan - Content
-
... ... @@ -1,18 +1,14 @@ 1 -|= 2 -| {{toc style="disc" minLevel="2"}}{{/toc}}1 +|=Contents 2 +| 3 3 4 -= =Overview==4 +{{toc style="disc" minLevel="2"}}{{/toc}} 5 5 6 - Ifyou've ever used EOModeler's Java sourcecode generator, you know how much of a pain it can be when you make changes to your model objects and have to merge changesin later. One solution for this is to use [[EOGenerator>>http://www.rubicode.com/Software/EOGenerator/]],anapplication 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.6 +== Overview == 7 7 8 - {{warning}}8 +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. 9 9 10 - EOGeneratordon't work on Mac OS X 10.5. You either have to use [JavaEOGenerator|http://developer.apple.com/samplecode/JavaEOGenerator/]or[Velocity EOGenerator|WOL:Velocity EOGenerator (Veogen)].10 +== Advantages == 11 11 12 -{{/warning}} 13 - 14 -== Advantages == 15 - 16 16 There are several advantages to using EOGenerator over EOModeler's default Java file generation and merging with FileMerge. 17 17 18 18 * 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. ... ... @@ -19,7 +19,7 @@ 19 19 * 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. 20 20 * As David LaBer put it, "all the cool kids use it - and we all know looking cool is the **most** important criteria". 21 21 22 -== How To Use It == 18 +== How To Use It == 23 23 24 24 Kieran Kelleher has writtten an [[Introduction to EOGenerator>>http://homepage.mac.com/kelleherk/iblog/C1837526061/E1908382110/index.html]] on his blog. 25 25 ... ... @@ -30,34 +30,34 @@ 30 30 31 31 {{panel}} 32 32 33 -eogenerator \-model /path/to/model/YourModel.eomodeld\-destination /path/to/source/folder34 - \-subclassDestination /path/to/source/folder\-templatedir /path/to/EOGenerator/templates\-java\-packagedirs29 +eogenerator -model /path/to/model/YourModel.eomodeld -destination /path/to/source/folder 30 + -subclassDestination /path/to/source/folder -templatedir /path/to/EOGenerator/templates -java -packagedirs 35 35 36 36 {{/panel}} 37 37 38 38 Voila. EOGenerator will spit out your Java files for you. Let's break down the commands you can pass in: 39 39 40 -* 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 41 -* destination <path>, the folder that Person.java-style java files will be produced in (the non-editable files) 42 -* java, produce java files 43 -* javaTemplate <filename>, the name of the Java template to use inside of the template dir (//Person)// 44 -* 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 45 -* 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 : -) )46 -* 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 47 -* subclassDestination <path>, the folder that Person.java-style java files will be produced in (the editable files) 48 -* subclassJavaTemplate <filename>, the name of the Java subclass template to use inside of the template dir (Person) 49 -* templatedir <path>, the path to the folder that contains EOGenerator templates 50 -* verbose, turn on verbose output 36 +* --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// 37 +* --destination <path>, the folder that //Person.java//--//style java files will be produced in (the non-editable files)// 38 +* --java, produce java files-- 39 +* --javaTemplate <filename>, the name of the Java template to use inside of the template dir (//Person)//-- 40 +* --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 41 +* --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 :) )-- 42 +* --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 43 +* --subclassDestination <path>, the folder that Person.java--style java files will be produced in (the editable files) 44 +* --subclassJavaTemplate <filename>, the name of the Java subclass template to use inside of the template dir (Person)-- 45 +* --templatedir <path>, the path to the folder that contains EOGenerator templates-- 46 +* --verbose, turn on verbose output-- 51 51 52 -== Custom EOGenerator Mods == 48 +== Custom EOGenerator Mods == 53 53 54 -=== Zak Burke === 50 +=== Zak Burke === 55 55 56 56 Allow setting nulls on a to-one relationship (and turn it into a remove). Note, this is also included in Jonathan Rentzsch's templates. 57 57 58 58 {{code}} 59 59 60 -public void save<$ToOneRelationship.name.initialCapitalString$>(<$ToOneRelationship.destinationEntity.referenceJavaClassName$> value) 56 + public void save<$ToOneRelationship.name.initialCapitalString$>(<$ToOneRelationship.destinationEntity.referenceJavaClassName$> value) 61 61 { 62 62 if (value == null) 63 63 { ... ... @@ -73,13 +73,13 @@ 73 73 74 74 {{/code}} 75 75 76 -=== Chuck Hill === 72 +=== Chuck Hill === 77 77 78 78 Return the list of changes between the current EO and the last committed version of the EO: 79 79 80 80 {{code}} 81 81 82 -public NSDictionary changedProperties() { 78 + public NSDictionary changedProperties() { 83 83 NSDictionary commitedValues = editingContext().committedSnapshotForObject(this); 84 84 return changesFromSnapshot(commitedValues); 85 85 } ... ... @@ -86,13 +86,13 @@ 86 86 87 87 {{/code}} 88 88 89 -=== Jonathan Rentzsch === 85 +=== Jonathan Rentzsch === 90 90 91 91 Jonathan Rentzsch has provided his base EOGenerator templates, which are a must-have: 92 92 93 - [[http://rentzsch.com/share/eogenerator52templates.zip]]89 +http:~/~/rentzsch.com/share/eogenerator52templates.zip 94 94 95 -=== Markus Ruggiero === 91 +=== Markus Ruggiero === 96 96 97 97 Constants for all attributes and relationships. This allows compile time error checking in situations like 98 98 addObjecttoBothSidesOfRelationshipWithKey(myObject, Person.TO//MANY//Children) ... ... @@ -99,7 +99,7 @@ 99 99 100 100 {{code}} 101 101 102 -<$foreach attribute classAttributes.@reversedArray do$> 98 + <$foreach attribute classAttributes.@reversedArray do$> 103 103 public static final String ATTRIBUTE_<$attribute.name$> = "<$attribute.name$>";<$endforeach do$> 104 104 105 105 <$foreach ToOneRelationship classToOneRelationships.@reversedArray do$> ... ... @@ -114,15 +114,15 @@ 114 114 115 115 {{code}} 116 116 117 -<$if attribute.userInfo.usage h1. booleanFlag $> // boolean accessors 113 + <$if attribute.userInfo.usage h1. booleanFlag $> // boolean accessors 118 118 public void <$attribute.userInfo.setterName$>(boolean newBoolean) { 119 119 set<$attribute.name.initialCapitalString$>(newBoolean ? "true" : "false"); 120 120 } 121 - 117 + 122 122 public boolean <$attribute.userInfo.getterName$>() { 123 123 return "true".equals(<$attribute.name$>()) ? true : false; 124 124 } 125 - 121 + 126 126 // validation 127 127 public String validate<$attribute.name.initialCapitalString$>(String newValue) { 128 128 if ( newValue null ) { ... ... @@ -137,13 +137,13 @@ 137 137 138 138 {{/code}} 139 139 140 -=== Mike Schrag === 136 +=== Mike Schrag === 141 141 142 142 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)~:// 143 143 144 144 {{code}} 145 145 146 -public static final String ENTITY_NAME = "<$name$>"; 142 + public static final String ENTITY_NAME = "<$name$>"; 147 147 148 148 {{/code}} 149 149 ... ... @@ -179,23 +179,15 @@ 179 179 180 180 {{code}} 181 181 182 -public static NSArray fetchAll<$classNameWithoutPackage$>s(EOEditingContext _editingContext) { 178 + public static NSArray fetchAll<$classNameWithoutPackage$>s(EOEditingContext _editingContext) { 183 183 return <$GEN_PREFIX$><$classNameWithoutPackage$>.fetchAll<$classNameWithoutPackage$>s(_editingContext, null); 184 184 } 185 185 186 -{{/code}} 187 - 188 -{{code}} 189 - 190 -public static NSArray fetchAll<$classNameWithoutPackage$>s(EOEditingContext _editingContext, NSArray _sortOrderings) { 182 + public static NSArray fetchAll<$classNameWithoutPackage$>s(EOEditingContext _editingContext, NSArray _sortOrderings) { 191 191 return <$GEN_PREFIX$><$classNameWithoutPackage$>.fetch<$classNameWithoutPackage$>s(_editingContext, null, _sortOrderings); 192 192 } 193 193 194 -{{/code}} 195 - 196 -{{code}} 197 - 198 -public static NSArray fetch<$classNameWithoutPackage$>s(EOEditingContext _editingContext, EOQualifier _qualifier, NSArray _sortOrderings) { 186 + public static NSArray fetch<$classNameWithoutPackage$>s(EOEditingContext _editingContext, EOQualifier _qualifier, NSArray _sortOrderings) { 199 199 EOFetchSpecification fetchSpec = new EOFetchSpecification(<$GEN_PREFIX$><$classNameWithoutPackage$>.ENTITY_NAME, _qualifier, _sortOrderings); 200 200 fetchSpec.setIsDeep(true); 201 201 NSArray eoObjects = _editingContext.objectsWithFetchSpecification(fetchSpec); ... ... @@ -202,19 +202,11 @@ 202 202 return eoObjects; 203 203 } 204 204 205 -{{/code}} 206 - 207 -{{code}} 208 - 209 -public static <$classNameWithoutPackage$> fetch<$classNameWithoutPackage$>(EOEditingContext _editingContext, String _keyName, Object _value) { 193 + public static <$classNameWithoutPackage$> fetch<$classNameWithoutPackage$>(EOEditingContext _editingContext, String _keyName, Object _value) { 210 210 return <$GEN_PREFIX$><$classNameWithoutPackage$>.fetch<$classNameWithoutPackage$>(_editingContext, new EOKeyValueQualifier(_keyName, EOQualifier.QualifierOperatorEqual, _value)); 211 211 } 212 212 213 -{{/code}} 214 - 215 -{{code}} 216 - 217 -public static <$classNameWithoutPackage$> fetch<$classNameWithoutPackage$>(EOEditingContext _editingContext, EOQualifier _qualifier) { 197 + public static <$classNameWithoutPackage$> fetch<$classNameWithoutPackage$>(EOEditingContext _editingContext, EOQualifier _qualifier) { 218 218 NSArray eoObjects = <$GEN_PREFIX$><$classNameWithoutPackage$>.fetch<$classNameWithoutPackage$>s(_editingContext, _qualifier, null); 219 219 <$classNameWithoutPackage$> eoObject; 220 220 int count = eoObjects.count(); ... ... @@ -229,22 +229,14 @@ 229 229 } 230 230 return eoObject; 231 231 } 232 - 233 -{{/code}} 234 - 235 -{{code}} 236 - 237 -public static <$classNameWithoutPackage$> fetchRequired<$classNameWithoutPackage$>(EOEditingContext _editingContext, String _keyName, Object _value) { 212 + 213 + public static <$classNameWithoutPackage$> fetchRequired<$classNameWithoutPackage$>(EOEditingContext _editingContext, String _keyName, Object _value) { 238 238 return <$GEN_PREFIX$><$classNameWithoutPackage$>.fetchRequired<$classNameWithoutPackage$>(_editingContext, new EOKeyValueQualifier(_keyName, EOQualifier.QualifierOperatorEqual, _value)); 239 239 } 240 240 241 -{{/code}} 242 - 243 -{{code}} 244 - 245 -public static <$classNameWithoutPackage$> fetchRequired<$classNameWithoutPackage$>(EOEditingContext _editingContext, EOQualifier _qualifier) { 217 + public static <$classNameWithoutPackage$> fetchRequired<$classNameWithoutPackage$>(EOEditingContext _editingContext, EOQualifier _qualifier) { 246 246 <$classNameWithoutPackage$> eoObject = <$GEN_PREFIX$><$classNameWithoutPackage$>.fetch<$classNameWithoutPackage$>(_editingContext, _qualifier); 247 - if (eoObject ==null) {219 + if (eoObject h1. null) { 248 248 throw new NoSuchElementException("There was no <$classNameWithoutPackage$> that matched the qualifier '" + _qualifier + "'."); 249 249 } 250 250 return eoObject; ... ... @@ -256,16 +256,12 @@ 256 256 257 257 {{code}} 258 258 259 -public <$classNameWithoutPackage$> localInstanceOf<$classNameWithoutPackage$>(EOEditingContext _editingContext) { 231 + public <$classNameWithoutPackage$> localInstanceOf<$classNameWithoutPackage$>(EOEditingContext _editingContext) { 260 260 return (<$classNameWithoutPackage$>)EOUtilities.localInstanceOfObject(_editingContext, this); 261 261 } 262 262 263 -{{/code}} 264 - 265 -{{code}} 266 - 267 -public static <$classNameWithoutPackage$> localInstanceOf<$classNameWithoutPackage$>(EOEditingContext _editingContext, <$classNameWithoutPackage$> _eo) { 268 - return (_eo == null) ? null : (<$classNameWithoutPackage$>)EOUtilities.localInstanceOfObject(_editingContext, _eo); 235 + public static <$classNameWithoutPackage$> localInstanceOf<$classNameWithoutPackage$>(EOEditingContext _editingContext, <$classNameWithoutPackage$> _eo) { 236 + return (_eo null) ? null : (<$classNameWithoutPackage$>)EOUtilities.localInstanceOfObject(_editingContext, _eo); 269 269 } 270 270 271 271 {{/code}} ... ... @@ -274,7 +274,7 @@ 274 274 275 275 {{code}} 276 276 277 -<$if !ToManyRelationship.inverseRelationship$> 245 + <$if !ToManyRelationship.inverseRelationship$> 278 278 public NSArray <$ToManyRelationship.name$>(EOQualifier qualifier) { 279 279 return <$ToManyRelationship.name$>(qualifier, null); 280 280 } ... ... @@ -283,12 +283,12 @@ 283 283 public NSArray <$ToManyRelationship.name$>(EOQualifier qualifier) { 284 284 return <$ToManyRelationship.name$>(qualifier, null, false); 285 285 } 286 - 287 - public NSArray <$ToManyRelationship.name$>(EOQualifier qualifier, boolean fetch) { 254 + 255 + public NSArray <$ToManyRelationship.name$>(EOQualifier qualifier, boolean fetch) { 288 288 return <$ToManyRelationship.name$>(qualifier, null, fetch); 289 289 } 290 290 <$endif$> 291 - 259 + 292 292 public NSArray <$ToManyRelationship.name$>(EOQualifier qualifier, NSArray sortOrderings<$if ToManyRelationship.inverseRelationship$>, boolean fetch<$endif$>) { 293 293 NSArray results; 294 294 <$if ToManyRelationship.inverseRelationship$> ... ... @@ -324,25 +324,25 @@ 324 324 325 325 {{/code}} 326 326 327 -=== John Huss === 295 +=== John Huss === 328 328 329 -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). 297 +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).// 330 330 331 331 {{code}} 332 332 333 -@SuppressWarnings("all") 301 + @SuppressWarnings("all") 334 334 public class _Invoice extends ERXGenericRecord { 335 335 } 336 336 337 337 {{/code}} 338 338 339 -=== Guido Neitzer === 307 +=== Guido Neitzer === 340 340 341 341 Create awakeFromInsertion() and awakeFromFetch() in your EOGenerator template as a method stub that only calls super() and has a comment for "initialize your object here ...". You only have to put in the code at that place and can't possibly forget to call super(). Here is an example: 342 342 343 343 {{code}} 344 344 345 -/** 313 +/** 346 346 * Initialization of the instance while inserting it into an editing context 347 347 */ 348 348 public void awakeFromInsertion (EOEditingContext editingContext) { ... ... @@ -353,3 +353,5 @@ 353 353 {{/code}} 354 354 355 355 This is from my JavaSubclassSourceTemplate.eotemplate 324 + 325 +Category:WebObjects