use of org.eclipse.persistence.logging.SessionLogEntry in project eclipselink by eclipse-ee4j.
the class SLF4JLoggerHelper method testLogMessage.
/**
* Test {@code SLF4JLogger.log(SessionLogEntry)} method with regular {@link String} message.
* Matrix of logger level x category settings with all log entry log levels is being checked.
*/
public void testLogMessage() {
// Verify loggers for logger level x category matrix.
for (LogCategory category : LogCategory.values()) {
final String nameSpace = category.getNameSpace();
final Logger categoryLogger = loggerContext.getLogger(nameSpace);
categoryLogger.setLevel(Level.ALL);
for (LogLevel loggerLevel : LogLevel.values()) {
// Verify messages with all log levels.
logger.setLevel(loggerLevel.getId(), category.getName());
for (LogLevel messageLevel : LogLevel.values()) {
final String message = "Log message";
final SessionLogEntry logEntry = createLogEntry(category, messageLevel, message);
// Logback log event additional check.
final Check check = new Check() {
@Override
public void check(final ILoggingEvent logEvent) {
assertEquals("Logged message \"" + message + "\" must be stored as a message.", message, logEvent.getMessage());
assertNull("There can't be any arguments for already rendered message.", logEvent.getArgumentArray());
}
};
testLogEntry(category, loggerLevel, messageLevel, categoryLogger, logEntry, check);
}
}
}
}
use of org.eclipse.persistence.logging.SessionLogEntry in project eclipselink by eclipse-ee4j.
the class SLF4JLoggerHelper method initLogEntry.
/**
* Create a new instance of {@link SessionLogEntry} class and set provided session, log level and logging category
* to it.
* @param level Log level of the new log entry.
* @param category Logging category of the new log entry.
* @return The new instance of {@link SessionLogEntry} class with all provided values set.
*/
private SessionLogEntry initLogEntry(final LogCategory category, final LogLevel level) {
final SessionLogEntry logEntry = new SessionLogEntry(session);
logEntry.setLevel(level.getId());
logEntry.setNameSpace(category.getName());
return logEntry;
}
use of org.eclipse.persistence.logging.SessionLogEntry in project eclipselink by eclipse-ee4j.
the class SLF4JLoggerHelper method createLogEntry.
/**
* Create a new instance of {@link SessionLogEntry} class and set provided session, log level, logging category,
* {@link String} message and {@link Throwable} to it.
* @param level Log level of the new log entry.
* @param category Logging category of the new log entry.
* @param message {@link String} message of the new log entry.
* @param throwable {@link Throwable} argument of the new log entry.
* @return The new instance of {@link SessionLogEntry} class with all provided values set.
*/
private SessionLogEntry createLogEntry(final LogCategory category, final LogLevel level, final String message, final Throwable throwable) {
final SessionLogEntry logEntry = initLogEntry(category, level);
logEntry.setMessage(message);
logEntry.setException(throwable);
return logEntry;
}
use of org.eclipse.persistence.logging.SessionLogEntry in project eclipselink by eclipse-ee4j.
the class SLF4JLoggerHelper method createLogEntry.
/**
* Create a new instance of {@link SessionLogEntry} class and set provided session, log level, logging category
* and {@link Throwable} to it.
* @param level Log level of the new log entry.
* @param category Logging category of the new log entry.
* @param throwable {@link Throwable} argument of the new log entry.
* @return The new instance of {@link SessionLogEntry} class with all provided values set.
*/
private SessionLogEntry createLogEntry(final LogCategory category, final LogLevel level, final Throwable throwable) {
final SessionLogEntry logEntry = initLogEntry(category, level);
logEntry.setException(throwable);
return logEntry;
}
use of org.eclipse.persistence.logging.SessionLogEntry in project eclipselink by eclipse-ee4j.
the class EntityManagerJUnitTestSuite method testMergeDetachedObject.
public void testMergeDetachedObject() {
// Step 1 - read a department and clear the cache.
clearCache();
EntityManager em = createEntityManager();
Query query = em.createNamedQuery("findAllSQLDepartments");
Collection departments = query.getResultList();
Department detachedDepartment;
// and a second time with the department table empty.
if (departments.isEmpty()) {
beginTransaction(em);
detachedDepartment = new Department();
detachedDepartment.setName("Department X");
em.persist(detachedDepartment);
commitTransaction(em);
} else {
detachedDepartment = (Department) departments.iterator().next();
}
closeEntityManager(em);
clearCache();
// Step 2 - create a new em, create a new employee with the
// detached department and then query the departments again.
em = createEntityManager();
beginTransaction(em);
Employee emp = new Employee();
emp.setFirstName("Crazy");
emp.setLastName("Kid");
emp.setId(41);
emp.setDepartment(detachedDepartment);
em.persist(emp);
// the try/catch should be removed when the bug is fixed
try {
commitTransaction(em);
em.createNamedQuery("findAllSQLDepartments").getResultList();
} catch (RuntimeException e) {
getDatabaseSession().log(new SessionLogEntry(getDatabaseSession(), SessionLog.WARNING, SessionLog.TRANSACTION, e));
}
closeEntityManager(em);
}
Aggregations