class HibernateGroupDAO extends HibernatePersistentObjectDAO<Group> implements GroupDAO {

	@Override
	public void inheritACLs(Group group, long parentGroupId) {
		long groupId = group.getId();
		if (groupId == parentGroupId)
			return;

		try {
			String sql = "delete from ld_menugroup where ld_groupid=" + groupId;
			log.debug("Delete all menugroup for group {}", groupId);
			jdbcUpdate(sql);

			sql = "delete from ld_foldergroup where ld_groupid=" + groupId;
			log.debug("Delete all foldergroup for group {}", groupId);
			jdbcUpdate(sql);

			if (parentGroupId != Group.GROUPID_ADMIN) {
				log.debug("Replicate all ACLs from group {} to group {}", parentGroupId, groupId);

				sql = "insert into ld_menugroup(ld_menuid, ld_groupid, ld_write) select B.ld_menuid," + groupId
						+ ", B.ld_write from ld_menugroup B where B.ld_groupid= " + parentGroupId;
				log.debug("Replicate all ACLs from group {}", parentGroupId);
				jdbcUpdate(sql);

				sql = "insert into ld_foldergroup(ld_folderid, ld_groupid, ld_write , ld_add, ld_security, ld_immutable, ld_delete, ld_rename, ld_import, ld_export, ld_sign, ld_archive, ld_workflow, ld_download, ld_calendar, ld_subscription, ld_print, ld_password, ld_move, ld_email, ld_automation) "
						+ "select B.ld_folderid," + groupId
						+ ", B.ld_write, B.ld_add, B.ld_security, B.ld_immutable, B.ld_delete, B.ld_rename, B.ld_import, B.ld_export, B.ld_sign, B.ld_archive, B.ld_workflow, B.ld_download, B.ld_calendar, B.ld_subscription, B.ld_print, B.ld_password, B.ld_move, B.ld_email, B.ld_automation from ld_foldergroup B "
						+ "where B.ld_groupid= " + parentGroupId;
				jdbcUpdate(sql);
			} else {
				// Inheriting from admin means access everything
				log.debug("Replicate all admin ACLs to group {}", groupId);

				sql = "insert into ld_menugroup(ld_menuid, ld_groupid, ld_write) select B.ld_id," + groupId
						+ ",1 from ld_menu B where B.ld_deleted=0";
				jdbcUpdate(sql);

				sql = "insert into ld_foldergroup(ld_folderid, ld_groupid, ld_write, ld_add, ld_security, ld_immutable, ld_delete, ld_rename, ld_import, ld_export, ld_sign, ld_archive, ld_workflow, ld_download, ld_calendar, ld_subscription, ld_print, ld_password, ld_move, ld_email, ld_automation) "
						+ "select B.ld_id," + groupId + ",1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 from ld_folder B "
						+ "where B.ld_deleted=0";
				jdbcUpdate(sql);
			}

			fixGuestPermissions(group);
		} catch (Throwable e) {
			log.error(e.getMessage(), e);
		}
	}

	private  HibernateGroupDAO();

}