Changes for page EOF-Using EOF-EOGenerator
Last modified by Pascal Robert on 2012/01/21 22:03
From version 30.1
edited by Pascal Robert
on 2012/01/21 22:03
on 2012/01/21 22:03
Change comment:
There is no comment for this version
To version 29.1
edited by Quinton Dolan
on 2007/07/16 22:26
on 2007/07/16 22:26
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,22 +1,14 @@ 1 -{{warning}} 2 -This is deprecated information! 3 -{{/warning}} 1 +|=Contents 2 +| 4 4 5 -|= Contents 6 -| {{toc style="disc" minLevel="2"}}{{/toc}} 4 +{{toc style="disc" minLevel="2"}}{{/toc}} 7 7 8 -== Overview == 6 +== Overview == 9 9 10 -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. 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. 11 11 12 - {{warning}}10 +== Advantages == 13 13 14 -EOGenerator doesn't work on Mac OS X 10.5. You have to use [JavaEOGenerator|http://developer.apple.com/samplecode/JavaEOGenerator/] or [Velocity EOGenerator|WOL:Velocity EOGenerator (Veogen)]. 15 - 16 -{{/warning}} 17 - 18 -== Advantages == 19 - 20 20 There are several advantages to using EOGenerator over EOModeler's default Java file generation and merging with FileMerge. 21 21 22 22 * 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. ... ... @@ -23,7 +23,7 @@ 23 23 * 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 24 * As David LaBer put it, "all the cool kids use it - and we all know looking cool is the **most** important criteria". 25 25 26 -== How To Use It == 18 +== How To Use It == 27 27 28 28 Kieran Kelleher has writtten an [[Introduction to EOGenerator>>http://homepage.mac.com/kelleherk/iblog/C1837526061/E1908382110/index.html]] on his blog. 29 29 ... ... @@ -34,34 +34,34 @@ 34 34 35 35 {{panel}} 36 36 37 -eogenerator \-model /path/to/model/YourModel.eomodeld\-destination /path/to/source/folder38 - \-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 39 39 40 40 {{/panel}} 41 41 42 42 Voila. EOGenerator will spit out your Java files for you. Let's break down the commands you can pass in: 43 43 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 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-- 55 55 56 -== Custom EOGenerator Mods == 48 +== Custom EOGenerator Mods == 57 57 58 -=== Zak Burke === 50 +=== Zak Burke === 59 59 60 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. 61 61 62 62 {{code}} 63 63 64 -public void save<$ToOneRelationship.name.initialCapitalString$>(<$ToOneRelationship.destinationEntity.referenceJavaClassName$> value) 56 + public void save<$ToOneRelationship.name.initialCapitalString$>(<$ToOneRelationship.destinationEntity.referenceJavaClassName$> value) 65 65 { 66 66 if (value == null) 67 67 { ... ... @@ -77,13 +77,13 @@ 77 77 78 78 {{/code}} 79 79 80 -=== Chuck Hill === 72 +=== Chuck Hill === 81 81 82 82 Return the list of changes between the current EO and the last committed version of the EO: 83 83 84 84 {{code}} 85 85 86 -public NSDictionary changedProperties() { 78 + public NSDictionary changedProperties() { 87 87 NSDictionary commitedValues = editingContext().committedSnapshotForObject(this); 88 88 return changesFromSnapshot(commitedValues); 89 89 } ... ... @@ -90,13 +90,13 @@ 90 90 91 91 {{/code}} 92 92 93 -=== Jonathan Rentzsch === 85 +=== Jonathan Rentzsch === 94 94 95 95 Jonathan Rentzsch has provided his base EOGenerator templates, which are a must-have: 96 96 97 - [[http://rentzsch.com/share/eogenerator52templates.zip]]89 +http:~/~/rentzsch.com/share/eogenerator52templates.zip 98 98 99 -=== Markus Ruggiero === 91 +=== Markus Ruggiero === 100 100 101 101 Constants for all attributes and relationships. This allows compile time error checking in situations like 102 102 addObjecttoBothSidesOfRelationshipWithKey(myObject, Person.TO//MANY//Children) ... ... @@ -103,7 +103,7 @@ 103 103 104 104 {{code}} 105 105 106 -<$foreach attribute classAttributes.@reversedArray do$> 98 + <$foreach attribute classAttributes.@reversedArray do$> 107 107 public static final String ATTRIBUTE_<$attribute.name$> = "<$attribute.name$>";<$endforeach do$> 108 108 109 109 <$foreach ToOneRelationship classToOneRelationships.@reversedArray do$> ... ... @@ -118,15 +118,15 @@ 118 118 119 119 {{code}} 120 120 121 -<$if attribute.userInfo.usage h1. booleanFlag $> // boolean accessors 113 + <$if attribute.userInfo.usage h1. booleanFlag $> // boolean accessors 122 122 public void <$attribute.userInfo.setterName$>(boolean newBoolean) { 123 123 set<$attribute.name.initialCapitalString$>(newBoolean ? "true" : "false"); 124 124 } 125 - 117 + 126 126 public boolean <$attribute.userInfo.getterName$>() { 127 127 return "true".equals(<$attribute.name$>()) ? true : false; 128 128 } 129 - 121 + 130 130 // validation 131 131 public String validate<$attribute.name.initialCapitalString$>(String newValue) { 132 132 if ( newValue null ) { ... ... @@ -141,19 +141,19 @@ 141 141 142 142 {{/code}} 143 143 144 -=== Mike Schrag === 136 +=== Mike Schrag === 145 145 146 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)~:// 147 147 148 148 {{code}} 149 149 150 -public static final String ENTITY_NAME = "<$name$>"; 142 + public static final String ENTITY_NAME = "<$name$>"; 151 151 152 152 {{/code}} 153 153 154 154 Add a static factory method to your EO's ( Person createPerson(...) ) that shows you what required attributes and relationships are configured for you entity (attempts to provide a replacement "constructor" since EO constructors are empty): 155 155 156 -{{code}} 148 +{{code bar="true"}} 157 157 158 158 public static <$classNameWithoutPackage$> create<$classNameWithoutPackage$>(EOEditingContext _editingContext<$foreach Attribute classAttributes.@sortedNameArray do$><$if !Attribute.allowsNull$>, <$Attribute.javaValueClassName$> _<$Attribute.name$><$endif$><$endforeach do$><$foreach ToOneRelationship classToOneRelationships.@sortedNameArray do$><$if ToOneRelationship.isMandatory$>, <$ToOneRelationship.destinationEntity.referenceJavaClassName$> _<$ToOneRelationship.name$><$endif$><$endforeach do$>) { 159 159 <$classNameWithoutPackage$> eoObject = (<$classNameWithoutPackage$>)EOUtilities.createAndInsertInstance(_editingContext, <$GEN_PREFIX$><$classNameWithoutPackage$>.ENTITY_NAME);<$foreach Attribute classAttributes.@sortedNameArray do$><$if !Attribute.allowsNull$> ... ... @@ -166,7 +166,7 @@ 166 166 167 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): 168 168 169 -{{code}} 161 +{{code bar="true"}} 170 170 171 171 public static <$classNameWithoutPackage$> create<$classNameWithoutPackage$>(EOEditingContext editingContext<$foreach Attribute classAttributes.@sortedNameArray do$><$if !Attribute.allowsNull$>, <$Attribute.javaValueClassName$> <$Attribute.name$><$endif$><$endforeach do$><$foreach Attribute parentEntity.classAttributes.@sortedNameArray do$><$if !Attribute.allowsNull$><$set RestrictingQualifierKey = false$><$foreach QualifierKey restrictingQualifier.allQualifierKeys do$><$if Attribute.name = QualifierKey$><$set RestrictingQualifierKey = true$><$endif$><$endforeach do$><$if RestrictingQualifierKey = false$>, <$Attribute.javaValueClassName$> <$Attribute.name$><$endif$><$endif$><$endforeach do$><$foreach ToOneRelationship classToOneRelationships.@sortedNameArray do$><$if ToOneRelationship.isMandatory$>, <$ToOneRelationship.destinationEntity.referenceJavaClassName$> <$ToOneRelationship.name$><$endif$><$endforeach do$><$foreach ToOneRelationship parentEntity.classToOneRelationships.@sortedNameArray do$><$if ToOneRelationship.isMandatory$>, <$ToOneRelationship.destinationEntity.referenceJavaClassName$> <$ToOneRelationship.name$><$endif$><$endforeach do$>) { 172 172 <$classNameWithoutPackage$> eoObject = (<$classNameWithoutPackage$>)EOUtilities.createAndInsertInstance(editingContext, <$GEN_PREFIX$><$classNameWithoutPackage$>.ENTITY_NAME);<$foreach Attribute classAttributes.@sortedNameArray do$><$if !Attribute.allowsNull$> ... ... @@ -183,23 +183,15 @@ 183 183 184 184 {{code}} 185 185 186 -public static NSArray fetchAll<$classNameWithoutPackage$>s(EOEditingContext _editingContext) { 178 + public static NSArray fetchAll<$classNameWithoutPackage$>s(EOEditingContext _editingContext) { 187 187 return <$GEN_PREFIX$><$classNameWithoutPackage$>.fetchAll<$classNameWithoutPackage$>s(_editingContext, null); 188 188 } 189 189 190 -{{/code}} 191 - 192 -{{code}} 193 - 194 -public static NSArray fetchAll<$classNameWithoutPackage$>s(EOEditingContext _editingContext, NSArray _sortOrderings) { 182 + public static NSArray fetchAll<$classNameWithoutPackage$>s(EOEditingContext _editingContext, NSArray _sortOrderings) { 195 195 return <$GEN_PREFIX$><$classNameWithoutPackage$>.fetch<$classNameWithoutPackage$>s(_editingContext, null, _sortOrderings); 196 196 } 197 197 198 -{{/code}} 199 - 200 -{{code}} 201 - 202 -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) { 203 203 EOFetchSpecification fetchSpec = new EOFetchSpecification(<$GEN_PREFIX$><$classNameWithoutPackage$>.ENTITY_NAME, _qualifier, _sortOrderings); 204 204 fetchSpec.setIsDeep(true); 205 205 NSArray eoObjects = _editingContext.objectsWithFetchSpecification(fetchSpec); ... ... @@ -206,19 +206,11 @@ 206 206 return eoObjects; 207 207 } 208 208 209 -{{/code}} 210 - 211 -{{code}} 212 - 213 -public static <$classNameWithoutPackage$> fetch<$classNameWithoutPackage$>(EOEditingContext _editingContext, String _keyName, Object _value) { 193 + public static <$classNameWithoutPackage$> fetch<$classNameWithoutPackage$>(EOEditingContext _editingContext, String _keyName, Object _value) { 214 214 return <$GEN_PREFIX$><$classNameWithoutPackage$>.fetch<$classNameWithoutPackage$>(_editingContext, new EOKeyValueQualifier(_keyName, EOQualifier.QualifierOperatorEqual, _value)); 215 215 } 216 216 217 -{{/code}} 218 - 219 -{{code}} 220 - 221 -public static <$classNameWithoutPackage$> fetch<$classNameWithoutPackage$>(EOEditingContext _editingContext, EOQualifier _qualifier) { 197 + public static <$classNameWithoutPackage$> fetch<$classNameWithoutPackage$>(EOEditingContext _editingContext, EOQualifier _qualifier) { 222 222 NSArray eoObjects = <$GEN_PREFIX$><$classNameWithoutPackage$>.fetch<$classNameWithoutPackage$>s(_editingContext, _qualifier, null); 223 223 <$classNameWithoutPackage$> eoObject; 224 224 int count = eoObjects.count(); ... ... @@ -233,22 +233,14 @@ 233 233 } 234 234 return eoObject; 235 235 } 236 - 237 -{{/code}} 238 - 239 -{{code}} 240 - 241 -public static <$classNameWithoutPackage$> fetchRequired<$classNameWithoutPackage$>(EOEditingContext _editingContext, String _keyName, Object _value) { 212 + 213 + public static <$classNameWithoutPackage$> fetchRequired<$classNameWithoutPackage$>(EOEditingContext _editingContext, String _keyName, Object _value) { 242 242 return <$GEN_PREFIX$><$classNameWithoutPackage$>.fetchRequired<$classNameWithoutPackage$>(_editingContext, new EOKeyValueQualifier(_keyName, EOQualifier.QualifierOperatorEqual, _value)); 243 243 } 244 244 245 -{{/code}} 246 - 247 -{{code}} 248 - 249 -public static <$classNameWithoutPackage$> fetchRequired<$classNameWithoutPackage$>(EOEditingContext _editingContext, EOQualifier _qualifier) { 217 + public static <$classNameWithoutPackage$> fetchRequired<$classNameWithoutPackage$>(EOEditingContext _editingContext, EOQualifier _qualifier) { 250 250 <$classNameWithoutPackage$> eoObject = <$GEN_PREFIX$><$classNameWithoutPackage$>.fetch<$classNameWithoutPackage$>(_editingContext, _qualifier); 251 - if (eoObject ==null) {219 + if (eoObject h1. null) { 252 252 throw new NoSuchElementException("There was no <$classNameWithoutPackage$> that matched the qualifier '" + _qualifier + "'."); 253 253 } 254 254 return eoObject; ... ... @@ -260,16 +260,12 @@ 260 260 261 261 {{code}} 262 262 263 -public <$classNameWithoutPackage$> localInstanceOf<$classNameWithoutPackage$>(EOEditingContext _editingContext) { 231 + public <$classNameWithoutPackage$> localInstanceOf<$classNameWithoutPackage$>(EOEditingContext _editingContext) { 264 264 return (<$classNameWithoutPackage$>)EOUtilities.localInstanceOfObject(_editingContext, this); 265 265 } 266 266 267 -{{/code}} 268 - 269 -{{code}} 270 - 271 -public static <$classNameWithoutPackage$> localInstanceOf<$classNameWithoutPackage$>(EOEditingContext _editingContext, <$classNameWithoutPackage$> _eo) { 272 - 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); 273 273 } 274 274 275 275 {{/code}} ... ... @@ -278,7 +278,7 @@ 278 278 279 279 {{code}} 280 280 281 -<$if !ToManyRelationship.inverseRelationship$> 245 + <$if !ToManyRelationship.inverseRelationship$> 282 282 public NSArray <$ToManyRelationship.name$>(EOQualifier qualifier) { 283 283 return <$ToManyRelationship.name$>(qualifier, null); 284 284 } ... ... @@ -287,12 +287,12 @@ 287 287 public NSArray <$ToManyRelationship.name$>(EOQualifier qualifier) { 288 288 return <$ToManyRelationship.name$>(qualifier, null, false); 289 289 } 290 - 291 - public NSArray <$ToManyRelationship.name$>(EOQualifier qualifier, boolean fetch) { 254 + 255 + public NSArray <$ToManyRelationship.name$>(EOQualifier qualifier, boolean fetch) { 292 292 return <$ToManyRelationship.name$>(qualifier, null, fetch); 293 293 } 294 294 <$endif$> 295 - 259 + 296 296 public NSArray <$ToManyRelationship.name$>(EOQualifier qualifier, NSArray sortOrderings<$if ToManyRelationship.inverseRelationship$>, boolean fetch<$endif$>) { 297 297 NSArray results; 298 298 <$if ToManyRelationship.inverseRelationship$> ... ... @@ -328,25 +328,25 @@ 328 328 329 329 {{/code}} 330 330 331 -=== John Huss === 295 +=== John Huss === 332 332 333 -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).// 334 334 335 335 {{code}} 336 336 337 -@SuppressWarnings("all") 301 + @SuppressWarnings("all") 338 338 public class _Invoice extends ERXGenericRecord { 339 339 } 340 340 341 341 {{/code}} 342 342 343 -=== Guido Neitzer === 307 +=== Guido Neitzer === 344 344 345 345 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: 346 346 347 347 {{code}} 348 348 349 -/** 313 +/** 350 350 * Initialization of the instance while inserting it into an editing context 351 351 */ 352 352 public void awakeFromInsertion (EOEditingContext editingContext) { ... ... @@ -357,3 +357,5 @@ 357 357 {{/code}} 358 358 359 359 This is from my JavaSubclassSourceTemplate.eotemplate 324 + 325 +Category:WebObjects