Date: 2004-04-21T05:03:41
   Editor: 213.222.53.210 <>
   Wiki: DB Torque Wiki
   Page: FrequentlyAskedQuestions
   URL: http://wiki.apache.org/db-torque/FrequentlyAskedQuestions

   no comment

Change Log:

------------------------------------------------------------------------------
@@ -179,9 +179,44 @@
 
 == We have an existing database where some of the table names have spaces as part of 
the name. Is there a way in which Torque could replace spaces by, say, underscores? 
What about table columns with spaces in the names? ==
 
-'''Answer:''' ????
-
 -- Daniel Canas
+
+'''Answer:''' Quick way -> No. And we hope that in the next release there will be a 
way for plugging external Name Genrator. But for now you can still change the genrator 
to fit your needs. For example I have extended JavaNAmeGeneretor in this way:
+
+1) added a single line to interface 
org.apache.torque.engine.database.model.NameGenerator;
+
+       String CONV_METHOD_UNDERSCORE_IGNORE_DOTS = "underscore_ignore_dots";
+
+2) added a single conversion method to class 
org.apache.torque.engine.database.model.JavaNameGenerator;
+
+       protected String underscoreIgnoreDotsMethod(String schemaName) {
+               schemaName = schemaName.replaceAll("\\.", "_");
+
+               StringBuffer name = new StringBuffer();
+               StringTokenizer tok =
+                       new StringTokenizer(schemaName, 
String.valueOf(STD_SEPARATOR_CHAR));
+               while (tok.hasMoreTokens()) {
+                       String namePart = ((String) tok.nextElement()).toLowerCase();
+                       name.append(StringUtils.capitalize(namePart));
+               }
+               return name.toString();
+       }
+3) added a single condition to class 
org.apache.torque.engine.database.model.JavaNameGenerator;        method:  String 
generateName(List inputs);
+
+               } else if (CONV_METHOD_UNDERSCORE_IGNORE_DOTS.equals(method)) {
+                       javaName = underscoreIgnoreDotsMethod(schemaName);
+
+4) rebuilt the torque-generator maven plugin (src/generator$ maven jar:install) 
+
+5) now I can use the attribute value in the database tags of my schemas
+
+<database defaultJavaNamingMethod="underscore_ignore_dots" .....
+
+My code ignores gots inside the name you can ignore spaces for your case ..or make 
whatever conversions you need.
+(this is the way in short to add new naming method)
+
+-- Bogdan Vatkov
+
 
 == The save methods internally use Transaction.start(), what if I want save of 
multiple entities to be wrapped in single transaction? ==
 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to