package com.eactive.eai.rms.data.entity.onl.logger;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;

import com.eactive.eai.data.entity.onl.logger.QSubMessageLog;
import com.eactive.eai.data.entity.onl.logger.SubMessageLog;
import com.eactive.eai.data.entity.onl.logger.SubMessageLogId;
import com.querydsl.core.types.dsl.EntityPathBase;
import com.querydsl.jpa.impl.JPAQueryFactory;

@Repository
public class SubMessageLogRepositoryImpl implements SubMessageLogRepository {

	private EntityManager entityManager;

	@PersistenceContext
	public void setEntityManager(EntityManager entityManager) {
		this.entityManager = entityManager;
	}

	@Override
	public SubMessageLog getById(Class<? extends SubMessageLog> clazz, SubMessageLogId subMessageLogId) {
		QSubMessageLog qSubMessageLog = QSubMessageLog.subMessageLog;
		EntityPathBase<? extends SubMessageLog> entityPathBase = new EntityPathBase<>(clazz,
				QSubMessageLog.subMessageLog.getMetadata().getName());

		return new JPAQueryFactory(entityManager)
				.select(qSubMessageLog)
				.from(entityPathBase)
				.where(qSubMessageLog.id.eq(subMessageLogId))
				.fetchOne();
	}


}
