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
on 2007/09/03 13:44
Change comment:
There is no comment for this version
To version 17.1
edited by David Holt
on 2007/08/14 11:27
on 2007/08/14 11:27
Change comment:
Corrected some slight errors in the code that were created in the transfer from the older Wiki
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.dholt - Content
-
... ... @@ -1,12 +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 - ==Advantages==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 +== Advantages == 11 + 10 10 There are several advantages to using EOGenerator over EOModeler's default Java file generation and merging with FileMerge. 11 11 12 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,7 +13,7 @@ 13 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. 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 -== How To Use It == 18 +== How To Use It == 17 17 18 18 Kieran Kelleher has writtten an [[Introduction to EOGenerator>>http://homepage.mac.com/kelleherk/iblog/C1837526061/E1908382110/index.html]] on his blog. 19 19 ... ... @@ -24,34 +24,34 @@ 24 24 25 25 {{panel}} 26 26 27 -eogenerator \-model /path/to/model/YourModel.eomodeld\-destination /path/to/source/folder28 - \-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 29 29 30 30 {{/panel}} 31 31 32 32 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 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-- 45 45 46 -== Custom EOGenerator Mods == 48 +== Custom EOGenerator Mods == 47 47 48 -=== Zak Burke === 50 +=== Zak Burke === 49 49 50 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. 51 51 52 52 {{code}} 53 53 54 -public void save<$ToOneRelationship.name.initialCapitalString$>(<$ToOneRelationship.destinationEntity.referenceJavaClassName$> value) 56 + public void save<$ToOneRelationship.name.initialCapitalString$>(<$ToOneRelationship.destinationEntity.referenceJavaClassName$> value) 55 55 { 56 56 if (value == null) 57 57 { ... ... @@ -67,13 +67,13 @@ 67 67 68 68 {{/code}} 69 69 70 -=== Chuck Hill === 72 +=== Chuck Hill === 71 71 72 72 Return the list of changes between the current EO and the last committed version of the EO: 73 73 74 74 {{code}} 75 75 76 -public NSDictionary changedProperties() { 78 + public NSDictionary changedProperties() { 77 77 NSDictionary commitedValues = editingContext().committedSnapshotForObject(this); 78 78 return changesFromSnapshot(commitedValues); 79 79 } ... ... @@ -80,13 +80,13 @@ 80 80 81 81 {{/code}} 82 82 83 -=== Jonathan Rentzsch === 85 +=== Jonathan Rentzsch === 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]]89 +http:~/~/rentzsch.com/share/eogenerator52templates.zip 88 88 89 -=== Markus Ruggiero === 91 +=== Markus Ruggiero === 90 90 91 91 Constants for all attributes and relationships. This allows compile time error checking in situations like 92 92 addObjecttoBothSidesOfRelationshipWithKey(myObject, Person.TO//MANY//Children) ... ... @@ -93,7 +93,7 @@ 93 93 94 94 {{code}} 95 95 96 -<$foreach attribute classAttributes.@reversedArray do$> 98 + <$foreach attribute classAttributes.@reversedArray do$> 97 97 public static final String ATTRIBUTE_<$attribute.name$> = "<$attribute.name$>";<$endforeach do$> 98 98 99 99 <$foreach ToOneRelationship classToOneRelationships.@reversedArray do$> ... ... @@ -108,15 +108,15 @@ 108 108 109 109 {{code}} 110 110 111 -<$if attribute.userInfo.usage h1. booleanFlag $> // boolean accessors 113 + <$if attribute.userInfo.usage h1. booleanFlag $> // boolean accessors 112 112 public void <$attribute.userInfo.setterName$>(boolean newBoolean) { 113 113 set<$attribute.name.initialCapitalString$>(newBoolean ? "true" : "false"); 114 114 } 115 - 117 + 116 116 public boolean <$attribute.userInfo.getterName$>() { 117 117 return "true".equals(<$attribute.name$>()) ? true : false; 118 118 } 119 - 121 + 120 120 // validation 121 121 public String validate<$attribute.name.initialCapitalString$>(String newValue) { 122 122 if ( newValue null ) { ... ... @@ -131,13 +131,13 @@ 131 131 132 132 {{/code}} 133 133 134 -=== Mike Schrag === 136 +=== Mike Schrag === 135 135 136 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)~:// 137 137 138 138 {{code}} 139 139 140 -public static final String ENTITY_NAME = "<$name$>"; 142 + public static final String ENTITY_NAME = "<$name$>"; 141 141 142 142 {{/code}} 143 143 ... ... @@ -173,7 +173,7 @@ 173 173 174 174 {{code}} 175 175 176 -public static NSArray fetchAll<$classNameWithoutPackage$>s(EOEditingContext _editingContext) { 178 + public static NSArray fetchAll<$classNameWithoutPackage$>s(EOEditingContext _editingContext) { 177 177 return <$GEN_PREFIX$><$classNameWithoutPackage$>.fetchAll<$classNameWithoutPackage$>s(_editingContext, null); 178 178 } 179 179 ... ... @@ -181,7 +181,7 @@ 181 181 182 182 {{code}} 183 183 184 -public static NSArray fetchAll<$classNameWithoutPackage$>s(EOEditingContext _editingContext, NSArray _sortOrderings) { 186 + public static NSArray fetchAll<$classNameWithoutPackage$>s(EOEditingContext _editingContext, NSArray _sortOrderings) { 185 185 return <$GEN_PREFIX$><$classNameWithoutPackage$>.fetch<$classNameWithoutPackage$>s(_editingContext, null, _sortOrderings); 186 186 } 187 187 ... ... @@ -189,7 +189,7 @@ 189 189 190 190 {{code}} 191 191 192 -public static NSArray fetch<$classNameWithoutPackage$>s(EOEditingContext _editingContext, EOQualifier _qualifier, NSArray _sortOrderings) { 194 + 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 195 NSArray eoObjects = _editingContext.objectsWithFetchSpecification(fetchSpec); ... ... @@ -200,7 +200,7 @@ 200 200 201 201 {{code}} 202 202 203 -public static <$classNameWithoutPackage$> fetch<$classNameWithoutPackage$>(EOEditingContext _editingContext, String _keyName, Object _value) { 205 + 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 } 206 206 ... ... @@ -208,7 +208,7 @@ 208 208 209 209 {{code}} 210 210 211 -public static <$classNameWithoutPackage$> fetch<$classNameWithoutPackage$>(EOEditingContext _editingContext, EOQualifier _qualifier) { 213 + 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; 214 214 int count = eoObjects.count(); ... ... @@ -228,7 +228,7 @@ 228 228 229 229 {{code}} 230 230 231 -public static <$classNameWithoutPackage$> fetchRequired<$classNameWithoutPackage$>(EOEditingContext _editingContext, String _keyName, Object _value) { 233 + 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 } 234 234 ... ... @@ -236,7 +236,7 @@ 236 236 237 237 {{code}} 238 238 239 -public static <$classNameWithoutPackage$> fetchRequired<$classNameWithoutPackage$>(EOEditingContext _editingContext, EOQualifier _qualifier) { 241 + public static <$classNameWithoutPackage$> fetchRequired<$classNameWithoutPackage$>(EOEditingContext _editingContext, EOQualifier _qualifier) { 240 240 <$classNameWithoutPackage$> eoObject = <$GEN_PREFIX$><$classNameWithoutPackage$>.fetch<$classNameWithoutPackage$>(_editingContext, _qualifier); 241 241 if (eoObject == null) { 242 242 throw new NoSuchElementException("There was no <$classNameWithoutPackage$> that matched the qualifier '" + _qualifier + "'."); ... ... @@ -250,7 +250,7 @@ 250 250 251 251 {{code}} 252 252 253 -public <$classNameWithoutPackage$> localInstanceOf<$classNameWithoutPackage$>(EOEditingContext _editingContext) { 255 + public <$classNameWithoutPackage$> localInstanceOf<$classNameWithoutPackage$>(EOEditingContext _editingContext) { 254 254 return (<$classNameWithoutPackage$>)EOUtilities.localInstanceOfObject(_editingContext, this); 255 255 } 256 256 ... ... @@ -258,7 +258,7 @@ 258 258 259 259 {{code}} 260 260 261 -public static <$classNameWithoutPackage$> localInstanceOf<$classNameWithoutPackage$>(EOEditingContext _editingContext, <$classNameWithoutPackage$> _eo) { 263 + public static <$classNameWithoutPackage$> localInstanceOf<$classNameWithoutPackage$>(EOEditingContext _editingContext, <$classNameWithoutPackage$> _eo) { 262 262 return (_eo == null) ? null : (<$classNameWithoutPackage$>)EOUtilities.localInstanceOfObject(_editingContext, _eo); 263 263 } 264 264 ... ... @@ -268,7 +268,7 @@ 268 268 269 269 {{code}} 270 270 271 -<$if !ToManyRelationship.inverseRelationship$> 273 + <$if !ToManyRelationship.inverseRelationship$> 272 272 public NSArray <$ToManyRelationship.name$>(EOQualifier qualifier) { 273 273 return <$ToManyRelationship.name$>(qualifier, null); 274 274 } ... ... @@ -277,12 +277,12 @@ 277 277 public NSArray <$ToManyRelationship.name$>(EOQualifier qualifier) { 278 278 return <$ToManyRelationship.name$>(qualifier, null, false); 279 279 } 280 - 281 - public NSArray <$ToManyRelationship.name$>(EOQualifier qualifier, boolean fetch) { 282 + 283 + public NSArray <$ToManyRelationship.name$>(EOQualifier qualifier, boolean fetch) { 282 282 return <$ToManyRelationship.name$>(qualifier, null, fetch); 283 283 } 284 284 <$endif$> 285 - 287 + 286 286 public NSArray <$ToManyRelationship.name$>(EOQualifier qualifier, NSArray sortOrderings<$if ToManyRelationship.inverseRelationship$>, boolean fetch<$endif$>) { 287 287 NSArray results; 288 288 <$if ToManyRelationship.inverseRelationship$> ... ... @@ -318,25 +318,25 @@ 318 318 319 319 {{/code}} 320 320 321 -=== John Huss === 323 +=== 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). 325 +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 327 -@SuppressWarnings("all") 329 + @SuppressWarnings("all") 328 328 public class _Invoice extends ERXGenericRecord { 329 329 } 330 330 331 331 {{/code}} 332 332 333 -=== Guido Neitzer === 335 +=== Guido Neitzer === 334 334 335 335 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: 336 336 337 337 {{code}} 338 338 339 -/** 341 +/** 340 340 * Initialization of the instance while inserting it into an editing context 341 341 */ 342 342 public void awakeFromInsertion (EOEditingContext editingContext) { ... ... @@ -347,3 +347,5 @@ 347 347 {{/code}} 348 348 349 349 This is from my JavaSubclassSourceTemplate.eotemplate 352 + 353 +Category:WebObjects