-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: ImprovedNamingStrategy bug or by design...underscores
PostPosted: Mon Apr 11, 2005 1:06 am 
Newbie

Joined: Thu Nov 18, 2004 6:51 pm
Posts: 10
Location: Arizona
Using ImprovedNamingStrategy but getting odd output. I am not sure if it is a bug or if it is by-design. When placing an explicit column name and using ImprovedNamingStrategy. I am inclined to think it is a bug but I see that it is released in Hibernate 3.

Q: Is this a bug or am I doing something wrong?

Code:
input   output   expected-output
TEAM_ID  tea_m_id     team_id
GS_USER  g_s_user     gs_user


// from ImprovedNamingStrategy
Code:
   private static String hibV21addUnderscores(String name) {
      StringBuffer buf = new StringBuffer(name.replace('.', '_'));
      for (int i = 1; i < buf.length() - 1; i++) {
         if ('_' != buf.charAt(i - 1)
               && Character.isUpperCase(buf.charAt(i))
               && !Character.isUpperCase(buf.charAt(i + 1))) {
            buf.insert(i++, '_');
         }
      }
      return buf.toString().toLowerCase();
   }



// However, if a line is added the intended result (team_id, gs_user) is realized.
Code:
   private static String modifiedAddUnderscores(String name) {
      StringBuffer buf = new StringBuffer(name.replace('.', '_'));
      for (int i = 1; i < buf.length() - 1; i++) {
         if (
         '_' != buf.charAt(i - 1) &&
         
'_' != buf.charAt(i + 1) &&
Code:
// this condition was added
               Character.isUpperCase(buf.charAt(i)) &&
               !Character.isUpperCase(buf.charAt(i + 1))
         ) {
            buf.insert(i++, '_');
         }
      }
      return buf.toString().toLowerCase();
   }



Thanks in advance,

John


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.