package com.eactive.eai.common.logger;

import com.eactive.eai.common.logger.async.HttpAdapterExtraLogH2Factory;
import com.eactive.eai.data.entity.onl.logger.HttpAdapterExtraLog;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.springframework.stereotype.Service;

@Service
public class HttpAdapterExtraLogFileLogger {

    public void writeFileLog(HttpAdapterExtraLog httpAdapterExtraLog){
        try (Session session = HttpAdapterExtraLogH2Factory.getInstance().openSession()) {
            Transaction transaction = null;

            try {
                // 트랜잭션 시작
                transaction = session.beginTransaction();

                session.persist(httpAdapterExtraLog);

                // 트랜잭션 커밋
                transaction.commit();
            } catch (Exception e) {
                if (transaction != null) {
                    transaction.rollback();
                }
                throw e;
            }
        }
    }
}
