package org.bench4q.master.domain.repository;

import org.apache.log4j.Logger;
import org.bench4q.master.exception.ExceptionUtils.EntityUniqueAlReadyExistException;
import org.bench4q.master.helper.SessionHelper;
import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;

public abstract class AbstractRepositoty {
	private SessionHelper sessionHelper;
	protected Logger logger = Logger.getLogger(AbstractRepositoty.class);

	protected SessionHelper getSessionHelper() {
		return sessionHelper;
	}

	@Autowired
	protected void setSessionHelper(SessionHelper sessionHelper) {
		this.sessionHelper = sessionHelper;
	}

	protected void releaseSession(Session session) {
		if (session != null) {
			session.close();
		}
	}

	protected abstract void guardOtherUniqueConditionForEntity(
			String uniquePropertyName, String value)
			throws EntityUniqueAlReadyExistException;

}
