From: <leg...@at...> - 2003-11-23 21:19:24
|
The following comment has been added to this issue: Author: Bertrand Renuart Created: Sun, 23 Nov 2003 3:18 PM Body: Thanks for having considered this case. A few remarks though after you applied the patch: - if you want CharBooleanType to throw an exception when it got something not TRUE nor FALSE, then the get() method on the ancestor should throw HibernateException as well (as nearly all other types do). - below is what I propose for CharBooleanType.get(): public Object get(ResultSet rs, String name) throws HibernateException, SQLException { String code = rs.getString(name); if (code==null) return null; if ( code.equalsIgnoreCase(getTrueString())) return Boolean.TRUE; if( code.equalsIgnoreCase(getFalseString())) return Boolean.FALSE; throw new HibernateException("Unable to convert '" + code + "' data to a Boolean"); } - on the other hand, I think you made a mistake in your refactoring effort. For CharBooleanType.set(), you wrote: st.setString( index, toString(value) ); where I believe it should be: st.setString( index, toCharacter(value) ); --------------------------------------------------------------------- View the issue: http://opensource.atlassian.com/projects/hibernate/secure/ViewIssue.jspa?key=HB-487 Here is an overview of the issue: --------------------------------------------------------------------- Key: HB-487 Summary: Unecessary object creation in CharBooleanType Type: Patch Status: Open Priority: Trivial Project: Hibernate2 Components: core Versions: 2.1 beta 6 Assignee: Max Rydahl Andersen Reporter: Bertrand Renuart Created: Fri, 21 Nov 2003 1:51 PM Updated: Sun, 23 Nov 2003 3:18 PM Description: Unecessary objects are created when converting the data retrieved from the resultset to a Boolean. Original code: -------------- return new Boolean( code.toUpperCase().equals( getTrueString() ) ); Explanation: ------------ - code.toUpperCase() creates a new String - code.equalsIgnoreCase() should be used instead - new Boolean() creates a new Boolean instance where Boolean.TRUE | FALSE could be used This would lead to the following code: if ( code.equalsIgnoreCase(getTrueString())) { return Boolean.TRUE; } else { return Boolean.FALSE; } A bit more efficient ;-) Note: what should we do if code != getFalseString()? Should we throw an SQLException ? --------------------------------------------------------------------- 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 |