use of org.eclipse.persistence.logging.AbstractSessionLog in project adeptj-modules by AdeptJ.
the class JpaActivator method disposeEclipseLinkSingletonLog.
static void disposeEclipseLinkSingletonLog() {
// of SLF4JLogger if this bundle or EntityManagerFactoryLifecycle is going to be stopped.
try {
Field field = FieldUtils.getDeclaredField(AbstractSessionLog.class, FIELD_DEFAULT_LOG, true);
if (field == null) {
LOGGER.warn("Field defaultLog is not found in EclipseLink AbstractSessionLog!!");
return;
}
Object defaultLog = field.get(null);
if (defaultLog instanceof SessionLog) {
((SessionLog) defaultLog).setSession(null);
field.set(null, null);
}
} catch (IllegalAccessException ex) {
LOGGER.error(ex.getMessage(), ex);
}
}
use of org.eclipse.persistence.logging.AbstractSessionLog in project eclipselink by eclipse-ee4j.
the class EntityManagerSetupImpl method updateLoggers.
/**
* Update loggers and settings for the singleton logger and the session logger.
* @param persistenceProperties the properties map
* @param serverPlatformChanged the boolean that denotes a serverPlatform change in the session.
*/
protected void updateLoggers(Map persistenceProperties, boolean serverPlatformChanged, ClassLoader loader) {
// Logger(SessionLog type) can be specified by the logger property or ServerPlatform.getServerLog().
// The logger property has a higher priority to ServerPlatform.getServerLog().
String loggerClassName = PropertiesHandler.getPropertyValueLogDebug(PersistenceUnitProperties.LOGGING_LOGGER, persistenceProperties, session);
// The sessionLog instance should be different from the singletonLog because they have
// different state.
SessionLog singletonLog = null, sessionLog = null;
if (loggerClassName != null) {
SessionLog currentLog = session.getSessionLog();
if (loggerClassName.equals(LoggerType.ServerLogger)) {
ServerPlatform serverPlatform = session.getServerPlatform();
singletonLog = serverPlatform.getServerLog();
sessionLog = serverPlatform.getServerLog();
} else if (!currentLog.getClass().getName().equals(loggerClassName)) {
// Logger class was specified and it's not what's already there.
try {
Class<? extends SessionLog> sessionLogClass = findClassForProperty(loggerClassName, PersistenceUnitProperties.LOGGING_LOGGER, loader);
singletonLog = sessionLogClass.getConstructor().newInstance();
sessionLog = sessionLogClass.getConstructor().newInstance();
} catch (Exception ex) {
throw EntityManagerSetupException.failedToInstantiateLogger(loggerClassName, PersistenceUnitProperties.LOGGING_LOGGER, ex);
}
}
} else if (serverPlatformChanged) {
ServerPlatform serverPlatform = session.getServerPlatform();
singletonLog = serverPlatform.getServerLog();
sessionLog = serverPlatform.getServerLog();
}
// Don't change default loggers if the new loggers have not been created.
if (singletonLog != null && sessionLog != null) {
AbstractSessionLog.setLog(singletonLog);
session.setSessionLog(sessionLog);
}
// Bug5389828. Update the logging settings for the singleton logger.
initOrUpdateLogging(persistenceProperties, AbstractSessionLog.getLog());
initOrUpdateLogging(persistenceProperties, session.getSessionLog());
// Set logging file.
String loggingFileString = (String) persistenceProperties.get(PersistenceUnitProperties.LOGGING_FILE);
if (loggingFileString != null) {
if (!loggingFileString.trim().equals("")) {
try {
if (sessionLog != null) {
if (sessionLog instanceof AbstractSessionLog) {
FileOutputStream fos = new FileOutputStream(loggingFileString);
((AbstractSessionLog) sessionLog).setWriter(fos);
} else {
FileWriter fw = new FileWriter(loggingFileString);
sessionLog.setWriter(fw);
}
}
} catch (IOException e) {
session.handleException(ValidationException.invalidLoggingFile(loggingFileString, e));
}
} else {
session.handleException(ValidationException.invalidLoggingFile());
}
}
}
Aggregations