Skip to content

Commit

Permalink
Issue #1668 - Lowered log level and made messages less aggressive. (#…
Browse files Browse the repository at this point in the history
…1670)

* Issue #1668 - Lowered log level and made messages less aggressive.
              Also fixed module info for pgsql and oracle modules.
Signed-off-by: Tomáš Kraus <tomas.kraus@oracle.com>
  • Loading branch information
Tomas-Kraus committed Sep 9, 2022
1 parent 90d9115 commit 1db179c
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 14 deletions.
2 changes: 2 additions & 0 deletions bundles/eclipselink/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@

requires static com.sun.xml.bind.core;

uses org.eclipse.persistence.internal.databaseaccess.spi.JsonPlatformProvider;

exports org.eclipse.persistence.jpa.jpql;
exports org.eclipse.persistence.jpa.jpql.parser;
exports org.eclipse.persistence.jpa.jpql.utility.iterable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
requires static jakarta.messaging;
requires static jakarta.resource;

uses org.eclipse.persistence.internal.databaseaccess.spi.JsonPlatformProvider;

exports org.eclipse.persistence;
exports org.eclipse.persistence.annotations;
exports org.eclipse.persistence.config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,88 @@
// - 1391: JSON support in JPA
package org.eclipse.persistence.internal.databaseaccess;

import java.lang.reflect.InvocationTargetException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.function.Supplier;

import org.eclipse.persistence.internal.databaseaccess.spi.JsonPlatformProvider;
import org.eclipse.persistence.logging.AbstractSessionLog;
import org.eclipse.persistence.logging.SessionLog;

/**
* Java service manager and service loader for {@link DatabaseJsonPlatform} interface.
*/
public class JsonPlatformManager {

// Lazy singleton initialization in nested class
private static final class Instance {
private static final JsonPlatformManager INSTANCE = new JsonPlatformManager();
}

/**
* Get {@link DatabaseJsonPlatform} implementations manager instance.
*
* @return {@link DatabaseJsonPlatform} implementations manager instance
*/
public static final JsonPlatformManager getInstance() {
return Instance.INSTANCE;
public static JsonPlatformManager getInstance() {
return new JsonPlatformManager();
}

// Initialize Map of known DatabasePlatform to DatabaseJsonPlatform mappings.
private static Map<Class<? extends DatabasePlatform>, Supplier<DatabaseJsonPlatform>> initDirectMap() {
final Map<Class<? extends DatabasePlatform>, Supplier<DatabaseJsonPlatform>> fallbackMap = new HashMap<>();
addProvider(fallbackMap, "org.eclipse.persistence.pgsql.PostgreSQLJsonPlatformProvider");
addProvider(fallbackMap, "org.eclipse.persistence.platform.database.oracle.json.OracleJsonPlatformProvider");
addProvider(fallbackMap, "org.eclipse.persistence.json.DefaultJsonPlatformProvider");
return fallbackMap;
}

// Add Map of known JsonPlatformProvider.
private static void addProvider(
final Map<Class<? extends DatabasePlatform>, Supplier<DatabaseJsonPlatform>> fallbackMap, final String className) {
final Class<JsonPlatformProvider> providerClass = getProvider(className);
if (providerClass != null) {
try {
final JsonPlatformProvider provider = providerClass.getConstructor().newInstance();
final Map<Class<? extends DatabasePlatform>, Supplier<DatabaseJsonPlatform>> platformsMap = provider.platforms();
if (platformsMap != null) {
fallbackMap.putAll(platformsMap);
}
} catch (ReflectiveOperationException ex) {
AbstractSessionLog.getLog().log(
SessionLog.FINE,
String.format("Invocation of static platform method on class %s failed: %s", className, ex.getMessage()));
}
}
}

// Get known JsonPlatformProvider by name.
@SuppressWarnings("unchecked")
private static Class<JsonPlatformProvider> getProvider(final String className) {
try {
Class<?> candidate = Class.forName(className);
if (JsonPlatformProvider.class.isAssignableFrom(candidate)) {
return (Class<JsonPlatformProvider>) candidate;
} else {
AbstractSessionLog.getLog().log(
SessionLog.FINE,
String.format("JsonPlatformProvider candidate class %s does not implement JsonPlatformProvider", className));
}
} catch (ClassNotFoundException ex) {
AbstractSessionLog.getLog().log(
SessionLog.FINE,
String.format("JsonPlatformProvider class %s was not found", className));
}
return null;
}

// Loaded {@link DatabaseJsonPlatform} instance initializers for registered database platforms
// All {@link DatabaseJsonPlatform} instance initializers for registered database platforms
private final Map<Class<? extends DatabasePlatform>, Supplier<DatabaseJsonPlatform>> platforms;

// Initialize singleton instance of {@link DatabaseJsonPlatform} implementations manager.
// Manager builds DatabasePlatform -> Supplier<DatabaseJsonPlatform>> mapping based
// on all returned mappings from SPI providers. 1st returned mapping wins for specific
// DatabasePlatform, but no providers order is specified.
private JsonPlatformManager() {
final Map<Class<? extends DatabasePlatform>, Supplier<DatabaseJsonPlatform>> converters = new HashMap<>();
final Map<Class<? extends DatabasePlatform>, Supplier<DatabaseJsonPlatform>> converters = initDirectMap();
final ServiceLoader<JsonPlatformProvider> providers = ServiceLoader.load(JsonPlatformProvider.class);
for (final JsonPlatformProvider provider : providers) {
final Map<Class<? extends DatabasePlatform>, Supplier<DatabaseJsonPlatform>> providerConverters = provider.platforms();
Expand All @@ -73,16 +119,16 @@ private JsonPlatformManager() {
* @return JSON extension instance mapped to provided database platform
*/
public DatabaseJsonPlatform createPlatform(final Class<? extends DatabasePlatform> type) {
// Try database specific JSON platform.
// Try database specific JSON platform lookup.
Supplier<DatabaseJsonPlatform> supplier = platforms.get(type);
if (supplier != null) {
return supplier.get();
}
// Try default JSON platform.
// Try default JSON platform lookup.
supplier = platforms.get(DatabasePlatform.class);
return supplier != null
? supplier.get()
// Empty platform as a fallback (disable JSON support).
// Empty platform as latest possible option (disable JSON support).
: new DatabaseJsonPlatform() {};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,8 @@ public class LoggingLocalizationResource extends ListResourceBundle {
{ "broadcast_listening_sleep_on_error", "Warning: {0}: Exception {1} was thrown. The thread will sleep for {2} milliseconds before resuming listening." },
{ "dbPlatformHelper_defaultingPlatform", "Not able to detect platform for vendor name [{0}]. Defaulting to [{1}]. The database dialect used may not match with the database you are using. Please explicitly provide a platform using property \"eclipselink.target-database\"."},
{ "dbPlatformHelper_noMappingFound", "Can not load resource [{0}] that loads mapping from vendor name to database platform. Autodetection of database platform will not work."},
{ "pgsql10_platform_missing_json_extension", "Missing PostgreSQL10JsonPlatform from org.eclipse.persistence.pgsql module. JSON extension will not work properly. "},
{ "pgsql10_platform_with_json_extension", "PostgreSQL10Platform with org.eclipse.persistence.pgsql module. JSON extension is enabled."},
{ "pgsql10_platform_without_json_extension", "PostgreSQL10Platform without org.eclipse.persistence.pgsql module. JSON extension is disabled."},

{ "sessions_xml_path_where_session_load_from", "The session info is loaded from [{0}]."},
{ "resource_local_persistence_init_info_ignores_jta_data_source", "PersistenceUnitInfo {0} has transactionType RESOURCE_LOCAL and therefore jtaDataSource will be ignored"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,12 @@ public PostgreSQL10Platform() {
// does not break the CORBA Extension tests.
if (this.getJsonPlatform() instanceof PostgreSQL10JsonExtension) {
postgreSQL10JsonExtension = (PostgreSQL10JsonExtension) this.getJsonPlatform();
DefaultSessionLog.getLog().log(SessionLog.FINE, "pgsql10_platform_with_json_extension", null);
// Missing PostgreSQL10JsonPlatform from org.eclipse.persistence.pgsql module.
// This will cause JSON related functionality to fail.
} else {
DefaultSessionLog.getLog().log(SessionLog.SEVERE, "pgsql10_platform_missing_json_extension", null);
postgreSQL10JsonExtension = null;
DefaultSessionLog.getLog().log(SessionLog.FINE, "pgsql10_platform_without_json_extension", null);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

requires transitive org.eclipse.persistence.core;

provides org.eclipse.persistence.internal.databaseaccess.spi.JsonPlatformProvider with org.eclipse.persistence.json.DefaultJsonPlatformProvider;

exports org.eclipse.persistence.json to
org.eclipse.persistence.jpa,
org.eclipse.persistence.pgsql,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@
//exported through PUBLIC API
exports org.eclipse.persistence.internal.platform.database.oracle;
exports org.eclipse.persistence.platform.database.oracle.json;

provides org.eclipse.persistence.internal.databaseaccess.spi.JsonPlatformProvider with org.eclipse.persistence.platform.database.oracle.json.OracleJsonPlatformProvider;

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@
requires transitive org.eclipse.persistence.core;
requires transitive org.eclipse.persistence.json;

provides org.eclipse.persistence.internal.databaseaccess.spi.JsonPlatformProvider with org.eclipse.persistence.pgsql.PostgreSQLJsonPlatformProvider;

}

0 comments on commit 1db179c

Please sign in to comment.