Search in sources :

Example 6 with SessionLogEntry

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);
            }
        }
    }
}
Also used : LogCategory(org.eclipse.persistence.logging.LogCategory) Logger(ch.qos.logback.classic.Logger) SLF4JLogger(org.eclipse.persistence.logging.slf4j.SLF4JLogger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LogLevel(org.eclipse.persistence.logging.LogLevel) SessionLogEntry(org.eclipse.persistence.logging.SessionLogEntry)

Example 7 with SessionLogEntry

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;
}
Also used : SessionLogEntry(org.eclipse.persistence.logging.SessionLogEntry)

Example 8 with SessionLogEntry

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;
}
Also used : SessionLogEntry(org.eclipse.persistence.logging.SessionLogEntry)

Example 9 with SessionLogEntry

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;
}
Also used : SessionLogEntry(org.eclipse.persistence.logging.SessionLogEntry)

Example 10 with SessionLogEntry

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);
}
Also used : EntityManager(jakarta.persistence.EntityManager) JpaEntityManager(org.eclipse.persistence.jpa.JpaEntityManager) Department(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Department) Employee(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Employee) Query(jakarta.persistence.Query) JpaQuery(org.eclipse.persistence.jpa.JpaQuery) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) ObjectLevelReadQuery(org.eclipse.persistence.queries.ObjectLevelReadQuery) DatabaseQuery(org.eclipse.persistence.queries.DatabaseQuery) Collection(java.util.Collection) SessionLogEntry(org.eclipse.persistence.logging.SessionLogEntry)

Aggregations

SessionLogEntry (org.eclipse.persistence.logging.SessionLogEntry)18 Logger (ch.qos.logback.classic.Logger)3 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)3 LogCategory (org.eclipse.persistence.logging.LogCategory)3 LogLevel (org.eclipse.persistence.logging.LogLevel)3 SLF4JLogger (org.eclipse.persistence.logging.slf4j.SLF4JLogger)3 EntityManager (jakarta.persistence.EntityManager)2 Query (jakarta.persistence.Query)2 Collection (java.util.Collection)2 ClassReader (org.eclipse.persistence.internal.libraries.asm.ClassReader)2 EclipseLinkClassReader (org.eclipse.persistence.internal.libraries.asm.EclipseLinkClassReader)2 JpaEntityManager (org.eclipse.persistence.jpa.JpaEntityManager)2 JpaQuery (org.eclipse.persistence.jpa.JpaQuery)2 AbstractSessionLog (org.eclipse.persistence.logging.AbstractSessionLog)2 SessionLog (org.eclipse.persistence.logging.SessionLog)2 DatabaseQuery (org.eclipse.persistence.queries.DatabaseQuery)2 ObjectLevelReadQuery (org.eclipse.persistence.queries.ObjectLevelReadQuery)2 ReadAllQuery (org.eclipse.persistence.queries.ReadAllQuery)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1