Skip to content

Commit 116033f

Browse files
authored
LoggingLocalization performance improvement (#2174)
Signed-off-by: Radek Felcman <[email protected]>
1 parent e1d8076 commit 116033f

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/junit/localization/LocalizationTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2020 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2024 Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2020 IBM Corporation. All rights reserved.
44
*
55
* This program and the accompanying materials are made available under the
@@ -17,6 +17,7 @@
1717

1818
import org.junit.Assert;
1919
import org.junit.Test;
20+
import org.eclipse.persistence.internal.localization.EclipseLinkLocalization;
2021
import org.eclipse.persistence.internal.localization.LoggingLocalization;
2122

2223
public class LocalizationTest {
@@ -27,5 +28,7 @@ public void test() {
2728
"EclipseLink, version: EXAMPLE", LoggingLocalization.buildMessage("topLink_version", new Object[] { "EXAMPLE" }));
2829
Assert.assertEquals("LoggingLocalization.buildMessage could not find the correct translation.",
2930
"message_not_exist (There is no English translation for this message.)", LoggingLocalization.buildMessage("message_not_exist"));
31+
Assert.assertEquals("EclipseLinkLocalization.buildMessage could not find the correct translation.",
32+
"somekey1 (There is no English translation for this message.)", EclipseLinkLocalization.buildMessage("AAAAUnknownClass", "somekey1", null, true));
3033
}
3134
}

foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/localization/EclipseLinkLocalization.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2018 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2024 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0 which is available at
@@ -29,6 +29,9 @@
2929
*/
3030
public abstract class EclipseLinkLocalization {
3131

32+
// Get the current language's NoTranslationForThisLocale message.
33+
private static final String NO_TRANSLATION_MESSAGE = ResourceBundle.getBundle("org.eclipse.persistence.internal.localization.i18n.EclipseLinkLocalizationResource", Locale.getDefault()).getString("NoTranslationForThisLocale");
34+
3235
/**
3336
* Return the message for the given exception class and error number.
3437
*/
@@ -65,13 +68,18 @@ public static String buildMessage(String localizationClassName, String key, Obje
6568
} catch (java.util.MissingResourceException mre) {
6669
if (translate) {
6770
// Found bundle, but couldn't find translation.
68-
// Get the current language's NoTranslationForThisLocale message.
69-
bundle = ResourceBundle.getBundle("org.eclipse.persistence.internal.localization.i18n.EclipseLinkLocalizationResource", Locale.getDefault());
70-
String noTranslationMessage = bundle.getString("NoTranslationForThisLocale");
71-
return MessageFormat.format(message, arguments) + noTranslationMessage;
72-
}
71+
// Use the current language's NoTranslationForThisLocale message.
72+
if (arguments == null) {
73+
return message + NO_TRANSLATION_MESSAGE;
74+
} else {
75+
return MessageFormat.format(message, arguments) + NO_TRANSLATION_MESSAGE;
76+
} }
77+
}
78+
if (arguments == null) {
79+
return message;
80+
} else {
81+
return MessageFormat.format(message, arguments);
7382
}
74-
return MessageFormat.format(message, arguments);
7583
}
7684

7785
}

0 commit comments

Comments
 (0)