class HibernateMessageTemplateDAO extends HibernatePersistentObjectDAO<MessageTemplate> implements MessageTemplateDAO {

	@Override
	public MessageTemplate findByNameAndLanguage(String name, String language, long tenantId) {
		String lang = language;
		if (StringUtils.isEmpty(lang))
			lang = "en";

		try {
			List<MessageTemplate> buf = findByWhere(
					" _entity.language='" + lang + "' and _entity.name='" + name + "' and _entity.tenantId=" + tenantId,
					null, null);
			if (buf != null && !buf.isEmpty())
				return buf.get(0);

			buf = findByWhere(" _entity.language='en' and _entity.name='" + name + "' and _entity.tenantId=" + tenantId,
					null, null);
			if (buf != null && !buf.isEmpty())
				return buf.get(0);
		} catch (PersistenceException e) {
			log.error(e.getMessage(), e);
		}

		return null;
	}

	public  HibernateMessageTemplateDAO();

}