package org.apache.logging.log4j.core.appender.db.jpa.converter;

import java.util.Iterator;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
import org.apache.logging.log4j.ThreadContext;

@Converter(
   autoApply = false
)
public class ContextStackAttributeConverter implements AttributeConverter<ThreadContext.ContextStack, String> {
   public String convertToDatabaseColumn(ThreadContext.ContextStack contextStack) {
      if (contextStack == null) {
         return null;
      } else {
         StringBuilder builder = new StringBuilder();

         String value;
         for(Iterator i$ = contextStack.asList().iterator(); i$.hasNext(); builder.append(value)) {
            value = (String)i$.next();
            if (builder.length() > 0) {
               builder.append('\n');
            }
         }

         return builder.toString();
      }
   }

   public ThreadContext.ContextStack convertToEntityAttribute(String s) {
      throw new UnsupportedOperationException("Log events can only be persisted, not extracted.");
   }
}
