[Hibernate-issues] [Hibernate-JIRA] Updated: (HB-522) Correct collection type for sorted collections
From: <leg...@at...> - 2003-12-04 17:49:41
|
The following issue has been updated: Updater: Linus Kamb (mailto:li...@ir...) Date: Thu, 4 Dec 2003 11:49 AM Changes: Attachment changed to ClassMapping_v2.0.2.patch --------------------------------------------------------------------- For a full history of the issue, see: http://opensource.atlassian.com/projects/hibernate/secure/ViewIssue.jspa?key=HB-522&page=history --------------------------------------------------------------------- View the issue: http://opensource.atlassian.com/projects/hibernate/secure/ViewIssue.jspa?key=HB-522 Here is an overview of the issue: --------------------------------------------------------------------- Key: HB-522 Summary: Correct collection type for sorted collections Type: Patch Status: Unassigned Priority: Minor Project: Hibernate2 Components: toolset Versions: 2.0.2 Assignee: Reporter: Linus Kamb Created: Thu, 4 Dec 2003 11:46 AM Updated: Thu, 4 Dec 2003 11:49 AM Environment: Hibernate extensions 2.0.2 Description: When generating Java code from an hbm.xml file, all [sets|bags|maps] listed in the mapping file after a sorted [set|bag|map] will be generated as sorted. So, given the following mapping (in pseudo-hbm): Example (in pseudo-hbm :-) <mapping> <class name="SomeClass"> <set name="plainSet"> <one-to-many class="SomeOtherClass" /> </set> <set name="sortedSet" sort="MySorter" > <one-to-many class="YAClass" /> </set> </class> </mapping> This correctly generates public class SomeClass { private Set plainSet; // plus Set-based getters and setters private SortedSet sortedSet; // plus SortedSet-based getters and setters. } now, if I change the mapping: <mapping> <class name="SomeClass"> <set name="sortedSet" sort="MySorter" > <one-to-many class="YAClass" /> </set> <set name="plainSet"> <one-to-many class="SomeOtherClass" /> </set> </class> </mapping> This incorrectly generates public class SomeClass { private SortedSet sortedSet; // plus SortedSet-based getters and setters. private SortedSet plainSet; // plus SortedSet-based getters and setters. } [Since this is the first time I've entered anything in JIRA, and I don't see where to add that patch attachment, I am going to include it here.] --- hibernate-extensions-2.0.2/tools/src/net/sf/hibernate/tool/hbm2java/ClassMapping.java Tue Oct 21 15:14:16 2003 +++ /users/linus/projects/scratch/net/sf/hibernate/tools/hbm2java/ClassMapping.java Thu Dec 4 09:31:11 2003 @@ -488,6 +488,9 @@ private void doCollections(Element classElement, String xmlName, String interfaceClass, String implementingClass, MultiMap inheritedMeta) { + String originalInterface = interfaceClass; + String originalImplementingClass = implementingClass; + for (Iterator collections = classElement.getChildren(xmlName).iterator(); collections.hasNext();) { Element collection = (Element) collections.next(); @@ -495,15 +498,21 @@ String name = collection.getAttributeValue("name"); // Small hack to switch over to sortedSet/sortedMap if sort is specified. (that is sort != unsorted) - if (!"unsorted".equals(collection.getAttributeValue("sort"))) { - if("map".equals(xmlName)) { - interfaceClass = SortedMap.class.getName(); - implementingClass = TreeMap.class.getName(); - } else if("set".equals(xmlName)) { - interfaceClass = SortedSet.class.getName(); - implementingClass = TreeSet.class.getName(); - } - } + String sort = collection.getAttributeValue("sort"); + if ("unsorted".equals(sort) || + "".equals(sort)) { + interfaceClass = originalInterface; + implementingClass = originalImplementingClass; + } + else { + if("map".equals(xmlName)) { + interfaceClass = SortedMap.class.getName(); + implementingClass = TreeMap.class.getName(); + } else if("set".equals(xmlName)) { + interfaceClass = SortedSet.class.getName(); + implementingClass = TreeSet.class.getName(); + } + } ClassName interfaceClassName = new ClassName(); ClassName implementingClassName = new ClassName(); @@ -513,10 +522,11 @@ // add an import and field for this collection addImport(interfaceClassName); --------------------------------------------------------------------- JIRA INFORMATION: 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 If you want more information on JIRA, or have a bug to report see: http://www.atlassian.com/software/jira |