Uploaded image for project: 'Spring Roo'
  1. Spring Roo
  2. ROO-3501

DBRE: Creates invalid java identifiers with column names containing "#" character

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 1.2.5.RELEASE
    • Fix Version/s: None
    • Component/s: @ ROO SHELL, PERSISTENCE
    • Labels:
    • Environment:
      Windows with STS 3.5, Roo 1.2.5, DB2 AS 400

      Description

      We have a table with the name "Cust_Acct_#". When we try DBRE add-on to reverse engineer this schema, the generated code has methods getCustAcct#() which is not a valid java function name.

      I looked into the code and based on my limited knowledge of roo source, I am guessing this function in org.springframework.roo.addon.dbre.DbreTypeUtils.java needs to consider all the characters that are not part of valid java identifiers as Delim characters.

      DbreTypeUtils.java
        private static String getName(final String str, final boolean isField) {
              final StringBuilder result = new StringBuilder();
              boolean isDelimChar = false;
              for (int i = 0; i < str.length(); i++) {
                  final char c = str.charAt(i);
                  if (i == 0) {
                      if (c == '0' || c == '1' || c == '2' || c == '3' || c == '4'
                              || c == '5' || c == '6' || c == '7' || c == '8'
                              || c == '9') {
                          result.append(isField ? "f" : "T");
                          result.append(c);
                      }
                      else {
                          result.append(isField ? Character.toLowerCase(c)
                                  : Character.toUpperCase(c));
                      }
                      continue;
                  }
                  else if (i > 0 && (c == '_' || c == '-' || c == '\\' || c == '/')
                          || c == '.' || c == ' ') {
                      isDelimChar = true;
                      continue;
                  }
      
                  if (isDelimChar) {
                      result.append(Character.toUpperCase(c));
                      isDelimChar = false;
                  }
                  else {
                      if (i > 1 && Character.isLowerCase(str.charAt(i - 1))
                              && Character.isUpperCase(c)) {
                          result.append(c);
                      }
                      else {
                          result.append(Character.toLowerCase(c));
                      }
                  }
              }
              if (ReservedWords.RESERVED_JAVA_KEYWORDS.contains(result.toString())) {
                  result.append("1");
              }
              return result.toString();
          }
      
      
      
      
      

        Attachments

          Activity

            People

            • Assignee:
              jmvivo Jose Manuel Vivó ( Chema ) - DISID.
              Reporter:
              amuser Sumanth Gangasani
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: