class HibernateSystemMessageDAO extends HibernatePersistentObjectDAO<SystemMessage> implements SystemMessageDAO {

	@Override
	public List<SystemMessage> findMessagesToBeSent(int type, int maxTrial) {
		String sql = "select ld_lastmodified, ld_author, ld_messagetext, ld_subject, ld_sentdate, ld_datescope, ld_prio, ld_confirmation, ld_lastnotified, ld_status, ld_trials, ld_type, ld_id, ld_html, ld_author, ld_tenantid "
				+ " from ld_systemmessage where ld_deleted = 0 and not ld_status = " + SystemMessage.STATUS_DELIVERED
				+ " and ld_type = " + type;
		if (maxTrial > 0)
			sql = sql + " and ld_trials < " + maxTrial;
		sql = sql + " order by ld_sentdate desc";

		try {
			List<SystemMessage> messages = (List<SystemMessage>) query(sql, null, new SystemMessageMapper(), null);
			return messages;
		} catch (PersistenceException e) {
			log.error(e.getMessage(), e);
			return new ArrayList<SystemMessage>();
		}
	}

	public  HibernateSystemMessageDAO();

}