From 49663810319ed3b015726162d80096516c90b020 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kraus?= Date: Wed, 17 Jul 2024 17:10:09 +0200 Subject: [PATCH] Review notes and some discussed changes applied. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tomáš Kraus --- .../org.eclipse.persistence.core/pom.xml | 2 ++ .../src/main/java/module-info.java | 4 +-- .../i18n/ExceptionLocalizationResource.java | 3 ++- .../internal/sessions/AbstractSession.java | 8 ++++-- .../eclipse/persistence/sessions/Project.java | 26 +++++-------------- 5 files changed, 17 insertions(+), 26 deletions(-) diff --git a/foundation/org.eclipse.persistence.core/pom.xml b/foundation/org.eclipse.persistence.core/pom.xml index 07b4e97df01..b5ef168ef02 100644 --- a/foundation/org.eclipse.persistence.core/pom.xml +++ b/foundation/org.eclipse.persistence.core/pom.xml @@ -214,6 +214,8 @@ org.eclipse.persistence.core/org.eclipse.persistence.internal.oxm.conversion=org.eclipse.persistence.core.test --add-exports org.eclipse.persistence.core/org.eclipse.persistence.internal.oxm.schema.model=org.eclipse.persistence.core.test + --add-exports + org.eclipse.persistence.core/org.eclipse.persistence.internal.jpa.jpql=org.eclipse.persistence.core.test diff --git a/foundation/org.eclipse.persistence.core/src/main/java/module-info.java b/foundation/org.eclipse.persistence.core/src/main/java/module-info.java index c7d776f3881..3d6419ee3d2 100644 --- a/foundation/org.eclipse.persistence.core/src/main/java/module-info.java +++ b/foundation/org.eclipse.persistence.core/src/main/java/module-info.java @@ -183,9 +183,7 @@ exports org.eclipse.persistence.internal.sessions.factories.model.transport.naming; //INTERNAL ONLY exports - exports org.eclipse.persistence.internal.jpa.jpql to - org.eclipse.persistence.jpa, - org.eclipse.persistence.core.test; + exports org.eclipse.persistence.internal.jpa.jpql to org.eclipse.persistence.jpa; exports org.eclipse.persistence.internal.localization to org.eclipse.persistence.dbws, org.eclipse.persistence.jpa, diff --git a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/localization/i18n/ExceptionLocalizationResource.java b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/localization/i18n/ExceptionLocalizationResource.java index 98baa7fcfec..4a8d3becb5f 100644 --- a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/localization/i18n/ExceptionLocalizationResource.java +++ b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/localization/i18n/ExceptionLocalizationResource.java @@ -284,7 +284,8 @@ public class ExceptionLocalizationResource extends ListResourceBundle { { "find_option_class_unknown", "The FindOption implementing the {0} class is not supported"}, { "refresh_option_class_unknown", "The RefreshOption implementing class {0} is not supported"}, { "lock_option_class_unknown", "The LockOption implementing class {0} is not supported"}, - { "typed_query_reference_is_null", "Reference to a named query is null"} + { "typed_query_reference_is_null", "Reference to a named query is null"}, + { "missing_jpql_parser_class", "Could not load the JPQL parser class."} }; /** * Return the lookup table. diff --git a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/sessions/AbstractSession.java b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/sessions/AbstractSession.java index 4c6ed2c7fc1..1296727bd42 100644 --- a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/sessions/AbstractSession.java +++ b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/sessions/AbstractSession.java @@ -430,7 +430,11 @@ public JPAQueryBuilder getQueryBuilder() { if (parent != null) { this.queryBuilder = parent.getQueryBuilder(); } else { - this.queryBuilder = getProject().getQueryBuilder(); + // Project may not be set + Project project = getProject(); + if (project != null) { + this.queryBuilder = project.getQueryBuilder(); + } if (this.queryBuilder == null) { this.queryBuilder = buildDefaultQueryBuilder(); } @@ -471,7 +475,7 @@ protected JPAQueryBuilder buildDefaultQueryBuilder() { builder = PrivilegedAccessHelper.newInstanceFromClass(parserClass); } } catch (Exception e) { - throw new IllegalStateException("Could not load the JPQL parser class." /* TODO: Localize string */, e); + throw new IllegalStateException(ExceptionLocalization.buildMessage("missing_jpql_parser_class"), e); } if (validation != null) { builder.setValidationLevel(validation); diff --git a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/sessions/Project.java b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/sessions/Project.java index a0eb8bcf05d..1dba16b32b5 100644 --- a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/sessions/Project.java +++ b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/sessions/Project.java @@ -49,10 +49,8 @@ import org.eclipse.persistence.internal.helper.ConcurrentFixedCache; import org.eclipse.persistence.internal.identitymaps.AbstractIdentityMap; import org.eclipse.persistence.internal.identitymaps.IdentityMap; -import org.eclipse.persistence.internal.jpa.jpql.HermesParser; +import org.eclipse.persistence.internal.localization.ExceptionLocalization; import org.eclipse.persistence.internal.security.PrivilegedAccessHelper; -import org.eclipse.persistence.internal.security.PrivilegedClassForName; -import org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass; import org.eclipse.persistence.internal.sessions.AbstractSession; import org.eclipse.persistence.internal.sessions.DatabaseSessionImpl; import org.eclipse.persistence.queries.AttributeGroup; @@ -65,7 +63,6 @@ import org.eclipse.persistence.sessions.server.ServerSession; import java.io.Serializable; -import java.security.AccessController; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -214,9 +211,6 @@ public class Project extends CoreProject queryBuilderSupplier; -// /** JPA query builder. Default value is {@link HermesParser}. */ -// private JPAQueryBuilder queryBuilder; - /** * PUBLIC: * Create a new project. @@ -235,7 +229,6 @@ public Project() { this.metamodelIdClassMap = new HashMap<>(); this.attributeGroups = new HashMap<>(); this.queryBuilderSupplier = new DefaultQueryBuilderSupplier<>(); -// this.queryBuilder = null; } /** @@ -1649,10 +1642,7 @@ public void setQueryBuilderSupplier(Supplier queryBui } /** - * Get JPA query builder. - * Returned {@link JPAQueryBuilder} instance is initialized with 1st call of this method. Returned value depends - * on instance factory, which may be set using {@link #setQueryBuilderSupplier(java.util.function.Supplier)} before - * this 1st method call happens. Default instance factory value is {@link HermesParser}. + * Create new instance of {@link JPAQueryBuilder}. * * @return the JPA query builder */ @@ -1671,17 +1661,13 @@ private DefaultQueryBuilderSupplier() { } @Override + @SuppressWarnings({"unchecked", "deprecation"}) public T get() { try { - if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) { - Class parserClass = AccessController.doPrivileged(new PrivilegedClassForName<>(DEFAULT_BUILDER_CLASS_NAME)); - return AccessController.doPrivileged(new PrivilegedNewInstanceFromClass<>(parserClass)); - } else { - Class parserClass = PrivilegedAccessHelper.getClassForName(DEFAULT_BUILDER_CLASS_NAME); - return PrivilegedAccessHelper.newInstanceFromClass(parserClass); - } + Class parserClass = (Class) Class.forName(DEFAULT_BUILDER_CLASS_NAME); + return parserClass.newInstance(); } catch (Exception e) { - throw new IllegalStateException("Could not load the JPQL parser class." /* TODO: Localize string */, e); + throw new IllegalStateException(ExceptionLocalization.buildMessage("missing_jpql_parser_class"), e); } }