class HibernateFolderHistoryDAO extends HibernatePersistentObjectDAO<FolderHistory> implements FolderHistoryDAO {

	@Override
	public List<FolderHistory> findByPath(String pathExpression, Date olderDate, Collection<String> events,
			Integer max) {
		StringBuffer query = new StringBuffer(
				"(_entity.path like '" + pathExpression + "' or _entity.pathOld like '" + pathExpression + "') ");
		List<Object> params = new ArrayList<Object>();
		if (olderDate != null) {
			query.append(" and _entity.date >= ?1 ");
			params.add(olderDate);
		}
		if (events != null && !events.isEmpty()) {
			StringBuffer eventsStr = new StringBuffer("(");
			for (String event : events) {
				if (eventsStr.length() > 1)
					eventsStr.append(",");
				eventsStr.append("'" + event + "'");
			}
			eventsStr.append(")");
			query.append(" and _entity.event in " + eventsStr);
		}

		try {
			return findByWhere(query.toString(), params.toArray(new Object[0]), "order by _entity.date asc", max);
		} catch (PersistenceException e) {
			log.error(e.getMessage(), e);
			return new ArrayList<FolderHistory>();
		}
	}

	private  HibernateFolderHistoryDAO();

}