Uploaded image for project: 'OpenJPA'
  1. OpenJPA
  2. OPENJPA-604

Log spec sets in persistence unit's property fail with exception when run in different locale

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.0.3, 1.1.0, 1.2.0
    • 1.2.0
    • lib
    • None

    Description

      When an application sets the Log property in a persistence unit (persistence.xml) or passes in through map during createEntityManager[Factory] using one locale, this setting will fail when runs in a different locale.

      It is caused by the LogImpl:

      1) retrieve the *_STR from the localizer.properties

      public static final String TRACE_STR = _loc.get("log-trace").getMessage();
      public static final String INFO_STR = _loc.get("log-info").getMessage();
      public static final String WARN_STR = _loc.get("log-warn").getMessage();
      public static final String ERROR_STR = _loc.get("log-error").getMessage();
      public static final String FATAL_STR = _loc.get("log-fatal").getMessage();

      2) compare only the current locale *_STR values;

      public static short getLevel(String str)

      { str = str.toUpperCase().trim(); short val = TRACE_STR.equals(str) ? Log.TRACE : INFO_STR.equals(str) ? Log.INFO : WARN_STR.equals(str) ? Log.WARN : ERROR_STR.equals(str) ? Log.ERROR : FATAL_STR.equals(str) ? Log.FATAL : -1; if (val == -1) throw new IllegalArgumentException (_loc.get("log-bad-constant", str).getMessage()); return val; }

      I understand the intention is to match the Log setting using the same locale, however if the Log string is set in an application's persistence unit (persistence.xml) or business logic (createEntityManagerFactory( ...., map)), the application will fail.

      I see two alternatives:
      1) Since Log is part of the property and configuration framework, none of these property settings are local sensitive. We can make Log property NOT locale sensitive, i.e. always use TRACE, INFO, WARN, ERROR and FATAL as the Log values.

      2) Access both English (as in alternative 1) and also whatever current locale Log values. I.e. English only Log values will work when set in persistence.xml and business logic regardless of the current locale setting but locale specific settings ONLY work in the same current locale.

      Personally, the second option is more attractive and also backward compatible with existing application that uses locale specific behavior.

      Please comment on your preference!
      Albert Lee.

      Attachments

        1. OPENJPA-604.opt1.patch
          2 kB
          Albert Lee
        2. OPENJPA-604.opt2.patch
          3 kB
          Albert Lee

        Activity

          mikedd Michael Dick added a comment -

          I'm not sure there's a compelling use case for translated log levels. I'd lean towards option 1 for code clarity and documentation purposes.

          mikedd Michael Dick added a comment - I'm not sure there's a compelling use case for translated log levels. I'd lean towards option 1 for code clarity and documentation purposes.

          Without having a use-case in front of me, I don't understand the value of having localized Log properties. I'd prefer #1.

          clr Craig L Russell added a comment - Without having a use-case in front of me, I don't understand the value of having localized Log properties. I'd prefer #1.
          allee8285 Albert Lee added a comment -

          I have the same feeling at the first glance and it was also my first choice.

          After some thought, I was worried about if there is any existing application that actually uses locale specific Log spec in their p.xml or Map passed to createEntityManager[Factory], option 1 will break their application. Option 2 is a compromise to avoid any back compatibility breakage but still support option 1, which is the preferred behavior.

          If there are any strong opinions that backward compatibility is NOT a concern, I can go for option 1.

          Albert Lee.

          allee8285 Albert Lee added a comment - I have the same feeling at the first glance and it was also my first choice. After some thought, I was worried about if there is any existing application that actually uses locale specific Log spec in their p.xml or Map passed to createEntityManager [Factory] , option 1 will break their application. Option 2 is a compromise to avoid any back compatibility breakage but still support option 1, which is the preferred behavior. If there are any strong opinions that backward compatibility is NOT a concern, I can go for option 1. Albert Lee.
          allee8285 Albert Lee added a comment -

          I shall commit option 2 patch tomorrow morning , if I don't hear any objection to this solution.

          Thanks,
          Albert Lee.

          allee8285 Albert Lee added a comment - I shall commit option 2 patch tomorrow morning , if I don't hear any objection to this solution. Thanks, Albert Lee.
          allee8285 Albert Lee added a comment -

          The consensus is to take option 1 for its simplicity and intuitive usage.

          Thanks for all the input.
          Albert Lee.

          allee8285 Albert Lee added a comment - The consensus is to take option 1 for its simplicity and intuitive usage. Thanks for all the input. Albert Lee.

          People

            allee8285 Albert Lee
            allee8285 Albert Lee
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: