From: Jarkko L. (JIRA) <no...@at...> - 2006-05-19 10:43:21
|
Patch to allow reverse engineering to work with tables and associations ending with "s" ---------------------------------------------------------------------------------------- Key: HBX-664 URL: http://opensource.atlassian.com/projects/hibernate/browse/HBX-664 Project: Hibernate Tools Type: Patch Components: reverse-engineer Versions: 3.1.beta5 Reporter: Jarkko Lietolahti Index: java/org/hibernate/tool/hbm2x/pojo/BasicPOJOClass.java =================================================================== --- java/org/hibernate/tool/hbm2x/pojo/BasicPOJOClass.java (revision 9925) +++ java/org/hibernate/tool/hbm2x/pojo/BasicPOJOClass.java (working copy) @@ -86,6 +86,10 @@ return StringHelper.unqualify(getMappedClassName()); } + public String getShortNamePlural() { + return ReverseEngineeringStrategyUtil.simplePluralize(getShortName()); + } + public String getQualifiedDeclarationName() { String generatedName = getMetaAsString( MetaAttributeConstants.GENERATED_CLASS ); if ( generatedName == null || generatedName.trim().length() == 0 ) { Index: java/org/hibernate/tool/hbm2x/pojo/POJOClass.java =================================================================== --- java/org/hibernate/tool/hbm2x/pojo/POJOClass.java (revision 9925) +++ java/org/hibernate/tool/hbm2x/pojo/POJOClass.java (working copy) @@ -74,7 +74,8 @@ public String getPackageName(); public String getShortName(); - + public String getShortNamePlural(); + public Iterator getToStringPropertiesIterator(); public Iterator getEqualsHashCodePropertiesIterator(); Index: templates/seam/editorbean.java.ftl =================================================================== --- templates/seam/editorbean.java.ftl (revision 9925) +++ templates/seam/editorbean.java.ftl (working copy) @@ -1,5 +1,5 @@ ${pojo.getPackageDeclaration()} -// Generated ${date} by Hibernate Tools ${version} +// Generated ${date} by Hibernate Tools ${version}-jab <#assign classbody> <#assign entityEditor = pojo.shortName.toLowerCase() + "Editor"><#assign entityFinder = pojo.shortName.toLowerCase() + "Finder"><#assign entityList = pojo.shortName.toLowerCase() + "List"><#assign entity = pojo.shortName.toLowerCase()><#assign entityClass = pojo.importType(pojo.qualifiedDeclarationName)> @@ -38,7 +38,7 @@ @${pojo.importType("org.jboss.seam.annotations.In")}(required=false) private transient ${pojo.shortName}Finder ${entityFinder}; - @${pojo.importType("org.jboss.seam.annotations.In")} + @${pojo.importType("org.jboss.seam.annotations.In")}(create=true) private transient ${pojo.importType("java.util.ResourceBundle")} resourceBundle; @${pojo.importType("org.jboss.seam.annotations.Begin")}(join=true) @@ -57,7 +57,7 @@ </#if> entityManager.persist(instance); isNew = false; <#foreach property in pojo.getAllPropertiesIterator()><#if c2h.isManyToOne(property)><#assign getter = "get" + pojo.getPropertyName(property)> if (instance.${getter}()!=null) { - instance.${getter}().get${pojo.shortName}s().add(instance); + instance.${getter}().get${pojo.shortNamePlural}().add(instance); } </#if></#foreach> refreshFinder(); return "edit${pojo.shortName}"; @@ -72,7 +72,8 @@ @${pojo.importType("org.jboss.seam.annotations.End")}(ifOutcome="find") public String delete() { entityManager.remove(instance); -<#foreach property in pojo.getAllPropertiesIterator()><#if c2h.isManyToOne(property)><#assign getter = "get" + pojo.getPropertyName(property)> instance.${getter}().get${pojo.shortName}s().remove(instance); +<#foreach property in pojo.getAllPropertiesIterator()><#if c2h.isManyToOne(property)><#assign getter = "get" + pojo.getPropertyName(property)> + instance.${getter}().get${pojo.shortNamePlural}().remove(instance); </#if></#foreach> refreshFinder(); return doneOutcome; } -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira |
From: Max R. A. (JIRA) <no...@at...> - 2006-05-19 11:44:17
|
[ http://opensource.atlassian.com/projects/hibernate/browse/HBX-664?page=comments#action_23132 ] Max Rydahl Andersen commented on HBX-664: ----------------------------------------- thanks - but what does this patch actually fix ? the reverse engineering works fine with everything so I assume it is something seam template specific....maybe you have a testcase? > Patch to allow reverse engineering to work with tables and associations ending with "s" > ---------------------------------------------------------------------------------------- > > Key: HBX-664 > URL: http://opensource.atlassian.com/projects/hibernate/browse/HBX-664 > Project: Hibernate Tools > Type: Patch > Components: reverse-engineer > Versions: 3.1.beta5 > Reporter: Jarkko Lietolahti > > > Index: java/org/hibernate/tool/hbm2x/pojo/BasicPOJOClass.java > =================================================================== > --- java/org/hibernate/tool/hbm2x/pojo/BasicPOJOClass.java (revision 9925) > +++ java/org/hibernate/tool/hbm2x/pojo/BasicPOJOClass.java (working copy) > @@ -86,6 +86,10 @@ > return StringHelper.unqualify(getMappedClassName()); > } > > + public String getShortNamePlural() { > + return ReverseEngineeringStrategyUtil.simplePluralize(getShortName()); > + } > + > public String getQualifiedDeclarationName() { > String generatedName = getMetaAsString( MetaAttributeConstants.GENERATED_CLASS ); > if ( generatedName == null || generatedName.trim().length() == 0 ) { > Index: java/org/hibernate/tool/hbm2x/pojo/POJOClass.java > =================================================================== > --- java/org/hibernate/tool/hbm2x/pojo/POJOClass.java (revision 9925) > +++ java/org/hibernate/tool/hbm2x/pojo/POJOClass.java (working copy) > @@ -74,7 +74,8 @@ > > public String getPackageName(); > public String getShortName(); > - > + public String getShortNamePlural(); > + > public Iterator getToStringPropertiesIterator(); > public Iterator getEqualsHashCodePropertiesIterator(); > > Index: templates/seam/editorbean.java.ftl > =================================================================== > --- templates/seam/editorbean.java.ftl (revision 9925) > +++ templates/seam/editorbean.java.ftl (working copy) > @@ -1,5 +1,5 @@ > ${pojo.getPackageDeclaration()} > -// Generated ${date} by Hibernate Tools ${version} > +// Generated ${date} by Hibernate Tools ${version}-jab > > <#assign classbody> > <#assign entityEditor = pojo.shortName.toLowerCase() + "Editor"><#assign entityFinder = pojo.shortName.toLowerCase() + "Finder"><#assign entityList = pojo.shortName.toLowerCase() + "List"><#assign entity = pojo.shortName.toLowerCase()><#assign entityClass = pojo.importType(pojo.qualifiedDeclarationName)> > @@ -38,7 +38,7 @@ > @${pojo.importType("org.jboss.seam.annotations.In")}(required=false) > private transient ${pojo.shortName}Finder ${entityFinder}; > > - @${pojo.importType("org.jboss.seam.annotations.In")} > + @${pojo.importType("org.jboss.seam.annotations.In")}(create=true) > private transient ${pojo.importType("java.util.ResourceBundle")} resourceBundle; > > @${pojo.importType("org.jboss.seam.annotations.Begin")}(join=true) > @@ -57,7 +57,7 @@ > </#if> entityManager.persist(instance); > isNew = false; > <#foreach property in pojo.getAllPropertiesIterator()><#if c2h.isManyToOne(property)><#assign getter = "get" + pojo.getPropertyName(property)> if (instance.${getter}()!=null) { > - instance.${getter}().get${pojo.shortName}s().add(instance); > + instance.${getter}().get${pojo.shortNamePlural}().add(instance); > } > </#if></#foreach> refreshFinder(); > return "edit${pojo.shortName}"; > @@ -72,7 +72,8 @@ > @${pojo.importType("org.jboss.seam.annotations.End")}(ifOutcome="find") > public String delete() { > entityManager.remove(instance); > -<#foreach property in pojo.getAllPropertiesIterator()><#if c2h.isManyToOne(property)><#assign getter = "get" + pojo.getPropertyName(property)> instance.${getter}().get${pojo.shortName}s().remove(instance); > +<#foreach property in pojo.getAllPropertiesIterator()><#if c2h.isManyToOne(property)><#assign getter = "get" + pojo.getPropertyName(property)> > + instance.${getter}().get${pojo.shortNamePlural}().remove(instance); > </#if></#foreach> refreshFinder(); > return doneOutcome; > } -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira |
From: Jarkko L. (JIRA) <no...@at...> - 2006-05-19 11:57:11
|
[ http://opensource.atlassian.com/projects/hibernate/browse/HBX-664?page=comments#action_23133 ] Jarkko Lietolahti commented on HBX-664: --------------------------------------- i was thinking it might no be that clear ;) Yes, this is seam specifc (as the real change is in the seam template). The case is that when DefaultReverseEngineeringStrategy (foreignKeyToCollectionName() ) creates collections is uses ReverseEngineeringStrategyUtil.simplePluralize to name the getter-method in the entity. Now in the seam template the old way was simply to add "s" when calling the entitys getter. Compared to simplePluralize which uses weird english-only heuristic to determine the name. instance.${getter}().get${pojo.shortName}s().remove(instance); ReverseEngineeringStrategyUtil.java ... static public String simplePluralize(String singular) { char last = singular.charAt( singular.length()-1 ); switch (last) { case 'x': case 's': singular += "es"; break; case 'y': singular = singular.substring( 0, singular.length()-1 ) + "ies"; break; default: singular += "s"; } return singular; } btw, just noticed that the patch contains few things which are not related to this issue (but to an other one which is that the messages.properties is not initialized properly): - @${pojo.importType("org.jboss.seam.annotations.In")} + @${pojo.importType("org.jboss.seam.annotations.In")}(create=true) Those lines can be removed from the patch. > Patch to allow reverse engineering to work with tables and associations ending with "s" > ---------------------------------------------------------------------------------------- > > Key: HBX-664 > URL: http://opensource.atlassian.com/projects/hibernate/browse/HBX-664 > Project: Hibernate Tools > Type: Patch > Components: reverse-engineer > Versions: 3.1.beta5 > Reporter: Jarkko Lietolahti > > > Index: java/org/hibernate/tool/hbm2x/pojo/BasicPOJOClass.java > =================================================================== > --- java/org/hibernate/tool/hbm2x/pojo/BasicPOJOClass.java (revision 9925) > +++ java/org/hibernate/tool/hbm2x/pojo/BasicPOJOClass.java (working copy) > @@ -86,6 +86,10 @@ > return StringHelper.unqualify(getMappedClassName()); > } > > + public String getShortNamePlural() { > + return ReverseEngineeringStrategyUtil.simplePluralize(getShortName()); > + } > + > public String getQualifiedDeclarationName() { > String generatedName = getMetaAsString( MetaAttributeConstants.GENERATED_CLASS ); > if ( generatedName == null || generatedName.trim().length() == 0 ) { > Index: java/org/hibernate/tool/hbm2x/pojo/POJOClass.java > =================================================================== > --- java/org/hibernate/tool/hbm2x/pojo/POJOClass.java (revision 9925) > +++ java/org/hibernate/tool/hbm2x/pojo/POJOClass.java (working copy) > @@ -74,7 +74,8 @@ > > public String getPackageName(); > public String getShortName(); > - > + public String getShortNamePlural(); > + > public Iterator getToStringPropertiesIterator(); > public Iterator getEqualsHashCodePropertiesIterator(); > > Index: templates/seam/editorbean.java.ftl > =================================================================== > --- templates/seam/editorbean.java.ftl (revision 9925) > +++ templates/seam/editorbean.java.ftl (working copy) > @@ -1,5 +1,5 @@ > ${pojo.getPackageDeclaration()} > -// Generated ${date} by Hibernate Tools ${version} > +// Generated ${date} by Hibernate Tools ${version}-jab > > <#assign classbody> > <#assign entityEditor = pojo.shortName.toLowerCase() + "Editor"><#assign entityFinder = pojo.shortName.toLowerCase() + "Finder"><#assign entityList = pojo.shortName.toLowerCase() + "List"><#assign entity = pojo.shortName.toLowerCase()><#assign entityClass = pojo.importType(pojo.qualifiedDeclarationName)> > @@ -38,7 +38,7 @@ > @${pojo.importType("org.jboss.seam.annotations.In")}(required=false) > private transient ${pojo.shortName}Finder ${entityFinder}; > > - @${pojo.importType("org.jboss.seam.annotations.In")} > + @${pojo.importType("org.jboss.seam.annotations.In")}(create=true) > private transient ${pojo.importType("java.util.ResourceBundle")} resourceBundle; > > @${pojo.importType("org.jboss.seam.annotations.Begin")}(join=true) > @@ -57,7 +57,7 @@ > </#if> entityManager.persist(instance); > isNew = false; > <#foreach property in pojo.getAllPropertiesIterator()><#if c2h.isManyToOne(property)><#assign getter = "get" + pojo.getPropertyName(property)> if (instance.${getter}()!=null) { > - instance.${getter}().get${pojo.shortName}s().add(instance); > + instance.${getter}().get${pojo.shortNamePlural}().add(instance); > } > </#if></#foreach> refreshFinder(); > return "edit${pojo.shortName}"; > @@ -72,7 +72,8 @@ > @${pojo.importType("org.jboss.seam.annotations.End")}(ifOutcome="find") > public String delete() { > entityManager.remove(instance); > -<#foreach property in pojo.getAllPropertiesIterator()><#if c2h.isManyToOne(property)><#assign getter = "get" + pojo.getPropertyName(property)> instance.${getter}().get${pojo.shortName}s().remove(instance); > +<#foreach property in pojo.getAllPropertiesIterator()><#if c2h.isManyToOne(property)><#assign getter = "get" + pojo.getPropertyName(property)> > + instance.${getter}().get${pojo.shortNamePlural}().remove(instance); > </#if></#foreach> refreshFinder(); > return doneOutcome; > } -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira |